]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliParticleContainer.cxx
From Salvatore and Marta:
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliParticleContainer.cxx
1 //
2 // Particle Container
3 //
4 // Author: M. Verweij
5
6 #include <TClonesArray.h>
7
8 #include "AliVEvent.h"
9 #include "AliLog.h"
10
11 #include "AliParticleContainer.h"
12
13 ClassImp(AliParticleContainer)
14
15 //________________________________________________________________________
16 AliParticleContainer::AliParticleContainer():
17   AliEmcalContainer("AliParticleContainer"),
18   fParticlePtCut(0.15),
19   fParticleMinEta(-0.9),
20   fParticleMaxEta(0.9),
21   fParticleMinPhi(-10),
22   fParticleMaxPhi(10),
23   fTrackBitMap(0),
24   fMCTrackBitMap(0),
25   fMinMCLabel(0)
26 {
27   // Default constructor.
28
29 }
30
31 //________________________________________________________________________
32 AliParticleContainer::AliParticleContainer(const char *name):
33   AliEmcalContainer(name),
34   fParticlePtCut(0.15),
35   fParticleMinEta(-0.9),
36   fParticleMaxEta(0.9),
37   fParticleMinPhi(-10),
38   fParticleMaxPhi(10),
39   fTrackBitMap(0),
40   fMCTrackBitMap(0),
41   fMinMCLabel(0)
42 {
43   // Standard constructor.
44
45 }
46
47 //________________________________________________________________________
48 void AliParticleContainer::SetParticleArray(AliVEvent *event) 
49 {
50   // Set jet array
51
52   SetArray(event, "AliVParticle");
53 }
54
55 //________________________________________________________________________
56 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt) const
57 {
58   // Get the leading particle; use p if "p" is contained in opt
59
60   TString option(opt);
61   option.ToLower();
62
63   AliVParticle *partMax = GetNextAcceptParticle(0);
64   AliVParticle *part = 0;
65
66   if (option.Contains("p")) {
67     while ((part = GetNextAcceptParticle())) {
68       if (part->P() > partMax->P()) partMax = part;
69     }
70   }
71   else {
72     while ((part = GetNextAcceptParticle())) {
73       if (part->Pt() > partMax->Pt()) partMax = part;
74     }
75   }
76
77   return partMax;
78 }
79
80 //________________________________________________________________________
81 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const {
82
83   //Get i^th jet in array
84
85   if(i<0 || i>fClArray->GetEntriesFast()) return 0;
86   AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
87   return vp;
88
89 }
90
91 //________________________________________________________________________
92 AliVParticle* AliParticleContainer::GetAcceptParticle(Int_t i) const {
93   //return pointer to particle if particle is accepted
94
95   AliVParticle *vp = GetParticle(i);
96   if(!vp) return 0;
97
98   if(AcceptParticle(vp))
99     return vp;
100   else {
101     AliDebug(2,"Particle not accepted.");
102     return 0;
103   }
104 }
105
106 //________________________________________________________________________
107 AliVParticle* AliParticleContainer::GetNextAcceptParticle(Int_t i) const {
108
109   //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
110
111   static Int_t counter = -1;
112   if (i>=0) counter = i;
113
114   const Int_t n = GetNEntries();
115   AliVParticle *p = 0;
116   while (counter < n && !p) { 
117     p = GetAcceptParticle(counter);
118     counter++;
119   }
120
121   return p;
122 }
123
124 //________________________________________________________________________
125 void AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
126 {
127   //Get momentum of the i^th particle in array
128
129   AliVParticle *vp = GetParticle(i);
130   if(vp) mom.SetPtEtaPhiM(vp->Pt(),vp->Eta(),vp->Phi(),0.139);
131 }
132
133 //________________________________________________________________________
134 Bool_t AliParticleContainer::AcceptParticle(AliVParticle *vp) const
135 {
136   // Return true if vp is accepted.
137
138   if (!vp)
139     return kFALSE;
140
141   if (TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
142     if(vp->TestBits(fMCTrackBitMap) != (Int_t)fMCTrackBitMap) {
143       AliDebug(2,"MC particle not accepted because of MC bit map.");
144       return kFALSE;
145     }
146   }
147   else {
148     if(vp->TestBits(fTrackBitMap) != (Int_t)fTrackBitMap) {
149       AliDebug(2,"Track not accepted because of bit map.");
150       return kFALSE;
151     }
152   }
153
154   if (vp->Pt() < fParticlePtCut)
155     return kFALSE;
156
157   if (vp->Eta() < fParticleMinEta || vp->Eta() > fParticleMaxEta || 
158       vp->Phi() < fParticleMinPhi || vp->Phi() > fParticleMaxPhi)
159     return kFALSE;
160   
161   return kTRUE;
162 }