]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliDimuCombinator.cxx
69e13388d30d3a7e4c407381f2eadf76ebf71788
[u/mrichter/AliRoot.git] / EVGEN / AliDimuCombinator.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /*
17 $Log$
18 Revision 1.3  1999/09/29 09:24:08  fca
19 Introduction of the Copyright and cvs Log
20
21 */
22
23 //
24 //
25 //
26 //
27 #include "AliDimuCombinator.h" 
28 #include "AliRun.h" 
29 #include "AliPDG.h" 
30 #include "TRandom.h" 
31 //
32 ClassImp(AliDimuCombinator)
33 //
34 //                       Iterators
35 // 
36  TParticle* AliDimuCombinator::FirstMuon()
37      {
38          fimuon1=fimin1;
39          fmuon1 = (TParticle*) fPartArray->UncheckedAt(fimuon1);
40          while(Type(fmuon1)!=kMuonPlus && Type(fmuon1)!=kMuonMinus) {
41              fimuon1++;
42              if (fimuon1 >= fimax1) {fmuon1=0; break;}
43              fmuon1 = (TParticle*) fPartArray->UncheckedAt(fimuon1);
44          }
45          return fmuon1;
46      }
47              
48  TParticle* AliDimuCombinator::FirstMuonSelected()
49      {
50          TParticle * muon=FirstMuon();
51          while(muon!=0 && !Selected(muon)) {muon=NextMuon();}
52          return muon;
53      }
54              
55
56  TParticle* AliDimuCombinator::NextMuon()
57      {
58          fimuon1++;
59          if (fimuon1>=fNParticle) {fmuon1 = 0; return fmuon1;}
60          
61          fmuon1 = (TParticle*) fPartArray->UncheckedAt(fimuon1);
62          while(Type(fmuon1)!=kMuonPlus && Type(fmuon1)!=kMuonMinus) {
63              fimuon1++;
64              if (fimuon1>=fimax1) {fmuon1 = 0; break;}
65              fmuon1 = (TParticle*) fPartArray->UncheckedAt(fimuon1);
66          }
67          return fmuon1;
68      }
69
70 TParticle* AliDimuCombinator::NextMuonSelected()
71      {
72          TParticle * muon=NextMuon();
73          while(muon !=0 && !Selected(muon)) {muon=NextMuon();}
74          return muon;
75      }
76
77
78  void AliDimuCombinator::FirstPartner()
79      {
80          if (fimin1==fimin2) {
81              fimuon2=fimuon1+1;
82          } else {
83              fimuon2=fimin2;
84          }
85          if (fimuon2 >= fimax2) {fmuon2=0; return;}
86          fmuon2 = (TParticle*) fPartArray->UncheckedAt(fimuon2);
87          while(Type(fmuon2)!=kMuonPlus && Type(fmuon2)!=kMuonMinus) {
88              fimuon2++;
89              if (fimuon2 >= fimax2) {fmuon2=0; break;}
90              fmuon2 = (TParticle*) fPartArray->UncheckedAt(fimuon2);
91          }
92      }
93 void AliDimuCombinator::FirstPartnerSelected()
94 {
95          FirstPartner();
96          while(fmuon2 !=0 && !Selected(fmuon2)) {NextPartner();}
97 }
98
99
100  void AliDimuCombinator::NextPartner()
101      {
102          fimuon2++;
103          if (fimuon2>=fimax2) {fmuon2 = 0; return;}
104
105          
106          fmuon2 = (TParticle*) fPartArray->UncheckedAt(fimuon2);
107
108          while(Type(fmuon2)!=kMuonPlus && Type(fmuon2)!=kMuonMinus) {
109              fimuon2++;
110              if (fimuon2>=fimax2) {fmuon2 = 0; break;}
111              fmuon2 = (TParticle*) fPartArray->UncheckedAt(fimuon2);
112          }
113
114      }
115
116 void AliDimuCombinator::NextPartnerSelected()
117 {
118          NextPartner();
119          while(fmuon2 !=0 && !Selected(fmuon2)) {NextPartner();}
120 }
121
122
123  TParticle*  AliDimuCombinator::Partner()
124      {
125          return fmuon2;
126      }
127
128 void AliDimuCombinator::FirstMuonPair(TParticle* & muon1, TParticle* & muon2)
129      {
130          FirstMuon();
131          FirstPartner();
132          muon1=fmuon1;
133          muon2=fmuon2;   
134      }
135 void AliDimuCombinator::NextMuonPair(TParticle* & muon1, TParticle* & muon2)
136      {
137          NextPartner();
138          if (!Partner()) {
139              NextMuon();
140              FirstPartner();
141          }
142          muon1=fmuon1;
143          muon2=fmuon2;   
144      }
145 void AliDimuCombinator::FirstMuonPairSelected(TParticle* & muon1, TParticle* & muon2)
146      {
147          FirstMuonSelected();
148          FirstPartnerSelected();
149          muon1=fmuon1;
150          muon2=fmuon2;   
151      }
152 void AliDimuCombinator::NextMuonPairSelected(TParticle* & muon1, TParticle* & muon2)
153      {
154          NextPartnerSelected();
155          if (!Partner()) {
156              NextMuonSelected();
157              FirstPartnerSelected();
158          }
159          muon1=fmuon1;
160          muon2=fmuon2;   
161      }
162 void AliDimuCombinator::ResetRange()
163 {
164     fimin1=fimin2=0;
165     fimax1=fimax2=fNParticle;
166 }
167
168 void AliDimuCombinator::SetFirstRange(Int_t from, Int_t to)
169 {
170     fimin1=from;
171     fimax1=to;
172     if (fimax1 > fNParticle) fimax1=fNParticle;
173 }
174
175 void AliDimuCombinator::SetSecondRange(Int_t from, Int_t to)
176 {
177     fimin2=from;
178     fimax2=to;
179     if (fimax2 > fNParticle) fimax2=fNParticle;
180 }
181 //
182 //                       Selection
183 //
184
185 Bool_t AliDimuCombinator::Selected(TParticle* part)
186 {
187 // 
188 //
189     if (part==0) {return 0;}
190     
191     if (part->Pt() > fPtMin && part->Eta()>fEtaMin && part->Eta()<fEtaMax) {
192         return 1;
193     } else {
194         return 0;
195     }
196     
197     
198 }
199
200 Bool_t AliDimuCombinator::Selected(TParticle* part1, TParticle* part2)
201 {
202      return Selected(part1)*Selected(part2);
203 }
204 //
205 //                       Kinematics
206 //
207 Float_t AliDimuCombinator::Mass(TParticle* part1, TParticle* part2)
208 {
209     Float_t px,py,pz,e;
210     px=part1->Px()+part2->Px();
211     py=part1->Py()+part2->Py();
212     pz=part1->Pz()+part2->Pz();    
213     e =part1->Energy()+part2->Energy();
214     Float_t p=px*px+py*py+pz*pz;
215     if (e*e < p) {
216         return -1; 
217     } else {
218         return TMath::Sqrt(e*e-p);
219     }
220 }
221
222 Float_t AliDimuCombinator::PT(TParticle* part1, TParticle* part2)
223 {
224     Float_t px,py;
225     px=part1->Px()+part2->Px();
226     py=part1->Py()+part2->Py();
227     return TMath::Sqrt(px*px+py*py);
228 }
229
230 Float_t AliDimuCombinator::Pz(TParticle* part1, TParticle* part2)
231 {
232     return part1->Pz()+part2->Pz();
233 }
234
235 Float_t AliDimuCombinator::Y(TParticle* part1, TParticle* part2)
236 {
237     Float_t pz,e;
238     pz=part1->Pz()+part2->Pz();
239     e =part1->Energy()+part2->Energy();
240     return 0.5*TMath::Log((e+pz)/(e-pz));
241 }
242 //                  Response
243 //
244 void AliDimuCombinator::SmearGauss(Float_t width, Float_t & value)
245 {
246     value+=gRandom->Gaus(0, width);
247 }
248 //              Weighting
249 // 
250
251 Float_t AliDimuCombinator::Decay_Prob(TParticle* part)
252 {
253     Float_t d, h, theta, CTau;
254     TParticle* parent = Parent(part);
255     Int_t ipar=Type(parent);
256     if (ipar==8 || ipar==9) {
257         CTau=780.4;
258     } else if (ipar==11 || ipar==12) {
259         CTau=370.9;
260     } else {
261         CTau=0;
262     }
263     
264     
265     Float_t GammaBeta=(parent->P())/(parent->GetMass());
266 //
267 // this part is still very ALICE muon-arm specific
268 //
269     theta=parent->Theta();
270     h=90*TMath::Tan(theta);
271     
272     if (h<4) {
273         d=4/TMath::Sin(theta);
274     } else {
275         d=90/TMath::Cos(theta);
276     }
277     
278     if (CTau > 0) {
279         return 1-TMath::Exp(-d/CTau/GammaBeta);
280     } else {
281         return 1;
282     }
283 }
284
285 Float_t AliDimuCombinator::Weight(TParticle* part1, TParticle* part2)
286 {
287     Float_t wgt=(part1->GetWeight())*(part2->GetWeight());
288     
289     if (Correlated(part1, part2)) {
290         return wgt/(Parent(part1)->GetWeight())*fRate1;
291     } else {
292         return wgt*fRate1*fRate2;
293     }
294
295
296
297 Float_t AliDimuCombinator::Weight(TParticle* part)
298 {
299     return (part->GetWeight())*(Parent(part)->GetWeight())*fRate1;
300 }
301 Bool_t  AliDimuCombinator::Correlated(TParticle* part1, TParticle* part2)
302 {
303     if (Origin(part1) == Origin(part2)) {
304         return kTRUE;
305     } else {
306         return kFALSE;
307     }
308 }
309
310 TParticle* AliDimuCombinator::Parent(TParticle* part)
311 {
312     return (TParticle*) (fPartArray->UncheckedAt(part->GetFirstMother()));
313 }
314
315 Int_t AliDimuCombinator::Origin(TParticle* part)
316 {
317     Int_t iparent= part->GetFirstMother();
318     if (iparent < 0) return iparent;
319     Int_t ip;
320     while(1) {
321         ip=((TParticle*) fPartArray->UncheckedAt(iparent))->GetFirstMother();
322         if (ip < 0) {
323             break;
324         } else {
325             iparent=ip;
326         }
327     }
328     return iparent;
329 }
330