1 |
|
#include "UserCode/HbbAnalysis/interface/Objects.hh" |
2 |
+ |
#include <cmath> |
3 |
|
|
4 |
|
namespace HbbAnalysis { |
4 |
– |
|
5 |
– |
double DeltaPhi(const double phi1, const double phi2) |
6 |
– |
{ |
7 |
– |
|
8 |
– |
double dPhi = phi1 - phi2; |
9 |
– |
if (dPhi<0) dPhi += 2*TMath::Pi(); |
5 |
|
|
6 |
< |
return dPhi; |
6 |
> |
double DeltaR(const TLorentzVector & v1, const TLorentzVector & v2){ |
7 |
> |
double dEta = v1.Eta() - v2.Eta(); |
8 |
> |
double dPhi = fabs(v1.Phi() - v2.Phi()); |
9 |
> |
if (dPhi > TMath::Pi()) dPhi = (2.0*TMath::Pi() - dPhi); |
10 |
> |
return sqrt(dEta*dEta+dPhi*dPhi); |
11 |
|
} |
12 |
|
|
13 |
< |
double DeltaR(const BaseVars & v1, const BaseVars & v2) |
13 |
> |
double DeltaPhi(const double phi1, const double phi2) |
14 |
|
{ |
15 |
+ |
double dPhi = fabs(phi1 - phi2); |
16 |
+ |
if (dPhi > TMath::Pi()) dPhi = (2.0*TMath::Pi() - dPhi); |
17 |
+ |
//double dPhi = phi1 - phi2; |
18 |
|
|
19 |
< |
double dEta = v1.eta - v2.eta; |
18 |
< |
double dPhi = v1.phi - v2.phi; |
19 |
< |
if (dPhi<0) dPhi += 2*TMath::Pi(); |
20 |
< |
|
21 |
< |
return sqrt(dEta*dEta+dPhi*dPhi); |
19 |
> |
return dPhi; |
20 |
|
} |
21 |
< |
|
22 |
< |
double SameSign(const BaseVars & v1, const BaseVars & v2) |
21 |
> |
|
22 |
> |
bool SameSign(double charge1, double charge2) |
23 |
|
{ |
24 |
< |
|
25 |
< |
return v1.charge == v2.charge; |
24 |
> |
double product = charge1 * charge2; |
25 |
> |
return ((product > 0.5) && (product < 1.5)); |
26 |
|
} |
27 |
|
|
28 |
< |
double OppSign(const BaseVars & v1, const BaseVars & v2) |
28 |
> |
bool OppSign(double charge1, double charge2) |
29 |
|
{ |
30 |
< |
|
31 |
< |
return (v1.charge != v2.charge && |
34 |
< |
v1.charge != 0 && |
35 |
< |
v2.charge != 0); |
30 |
> |
double product = charge1 * charge2; |
31 |
> |
return ((product < -0.5) && (product > -1.5)); |
32 |
|
} |
33 |
+ |
/*Fix - base vars no longer exists |
34 |
|
|
35 |
|
TLorentzVector FourMomentum(const BaseVars & v, const double scale) |
36 |
|
{ |
43 |
|
|
44 |
|
return TLorentzVector(lpx/scale,lpy/scale,lpz/scale,lE/scale); |
45 |
|
|
46 |
< |
} |
46 |
> |
}*/ |
47 |
|
|
48 |
< |
double TransverseMass(const BaseVars & leg1, |
49 |
< |
const BaseVars & leg2, |
48 |
> |
double TransverseMass(//const BaseVars & leg1, |
49 |
> |
//const BaseVars & leg2, |
50 |
> |
const TLorentzVector & leg1, |
51 |
> |
const TLorentzVector & leg2, |
52 |
|
const double mEx, |
53 |
|
const double mEy) |
54 |
|
{ |
55 |
< |
double px = leg1.pT*cos(leg1.phi) + leg2.pT*cos(leg2.phi) + mEx; |
56 |
< |
double py = leg1.pT*sin(leg1.phi) + leg2.pT*sin(leg2.phi) + mEy; |
57 |
< |
double et = leg1.pT + leg2.pT + TMath::Sqrt(mEx*mEx + mEy*mEy); |
55 |
> |
double px = leg1.Pt()*cos(leg1.Phi()) + leg2.Pt()*cos(leg2.Phi()) + mEx; |
56 |
> |
double py = leg1.Pt()*sin(leg1.Phi()) + leg2.Pt()*sin(leg2.Phi()) + mEy; |
57 |
> |
double et = leg1.Pt() + leg2.Pt() + TMath::Sqrt(mEx*mEx + mEy*mEy); |
58 |
|
double mt2 = et*et - (px*px + py*py); |
59 |
|
if ( mt2 < 0 ) { |
60 |
< |
std::cout << " --- WARNING : mt2 = " << mt2 << " is negative... Set to 0."; |
60 |
> |
//std::cout << " --- WARNING : mt2 = " << mt2 << " is negative... Set to 0."; |
61 |
|
return 0.; |
62 |
|
} |
63 |
|
return sqrt(mt2); |
64 |
|
} |
65 |
|
|
66 |
< |
double TransverseMass(const BaseVars & leg1, |
66 |
> |
double TransverseMass(//const BaseVars & leg1, |
67 |
> |
const TLorentzVector & leg1, |
68 |
|
const double mEx, |
69 |
|
const double mEy) |
70 |
|
{ |
71 |
< |
double px = leg1.pT*cos(leg1.phi) + mEx; |
72 |
< |
double py = leg1.pT*sin(leg1.phi) + mEy; |
73 |
< |
double et = leg1.pT + TMath::Sqrt(mEx*mEx + mEy*mEy); |
71 |
> |
double px = leg1.Pt()*cos(leg1.Phi()) + mEx; |
72 |
> |
double py = leg1.Pt()*sin(leg1.Phi()) + mEy; |
73 |
> |
double et = leg1.Pt() + TMath::Sqrt(mEx*mEx + mEy*mEy); |
74 |
|
double mt = et*et - (px*px + py*py); |
75 |
|
if ( mt < 0 ) { |
76 |
< |
std::cout << " --- WARNING : mt = " << mt << " is negative... Set to 0."; |
76 |
> |
//std::cout << " --- WARNING : mt = " << mt << " is negative... Set to 0."; |
77 |
|
return 0.; |
78 |
|
} |
79 |
|
return sqrt(mt); |
80 |
|
} |
81 |
|
|
82 |
< |
TLorentzVector FourMomentumCDFmethod(const BaseVars & leg1, |
83 |
< |
const BaseVars & leg2, |
82 |
> |
TLorentzVector FourMomentumCDFmethod(//const BaseVars & leg1, |
83 |
> |
//const BaseVars & leg2, |
84 |
> |
const TLorentzVector & leg1, |
85 |
> |
const TLorentzVector & leg2, |
86 |
|
double mEx, |
87 |
|
double mEy) |
88 |
|
{ |
89 |
< |
double lpx = leg1.pT*cos(leg1.phi) + leg2.pT*cos(leg2.phi) + mEx; |
90 |
< |
double lpy = leg1.pT*sin(leg1.phi) + leg2.pT*sin(leg2.phi) + mEy; |
91 |
< |
double lpz = leg1.pT*sinh(leg1.eta) + leg2.pT*sinh(leg2.eta); |
92 |
< |
double le = leg1.pT*cosh(leg1.eta) + leg2.pT*cosh(leg2.eta) + TMath::Sqrt(mEx*mEx + mEy*mEy); |
89 |
> |
double lpx = leg1.Pt()*cos(leg1.Phi()) + leg2.Pt()*cos(leg2.Phi()) + mEx; |
90 |
> |
double lpy = leg1.Pt()*sin(leg1.Phi()) + leg2.Pt()*sin(leg2.Phi()) + mEy; |
91 |
> |
double lpz = leg1.Pt()*sinh(leg1.Eta()) + leg2.Pt()*sinh(leg2.Eta()); |
92 |
> |
double le = leg1.Pt()*cosh(leg1.Eta()) + leg2.Pt()*cosh(leg2.Eta()) + TMath::Sqrt(mEx*mEx + mEy*mEy); |
93 |
|
return TLorentzVector(lpx, lpy, lpz, le); |
94 |
|
} |
95 |
|
|
96 |
< |
TLorentzVector FourMomentumCollinearApprox(const BaseVars & leg1, |
97 |
< |
const BaseVars & leg2, |
96 |
> |
TLorentzVector FourMomentumCollinearApprox(//const BaseVars & leg1, |
97 |
> |
//const BaseVars & leg2, |
98 |
> |
const TLorentzVector & leg1, |
99 |
> |
const TLorentzVector & leg2, |
100 |
|
double mEx, |
101 |
|
double mEy) |
102 |
|
{ |
103 |
< |
double px1 = leg1.pT*cos(leg1.phi); |
104 |
< |
double px2 = leg2.pT*cos(leg2.phi); |
105 |
< |
double py1 = leg1.pT*sin(leg1.phi); |
106 |
< |
double py2 = leg2.pT*sin(leg2.phi); |
103 |
< |
|
103 |
> |
double px1 = leg1.Pt()*cos(leg1.Phi()); |
104 |
> |
double px2 = leg2.Pt()*cos(leg2.Phi()); |
105 |
> |
double py1 = leg1.Pt()*sin(leg1.Phi()); |
106 |
> |
double py2 = leg2.Pt()*sin(leg2.Phi()); |
107 |
|
|
108 |
|
double x1_numerator = px1*py2 - px2*py1; |
109 |
|
double x1_denominator = py2*(px1 + mEx) - px2*(py1 + mEy); |
115 |
|
|
116 |
|
if ( (x1 > 0. && x1 < 1.) && |
117 |
|
(x2 > 0. && x2 < 1.) ) { |
118 |
< |
TLorentzVector p4 = FourMomentum(leg1,1/x1) + FourMomentum(leg2,1/x2); |
118 |
> |
TLorentzVector p4 = leg1*x1 + leg2*x2; |
119 |
|
return p4; |
120 |
|
} else { |
121 |
|
return TLorentzVector(0,0,0,0); |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
+ |
/* |
126 |
+ |
double EtaDetector(const BaseVars & v1){ |
127 |
+ |
double pDet[3]; |
128 |
+ |
pDet[0] = v1.pT*cos(v1.phi) + v1.vx; |
129 |
+ |
pDet[1] = v1.pT*sin(v1.phi) + v1.vy; |
130 |
+ |
|
131 |
+ |
double theta = 2*atan(exp(-v1.eta)); |
132 |
+ |
if (pDet[1]<0) theta = TMath::Pi()+theta; |
133 |
+ |
|
134 |
+ |
if (tan(theta)!=0) pDet[2] = v1.pT/tan(theta) + v1.vz; |
135 |
+ |
else return -10; |
136 |
+ |
|
137 |
+ |
double pTDet = sqrt(pDet[0]*pDet[0] + pDet[1]*pDet[1]); |
138 |
+ |
double pDetNorm = sqrt(pDet[0]*pDet[0] + pDet[1]*pDet[1] + pDet[2]*pDet[2]); |
139 |
+ |
double thetaDet = 0; |
140 |
+ |
double cosThetaDet = 0; |
141 |
+ |
if (pDetNorm!=0) cosThetaDet = pDet[2]/pDetNorm; |
142 |
+ |
else return -10; |
143 |
+ |
if (pDet[2]!=0) thetaDet = atan(pTDet/pDet[2]); |
144 |
+ |
else return -10; |
145 |
+ |
if (cosThetaDet<0) thetaDet += TMath::Pi(); |
146 |
+ |
|
147 |
+ |
return -log(tan(thetaDet/2.)); |
148 |
+ |
} |
149 |
+ |
|
150 |
+ |
double EtaDetector(const GenVars & v1){ |
151 |
+ |
double pDet[3]; |
152 |
+ |
pDet[0] = v1.pT*cos(v1.phi) + v1.vx; |
153 |
+ |
pDet[1] = v1.pT*sin(v1.phi) + v1.vy; |
154 |
+ |
|
155 |
+ |
double theta = 2*atan(exp(-v1.eta)); |
156 |
+ |
if (pDet[1]<0) theta = TMath::Pi()+theta; |
157 |
+ |
|
158 |
+ |
if (tan(theta)!=0) pDet[2] = v1.pT/tan(theta) + v1.vz; |
159 |
+ |
else return -10; |
160 |
+ |
|
161 |
+ |
double pTDet = sqrt(pDet[0]*pDet[0] + pDet[1]*pDet[1]); |
162 |
+ |
double pDetNorm = sqrt(pDet[0]*pDet[0] + pDet[1]*pDet[1] + pDet[2]*pDet[2]); |
163 |
+ |
double thetaDet = 0; |
164 |
+ |
double cosThetaDet = 0; |
165 |
+ |
if (pDetNorm!=0) cosThetaDet = pDet[2]/pDetNorm; |
166 |
+ |
else return -10; |
167 |
+ |
if (pDet[2]!=0) thetaDet = atan(pTDet/pDet[2]); |
168 |
+ |
else return -10; |
169 |
+ |
if (cosThetaDet<0) thetaDet += TMath::Pi(); |
170 |
+ |
|
171 |
+ |
return -log(tan(thetaDet/2.)); |
172 |
+ |
}*/ |
173 |
+ |
|
174 |
+ |
|
175 |
+ |
|
176 |
|
}//namespace |
177 |
|
|