Correcting coding convention violations
[u/mrichter/AliRoot.git] / EVGEN / AliDimuCombinator.cxx
CommitLineData
4c039060 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$
d430df3f 18Revision 1.6 2000/06/14 15:19:47 morsch
19Include clean-up (IH)
20
5c3fd7ea 21Revision 1.5 2000/06/09 20:35:32 morsch
22All coding rule violations except RS3 corrected
23
f87cfe57 24Revision 1.4 2000/03/20 18:03:24 morsch
25Change muon particle code to PDG code.
26
127b88a2 27Revision 1.3 1999/09/29 09:24:08 fca
28Introduction of the Copyright and cvs Log
29
4c039060 30*/
31
fe4da5cc 32//
33//
34//
35//
dafbc1c5 36#include "AliDimuCombinator.h"
127b88a2 37#include "AliPDG.h"
f87cfe57 38#include <TRandom.h>
39#include <TClonesArray.h>
d430df3f 40#include <TParticle.h>
5c3fd7ea 41
fe4da5cc 42//
dafbc1c5 43ClassImp(AliDimuCombinator)
f87cfe57 44 AliDimuCombinator::AliDimuCombinator(TClonesArray* Partarray)
45{
46// Constructor
47 fPartArray=Partarray;
48 fNParticle=fPartArray->GetEntriesFast();
49
d430df3f 50 fImuon1 =0;
51 fImuon2 =0;
52 fMuon1 =0;
53 fMuon2 =0;
54 fImin1 = 0;
55 fImin2 = 0;
56 fImax1 = fNParticle;
57 fImax2 = fNParticle;
f87cfe57 58 fPtMin =0;
59 fEtaMin =-10;
60 fEtaMax =-10;
61 fRate1=1.;
62 fRate2=1.;
63}
64
65AliDimuCombinator::AliDimuCombinator(const AliDimuCombinator & combinator)
66{
67// copy constructor
68}
69
70
fe4da5cc 71//
72// Iterators
73//
f87cfe57 74TParticle* AliDimuCombinator::FirstMuon()
75{
76// Single muon iterator: initialisation
d430df3f 77 fImuon1=fImin1;
78 fMuon1 = (TParticle*) fPartArray->UncheckedAt(fImuon1);
79 while(Type(fMuon1)!=kMuonPlus && Type(fMuon1)!=kMuonMinus) {
80 fImuon1++;
81 if (fImuon1 >= fImax1) {fMuon1=0; break;}
82 fMuon1 = (TParticle*) fPartArray->UncheckedAt(fImuon1);
f87cfe57 83 }
d430df3f 84 return fMuon1;
f87cfe57 85}
86
87TParticle* AliDimuCombinator::FirstMuonSelected()
88{
89// Single selected muon iterator: initialisation
90 TParticle * muon=FirstMuon();
91 while(muon!=0 && !Selected(muon)) {muon=NextMuon();}
92 return muon;
93}
94
95
96TParticle* AliDimuCombinator::NextMuon()
97{
98// Single muon iterator: increment
d430df3f 99 fImuon1++;
100 if (fImuon1>=fNParticle) {fMuon1 = 0; return fMuon1;}
f87cfe57 101
d430df3f 102 fMuon1 = (TParticle*) fPartArray->UncheckedAt(fImuon1);
103 while(Type(fMuon1)!=kMuonPlus && Type(fMuon1)!=kMuonMinus) {
104 fImuon1++;
105 if (fImuon1>=fImax1) {fMuon1 = 0; break;}
106 fMuon1 = (TParticle*) fPartArray->UncheckedAt(fImuon1);
f87cfe57 107 }
d430df3f 108 return fMuon1;
f87cfe57 109}
fe4da5cc 110
1578254f 111TParticle* AliDimuCombinator::NextMuonSelected()
fe4da5cc 112{
f87cfe57 113// Single selected muon iterator: increment
114 TParticle * muon=NextMuon();
115 while(muon !=0 && !Selected(muon)) {muon=NextMuon();}
116 return muon;
fe4da5cc 117}
118
119
f87cfe57 120void AliDimuCombinator::FirstPartner()
121{
122// Helper for dimuon iterator: initialisation
d430df3f 123 if (fImin1==fImin2) {
124 fImuon2=fImuon1+1;
f87cfe57 125 } else {
d430df3f 126 fImuon2=fImin2;
f87cfe57 127 }
d430df3f 128 if (fImuon2 >= fImax2) {fMuon2=0; return;}
129 fMuon2 = (TParticle*) fPartArray->UncheckedAt(fImuon2);
130 while(Type(fMuon2)!=kMuonPlus && Type(fMuon2)!=kMuonMinus) {
131 fImuon2++;
132 if (fImuon2 >= fImax2) {fMuon2=0; break;}
133 fMuon2 = (TParticle*) fPartArray->UncheckedAt(fImuon2);
f87cfe57 134 }
135}
fe4da5cc 136
f87cfe57 137void AliDimuCombinator::FirstPartnerSelected()
138{
139// Helper for selected dimuon iterator: initialisation
140 FirstPartner();
d430df3f 141 while(fMuon2 !=0 && !Selected(fMuon2)) {NextPartner();}
f87cfe57 142}
fe4da5cc 143
fe4da5cc 144
f87cfe57 145void AliDimuCombinator::NextPartner()
146{
147// Helper for dimuon iterator: increment
d430df3f 148 fImuon2++;
149 if (fImuon2>=fImax2) {fMuon2 = 0; return;}
f87cfe57 150
151
d430df3f 152 fMuon2 = (TParticle*) fPartArray->UncheckedAt(fImuon2);
f87cfe57 153
d430df3f 154 while(Type(fMuon2)!=kMuonPlus && Type(fMuon2)!=kMuonMinus) {
155 fImuon2++;
156 if (fImuon2>=fImax2) {fMuon2 = 0; break;}
157 fMuon2 = (TParticle*) fPartArray->UncheckedAt(fImuon2);
f87cfe57 158 }
159}
fe4da5cc 160
dafbc1c5 161void AliDimuCombinator::NextPartnerSelected()
fe4da5cc 162{
f87cfe57 163// Helper for selected dimuon iterator: increment
164 NextPartner();
d430df3f 165 while(fMuon2 !=0 && !Selected(fMuon2)) {NextPartner();}
fe4da5cc 166}
167
168
f87cfe57 169TParticle* AliDimuCombinator::Partner()
170{
171// Returns current partner for muon to form a dimuon
d430df3f 172 return fMuon2;
f87cfe57 173}
fe4da5cc 174
1578254f 175void AliDimuCombinator::FirstMuonPair(TParticle* & muon1, TParticle* & muon2)
f87cfe57 176{
177// Dimuon iterator: initialisation
178 FirstMuon();
179 FirstPartner();
d430df3f 180 muon1=fMuon1;
181 muon2=fMuon2;
f87cfe57 182}
183
1578254f 184void AliDimuCombinator::NextMuonPair(TParticle* & muon1, TParticle* & muon2)
f87cfe57 185{
186// Dimuon iterator: increment
187 NextPartner();
188 if (!Partner()) {
189 NextMuon();
190 FirstPartner();
191 }
d430df3f 192 muon1=fMuon1;
193 muon2=fMuon2;
f87cfe57 194}
195void AliDimuCombinator::FirstMuonPairSelected(TParticle* & muon1,
196 TParticle* & muon2)
197{
198// Selected dimuon iterator: initialisation
199 FirstMuonSelected();
200 FirstPartnerSelected();
d430df3f 201 muon1=fMuon1;
202 muon2=fMuon2;
f87cfe57 203}
204
205void AliDimuCombinator::NextMuonPairSelected(TParticle* & muon1,
206 TParticle* & muon2)
207{
208// Selected dimuon iterator: increment
209 NextPartnerSelected();
210 if (!Partner()) {
211 NextMuonSelected();
212 FirstPartnerSelected();
213 }
d430df3f 214 muon1=fMuon1;
215 muon2=fMuon2;
f87cfe57 216}
217
dafbc1c5 218void AliDimuCombinator::ResetRange()
fe4da5cc 219{
f87cfe57 220// Reset index ranges for single muons
d430df3f 221 fImin1=fImin2=0;
222 fImax1=fImax2=fNParticle;
fe4da5cc 223}
224
dafbc1c5 225void AliDimuCombinator::SetFirstRange(Int_t from, Int_t to)
fe4da5cc 226{
f87cfe57 227// Reset index range for first muon
d430df3f 228 fImin1=from;
229 fImax1=to;
230 if (fImax1 > fNParticle) fImax1=fNParticle;
fe4da5cc 231}
232
dafbc1c5 233void AliDimuCombinator::SetSecondRange(Int_t from, Int_t to)
fe4da5cc 234{
f87cfe57 235// Reset index range for second muon
d430df3f 236 fImin2=from;
237 fImax2=to;
238 if (fImax2 > fNParticle) fImax2=fNParticle;
fe4da5cc 239}
240//
241// Selection
242//
243
1578254f 244Bool_t AliDimuCombinator::Selected(TParticle* part)
fe4da5cc 245{
f87cfe57 246// Selection cut for single muon
fe4da5cc 247//
248 if (part==0) {return 0;}
249
1578254f 250 if (part->Pt() > fPtMin && part->Eta()>fEtaMin && part->Eta()<fEtaMax) {
fe4da5cc 251 return 1;
252 } else {
253 return 0;
254 }
fe4da5cc 255}
256
1578254f 257Bool_t AliDimuCombinator::Selected(TParticle* part1, TParticle* part2)
fe4da5cc 258{
f87cfe57 259// Selection cut for dimuons
260//
fe4da5cc 261 return Selected(part1)*Selected(part2);
262}
263//
264// Kinematics
265//
1578254f 266Float_t AliDimuCombinator::Mass(TParticle* part1, TParticle* part2)
fe4da5cc 267{
f87cfe57 268// Invariant mass
269//
fe4da5cc 270 Float_t px,py,pz,e;
1578254f 271 px=part1->Px()+part2->Px();
272 py=part1->Py()+part2->Py();
273 pz=part1->Pz()+part2->Pz();
274 e =part1->Energy()+part2->Energy();
fe4da5cc 275 Float_t p=px*px+py*py+pz*pz;
276 if (e*e < p) {
277 return -1;
278 } else {
279 return TMath::Sqrt(e*e-p);
280 }
281}
282
1578254f 283Float_t AliDimuCombinator::PT(TParticle* part1, TParticle* part2)
fe4da5cc 284{
f87cfe57 285// Transverse momentum of dimuons
286//
fe4da5cc 287 Float_t px,py;
1578254f 288 px=part1->Px()+part2->Px();
289 py=part1->Py()+part2->Py();
fe4da5cc 290 return TMath::Sqrt(px*px+py*py);
291}
292
1578254f 293Float_t AliDimuCombinator::Pz(TParticle* part1, TParticle* part2)
fe4da5cc 294{
f87cfe57 295// Pz of dimuon system
296//
1578254f 297 return part1->Pz()+part2->Pz();
fe4da5cc 298}
299
1578254f 300Float_t AliDimuCombinator::Y(TParticle* part1, TParticle* part2)
fe4da5cc 301{
f87cfe57 302// Rapidity of dimuon system
303//
fe4da5cc 304 Float_t pz,e;
1578254f 305 pz=part1->Pz()+part2->Pz();
306 e =part1->Energy()+part2->Energy();
fe4da5cc 307 return 0.5*TMath::Log((e+pz)/(e-pz));
308}
309// Response
310//
dafbc1c5 311void AliDimuCombinator::SmearGauss(Float_t width, Float_t & value)
fe4da5cc 312{
f87cfe57 313// Apply gaussian smearing
314//
fe4da5cc 315 value+=gRandom->Gaus(0, width);
316}
317// Weighting
318//
319
f87cfe57 320Float_t AliDimuCombinator::DecayProbability(TParticle* part)
fe4da5cc 321{
f87cfe57 322// Calculate decay probability for muons from pion and kaon decays
323//
324 Float_t d, h, theta, cTau;
1578254f 325 TParticle* parent = Parent(part);
7d566a7d 326 Int_t ipar=Type(parent);
f87cfe57 327 if (ipar==kPiPlus || ipar==kPiMinus) {
328 cTau=780.4;
329 } else if (ipar==kKPlus || ipar==kKMinus) {
330 cTau=370.9;
7d566a7d 331 } else {
f87cfe57 332 cTau=0;
7d566a7d 333 }
334
335
f87cfe57 336 Float_t gammaBeta=(parent->P())/(parent->GetMass());
7d566a7d 337//
338// this part is still very ALICE muon-arm specific
339//
1578254f 340 theta=parent->Theta();
7d566a7d 341 h=90*TMath::Tan(theta);
342
343 if (h<4) {
344 d=4/TMath::Sin(theta);
fe4da5cc 345 } else {
7d566a7d 346 d=90/TMath::Cos(theta);
347 }
348
f87cfe57 349 if (cTau > 0) {
350 return 1-TMath::Exp(-d/cTau/gammaBeta);
7d566a7d 351 } else {
352 return 1;
fe4da5cc 353 }
354}
355
1578254f 356Float_t AliDimuCombinator::Weight(TParticle* part1, TParticle* part2)
7d566a7d 357{
f87cfe57 358// Dimuon weight
359
1578254f 360 Float_t wgt=(part1->GetWeight())*(part2->GetWeight());
7d566a7d 361
362 if (Correlated(part1, part2)) {
1578254f 363 return wgt/(Parent(part1)->GetWeight())*fRate1;
7d566a7d 364 } else {
365 return wgt*fRate1*fRate2;
366 }
367}
368
369
1578254f 370Float_t AliDimuCombinator::Weight(TParticle* part)
fe4da5cc 371{
f87cfe57 372// Single muon weight
1578254f 373 return (part->GetWeight())*(Parent(part)->GetWeight())*fRate1;
7d566a7d 374}
f87cfe57 375
1578254f 376Bool_t AliDimuCombinator::Correlated(TParticle* part1, TParticle* part2)
7d566a7d 377{
f87cfe57 378// Check if muons are correlated
379//
7d566a7d 380 if (Origin(part1) == Origin(part2)) {
381 return kTRUE;
382 } else {
383 return kFALSE;
384 }
385}
1578254f 386
387TParticle* AliDimuCombinator::Parent(TParticle* part)
7d566a7d 388{
f87cfe57 389// Return pointer to parent
390//
1578254f 391 return (TParticle*) (fPartArray->UncheckedAt(part->GetFirstMother()));
7d566a7d 392}
393
1578254f 394Int_t AliDimuCombinator::Origin(TParticle* part)
7d566a7d 395{
f87cfe57 396// Return pointer to primary particle
397//
1578254f 398 Int_t iparent= part->GetFirstMother();
7d566a7d 399 if (iparent < 0) return iparent;
400 Int_t ip;
401 while(1) {
1578254f 402 ip=((TParticle*) fPartArray->UncheckedAt(iparent))->GetFirstMother();
7d566a7d 403 if (ip < 0) {
404 break;
405 } else {
406 iparent=ip;
407 }
408 }
409 return iparent;
fe4da5cc 410}
411
d430df3f 412Int_t AliDimuCombinator::Type(TParticle *part)
413{
414// Return particle type for
415return part->GetPdgCode();
416}
417
f87cfe57 418AliDimuCombinator& AliDimuCombinator::operator=(const AliDimuCombinator& rhs)
419{
420// Assignment operator
421 return *this;
422}
423
424
425
426
427
428
429
430