]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/EMCAL/AliParticleContainer.cxx
Merge branch 'feature-movesplit'
[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   fMinDistanceTPCSectorEdge(-1),
25   fTrackBitMap(0),
26   fMCTrackBitMap(0),
27   fMinMCLabel(0),
28   fMinMCLabelAccept(-1),
29   fMCFlag(0),
30   fGeneratorIndex(-1),
31   fCharge(-1)
32 {
33   // Default constructor.
34
35   fClassName = "AliVParticle";
36 }
37
38 //________________________________________________________________________
39 AliParticleContainer::AliParticleContainer(const char *name):
40   AliEmcalContainer(name),
41   fParticlePtCut(0.15),
42   fParticleMinEta(-0.9),
43   fParticleMaxEta(0.9),
44   fParticleMinPhi(-10),
45   fParticleMaxPhi(10),
46   fMinDistanceTPCSectorEdge(-1),
47   fTrackBitMap(0),
48   fMCTrackBitMap(0),
49   fMinMCLabel(0),
50   fMinMCLabelAccept(-1),
51   fMCFlag(0),
52   fGeneratorIndex(-1),
53   fCharge(-1)
54 {
55   // Standard constructor.
56
57   fClassName = "AliVParticle";
58 }
59
60 //________________________________________________________________________
61 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt) 
62 {
63   // Get the leading particle; use p if "p" is contained in opt
64
65   TString option(opt);
66   option.ToLower();
67
68   Int_t tempID = fCurrentID;
69
70   AliVParticle *partMax = GetNextAcceptParticle(0);
71   AliVParticle *part = 0;
72
73   if (option.Contains("p")) {
74     while ((part = GetNextAcceptParticle())) {
75       if (part->P() > partMax->P()) partMax = part;
76     }
77   }
78   else {
79     while ((part = GetNextAcceptParticle())) {
80       if (part->Pt() > partMax->Pt()) partMax = part;
81     }
82   }
83
84   fCurrentID = tempID;
85
86   return partMax;
87 }
88
89 //________________________________________________________________________
90 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const 
91 {
92   //Get i^th jet in array
93
94   if(i<0 || i>=fClArray->GetEntriesFast()) return 0;
95   AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
96   return vp;
97
98 }
99
100 //________________________________________________________________________
101 AliVParticle* AliParticleContainer::GetAcceptParticle(Int_t i) {
102   //return pointer to particle if particle is accepted
103
104   AliVParticle *vp = GetParticle(i);
105   if(!vp) return 0;
106
107   if(AcceptParticle(vp))
108       return vp;
109   else {
110     AliDebug(2,"Particle not accepted.");
111     return 0;
112   }
113 }
114
115 //________________________________________________________________________
116 AliVParticle* AliParticleContainer::GetParticleWithLabel(Int_t lab) const 
117 {
118   //Get particle with label lab in array
119   
120   Int_t i = GetIndexFromLabel(lab);
121   return GetParticle(i);
122 }
123
124 //________________________________________________________________________
125 AliVParticle* AliParticleContainer::GetAcceptParticleWithLabel(Int_t lab)  
126 {
127   //Get particle with label lab in array
128   
129   Int_t i = GetIndexFromLabel(lab);
130   return GetAcceptParticle(i);
131 }
132
133
134 //________________________________________________________________________
135 AliVParticle* AliParticleContainer::GetNextAcceptParticle(Int_t i) 
136 {
137   //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
138
139   if (i>=0) fCurrentID = i;
140
141   const Int_t n = GetNEntries();
142   AliVParticle *p = 0;
143   while (fCurrentID < n && !p) { 
144     p = GetAcceptParticle(fCurrentID);
145     fCurrentID++;
146   }
147
148   return p;
149 }
150
151 //________________________________________________________________________
152 AliVParticle* AliParticleContainer::GetNextParticle(Int_t i) 
153 {
154   //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
155
156   if (i>=0) fCurrentID = i;
157
158   const Int_t n = GetNEntries();
159   AliVParticle *p = 0;
160   while (fCurrentID < n && !p) { 
161     p = GetParticle(fCurrentID);
162     fCurrentID++;
163   }
164
165   return p;
166 }
167
168 //________________________________________________________________________
169 void AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
170 {
171   //Get momentum of the i^th particle in array
172
173   AliVParticle *vp = GetParticle(i);
174   if(vp) mom.SetPtEtaPhiM(vp->Pt(),vp->Eta(),vp->Phi(),0.139);
175 }
176
177 //________________________________________________________________________
178 Bool_t AliParticleContainer::AcceptParticle(AliVParticle *vp)
179 {
180   // Return true if vp is accepted.
181
182   fRejectionReason = 0;
183
184   if (!vp) {
185     fRejectionReason |= kNullObject;
186     return kFALSE;
187   }
188
189   if (vp->Pt() < fParticlePtCut) {
190     fRejectionReason |= kPtCut;
191     return kFALSE;
192   }
193
194   if (vp->Eta() < fParticleMinEta || vp->Eta() > fParticleMaxEta || 
195       vp->Phi() < fParticleMinPhi || vp->Phi() > fParticleMaxPhi) {
196     fRejectionReason |= kAcceptanceCut;
197     return kFALSE;
198   }
199
200   if(fMinDistanceTPCSectorEdge>0.) {
201     const Double_t pi = TMath::Pi();
202     const Double_t kSector = pi/9;
203     Double_t phiDist = TMath::Abs(vp->Phi() - TMath::FloorNint(vp->Phi()/kSector)*kSector);
204     if(phiDist<fMinDistanceTPCSectorEdge) {
205       fRejectionReason |= kMinDistanceTPCSectorEdgeCut;
206       return kFALSE;
207     }
208   }
209
210   if (TMath::Abs(vp->GetLabel()) < fMinMCLabelAccept) {
211     AliDebug(2,"Particle not accepted because label too small.");
212     fRejectionReason |= kMinMCLabelAccept;
213     return kFALSE;
214   }
215
216   if (TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
217     if(vp->TestBits(fMCTrackBitMap) != (Int_t)fMCTrackBitMap) {
218       AliDebug(2,"MC particle not accepted because of MC bit map.");
219       fRejectionReason |= kBitMapCut;
220       return kFALSE;
221     }
222   }
223   else {
224     if(vp->TestBits(fTrackBitMap) != (Int_t)fTrackBitMap) {
225       AliDebug(2,"Track not accepted because of bit map.");
226       fRejectionReason |= kBitMapCut;
227       return kFALSE;
228     }
229   }
230
231   if ((vp->GetFlag() & fMCFlag) != fMCFlag) {
232     fRejectionReason |= kMCFlag;
233     return kFALSE;
234   }
235
236   if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
237     fRejectionReason |= kMCGeneratorCut;
238     return kFALSE;
239   }
240
241   if (fCharge>=0 && fCharge != vp->Charge()) {
242     fRejectionReason |= kChargeCut;
243     return kFALSE;
244   }
245   
246   return kTRUE;
247 }
248
249 //________________________________________________________________________
250 Int_t AliParticleContainer::GetNAcceptedParticles()
251 {
252   // Get number of accepted particles
253
254   Int_t nPart = 0;
255
256   AliVParticle *vp = GetNextAcceptParticle(0);
257   if(vp) nPart = 1;
258   while (GetNextAcceptParticle())
259     nPart++;
260
261   return nPart;
262 }
263
264 //________________________________________________________________________
265 void AliParticleContainer::SetClassName(const char *clname)
266 {
267   // Set the class name
268
269   TClass cls(clname);
270   if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
271   else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
272 }