AliPhysics  vAN-20151012 (2287573)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliParticleContainer.cxx
Go to the documentation of this file.
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 #include "AliAODTrack.h"
12 
13 #include "AliParticleContainer.h"
14 
16 
17 //________________________________________________________________________
20  fParticlePtCut(0.15),
21  fParticleMinEta(-0.9),
22  fParticleMaxEta(0.9),
23  fParticleMinPhi(-10),
24  fParticleMaxPhi(10),
25  fPhiOffset(0.),
26  fMinDistanceTPCSectorEdge(-1),
27  fTrackBitMap(0),
28  fMCTrackBitMap(0),
29  fMinMCLabel(0),
30  fMinMCLabelAccept(-1),
31  fMCFlag(0),
32  fGeneratorIndex(-1),
33  fCharge(-1),
34  fFilterHybridTracks(kFALSE)
35 {
36  // Default constructor.
37 
38  fClassName = "AliVParticle";
39 }
40 
41 //________________________________________________________________________
43  AliEmcalContainer(name),
44  fParticlePtCut(0.15),
45  fParticleMinEta(-0.9),
46  fParticleMaxEta(0.9),
47  fParticleMinPhi(-10),
48  fParticleMaxPhi(10),
49  fPhiOffset(0.),
50  fMinDistanceTPCSectorEdge(-1),
51  fTrackBitMap(0),
52  fMCTrackBitMap(0),
53  fMinMCLabel(0),
54  fMinMCLabelAccept(-1),
55  fMCFlag(0),
56  fGeneratorIndex(-1),
57  fCharge(-1),
58  fFilterHybridTracks(kFALSE)
59 {
60  // Standard constructor.
61 
62  fClassName = "AliVParticle";
63 }
64 
65 //________________________________________________________________________
66 void AliParticleContainer::SetArray(AliVEvent *event)
67 {
68  // Get array from event.
69 
71 
72  if (fClassName != "AliAODTrack" && fFilterHybridTracks) {
73  AliWarning("Only class type AliAODTrack can be filtered for hybrid tracks. This functionality will be disabled.");
74  fFilterHybridTracks = kFALSE;
75  }
76 }
77 
78 //________________________________________________________________________
79 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
80 {
81  // Get the leading particle; use p if "p" is contained in opt
82 
83  TString option(opt);
84  option.ToLower();
85 
86  Int_t tempID = fCurrentID;
87 
88  AliVParticle *partMax = GetNextAcceptParticle(0);
89  AliVParticle *part = 0;
90 
91  if (option.Contains("p")) {
92  while ((part = GetNextAcceptParticle())) {
93  if (part->P() > partMax->P()) partMax = part;
94  }
95  }
96  else {
97  while ((part = GetNextAcceptParticle())) {
98  if (part->Pt() > partMax->Pt()) partMax = part;
99  }
100  }
101 
102  fCurrentID = tempID;
103 
104  return partMax;
105 }
106 
107 //________________________________________________________________________
108 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const
109 {
110  //Get i^th jet in array
111 
112  if(i<0 || i>=fClArray->GetEntriesFast()) return 0;
113  AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
114  return vp;
115 
116 }
117 
118 //________________________________________________________________________
120  //return pointer to particle if particle is accepted
121 
122  AliVParticle *vp = GetParticle(i);
123  if(!vp) return 0;
124 
125  if(AcceptParticle(vp))
126  return vp;
127  else {
128  AliDebug(2,"Particle not accepted.");
129  return 0;
130  }
131 }
132 
133 //________________________________________________________________________
134 AliVParticle* AliParticleContainer::GetParticleWithLabel(Int_t lab) const
135 {
136  //Get particle with label lab in array
137 
138  Int_t i = GetIndexFromLabel(lab);
139  return GetParticle(i);
140 }
141 
142 //________________________________________________________________________
144 {
145  //Get particle with label lab in array
146 
147  Int_t i = GetIndexFromLabel(lab);
148  return GetAcceptParticle(i);
149 }
150 
151 
152 //________________________________________________________________________
154 {
155  //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
156 
157  if (i>=0) fCurrentID = i;
158 
159  const Int_t n = GetNEntries();
160  AliVParticle *p = 0;
161  while (fCurrentID < n && !p) {
163  fCurrentID++;
164  }
165 
166  return p;
167 }
168 
169 //________________________________________________________________________
171 {
172  //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
173 
174  if (i>=0) fCurrentID = i;
175 
176  const Int_t n = GetNEntries();
177  AliVParticle *p = 0;
178  while (fCurrentID < n && !p) {
179  p = GetParticle(fCurrentID);
180  fCurrentID++;
181  }
182 
183  return p;
184 }
185 
186 //________________________________________________________________________
187 void AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
188 {
189  //Get momentum of the i^th particle in array
190 
191  AliVParticle *vp = GetParticle(i);
192  if(vp) mom.SetPtEtaPhiM(vp->Pt(),vp->Eta(),vp->Phi(),0.139);
193 }
194 
195 //________________________________________________________________________
196 Bool_t AliParticleContainer::AcceptParticle(AliVParticle *vp)
197 {
198  // Return true if vp is accepted.
199 
200  fRejectionReason = 0;
201 
202  if (!vp) {
204  return kFALSE;
205  }
206 
207  if (fFilterHybridTracks) { // the cast is safe because fFilterHybridTracks is reset in DoInit if the object type is not AliAODTrack
208  AliAODTrack* aodTrack = static_cast<AliAODTrack*>(vp);
209  if (!aodTrack->IsHybridGlobalConstrainedGlobal()) {
211  return kFALSE;
212  }
213  }
214 
215  if (vp->Pt() < fParticlePtCut) {
217  return kFALSE;
218  }
219 
220  Double_t phi = vp->Phi() + fPhiOffset;
221  Double_t tpi = TMath::TwoPi();
222  if(phi<0.) phi+=tpi;
223  if(phi>tpi) phi-=tpi;
224 
225  if (vp->Eta() < fParticleMinEta || vp->Eta() > fParticleMaxEta ||
226  phi < fParticleMinPhi || phi > fParticleMaxPhi) {
228  return kFALSE;
229  }
230 
232  const Double_t pi = TMath::Pi();
233  const Double_t kSector = pi/9;
234  Double_t phiDist = TMath::Abs(vp->Phi() - TMath::FloorNint(vp->Phi()/kSector)*kSector);
235  if(phiDist<fMinDistanceTPCSectorEdge) {
237  return kFALSE;
238  }
239  }
240 
241  if (TMath::Abs(vp->GetLabel()) < fMinMCLabelAccept) {
242  AliDebug(2,"Particle not accepted because label too small.");
244  return kFALSE;
245  }
246 
247  if (TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
248  if(vp->TestBits(fMCTrackBitMap) != (Int_t)fMCTrackBitMap) {
249  AliDebug(2,"MC particle not accepted because of MC bit map.");
251  return kFALSE;
252  }
253  }
254  else {
255  if(vp->TestBits(fTrackBitMap) != (Int_t)fTrackBitMap) {
256  AliDebug(2,"Track not accepted because of bit map.");
258  return kFALSE;
259  }
260  }
261 
262  if ((vp->GetFlag() & fMCFlag) != fMCFlag) {
264  return kFALSE;
265  }
266 
267  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
269  return kFALSE;
270  }
271 
272  if (fCharge>=0 && fCharge != vp->Charge()) {
274  return kFALSE;
275  }
276 
277  return kTRUE;
278 }
279 
280 //________________________________________________________________________
282 {
283  // Get number of accepted particles
284 
285  Int_t nPart = 0;
286 
287  AliVParticle *vp = GetNextAcceptParticle(0);
288  if(vp) nPart = 1;
289  while (GetNextAcceptParticle())
290  nPart++;
291 
292  return nPart;
293 }
294 
295 //________________________________________________________________________
296 void AliParticleContainer::SetClassName(const char *clname)
297 {
298  // Set the class name
299 
300  TClass cls(clname);
301  if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
302  else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
303 }
AliVParticle * GetParticleWithLabel(Int_t lab) const
ClassImp(AliParticleContainer) AliParticleContainer
Int_t GetIndexFromLabel(Int_t lab) const
void SetClassName(const char *clname)
virtual void SetArray(AliVEvent *event)
Bool_t AcceptParticle(AliVParticle *vp)
AliVParticle * GetAcceptParticleWithLabel(Int_t lab)
UInt_t fRejectionReason
event vertex array
void SetArray(AliVEvent *event)
AliVParticle * GetParticle(Int_t i) const
AliVParticle * GetAcceptParticle(Int_t i)
AliVParticle * GetLeadingParticle(const char *opt="")
void GetMomentum(TLorentzVector &mom, Int_t i) const
AliVParticle * GetNextAcceptParticle(Int_t i=-1)
AliVParticle * GetNextParticle(Int_t i=-1)
TClonesArray * fClArray
Int_t GetNEntries() const
Int_t fCurrentID
TClonesArray.