]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliParticleContainer.cxx
Move GenerateFixedBinArray to AliAnalysisTaskEmcal and change data type from Float...
[u/mrichter/AliRoot.git] / PWG / EMCAL / AliParticleContainer.cxx
1 // $Id$
2 //
3 // Container with name, TClonesArray and cuts for particles
4 //
5 // Author: M. Verweij
6
7 #include <TClonesArray.h>
8
9 #include "AliVEvent.h"
10 #include "AliLog.h"
11
12 #include "AliParticleContainer.h"
13
14 ClassImp(AliParticleContainer)
15
16 //________________________________________________________________________
17 AliParticleContainer::AliParticleContainer():
18   AliEmcalContainer("AliParticleContainer"),
19   fParticlePtCut(0.15),
20   fParticleMinEta(-0.9),
21   fParticleMaxEta(0.9),
22   fParticleMinPhi(-10),
23   fParticleMaxPhi(10),
24   fTrackBitMap(0),
25   fMCTrackBitMap(0),
26   fMinMCLabel(0),
27   fMCFlag(0),
28   fGeneratorIndex(-1)
29 {
30   // Default constructor.
31
32   fClassName = "AliVParticle";
33 }
34
35 //________________________________________________________________________
36 AliParticleContainer::AliParticleContainer(const char *name):
37   AliEmcalContainer(name),
38   fParticlePtCut(0.15),
39   fParticleMinEta(-0.9),
40   fParticleMaxEta(0.9),
41   fParticleMinPhi(-10),
42   fParticleMaxPhi(10),
43   fTrackBitMap(0),
44   fMCTrackBitMap(0),
45   fMinMCLabel(0),
46   fMCFlag(0),
47   fGeneratorIndex(-1)
48 {
49   // Standard constructor.
50
51   fClassName = "AliVParticle";
52 }
53
54 //________________________________________________________________________
55 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt) 
56 {
57   // Get the leading particle; use p if "p" is contained in opt
58
59   TString option(opt);
60   option.ToLower();
61
62   Int_t tempID = fCurrentID;
63
64   AliVParticle *partMax = GetNextAcceptParticle(0);
65   AliVParticle *part = 0;
66
67   if (option.Contains("p")) {
68     while ((part = GetNextAcceptParticle())) {
69       if (part->P() > partMax->P()) partMax = part;
70     }
71   }
72   else {
73     while ((part = GetNextAcceptParticle())) {
74       if (part->Pt() > partMax->Pt()) partMax = part;
75     }
76   }
77
78   fCurrentID = tempID;
79
80   return partMax;
81 }
82
83 //________________________________________________________________________
84 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const 
85 {
86   //Get i^th jet in array
87
88   if(i<0 || i>=fClArray->GetEntriesFast()) return 0;
89   AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
90   return vp;
91
92 }
93
94 //________________________________________________________________________
95 AliVParticle* AliParticleContainer::GetAcceptParticle(Int_t i) const {
96   //return pointer to particle if particle is accepted
97
98   AliVParticle *vp = GetParticle(i);
99   if(!vp) return 0;
100
101   if(AcceptParticle(vp))
102     return vp;
103   else {
104     AliDebug(2,"Particle not accepted.");
105     return 0;
106   }
107 }
108
109 //________________________________________________________________________
110 AliVParticle* AliParticleContainer::GetParticleWithLabel(Int_t lab) const 
111 {
112   //Get particle with label lab in array
113   
114   Int_t i = GetIndexFromLabel(lab);
115   return GetParticle(i);
116 }
117
118 //________________________________________________________________________
119 AliVParticle* AliParticleContainer::GetAcceptParticleWithLabel(Int_t lab) const 
120 {
121   //Get particle with label lab in array
122   
123   Int_t i = GetIndexFromLabel(lab);
124   return GetAcceptParticle(i);
125 }
126
127
128 //________________________________________________________________________
129 AliVParticle* AliParticleContainer::GetNextAcceptParticle(Int_t i) 
130 {
131   //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
132
133   if (i>=0) fCurrentID = i;
134
135   const Int_t n = GetNEntries();
136   AliVParticle *p = 0;
137   while (fCurrentID < n && !p) { 
138     p = GetAcceptParticle(fCurrentID);
139     fCurrentID++;
140   }
141
142   return p;
143 }
144
145 //________________________________________________________________________
146 AliVParticle* AliParticleContainer::GetNextParticle(Int_t i) 
147 {
148   //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
149
150   if (i>=0) fCurrentID = i;
151
152   const Int_t n = GetNEntries();
153   AliVParticle *p = 0;
154   while (fCurrentID < n && !p) { 
155     p = GetParticle(fCurrentID);
156     fCurrentID++;
157   }
158
159   return p;
160 }
161
162 //________________________________________________________________________
163 void AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
164 {
165   //Get momentum of the i^th particle in array
166
167   AliVParticle *vp = GetParticle(i);
168   if(vp) mom.SetPtEtaPhiM(vp->Pt(),vp->Eta(),vp->Phi(),0.139);
169 }
170
171 //________________________________________________________________________
172 Bool_t AliParticleContainer::AcceptParticle(AliVParticle *vp) const
173 {
174   // Return true if vp is accepted.
175
176   if (!vp)
177     return kFALSE;
178
179   if (TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
180     if(vp->TestBits(fMCTrackBitMap) != (Int_t)fMCTrackBitMap) {
181       AliDebug(2,"MC particle not accepted because of MC bit map.");
182       return kFALSE;
183     }
184   }
185   else {
186     if(vp->TestBits(fTrackBitMap) != (Int_t)fTrackBitMap) {
187       AliDebug(2,"Track not accepted because of bit map.");
188       return kFALSE;
189     }
190   }
191
192   if (vp->Pt() < fParticlePtCut)
193     return kFALSE;
194
195   if (vp->Eta() < fParticleMinEta || vp->Eta() > fParticleMaxEta || 
196       vp->Phi() < fParticleMinPhi || vp->Phi() > fParticleMaxPhi)
197     return kFALSE;
198
199   if ((vp->GetFlag() & fMCFlag) != fMCFlag) 
200     return kFALSE;
201
202   if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex())
203     return kFALSE;
204   
205   return kTRUE;
206 }
207
208 //________________________________________________________________________
209 Int_t AliParticleContainer::GetNAcceptedParticles()
210 {
211   // Get number of accepted particles
212
213   Int_t nPart = 0;
214
215   AliVParticle *vp = GetNextAcceptParticle(0);
216   if(vp) nPart = 1;
217   while (GetNextAcceptParticle())
218     nPart++;
219
220   return nPart;
221 }
222
223 //________________________________________________________________________
224 void AliParticleContainer::SetClassName(const char *clname)
225 {
226   // Set the class name
227
228   TClass cls(clname);
229   if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
230   else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
231 }