ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Angles/src/Angles.cc
Revision: 1.5
Committed: Mon Dec 17 12:34:56 2012 UTC (12 years, 5 months ago) by dkralph
Content type: text/plain
Branch: MAIN
Changes since 1.4: +0 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 khahn 1.2 #include <iostream>
2 khahn 1.1 #include "Angles.h"
3 khahn 1.2 #include "EventData.h"
4    
5 dkralph 1.4 void fillAngles(Angles &a,
6     TLorentzVector lep1, int lep1_q,
7     TLorentzVector lep2, int lep2_q,
8     TLorentzVector lep3, int lep3_q,
9     TLorentzVector lep4, int lep4_q
10     ) {
11    
12     LabVectors l;
13    
14     if( lep1_q > 0 ) {
15     l.vecl1p = lep1;
16     l.vecl1m = lep2;
17     } else {
18     l.vecl1p = lep2;
19     l.vecl1m = lep1;
20     }
21    
22     if( lep3_q > 0 ) {
23     l.vecl2p = lep3;
24     l.vecl2m = lep4;
25     } else {
26     l.vecl2p = lep4;
27     l.vecl2m = lep3;
28     }
29    
30     l.vecz1 = (l.vecl1p+l.vecl1m);
31     l.vecz2 = (l.vecl2p+l.vecl2m);
32     l.vec4l = (l.vecz1+l.vecz2);
33    
34     getAngles( l, a );
35     }
36 khahn 1.2 void fillAngles( EventData &data, Angles &a ) {
37    
38     LabVectors l;
39    
40     if( data.Z1leptons[0].charge > 0 ) {
41 khahn 1.3 l.vecl1p = data.Z1leptons[0].vec;
42     l.vecl1m = data.Z1leptons[1].vec;
43 khahn 1.2 } else {
44 khahn 1.3 l.vecl1p = data.Z1leptons[1].vec;
45     l.vecl1m = data.Z1leptons[0].vec;
46 khahn 1.2 }
47    
48     if( data.Z2leptons[0].charge > 0 ) {
49 khahn 1.3 l.vecl2p = data.Z2leptons[0].vec;
50     l.vecl2m = data.Z2leptons[1].vec;
51 khahn 1.2 } else {
52 khahn 1.3 l.vecl2p = data.Z2leptons[1].vec;
53     l.vecl2m = data.Z2leptons[0].vec;
54 khahn 1.2 }
55    
56     l.vecz1 = (l.vecl1p+l.vecl1m);
57     l.vecz2 = (l.vecl2p+l.vecl2m);
58     l.vec4l = (l.vecz1+l.vecz2);
59    
60     getAngles( l, a );
61     }
62 khahn 1.1
63     void getAngles( LabVectors &l,
64     Angles &a ) {
65    
66 dkralph 1.4 // cout << "ANGLES z1: " << setw(12) << l.vecz1.Pt() << setw(12) << l.vecz1.Eta() << setw(12) << l.vecz1.Phi() << endl;
67     // cout << "ANGLES z2: " << setw(12) << l.vecz2.Pt() << setw(12) << l.vecz2.Eta() << setw(12) << l.vecz2.Phi() << endl;
68     // cout << "ANGLES 4l: " << setw(12) << l.vec4l.Pt() << setw(12) << l.vec4l.Eta() << setw(12) << l.vec4l.Phi() << endl;
69     // cout << "ANGLES l1p:" << setw(12) << l.vecl1p.Pt() << setw(12) << l.vecl1p.Eta() << setw(12) << l.vecl1p.Phi() << endl;
70     // cout << "ANGLES l1m:" << setw(12) << l.vecl1m.Pt() << setw(12) << l.vecl1m.Eta() << setw(12) << l.vecl1m.Phi() << endl;
71     // cout << "ANGLES l2p:" << setw(12) << l.vecl2p.Pt() << setw(12) << l.vecl2p.Eta() << setw(12) << l.vecl2p.Phi() << endl;
72     // cout << "ANGLES l2m:" << setw(12) << l.vecl2m.Pt() << setw(12) << l.vecl2m.Eta() << setw(12) << l.vecl2m.Phi() << endl;
73 khahn 1.1 //
74     // define the frames
75     // --------------------------------------------------------------------------------------------------
76     TVector3 Xframe = l.vec4l.BoostVector();
77     TVector3 Z1frame = l.vecz1.BoostVector();
78     TVector3 Z2frame = l.vecz2.BoostVector();
79    
80     //
81     // costheta(l1m,X) in Z1 frame
82     // --------------------------------------------------------------------------------------------------
83     TLorentzVector vecl1m_in_Z1frame( l.vecl1m ); // make a copies of the vectors
84     TLorentzVector vec4l_in_Z1frame( l.vec4l ); //
85     vecl1m_in_Z1frame.Boost( -1*Z1frame ); // now go to the Z1 rest frame
86     vec4l_in_Z1frame.Boost( -1*Z1frame ); //
87     a.costheta1
88     = vecl1m_in_Z1frame.Vect().Dot(-1*vec4l_in_Z1frame.Vect()) /
89     (vecl1m_in_Z1frame.Vect().Mag()*vec4l_in_Z1frame.Vect().Mag());
90    
91     //
92     // costheta(l3,X) in Z2 frame
93     // --------------------------------------------------------------------------------------------------
94     TLorentzVector vecl2m_in_Z2frame( l.vecl2m ); // make copies of the vectors
95     TLorentzVector vec4l_in_Z2frame( l.vec4l ); //
96     vecl2m_in_Z2frame.Boost( -1*Z2frame ); // now go to the Z2 rest frame
97     vec4l_in_Z2frame.Boost( -1*Z2frame );
98     a.costheta2 =
99     vecl2m_in_Z2frame.Vect().Dot(-1*vec4l_in_Z2frame.Vect()) /
100     (vecl2m_in_Z2frame.Vect().Mag()*vec4l_in_Z2frame.Vect().Mag());
101    
102    
103     //
104     // Phi(Z1,Z2) in X frame
105     // --------------------------------------------------------------------------------------------------
106    
107     // this is essentially what they do and it reproduces their numbers,
108     // it's the angle between l1 and the z2 decay plane in the Z1 frame
109     TLorentzVector vecz2_in_Z1frame( l.vecz2 ); //
110     TLorentzVector vecl2m_in_Z1frame( l.vecl2m ); //
111     TLorentzVector vecl2p_in_Z1frame( l.vecl2p ); //
112     vecz2_in_Z1frame.Boost( -1*Z1frame ); //
113     vecl2m_in_Z1frame.Boost( -1*Z1frame ); //
114     vecl2p_in_Z1frame.Boost( -1*Z1frame ); //
115    
116     //
117     // define the Z2 coordinate system in the Z1 frame
118     // x : opposite the Z2 dir, lies in the Z2 decay plane
119     // z : orthogonal to the Z2 decay plane
120     // y : orthogonal to x&z, lies in the Z2 decay plane
121     TVector3 nnewX = ( -1*vecz2_in_Z1frame.Vect()).Unit();
122     TVector3 nnewZ = (vecl2m_in_Z1frame.Vect().Cross(vecl2p_in_Z1frame.Vect())).Unit();
123     TVector3 nnewY = nnewZ.Cross(nnewX).Unit();
124     TRotation rotation2;
125     rotation2 = (rotation2.RotateAxes( nnewX, nnewY, nnewZ )).Inverse();
126     TVector3 vecl1m_in_Z2coords_Z1frame = vecl1m_in_Z1frame.Vect().Transform(rotation2);
127    
128     //
129     // axes are redfined so that Phi is the angle between the Z1 orthogonal
130     // and the Z2 decay plane as given by y
131     //
132     TRotation rotation3;
133     TVector3 nnnewX( 0,1,0 );
134     TVector3 nnnewY( 0,0,1 );
135     TVector3 nnnewZ( 1,0,0 );
136     rotation3 = (rotation3.RotateAxes( nnnewX, nnnewY, nnnewZ )).Inverse();
137     TVector3 vecl1m_in_Z2coords_redefined_Z1frame = vecl1m_in_Z2coords_Z1frame.Transform(rotation3);
138     a.Phi = vecl1m_in_Z2coords_redefined_Z1frame.Phi();
139    
140    
141     //
142     // rather, I'd expect something like this ...
143     //
144     TLorentzVector vecl1p_in_Xframe( l.vecl1p ); // make a copies of the vectors
145     TLorentzVector vecl1m_in_Xframe( l.vecl1m ); //
146     TLorentzVector vecl2p_in_Xframe( l.vecl2p ); //
147     TLorentzVector vecl2m_in_Xframe( l.vecl2m ); //
148    
149     vecl1p_in_Xframe.Boost( -1*Xframe ); // go to the X rest frame
150     vecl1m_in_Xframe.Boost( -1*Xframe ); //
151     vecl2p_in_Xframe.Boost( -1*Xframe ); //
152     vecl2m_in_Xframe.Boost( -1*Xframe ); //
153    
154     /*
155     // sanity check ...
156     TLorentzVector z1inX = vecl1p_in_Xframe+vecl1m_in_Xframe;
157     TLorentzVector z2inX = vecl2p_in_Xframe+vecl2m_in_Xframe;
158     float dotz1z2 = z1inX.Vect().Dot(z2inX.Vect()) / (z1inX.Vect().Mag()*z2inX.Vect().Mag());
159     std::cout << "dotz1z2: " << dotz1z2 << std::endl;
160     */
161    
162     TVector3 Z1ortho_in_Xframe = // define the decay planes via the orthogonals
163     vecl1m_in_Xframe.Vect().Cross(vecl1p_in_Xframe.Vect());
164     TVector3 Z2ortho_in_Xframe =
165     vecl2m_in_Xframe.Vect().Cross(vecl2p_in_Xframe.Vect());
166    
167     /*
168     // sanity check ... why are these small but not exactly zero ???
169     float z1odot = Z1ortho_in_Xframe.Dot(z1inX.Vect())/(Z1ortho_in_Xframe.Mag()*z1inX.Vect().Mag());
170     float z2odot = Z2ortho_in_Xframe.Dot(z2inX.Vect())/(Z2ortho_in_Xframe.Mag()*z2inX.Vect().Mag());
171     float l1podot = Z1ortho_in_Xframe.Dot(vecl1p_in_Xframe.Vect())/(Z1ortho_in_Xframe.Mag()*vecl1p_in_Xframe.Vect().Mag());
172     float l1modot = Z1ortho_in_Xframe.Dot(vecl1m_in_Xframe.Vect())/(Z1ortho_in_Xframe.Mag()*vecl1m_in_Xframe.Vect().Mag());
173     std::cout << "Z1ortho_in_Xframe.Dot(z1inX): " << z1odot << "\t"
174     << "Z2ortho_in_Xframe.Dot(z2inX): " << z2odot << "\t"
175     << "Z1ortho_in_Xframe.Dot(veclp1_in_Xframe) : " << l1podot << "\t"
176     << "Z1ortho_in_Xframe.Dot(veclm1_in_Xframe) : " << l1modot << "\t"
177     << std::endl;
178     */
179    
180    
181     // a.Phi = Z1ortho_in_Xframe.DeltaPhi(Z2ortho_in_Xframe);
182     //a.Phi = Z1ortho_in_Xframe.Angle(Z2ortho_in_Xframe);
183    
184    
185    
186     //
187     // costheta*(Z1,pp) in X frame
188     // --------------------------------------------------------------------------------------------------
189     TLorentzVector vecz1_in_Xframe( l.vecz1 ); // make a copies of the vectors
190     TLorentzVector vecpp_in_Xframe( 0., 0., 1., 0. ); // define pp axis
191    
192     vecz1_in_Xframe.Boost( -1*Xframe ); // go to the X rest frame
193     vecpp_in_Xframe.Boost( -1*Xframe ); //
194    
195     a.costhetastar =
196     vecz1_in_Xframe.Vect().Dot(vecpp_in_Xframe.Vect()) /
197     (vecz1_in_Xframe.Vect().Mag()*vecpp_in_Xframe.Vect().Mag());
198    
199    
200     //
201     // Phi1(Z1,pp) in X frame
202     // --------------------------------------------------------------------------------------------------
203    
204     // define the Z1 decay plane in the Xframe
205     // y: orthogonal to the Z1 decay plane
206     // x: lies in the Z1 decay plane, but orthogonal to Z1
207     // z: z1 in Xframe
208     TVector3 newY = (vecl1p_in_Xframe.Vect().Unit().Cross(vecl1m_in_Xframe.Vect().Unit())).Unit();
209     TVector3 newX = (newY.Cross(vecz1_in_Xframe.Vect().Unit())).Unit();
210     TVector3 newZ( (vecz1_in_Xframe.Vect()).Unit() );
211    
212     TRotation rotation;
213     rotation = (rotation.RotateAxes( newX, newY, newZ )).Inverse();
214     TVector3 vecpp( 0., 0., 1. );
215     TVector3 vecpp_in_Z1coords_Xframe = vecpp.Transform(rotation);
216     a.Phi1 = vecpp_in_Z1coords_Xframe.Phi();
217    
218 khahn 1.2 // a.mz1 = (l.vecl1m+l.vecl1p).M();
219     // a.mz2 = (l.vecl2m+l.vecl2p).M();
220     // a.m4l = (l.vec4l).M();
221 khahn 1.1
222     };
223    
224    
225 dkralph 1.4 void computeMelaAngles(TLorentzVector p4M11, int Z1_lept1Id,
226     TLorentzVector p4M12, int Z1_lept2Id,
227     TLorentzVector p4M21, int Z2_lept1Id,
228     TLorentzVector p4M22, int Z2_lept2Id,
229     float& costhetastar,
230     float& costheta1,
231     float& costheta2,
232     float& Phi,
233     float& Phi1){
234    
235     //build Z 4-vectors
236     TLorentzVector p4Z1 = p4M11 + p4M12;
237     TLorentzVector p4Z2 = p4M21 + p4M22;
238    
239     // Sort Z1 leptons so that:
240     if ( (Z1_lept1Id*Z1_lept2Id<0 && Z1_lept1Id<0) || // for OS pairs: lep1 must be the negative one
241     (Z1_lept1Id*Z1_lept2Id>0 && p4M11.Phi()<=p4M12.Phi()) //for SS pairs: use random deterministic convention
242     ) {
243     swap(p4M11, p4M12);
244     }
245    
246     // Same for Z2 leptons
247     if ( (Z2_lept1Id*Z2_lept2Id<0 && Z2_lept1Id<0) ||
248     (Z2_lept1Id*Z2_lept2Id>0 && p4M21.Phi()<=p4M22.Phi())
249     ) {
250     swap(p4M21, p4M22);
251     }
252    
253    
254     //build H 4-vectors
255     TLorentzVector p4H = p4Z1 + p4Z2;
256    
257     // -----------------------------------
258    
259     //// costhetastar
260     TVector3 boostX = -(p4H.BoostVector());
261     TLorentzVector thep4Z1inXFrame( p4Z1 );
262     TLorentzVector thep4Z2inXFrame( p4Z2 );
263     thep4Z1inXFrame.Boost( boostX );
264     thep4Z2inXFrame.Boost( boostX );
265     TVector3 theZ1X_p3 = TVector3( thep4Z1inXFrame.X(), thep4Z1inXFrame.Y(), thep4Z1inXFrame.Z() );
266     TVector3 theZ2X_p3 = TVector3( thep4Z2inXFrame.X(), thep4Z2inXFrame.Y(), thep4Z2inXFrame.Z() );
267     costhetastar = theZ1X_p3.CosTheta();
268    
269     //// --------------------------- costheta1
270     TVector3 boostV1 = -(p4Z1.BoostVector());
271     TLorentzVector p4M11_BV1( p4M11 );
272     TLorentzVector p4M12_BV1( p4M12 );
273     TLorentzVector p4M21_BV1( p4M21 );
274     TLorentzVector p4M22_BV1( p4M22 );
275     p4M11_BV1.Boost( boostV1 );
276     p4M12_BV1.Boost( boostV1 );
277     p4M21_BV1.Boost( boostV1 );
278     p4M22_BV1.Boost( boostV1 );
279    
280     TLorentzVector p4V2_BV1 = p4M21_BV1 + p4M22_BV1;
281     //// costheta1
282     costheta1 = -p4V2_BV1.Vect().Dot( p4M11_BV1.Vect() )/p4V2_BV1.Vect().Mag()/p4M11_BV1.Vect().Mag();
283    
284     //// --------------------------- costheta2
285     TVector3 boostV2 = -(p4Z2.BoostVector());
286     TLorentzVector p4M11_BV2( p4M11 );
287     TLorentzVector p4M12_BV2( p4M12 );
288     TLorentzVector p4M21_BV2( p4M21 );
289     TLorentzVector p4M22_BV2( p4M22 );
290     p4M11_BV2.Boost( boostV2 );
291     p4M12_BV2.Boost( boostV2 );
292     p4M21_BV2.Boost( boostV2 );
293     p4M22_BV2.Boost( boostV2 );
294    
295     TLorentzVector p4V1_BV2 = p4M11_BV2 + p4M12_BV2;
296     //// costheta2
297     costheta2 = -p4V1_BV2.Vect().Dot( p4M21_BV2.Vect() )/p4V1_BV2.Vect().Mag()/p4M21_BV2.Vect().Mag();
298    
299     //// --------------------------- Phi and Phi1 (old phistar1 - azimuthal production angle)
300     // TVector3 boostX = -(thep4H.BoostVector());
301     TLorentzVector p4M11_BX( p4M11 );
302     TLorentzVector p4M12_BX( p4M12 );
303     TLorentzVector p4M21_BX( p4M21 );
304     TLorentzVector p4M22_BX( p4M22 );
305    
306     p4M11_BX.Boost( boostX );
307     p4M12_BX.Boost( boostX );
308     p4M21_BX.Boost( boostX );
309     p4M22_BX.Boost( boostX );
310    
311     TVector3 tmp1 = p4M11_BX.Vect().Cross( p4M12_BX.Vect() );
312     TVector3 tmp2 = p4M21_BX.Vect().Cross( p4M22_BX.Vect() );
313    
314     TVector3 normal1_BX( tmp1.X()/tmp1.Mag(), tmp1.Y()/tmp1.Mag(), tmp1.Z()/tmp1.Mag() );
315     TVector3 normal2_BX( tmp2.X()/tmp2.Mag(), tmp2.Y()/tmp2.Mag(), tmp2.Z()/tmp2.Mag() );
316    
317     //// Phi
318     TLorentzVector p4Z1_BX = p4M11_BX + p4M12_BX;
319     float tmpSgnPhi = p4Z1_BX.Vect().Dot( normal1_BX.Cross( normal2_BX) );
320     float sgnPhi = tmpSgnPhi/fabs(tmpSgnPhi);
321     Phi = sgnPhi * acos( -1.*normal1_BX.Dot( normal2_BX) );
322    
323    
324     //////////////
325    
326     TVector3 beamAxis(0,0,1);
327     TVector3 tmp3 = (p4M11_BX + p4M12_BX).Vect();
328    
329     TVector3 p3V1_BX( tmp3.X()/tmp3.Mag(), tmp3.Y()/tmp3.Mag(), tmp3.Z()/tmp3.Mag() );
330     TVector3 tmp4 = beamAxis.Cross( p3V1_BX );
331     TVector3 normalSC_BX( tmp4.X()/tmp4.Mag(), tmp4.Y()/tmp4.Mag(), tmp4.Z()/tmp4.Mag() );
332    
333     //// Phi1
334     float tmpSgnPhi1 = p4Z1_BX.Vect().Dot( normal1_BX.Cross( normalSC_BX) );
335     float sgnPhi1 = tmpSgnPhi1/fabs(tmpSgnPhi1);
336     Phi1 = sgnPhi1 * acos( normal1_BX.Dot( normalSC_BX) );
337    
338     }
339    
340     //----------------------------------------------------------------------------------------
341     void Angles::dump()
342     {
343     cout << "angles: "
344     << setw(12) << costheta1 << setw(12) << costheta2 << setw(12) << Phi
345     << setw(12) << costhetastar << setw(12) << Phi1
346     << endl;
347     }
348