ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HbbAnalysis/src/Objects.cc
Revision: 1.7
Committed: Thu Sep 15 09:46:20 2011 UTC (13 years, 7 months ago) by amagnan
Content type: text/plain
Branch: MAIN
CVS Tags: beforeMETHacks
Changes since 1.6: +40 -25 lines
Log Message:
add pair histos

File Contents

# Content
1 #include "UserCode/HbbAnalysis/interface/Objects.hh"
2
3 namespace HbbAnalysis {
4
5 double DeltaR(const TLorentzVector & v1, const TLorentzVector & v2){
6 double dEta = v1.Eta() - v2.Eta();
7 double dPhi = fabs(v1.Phi() - v2.Phi());
8 if (dPhi > TMath::Pi()) dPhi = (2.0*TMath::Pi() - dPhi);
9 return sqrt(dEta*dEta+dPhi*dPhi);
10 }
11
12 double DeltaPhi(const double phi1, const double phi2)
13 {
14 double dPhi = fabs(phi1 - phi2);
15 if (dPhi > TMath::Pi()) dPhi = (2.0*TMath::Pi() - dPhi);
16 //double dPhi = phi1 - phi2;
17
18 return dPhi;
19 }
20
21 double SameSign(const BaseVars & v1, const BaseVars & v2)
22 {
23
24 return v1.charge == v2.charge;
25 }
26
27 double OppSign(const BaseVars & v1, const BaseVars & v2)
28 {
29
30 return (v1.charge != v2.charge &&
31 v1.charge != 0 &&
32 v2.charge != 0);
33 }
34
35 TLorentzVector FourMomentum(const BaseVars & v, const double scale)
36 {
37 double lpx = v.pT*cos(v.phi);
38 double lpy = v.pT*sin(v.phi);
39 //double lp = v.pT/sin(2*atan(exp(-v.eta)));
40 //double lpz = sqrt(lp*lp - v.pT*v.pT);
41 double lpz = v.pT*sinh(v.eta);
42 double lE = v.pT*cosh(v.eta);//v.E
43
44 return TLorentzVector(lpx/scale,lpy/scale,lpz/scale,lE/scale);
45
46 }
47
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);
58 double mt2 = et*et - (px*px + py*py);
59 if ( mt2 < 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,
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);
74 double mt = et*et - (px*px + py*py);
75 if ( mt < 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,
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);
93 return TLorentzVector(lpx, lpy, lpz, le);
94 }
95
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());
107
108 double x1_numerator = px1*py2 - px2*py1;
109 double x1_denominator = py2*(px1 + mEx) - px2*(py1 + mEy);
110 double x1 = ( x1_denominator != 0. ) ? x1_numerator/x1_denominator : -1.;
111
112 double x2_numerator = x1_numerator;
113 double x2_denominator = px1*(py2 + mEy) - py1*(px2 + mEx);
114 double x2 = ( x2_denominator != 0. ) ? x2_numerator/x2_denominator : -1.;
115
116 if ( (x1 > 0. && x1 < 1.) &&
117 (x2 > 0. && x2 < 1.) ) {
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