AliPhysics  de71be2 (de71be2)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AliParticleContainer.cxx
Go to the documentation of this file.
1 //
2 // Container with name, TClonesArray and cuts for particles
3 //
4 // Author: M. Verweij, S. Aiola
5 
6 #include <TClonesArray.h>
7 
8 #include "AliVEvent.h"
9 #include "AliLog.h"
10 
11 #include "AliTLorentzVector.h"
12 #include "AliParticleContainer.h"
13 
15 
16 //________________________________________________________________________
19  fMinDistanceTPCSectorEdge(-1),
20  fCharge(-1),
21  fGeneratorIndex(-1)
22 {
23  // Default constructor.
24 
25  fClassName = "AliVParticle";
26 }
27 
28 //________________________________________________________________________
30  AliEmcalContainer(name),
31  fMinDistanceTPCSectorEdge(-1),
32  fCharge(-1),
33  fGeneratorIndex(-1)
34 {
35  // Standard constructor.
36 
37  fClassName = "AliVParticle";
38 }
39 
40 //________________________________________________________________________
41 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
42 {
43  // Get the leading particle; use p if "p" is contained in opt
44 
45  TString option(opt);
46  option.ToLower();
47 
48  Int_t tempID = fCurrentID;
49 
50  AliVParticle *partMax = GetNextAcceptParticle(0);
51  AliVParticle *part = 0;
52 
53  if (option.Contains("p")) {
54  while ((part = GetNextAcceptParticle())) {
55  if (part->P() > partMax->P()) partMax = part;
56  }
57  }
58  else {
59  while ((part = GetNextAcceptParticle())) {
60  if (part->Pt() > partMax->Pt()) partMax = part;
61  }
62  }
63 
64  fCurrentID = tempID;
65 
66  return partMax;
67 }
68 
69 //________________________________________________________________________
70 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const
71 {
72  //Get i^th jet in array
73 
74  if (i == -1) i = fCurrentID;
75  if (i < 0 || i >= this->fClArray->GetEntriesFast()) return 0;
76  AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
77  return vp;
78 }
79 
80 //________________________________________________________________________
82 {
83  //return pointer to particle if particle is accepted
84 
85  if (i == -1) i = fCurrentID;
86  if (AcceptParticle(i)) {
87  return GetParticle(i);
88  }
89  else {
90  AliDebug(2,"Particle not accepted.");
91  return 0;
92  }
93 }
94 
95 //________________________________________________________________________
97 {
98  //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
99 
100  if (i >= 0) fCurrentID = i;
101 
102  const Int_t n = GetNEntries();
103 
104  AliVParticle *p = 0;
105  do {
106  fCurrentID++;
107  if (fCurrentID >= n) break;
109  } while (!p);
110 
111  return p;
112 }
113 
114 //________________________________________________________________________
116 {
117  //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
118 
119  if (i >= 0) fCurrentID = i;
120 
121  const Int_t n = GetNEntries();
122  AliVParticle *p = 0;
123  do {
124  fCurrentID++;
125  if (fCurrentID >= n) break;
126  p = GetParticle(fCurrentID);
127  } while (!p);
128 
129  return p;
130 }
131 
132 //________________________________________________________________________
133 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, const AliVParticle* part, Double_t mass)
134 {
135  if (part) {
136  if (mass < 0) mass = part->M();
137  mom.SetPtEtaPhiM(part->Pt(), part->Eta(), part->Phi(), mass);
138  return kTRUE;
139  }
140  else {
141  mom.SetPtEtaPhiM(0, 0, 0, 0);
142  return kFALSE;
143  }
144 }
145 
146 //________________________________________________________________________
147 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, const AliVParticle* part)
148 {
149  return GetMomentum(mom,part,fMassHypothesis);
150 }
151 
152 //________________________________________________________________________
153 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i)
154 {
155  //Get momentum of the i^th particle in array
156 
157  Double_t mass = fMassHypothesis;
158 
159  if (i == -1) i = fCurrentID;
160  AliVParticle *vp = GetParticle(i);
161  if (vp) {
162  if (mass < 0) mass = vp->M();
163  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
164  return kTRUE;
165  }
166  else {
167  mom.SetPtEtaPhiM(0, 0, 0, 0);
168  return kFALSE;
169  }
170 }
171 
172 //________________________________________________________________________
173 Bool_t AliParticleContainer::GetNextMomentum(TLorentzVector &mom, Int_t i)
174 {
175  //Get momentum of the i^th particle in array
176 
177  Double_t mass = fMassHypothesis;
178 
179  AliVParticle *vp = GetNextParticle(i);
180  if (vp) {
181  if (mass < 0) mass = vp->M();
182  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
183  return kTRUE;
184  }
185  else {
186  mom.SetPtEtaPhiM(0, 0, 0, 0);
187  return kFALSE;
188  }
189 }
190 
191 //________________________________________________________________________
192 Bool_t AliParticleContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i)
193 {
194  //Get momentum of the i^th particle in array
195 
196  Double_t mass = fMassHypothesis;
197 
198  if (i == -1) i = fCurrentID;
199  AliVParticle *vp = GetAcceptParticle(i);
200  if (vp) {
201  if (mass < 0) mass = vp->M();
202  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
203  return kTRUE;
204  }
205  else {
206  mom.SetPtEtaPhiM(0, 0, 0, 0);
207  return kFALSE;
208  }
209 }
210 
211 //________________________________________________________________________
212 Bool_t AliParticleContainer::GetNextAcceptMomentum(TLorentzVector &mom, Int_t i)
213 {
214  //Get momentum of the i^th particle in array
215 
216  Double_t mass = fMassHypothesis;
217 
218  AliVParticle *vp = GetNextAcceptParticle(i);
219  if (vp) {
220  if (mass < 0) mass = vp->M();
221  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
222  return kTRUE;
223  }
224  else {
225  mom.SetPtEtaPhiM(0, 0, 0, 0);
226  return kFALSE;
227  }
228 }
229 
230 //________________________________________________________________________
231 Bool_t AliParticleContainer::AcceptParticle(const AliVParticle *vp)
232 {
233  // Return true if vp is accepted.
234  Bool_t r = ApplyParticleCuts(vp);
235  if (!r) return kFALSE;
236 
237  AliTLorentzVector mom;
238 
239  Int_t id = fClArray->IndexOf(vp);
240  if (id >= 0) {
241  GetMomentum(mom, id);
242  }
243  else {
244  GetMomentum(mom, vp);
245  }
246 
247  return ApplyKinematicCuts(mom);
248 }
249 
250 //________________________________________________________________________
252 {
253  // Return true if vp is accepted.
254  Bool_t r = ApplyParticleCuts(GetParticle(i));
255  if (!r) return kFALSE;
256 
257  AliTLorentzVector mom;
258  GetMomentum(mom, i);
259 
260  return ApplyKinematicCuts(mom);
261 }
262 
263 //________________________________________________________________________
264 Bool_t AliParticleContainer::ApplyParticleCuts(const AliVParticle* vp)
265 {
266  // Return true if i^th particle is accepted.
267 
268  fRejectionReason = 0;
269 
270  // Cuts on the particle properties
271 
272  if (!vp) {
274  return kFALSE;
275  }
276 
277  if (vp->TestBits(fBitMap) != (Int_t)fBitMap) {
279  return kFALSE;
280  }
281 
282  if (fMinMCLabel >= 0 && TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
284  return kFALSE;
285  }
286 
287  if (fMaxMCLabel >= 0 && TMath::Abs(vp->GetLabel()) < fMaxMCLabel) {
289  return kFALSE;
290  }
291 
292  if (fCharge>=0 && fCharge != vp->Charge()) {
294  return kFALSE;
295  }
296 
297  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
299  return kFALSE;
300  }
301 
302  return kTRUE;
303 }
304 
305 //________________________________________________________________________
306 Bool_t AliParticleContainer::ApplyKinematicCuts(const AliTLorentzVector& mom)
307 {
309  const Double_t pi = TMath::Pi();
310  const Double_t kSector = pi/9;
311  Double_t phiDist = TMath::Abs(mom.Phi() - TMath::FloorNint(mom.Phi()/kSector)*kSector);
312  if(phiDist<fMinDistanceTPCSectorEdge) {
314  return kFALSE;
315  }
316  }
317 
319 }
320 
321 //________________________________________________________________________
323 {
324  // Get number of accepted particles
325 
326  Int_t nPart = 0;
327 
328  AliVParticle *vp = GetNextAcceptParticle(0);
329  if(vp) nPart = 1;
330  while (GetNextAcceptParticle())
331  nPart++;
332 
333  return nPart;
334 }
335 
336 //________________________________________________________________________
337 void AliParticleContainer::SetClassName(const char *clname)
338 {
339  // Set the class name
340 
341  TClass cls(clname);
342  if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
343  else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
344 }
345 
346 //________________________________________________________________________
348 {
349  static TString trackString;
350 
351  if (GetMinPt() == 0) {
352  trackString = TString::Format("%s_pT0000", GetArrayName().Data());
353  }
354  else if (GetMinPt() < 1.0) {
355  trackString = TString::Format("%s_pT0%3.0f", GetArrayName().Data(), GetMinPt()*1000.0);
356  }
357  else {
358  trackString = TString::Format("%s_pT%4.0f", GetArrayName().Data(), GetMinPt()*1000.0);
359  }
360 
361  return trackString.Data();
362 }
virtual Bool_t GetNextMomentum(TLorentzVector &mom, Int_t i=-1)
ClassImp(AliParticleContainer) AliParticleContainer
const char * GetTitle() const
void SetClassName(const char *clname)
Double_t mass
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp)
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom)
UInt_t fRejectionReason
event vertex array
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i)
Double_t GetMinPt() const
virtual AliVParticle * GetLeadingParticle(const char *opt="")
virtual AliVParticle * GetParticle(Int_t i=-1) const
virtual Bool_t GetNextAcceptMomentum(TLorentzVector &mom, Int_t i=-1)
virtual Bool_t GetMomentum(TLorentzVector &mom, const AliVParticle *part, Double_t mass)
virtual AliVParticle * GetNextAcceptParticle(Int_t i=-1)
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
const TString & GetArrayName() const
virtual AliVParticle * GetNextParticle(Int_t i=-1)
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom)
TClonesArray * fClArray
Int_t GetNEntries() const
virtual AliVParticle * GetAcceptParticle(Int_t i=-1)
Int_t fCurrentID
TClonesArray.
virtual Bool_t AcceptParticle(const AliVParticle *vp)