1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 //_________________________________________________________________________
18 // Class for reading data (Kinematics) in order to do prompt gamma
19 // or other particle identification and correlations
21 //*-- Author: Gustavo Conesa (LNF-INFN)
22 //////////////////////////////////////////////////////////////////////////////
25 // --- ROOT system ---
27 #include <TParticle.h>
29 #include <TClonesArray.h>
30 //#include "Riostream.h"
32 //---- ANALYSIS system ----
33 #include "AliCaloTrackMCReader.h"
35 #include "AliGenEventHeader.h"
37 #include "AliAODCaloCluster.h"
38 #include "AliAODTrack.h"
40 ClassImp(AliCaloTrackMCReader)
42 //____________________________________________________________________________
43 AliCaloTrackMCReader::AliCaloTrackMCReader() :
44 AliCaloTrackReader(), fDecayPi0(0),
45 fNeutralParticlesArray(0x0), fChargedParticlesArray(0x0),
46 fStatusArray(0x0), fKeepAllStatus(0), fClonesArrayType(0)
50 //Initialize parameters
56 //____________________________________________________________________________
57 AliCaloTrackMCReader::AliCaloTrackMCReader(const AliCaloTrackMCReader & g) :
58 AliCaloTrackReader(g), fDecayPi0(g.fDecayPi0),
59 fNeutralParticlesArray(g.fNeutralParticlesArray?new TArrayI(*g.fNeutralParticlesArray):0x0),
60 fChargedParticlesArray(g.fChargedParticlesArray?new TArrayI(*g.fChargedParticlesArray):0x0),
61 fStatusArray(g.fStatusArray?new TArrayI(*g.fStatusArray):0x0),
62 fKeepAllStatus(g.fKeepAllStatus), fClonesArrayType(g.fClonesArrayType)
67 //_________________________________________________________________________
68 AliCaloTrackMCReader & AliCaloTrackMCReader::operator = (const AliCaloTrackMCReader & source)
70 // assignment operator
72 if(&source == this) return *this;
74 fDecayPi0 = source.fDecayPi0;
76 delete fChargedParticlesArray;
77 fChargedParticlesArray = source.fChargedParticlesArray?new TArrayI(*source.fChargedParticlesArray):0x0;
79 delete fNeutralParticlesArray;
80 fNeutralParticlesArray = source.fNeutralParticlesArray?new TArrayI(*source.fNeutralParticlesArray):0x0;
83 fStatusArray = source.fStatusArray?new TArrayI(*source.fStatusArray):0x0;
85 fKeepAllStatus = source.fKeepAllStatus ;
86 fClonesArrayType = source.fClonesArrayType ;
92 //_________________________________
93 AliCaloTrackMCReader::~AliCaloTrackMCReader() {
96 if(fChargedParticlesArray) delete fChargedParticlesArray ;
97 if(fNeutralParticlesArray) delete fNeutralParticlesArray ;
98 if(fStatusArray) delete fStatusArray ;
102 //____________________________________________________________________________
103 void AliCaloTrackMCReader::GetVertex(Double_t v[3]) const {
104 //Return vertex position
107 GetGenEventHeader()->PrimaryVertex(pv);
115 //_______________________________________________________________
116 void AliCaloTrackMCReader::InitParameters()
119 //Initialize the parameters of the analysis.
123 fChargedParticlesArray = new TArrayI(1);
124 fChargedParticlesArray->SetAt(11,0);
125 //Int_t pdgarray[]={12,14,16};// skip neutrinos
126 //fNeutralParticlesArray = new TArrayI(3, pdgarray);
127 fNeutralParticlesArray = new TArrayI(3);
128 fNeutralParticlesArray->SetAt(12,0); fNeutralParticlesArray->SetAt(14,1); fNeutralParticlesArray->SetAt(16,2);
129 fStatusArray = new TArrayI(1);
130 fStatusArray->SetAt(1,0);
132 fKeepAllStatus = kTRUE;
133 fClonesArrayType = kAliAOD ;
137 //____________________________________________________________________________
138 void AliCaloTrackMCReader::FillCalorimeters(const Int_t iParticle, TParticle* particle, TLorentzVector momentum,
139 Int_t &indexPHOS, Int_t &indexEMCAL) {
140 //Fill AODCaloClusters or TParticles lists of PHOS or EMCAL
143 if(fFillPHOS && fFidutialCut->IsInFidutialCut(momentum,"PHOS") && momentum.Pt() > fPHOSPtMin){
145 if(fClonesArrayType == kTParticle) new((*fAODPHOS)[indexPHOS++]) TParticle(*particle) ;
148 Char_t ttype= AliAODCluster::kPHOSNeutral;
149 Int_t labels[] = {iParticle};
150 Float_t x[] = {momentum.X(), momentum.Y(), momentum.Z()};
151 AliAODCaloCluster *calo = new((*fAODPHOS)[indexPHOS++])
152 AliAODCaloCluster(iParticle,1,labels,momentum.E(), x, NULL, ttype, 0);
153 SetCaloClusterPID(particle->GetPdgCode(),calo) ;
154 if(fDebug > 3 && momentum.Pt() > 0.2)
155 printf("Fill MC PHOS :: Selected tracks %s E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
156 particle->GetName(),momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
160 else if(fFillEMCAL && fFidutialCut->IsInFidutialCut(momentum,"EMCAL") && momentum.Pt() > fEMCALPtMin){
161 if(fClonesArrayType == kTParticle) new((*fAODEMCAL)[indexEMCAL++]) TParticle(*particle) ;
163 Char_t ttype= AliAODCluster::kEMCALClusterv1;
164 Int_t labels[] = {iParticle};
165 Float_t x[] = {momentum.X(), momentum.Y(), momentum.Z()};
166 AliAODCaloCluster *calo = new((*fAODEMCAL)[indexEMCAL++])
167 AliAODCaloCluster(iParticle,1,labels,momentum.E(), x, NULL, ttype, 0);
168 SetCaloClusterPID(particle->GetPdgCode(),calo) ;
169 if(fDebug > 3 && momentum.Pt() > 0.2)
170 printf("Fill MC EMCAL :: Selected tracks %s E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
171 particle->GetName(),momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
176 //____________________________________________________________________________
177 void AliCaloTrackMCReader::FillInputEvent()
179 //Create list of particles from EMCAL, PHOS and CTS.
181 if(fClonesArrayType == kTParticle){
182 fAODCTS = new TClonesArray("TParticle",0);
183 fAODEMCAL = new TClonesArray("TParticle",0);
184 fAODPHOS = new TClonesArray("TParticle",0);
186 else if(fClonesArrayType == kAliAOD){
187 fAODCTS = new TClonesArray("AliAODTrack",0);
188 fAODPHOS = new TClonesArray("AliAODCaloCluster",0);
189 fAODEMCAL = new TClonesArray("AliAODCaloCluster",0);
191 else {AliFatal("Wrong clones type");}
195 Int_t indexEMCAL = 0 ;
196 Int_t indexPHOS = 0 ;
198 Int_t iParticle = 0 ;
199 Double_t charge = 0.;
201 for (iParticle=0 ; iParticle < GetStack()->GetNtrack() ; iParticle++) {
202 TParticle * particle = GetStack()->Particle(iParticle);
203 TLorentzVector momentum;
206 Int_t pdg = particle->GetPdgCode();
208 //Keep particles with a given status
209 if(KeepParticleWithStatus(particle->GetStatusCode()) && (particle->Pt() > 0) ){
211 //Skip bizarre particles, they crash when charge is calculated
212 if(TMath::Abs(pdg) == 3124 || TMath::Abs(pdg) > 10000000) continue ;
214 charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
215 particle->Momentum(momentum);
216 //---------- Charged particles ----------------------
217 if((charge != 0) && (momentum.Pt() > fCTSPtMin) && (fFidutialCut->IsInFidutialCut(momentum,"CTS"))){
219 //Particles in CTS acceptance
220 if(fDebug > 3 && momentum.Pt() > 0.2)
221 printf("Fill MC CTS :: Selected tracks E %3.2f, pt %3.2f, phi %3.2f, eta %3.2f\n",
222 momentum.E(),momentum.Pt(),momentum.Phi()*TMath::RadToDeg(),momentum.Eta());
224 if(fClonesArrayType == kTParticle) new((*fAODCTS)[indexCh++]) TParticle(*particle) ;
226 x[0] = particle->Vx(); x[1] = particle->Vy(); x[2] = particle->Vz();
227 p[0] = particle->Px(); p[1] = particle->Py(); p[2] = particle->Pz();
228 AliAODTrack *aodTrack = new((*fAODCTS)[indexCh++])
229 AliAODTrack(0, iParticle, p, kTRUE, x, kFALSE,NULL, 0, 0,
232 kFALSE, // No fit performed
233 kFALSE, // No fit performed
234 AliAODTrack::kPrimary,
236 SetTrackChargeAndPID(pdg, aodTrack);
239 //Keep some charged particles in calorimeters lists
240 if((fFillPHOS || fFillEMCAL) && KeepChargedParticles(pdg)) FillCalorimeters(iParticle, particle, momentum, indexPHOS, indexEMCAL);
244 //-------------Neutral particles ----------------------
245 else if(charge == 0 && (fFillPHOS || fFillEMCAL)){
246 //Skip neutrinos or other neutral particles
247 //if(SkipNeutralParticles(pdg) || particle->IsPrimary()) continue ; // protection added (MG)
248 if(SkipNeutralParticles(pdg)) continue ;
250 //Fill particle/calocluster arrays
252 FillCalorimeters(iParticle, particle, momentum, indexPHOS, indexEMCAL);
255 //Sometimes pi0 are stable for the generator, if needed decay it by hand
257 if(momentum.Pt() > fPHOSPtMin || momentum.Pt() > fEMCALPtMin){
258 TLorentzVector lvGamma1, lvGamma2 ;
259 //Double_t angle = 0;
262 MakePi0Decay(momentum,lvGamma1,lvGamma2);//,angle);
264 //Check if Pi0 is in the acceptance of the calorimeters, if aperture angle is small, keep it
265 TParticle * pPhoton1 = new TParticle(22,1,iParticle,0,0,0,lvGamma1.Px(),lvGamma1.Py(),
266 lvGamma1.Pz(),lvGamma1.E(),0,0,0,0);
267 TParticle * pPhoton2 = new TParticle(22,1,iParticle,0,0,0,lvGamma2.Px(),lvGamma2.Py(),
268 lvGamma2.Pz(),lvGamma2.E(),0,0,0,0);
269 //Fill particle/calocluster arrays
270 FillCalorimeters(iParticle,pPhoton1,lvGamma1, indexPHOS, indexEMCAL);
271 FillCalorimeters(iParticle,pPhoton2,lvGamma2, indexPHOS, indexEMCAL);
274 else FillCalorimeters(iParticle,particle, momentum, indexPHOS, indexEMCAL); //Add the rest
277 } //particle with correct status
282 //________________________________________________________________
283 Bool_t AliCaloTrackMCReader::KeepParticleWithStatus(Int_t status) const {
284 //Check if status is equal to one of the list
285 //These particles will be used in analysis.
287 for(Int_t i= 0; i < fStatusArray->GetSize(); i++)
288 if(status == fStatusArray->At(i)) return kTRUE ;
297 //________________________________________________________________
298 Bool_t AliCaloTrackMCReader::KeepChargedParticles(Int_t pdg) const {
299 //Check if pdg is equal to one of the charged particles list
300 //These particles will be added to the calorimeters lists.
302 for(Int_t i= 0; i < fChargedParticlesArray->GetSize(); i++)
303 if(TMath::Abs(pdg) == fChargedParticlesArray->At(i)) return kTRUE ;
309 //________________________________________________________________
310 void AliCaloTrackMCReader::Print(const Option_t * opt) const
312 //Print some relevant parameters set for the analysis
316 Info("**** Print **** ", "%s %s", GetName(), GetTitle() ) ;
318 printf("Decay Pi0? : %d\n", fDecayPi0) ;
319 printf("TClonesArray type : %d\n", fClonesArrayType) ;
320 printf("Keep all status? : %d\n", fKeepAllStatus) ;
322 if(!fKeepAllStatus) printf("Keep particles with status : ");
323 for(Int_t i= 0; i < fStatusArray->GetSize(); i++)
324 printf(" %d ; ", fStatusArray->At(i));
327 printf("Skip neutral particles in calo : ");
328 for(Int_t i= 0; i < fNeutralParticlesArray->GetSize(); i++)
329 printf(" %d ; ", fNeutralParticlesArray->At(i));
332 printf("Keep charged particles in calo : ");
333 for(Int_t i= 0; i < fChargedParticlesArray->GetSize(); i++)
334 printf(" %d ; ", fChargedParticlesArray->At(i));
339 //____________________________________________________________________________
340 void AliCaloTrackMCReader::MakePi0Decay(TLorentzVector &p0, TLorentzVector &p1,
341 TLorentzVector &p2) const {//, Double_t &angle) {
342 // Perform isotropic decay pi0 -> 2 photons
343 // p0 is pi0 4-momentum (inut)
344 // p1 and p2 are photon 4-momenta (output)
345 // cout<<"Boost vector"<<endl;
346 Double_t mPi0 = TDatabasePDG::Instance()->GetParticle(111)->Mass();
347 TVector3 b = p0.BoostVector();
348 //cout<<"Parameters"<<endl;
349 //Double_t mPi0 = p0.M();
350 Double_t phi = TMath::TwoPi() * gRandom->Rndm();
351 Double_t cosThe = 2 * gRandom->Rndm() - 1;
352 Double_t cosPhi = TMath::Cos(phi);
353 Double_t sinPhi = TMath::Sin(phi);
354 Double_t sinThe = TMath::Sqrt(1-cosThe*cosThe);
355 Double_t ePi0 = mPi0/2.;
356 //cout<<"ePi0 "<<ePi0<<endl;
357 //cout<<"Components"<<endl;
358 p1.SetPx(+ePi0*cosPhi*sinThe);
359 p1.SetPy(+ePi0*sinPhi*sinThe);
360 p1.SetPz(+ePi0*cosThe);
362 //cout<<"p1: "<<p1.Px()<<" "<<p1.Py()<<" "<<p1.Pz()<<" "<<p1.E()<<endl;
363 //cout<<"p1 Mass: "<<p1.Px()*p1.Px()+p1.Py()*p1.Py()+p1.Pz()*p1.Pz()-p1.E()*p1.E()<<endl;
364 p2.SetPx(-ePi0*cosPhi*sinThe);
365 p2.SetPy(-ePi0*sinPhi*sinThe);
366 p2.SetPz(-ePi0*cosThe);
368 //cout<<"p2: "<<p2.Px()<<" "<<p2.Py()<<" "<<p2.Pz()<<" "<<p2.E()<<endl;
369 //cout<<"p2 Mass: "<<p2.Px()*p2.Px()+p2.Py()*p2.Py()+p2.Pz()*p2.Pz()-p2.E()*p2.E()<<endl;
370 //cout<<"Boost "<<b.X()<<" "<<b.Y()<<" "<<b.Z()<<endl;
372 //cout<<"p1: "<<p1.Px()<<" "<<p1.Py()<<" "<<p1.Pz()<<" "<<p1.E()<<endl;
374 //cout<<"p2: "<<p2.Px()<<" "<<p2.Py()<<" "<<p2.Pz()<<" "<<p2.E()<<endl;
375 //cout<<"angle"<<endl;
376 //angle = p1.Angle(p2.Vect());
380 //____________________________________________________________________________
381 void AliCaloTrackMCReader::SetInputEvent(TObject* /*esd*/, TObject* aod, TObject* mc) {
382 // Connect the data pointer
383 SetMC((AliMCEvent*) mc);
384 SetAOD((AliAODEvent*) aod);
388 //________________________________________________________________
389 Bool_t AliCaloTrackMCReader::SkipNeutralParticles(Int_t pdg) const {
390 //Check if pdg is equal to one of the neutral particles list
391 //These particles will be skipped from analysis.
393 for(Int_t i= 0; i < fNeutralParticlesArray->GetSize(); i++)
394 if(TMath::Abs(pdg) == fNeutralParticlesArray->At(i)) return kTRUE ;
401 //____________________________________________________________________
402 void AliCaloTrackMCReader::SetTrackChargeAndPID(const Int_t pdgCode, AliAODTrack *track) const {
403 //Give a PID weight for tracks equal to 1 depending on the particle type
405 Float_t pid[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
411 pid[AliAODTrack::kUnknown] = 1.;
416 track->SetCharge(-1);
417 pid[AliAODTrack::kElectron] = 1.;
422 track->SetCharge(+1);
423 pid[AliAODTrack::kElectron] = 1.;
428 track->SetCharge(-1);
429 pid[AliAODTrack::kMuon] = 1.;
434 track->SetCharge(+1);
435 pid[AliAODTrack::kMuon] = 1.;
441 pid[AliAODTrack::kUnknown] = 1.;
446 track->SetCharge(+1);
447 pid[AliAODTrack::kPion] = 1.;
452 track->SetCharge(-1);
453 pid[AliAODTrack::kPion] = 1.;
459 pid[AliAODTrack::kUnknown] = 1.;
464 track->SetCharge(+1);
465 pid[AliAODTrack::kKaon] = 1.;
470 track->SetCharge(-1);
471 pid[AliAODTrack::kKaon] = 1.;
477 pid[AliAODTrack::kUnknown] = 1.;
482 track->SetCharge(+1);
483 pid[AliAODTrack::kProton] = 1.;
487 case -2212: // anti-p
488 track->SetCharge(-1);
489 pid[AliAODTrack::kProton] = 1.;
495 pid[AliAODTrack::kUnknown] = 1.;
501 pid[AliAODTrack::kUnknown] = 1.;
505 case -311: // anti-K0
507 pid[AliAODTrack::kUnknown] = 1.;
513 pid[AliAODTrack::kUnknown] = 1.;
519 pid[AliAODTrack::kUnknown] = 1.;
524 track->SetCharge(+1);
525 pid[AliAODTrack::kUnknown] = 1.;
530 track->SetCharge(-1);
531 pid[AliAODTrack::kUnknown] = 1.;
536 track->SetCharge(-1);
537 pid[AliAODTrack::kUnknown] = 1.;
543 pid[AliAODTrack::kUnknown] = 1.;
548 track->SetCharge(-1);
549 pid[AliAODTrack::kUnknown] = 1.;
554 track->SetCharge(-1);
555 pid[AliAODTrack::kUnknown] = 1.;
561 pid[AliAODTrack::kUnknown] = 1.;
565 case -3122: // anti-Lambda
567 pid[AliAODTrack::kUnknown] = 1.;
571 case -3222: // anti-Sigma-
572 track->SetCharge(-1);
573 pid[AliAODTrack::kUnknown] = 1.;
577 case -3212: // anti-Sigma0
579 pid[AliAODTrack::kUnknown] = 1.;
583 case -3112: // anti-Sigma+
584 track->SetCharge(+1);
585 pid[AliAODTrack::kUnknown] = 1.;
589 case -3322: // anti-Xi0
591 pid[AliAODTrack::kUnknown] = 1.;
595 case -3312: // anti-Xi+
596 track->SetCharge(+1);
599 case -3334: // anti-Omega+
600 track->SetCharge(+1);
601 pid[AliAODTrack::kUnknown] = 1.;
606 track->SetCharge(+1);
607 pid[AliAODTrack::kUnknown] = 1.;
612 track->SetCharge(-1);
613 pid[AliAODTrack::kUnknown] = 1.;
619 pid[AliAODTrack::kUnknown] = 1.;
623 case -421: // anti-D0
625 pid[AliAODTrack::kUnknown] = 1.;
630 track->SetCharge(-99);
631 pid[AliAODTrack::kUnknown] = 1.;
640 //____________________________________________________________________
641 void AliCaloTrackMCReader::SetCaloClusterPID(const Int_t pdgCode, AliAODCaloCluster *calo) const {
642 //Give a PID weight for CaloClusters equal to 1 depending on the particle type
644 Float_t pid[13] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
649 pid[AliAODCaloCluster::kPhoton] = 1.;
654 pid[AliAODCaloCluster::kElectron] = 1.;
659 pid[AliAODCaloCluster::kElectron] = 1.;
664 pid[AliAODCaloCluster::kCharged] = 1.;
669 pid[AliAODCaloCluster::kCharged] = 1.;
674 pid[AliAODCaloCluster::kPi0] = 1.;
679 pid[AliAODCaloCluster::kCharged] = 1.;
684 pid[AliAODCaloCluster::kCharged] = 1.;
689 pid[AliAODCaloCluster::kKaon0] = 1.;
690 pid[AliAODCaloCluster::kNeutral] = 1;
695 pid[AliAODCaloCluster::kCharged] = 1.;
700 pid[AliAODCaloCluster::kCharged] = 1.;
705 pid[AliAODCaloCluster::kNeutron] = 1.;
706 pid[AliAODCaloCluster::kNeutral] = 1.;
711 pid[AliAODCaloCluster::kCharged] = 1.;
715 case -2212: // anti-p
716 pid[AliAODCaloCluster::kCharged] = 1.;
721 pid[AliAODCaloCluster::kKaon0] = 1.;
722 pid[AliAODCaloCluster::kNeutral] = 1.;
727 pid[AliAODCaloCluster::kKaon0] = 1.;
728 pid[AliAODCaloCluster::kNeutral] = 1.;
732 case -311: // anti-K0
733 pid[AliAODCaloCluster::kKaon0] = 1.;
734 pid[AliAODCaloCluster::kNeutral] = 1.;
739 pid[AliAODCaloCluster::kNeutral] = 1.;
744 pid[AliAODCaloCluster::kUnknown] = 1.;
749 pid[AliAODCaloCluster::kUnknown] = 1.;
754 pid[AliAODCaloCluster::kUnknown] = 1.;
759 pid[AliAODCaloCluster::kUnknown] = 1.;
764 pid[AliAODCaloCluster::kUnknown] = 1.;
769 pid[AliAODCaloCluster::kUnknown] = 1.;
774 pid[AliAODCaloCluster::kUnknown] = 1.;
779 pid[AliAODCaloCluster::kNeutron] = 1.;
780 pid[AliAODCaloCluster::kNeutral] = 1.;
784 case -3122: // anti-Lambda
785 pid[AliAODCaloCluster::kUnknown] = 1.;
789 case -3222: // anti-Sigma-
790 pid[AliAODCaloCluster::kUnknown] = 1.;
794 case -3212: // anti-Sigma0
795 pid[AliAODCaloCluster::kUnknown] = 1.;
799 case -3112: // anti-Sigma+
800 pid[AliAODCaloCluster::kUnknown] = 1.;
804 case -3322: // anti-Xi0
805 pid[AliAODCaloCluster::kUnknown] = 1.;
809 case -3312: // anti-Xi+
810 pid[AliAODCaloCluster::kUnknown] = 1.;
814 case -3334: // anti-Omega+
815 pid[AliAODCaloCluster::kUnknown] = 1.;
820 pid[AliAODCaloCluster::kUnknown] = 1.;
825 pid[AliAODCaloCluster::kUnknown] = 1.;
830 pid[AliAODCaloCluster::kUnknown] = 1.;
834 case -421: // anti-D0
835 pid[AliAODCaloCluster::kUnknown] = 1.;
840 pid[AliAODCaloCluster::kUnknown] = 1.;