mt2  8bbb7ce09375b7fc0edeb89e1fe1dbb76bbd0555
test.cxx
Go to the documentation of this file.
1 // Generates simple MC of decays of pair produced particles
2 // Computes mt2 using our calculator
3 // Computes mt2 with the bisection calculator as a reference for comparison
4 
5 #include "test.hpp"
6 
7 #include <cmath>
8 
9 #include <iostream>
10 #include <random>
11 #include <array>
12 #include <functional>
13 
14 #include "TFile.h"
15 #include "TLorentzVector.h"
16 #include "TTree.h"
17 
18 #include "mt2_bisect.hpp"
19 
20 #include "mt2.hpp"
21 #include "timer.hpp"
22 #include "polynomial.hpp"
23 
24 using namespace std;
25 
26 namespace{
27  //Top mass and number of random events to test
28  double mt_ = 172.5;
29  size_t nevents_ = 1e3;
30 
31  //For random number distribution
32  mt19937_64 prng_ = InitializePRNG();
33  bernoulli_distribution bernoulli_(7./8.);
34  uniform_real_distribution<> uniform_;
35  uniform_real_distribution<> unihalf_(0., 0.5);
36  uniform_real_distribution<> uni2pi_(0., 2.*acos(-1.));
37  exponential_distribution<> exponential_(0.01);
38 }
39 
40 int main(){
41  mt2_bisect::mt2 theirs;
42  MT2 mine;
43 
44  TFile file("mt2.root", "recreate");
45  file.cd();
46  TLorentzVector p4A, p4a, p4B, p4b, test_a, test_b;
47  double test_mass, their_mt2, my_mt2, test_mt2, unbalanced;
48  TTree tree("tree","tree");
49  tree.Branch("A", &p4A);
50  tree.Branch("a", &p4a);
51  tree.Branch("B", &p4B);
52  tree.Branch("b", &p4b);
53  tree.Branch("test_a", &test_a);
54  tree.Branch("test_b", &test_b);
55  tree.Branch("test_mass", &test_mass);
56  tree.Branch("theirs", &their_mt2);
57  tree.Branch("mine", &my_mt2);
58  tree.Branch("test_mt2", &test_mt2);
59  tree.Branch("unbalanced", &unbalanced);
60  Timer timer(nevents_, 1.);
61  timer.Start();
62  for(size_t event = 0; event < nevents_; ++event){
63  timer.Iterate();
64  double mA = bernoulli_(prng_) ? unihalf_(prng_)*mt_ : 0.;
65  double mB = bernoulli_(prng_) ? unihalf_(prng_)*mt_ : 0.;
66  double ma = bernoulli_(prng_) ? unihalf_(prng_)*mt_ : 0.;
67  double mb = bernoulli_(prng_) ? unihalf_(prng_)*mt_ : 0.;
68  double pxtA = bernoulli_(prng_) ? exponential_(prng_) : 0.;
69  double pytA = bernoulli_(prng_) ? exponential_(prng_) : 0.;
70  double pztA = bernoulli_(prng_) ? exponential_(prng_) : 0.;
71  double pxtB = bernoulli_(prng_) ? exponential_(prng_) : 0.;
72  double pytB = bernoulli_(prng_) ? exponential_(prng_) : 0.;
73  double pztB = bernoulli_(prng_) ? exponential_(prng_) : 0.;
74  double costA = uniform_(prng_);
75  double phiA = uni2pi_(prng_);
76  double costB = uniform_(prng_);
77  double phiB = uni2pi_(prng_);
78  test_mass = bernoulli_(prng_) ? exponential_(prng_) : 0.;
79 
80  double thetaA = acos(costA);
81  double thetaa = acos(-1.)-thetaA;
82  double etaA = -log(tan(0.5*thetaA));
83  double etaa = -log(tan(0.5*thetaa));
84  double sumA = mA+ma;
85  double diffA = mA-ma;
86  double pA = sqrt((mt_*mt_-sumA*sumA)*(mt_*mt_-diffA*diffA))/(2.*mt_);
87 
88  TLorentzVector p4TA;
89  p4TA.SetXYZM(pxtA, pytA, pztA, mt_);
90  p4A.SetPtEtaPhiM(pA, etaA, phiA, mA);
91  p4a.SetPtEtaPhiM(pA, etaa, -phiA, ma);
92  p4A.Boost(p4TA.BoostVector());
93  p4a.Boost(p4TA.BoostVector());
94 
95  double thetaB = acos(costB);
96  double thetab = acos(-1.)-thetaB;
97  double etaB = -log(tan(0.5*thetaB));
98  double etab = -log(tan(0.5*thetab));
99  double sumB = mB+mb;
100  double diffB = mB-mb;
101  double pB = sqrt((mt_*mt_-sumB*sumB)*(mt_*mt_-diffB*diffB))/(2.*mt_);
102  TLorentzVector p4TB;
103  p4TB.SetXYZM(pxtB, pytB, pztB, mt_);
104  p4B.SetPtEtaPhiM(pB, etaB, phiB, mB);
105  p4b.SetPtEtaPhiM(pB, etab, -phiB, mb);
106  p4B.Boost(p4TB.BoostVector());
107  p4b.Boost(p4TB.BoostVector());
108 
109  TLorentzVector p4c = p4a+p4b;
110 
111  double pa0[3] = {p4A.M(), p4A.Px(), p4A.Py()};
112  double pb0[3] = {p4B.M(), p4B.Px(), p4B.Py()};
113  double pmiss0[3] = {0., p4c.Px(), p4c.Py()};
114  theirs.set_mn(test_mass);
115  theirs.set_momenta(pa0, pb0, pmiss0);
116  mine.SetMomenta(p4A, p4B, p4c.Px(), p4c.Py());
117  mine.SetTestMass(test_mass);
118  their_mt2 = theirs.get_mt2();
119  my_mt2 = mine.GetMT2();
120  mine.GetInvisibleMomenta(test_a, test_b);
121  test_mt2 = mine.GetTrialMT2(test_a.Px(), test_a.Py());
122  unbalanced = mine.IsUnbalanced();
123  tree.Fill();
124  }
125  tree.Write();
126  file.Close();
127 }
128 
129 mt19937_64 InitializePRNG(){
130  array<int, 128> sd;
131  random_device r;
132  generate_n(sd.begin(), sd.size(), ref(r));
133  seed_seq ss(begin(sd), end(sd));
134  return mt19937_64(ss);
135 }
Definition: timer.hpp:6
void SetMomenta(const TLorentzVector &visible_A, const TLorentzVector &visible_B, double invisible_px, double invisible_py)
Definition: mt2.cpp:15
uniform_real_distribution unihalf_(0., 0.5)
double GetMT2() const
Definition: mt2.cpp:47
STL namespace.
int main()
Definition: test.cxx:40
bernoulli_distribution bernoulli_(7./8.)
Definition: mt2.hpp:6
uniform_real_distribution uniform_
Definition: test.cxx:34
void set_momenta(double *pa0, double *pb0, double *pmiss0)
Definition: mt2_bisect.cpp:61
void GetInvisibleMomenta(TLorentzVector &invisible_a, TLorentzVector &invisible_b) const
Definition: mt2.cpp:66
uniform_real_distribution uni2pi_(0., 2.*acos(-1.))
double get_mt2()
Definition: mt2_bisect.cpp:49
double IsUnbalanced() const
Definition: mt2.cpp:100
void set_mn(double mn)
Definition: mt2_bisect.cpp:129
double GetTrialMT2(double invisible_px_a, double invisible_py_a) const
Definition: mt2.cpp:52
exponential_distribution exponential_(0.01)
void Iterate()
Definition: timer.cpp:28
void Start()
Definition: timer.cpp:22
mt19937_64 InitializePRNG()
Definition: test.cxx:129
void SetTestMass(double test_mass)
Definition: mt2.cpp:9