-
Notifications
You must be signed in to change notification settings - Fork 0
/
NeutrinoReco.cc
executable file
·237 lines (174 loc) · 6.35 KB
/
NeutrinoReco.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "Neutrino.h"
#include "TMinuit.h"
#include "TLorentzVector.h"
#include <iostream>
double metfit(double fitterPrintLevel, int ysol, double mW)
{
//double Pxnu = 0.0;
TMinuit* minu = new TMinuit(5);
if (ysol == 1) minu->SetFCN(NeutrinoFit::delta1fcn);
if (ysol == 2) minu->SetFCN(NeutrinoFit::delta2fcn);
double arglist[20];
int ierflg = 0;
// Set print level.
arglist[0] = fitterPrintLevel;
minu->mnexcm("SET PRINT", arglist, 1, ierflg);
// Set strategy. Possible values: 0, 1, 2
arglist[0] = 2.0;
minu->mnexcm("SET STRATEGY", arglist, 1, ierflg);
arglist[0] = 1.0;
minu->mnexcm("CALL FCN", arglist, 1, ierflg);
// Calculate limits for the parameter:
Double_t upper = 0.0;
Double_t lower = 0.0;
Double_t start = 0.0;
if(NeutrinoFit::FullReco_Pxe < 0) {
upper = - mW*mW/(4*NeutrinoFit::FullReco_Pxe) -0.01;
lower = -9999.;
}
if(NeutrinoFit::FullReco_Pxe == 0) {
upper = 9999.;
lower = -9999.;
}
if(NeutrinoFit::FullReco_Pxe > 0) {
upper = 9999.;
lower = - mW*mW/(4*NeutrinoFit::FullReco_Pxe) +0.01;
}
if(NeutrinoFit::FullReco_MET_X > upper) start = upper -1;
else if(NeutrinoFit::FullReco_MET_X < lower) start = lower + 1;
else start = NeutrinoFit::FullReco_MET_X;
// Set parameters:
minu->mnparm(0, "Px", start, 0.001, lower, upper, ierflg);
arglist[0] = .5;
minu->mnexcm("SET ERR", arglist , 1, ierflg);
arglist[0] = 0.0;
minu->mnexcm("SET NOW", arglist , 1, ierflg);
ierflg = 0;
arglist[0] = 100;
arglist[1] = 1.;
minu->mnexcm("SIMPLEX", arglist, 2, ierflg);
arglist[0] = 500;
minu->mnexcm("MIGRAD", arglist, 1, ierflg);
minu->mnmnos() ;
double px_fit;
double px_fit_error;
int rtVal = minu->GetParameter(0, px_fit, px_fit_error);
if (rtVal < 0)
std::cerr << "Error with parameter." << std::endl;
//Pxnu = px_fit;
if (fitterPrintLevel > 0) {
std::cout<<"*******************************"<<std::endl;
std::cout << "Fit Results: Px(nu) = " << px_fit
<< " +- " << px_fit_error << std::endl;
std::cout<<"*******************************"<<std::endl;
}
delete minu;
return px_fit;
}
int pz_of_W(TLorentzVector lep, TLorentzVector* met, double* pz)
{
// function for the reconstruction of the pz value of the W
// using a W mass constrained
// If the transverse mass of the W is bigger than the W mass itself
// a fit changing the met is performed to ensure that the transverse
// W mass is equal to the W mass
const double MW = 80.4;
int nsol = 0;
//double pz[2]; // container for the two pz solutions;
// filling the global variables neccessary for Minuit
// lepton
NeutrinoFit::FullReco_PTe = lep.Pt();
NeutrinoFit::FullReco_Pxe = lep.Px();
NeutrinoFit::FullReco_Pye = lep.Py();
// met
NeutrinoFit::FullReco_MET_X = met->Px();
NeutrinoFit::FullReco_MET_Y = met->Py();
// std::cout << "Debug: met_px = " << met->Px() << "; met_py = " << met->Py() << std::endl;
// std::cout << "Debug: lep_px = " << lep.Px() << "; lep_py = " << lep.Py() << "; lep_pt = " << lep.Pt()<< std::endl;
double MisET2 = met->Px()*met->Px() + met->Py()*met->Py();
//transverse W-mass
double mWT = sqrt(2*(lep.Pt()*sqrt(MisET2) - lep.Px()*met->Px() - lep.Py()*met->Py()));
double PxNu_1 = 0;
double PxNu_2 = 0;
double PyNu_1 = 0.;
double PyNu_2 = 0.;
double PxNu = 0.;
double PyNu = 0.;
bool isComplex = false;
//check, whether transverse W-mass is larger than pole-mass mW or not.
if(mWT>MW){
isComplex = true;
// if mWT > mW correct PxNu and PyNu until mWT = MW
PxNu_1 = metfit(-1,1,MW); //(Printlevel, y-solution, MW)
PxNu_2 = metfit(-1,2,MW);
PyNu_1 = ((MW*MW*NeutrinoFit::FullReco_Pye + 2*NeutrinoFit::FullReco_Pxe*NeutrinoFit::FullReco_Pye*PxNu_1)
-(MW*NeutrinoFit::FullReco_PTe)*(sqrt(MW*MW + 4*NeutrinoFit::FullReco_Pxe*PxNu_1)))
/(2*NeutrinoFit::FullReco_Pxe*NeutrinoFit::FullReco_Pxe);
PyNu_2 = ((MW*MW*NeutrinoFit::FullReco_Pye + 2*NeutrinoFit::FullReco_Pxe*NeutrinoFit::FullReco_Pye*PxNu_2)
+(MW*NeutrinoFit::FullReco_PTe)*(sqrt(MW*MW + 4*NeutrinoFit::FullReco_Pxe*PxNu_2)))
/(2*NeutrinoFit::FullReco_Pxe*NeutrinoFit::FullReco_Pxe);
//Calculate delta1 and delta2 from PxNu_1 and PxNu_2:
double delta1 = sqrt((PxNu_1 - NeutrinoFit::FullReco_MET_X)*(PxNu_1 - NeutrinoFit::FullReco_MET_X) +(PyNu_1 - NeutrinoFit::FullReco_MET_Y)*(PyNu_1 - NeutrinoFit::FullReco_MET_Y));
double delta2 = sqrt((PxNu_2 - NeutrinoFit::FullReco_MET_X)*(PxNu_2 - NeutrinoFit::FullReco_MET_X) +(PyNu_2 - NeutrinoFit::FullReco_MET_Y)*(PyNu_2 - NeutrinoFit::FullReco_MET_Y));
//PxNu and PyNu(PxNu):
if(delta1<delta2) {
PxNu = PxNu_1;
PyNu = PyNu_1;
} else {
PxNu = PxNu_2;
PyNu = PyNu_2;
}
}
double pz1,pz2;
// z component of neutrino momentum ...
if( !isComplex) {
// ...for two real solutions (mWT < MW)
double mu = (MW*MW)/2 + met->Px()*lep.Px() + met->Py()*lep.Py();
double a = (mu*lep.Pz()) / (lep.E()*lep.E() - lep.Pz()*lep.Pz());
double a2 = TMath::Power(a,2);
double b = (TMath::Power(lep.E(),2.)*MisET2 - TMath::Power(mu,2.))/
(TMath::Power(lep.E(),2) - TMath::Power(lep.Pz(),2));
if(a2-b < 0) {
//std::cout<<"Complex !!!"<<std::endl; // should not happen anymore!
// Warning("pz_of_W",
// "Complex result should not happen anymore!!!");
pz1 = a;
pz2 = a;
nsol = 1;
} else {
double root = sqrt(a2-b);
pz1 = a + root;
pz2 = a - root;
nsol = 2;
}
} else {
// ... for complex solutions (mWT > MW): PzNu_OLD and new correction (mWT = MW)
double mu = (MW*MW)/2 + PxNu*lep.Px() + PyNu*lep.Py();
double a = (mu*lep.Pz())/(lep.E()*lep.E() -
lep.Pz()*lep.Pz());
double a2 = TMath::Power(a,2);
double b = (TMath::Power(lep.E(),2.)*(PxNu*PxNu+PyNu*PyNu) - TMath::Power(mu,2.))/
(TMath::Power(lep.E(),2) - TMath::Power(lep.Pz(),2));
if (a2-b >= 0) {
//double root = sqrt(a2-b);
//std::cout<<"a+sqrt(a2-b) = "<<(a+root)<<" a-sqrt(a2-b) = "<<(a-root)<<std::endl;
}
pz1 = a;
pz2 = a;
nsol = 1;
}
// smaller pz solution is written to entry 0
if (fabs(pz1) <= fabs(pz2) ) {
pz[0] = pz1;
pz[1] = pz2;
} else {
pz[0] = pz2;
pz[1] = pz1;
}
// change values of met in case of complex solution
if (isComplex) {
met->SetPx(PxNu);
met->SetPy(PyNu);
}
return nsol;
}