AliPhysics  ec707b8 (ec707b8)
 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 
17 
18 //________________________________________________________________________
21  fMinDistanceTPCSectorEdge(-1),
22  fCharge(-1),
23  fGeneratorIndex(-1)
24 {
25  // Default constructor.
26 
27  fClassName = "AliVParticle";
28 }
29 
30 //________________________________________________________________________
32  AliEmcalContainer(name),
33  fMinDistanceTPCSectorEdge(-1),
34  fCharge(-1),
35  fGeneratorIndex(-1)
36 {
37  // Standard constructor.
38 
39  fClassName = "AliVParticle";
40 }
41 
42 //________________________________________________________________________
43 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
44 {
45  // Get the leading particle; use p if "p" is contained in opt
46 
47  TString option(opt);
48  option.ToLower();
49 
50  Int_t tempID = fCurrentID;
52 
53  AliVParticle *partMax = GetNextAcceptParticle();
54  AliVParticle *part = 0;
55 
56  if (option.Contains("p")) {
57  while ((part = GetNextAcceptParticle())) {
58  if (part->P() > partMax->P()) partMax = part;
59  }
60  }
61  else {
62  while ((part = GetNextAcceptParticle())) {
63  if (part->Pt() > partMax->Pt()) partMax = part;
64  }
65  }
66 
67  fCurrentID = tempID;
68 
69  return partMax;
70 }
71 
72 //________________________________________________________________________
73 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const
74 {
75  //Get i^th jet in array
76 
77  if (i == -1) i = fCurrentID;
78  if (i < 0 || i >= this->fClArray->GetEntriesFast()) return 0;
79  AliVParticle *vp = static_cast<AliVParticle*>(fClArray->At(i));
80  return vp;
81 }
82 
83 //________________________________________________________________________
85 {
86  //return pointer to particle if particle is accepted
87 
88  if (i == -1) i = fCurrentID;
89  if (AcceptParticle(i)) {
90  return GetParticle(i);
91  }
92  else {
93  AliDebug(2,"Particle not accepted.");
94  return 0;
95  }
96 }
97 
98 //________________________________________________________________________
100 {
101  //Get next accepted particle
102 
103  const Int_t n = GetNEntries();
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
118 
119  const Int_t n = GetNEntries();
120  AliVParticle *p = 0;
121  do {
122  fCurrentID++;
123  if (fCurrentID >= n) break;
124  p = GetParticle(fCurrentID);
125  } while (!p);
126 
127  return p;
128 }
129 
130 //________________________________________________________________________
131 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, const AliVParticle* part, Double_t mass)
132 {
133  if (part) {
134  if (mass < 0) mass = part->M();
135  mom.SetPtEtaPhiM(part->Pt(), part->Eta(), part->Phi(), mass);
136  return kTRUE;
137  }
138  else {
139  mom.SetPtEtaPhiM(0, 0, 0, 0);
140  return kFALSE;
141  }
142 }
143 
144 //________________________________________________________________________
145 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, const AliVParticle* part)
146 {
147  return GetMomentum(mom,part,fMassHypothesis);
148 }
149 
150 //________________________________________________________________________
151 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i)
152 {
153  //Get momentum of the i^th particle in array
154 
155  Double_t mass = fMassHypothesis;
156 
157  if (i == -1) i = fCurrentID;
158  AliVParticle *vp = GetParticle(i);
159  if (vp) {
160  if (mass < 0) mass = vp->M();
161  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
162  return kTRUE;
163  }
164  else {
165  mom.SetPtEtaPhiM(0, 0, 0, 0);
166  return kFALSE;
167  }
168 }
169 
170 //________________________________________________________________________
171 Bool_t AliParticleContainer::GetNextMomentum(TLorentzVector &mom)
172 {
173  //Get momentum of the next particle in array
174 
175  Double_t mass = fMassHypothesis;
176 
177  AliVParticle *vp = GetNextParticle();
178  if (vp) {
179  if (mass < 0) mass = vp->M();
180  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
181  return kTRUE;
182  }
183  else {
184  mom.SetPtEtaPhiM(0, 0, 0, 0);
185  return kFALSE;
186  }
187 }
188 
189 //________________________________________________________________________
190 Bool_t AliParticleContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i)
191 {
192  //Get momentum of the i^th particle in array
193 
194  Double_t mass = fMassHypothesis;
195 
196  if (i == -1) i = fCurrentID;
197  AliVParticle *vp = GetAcceptParticle(i);
198  if (vp) {
199  if (mass < 0) mass = vp->M();
200  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
201  return kTRUE;
202  }
203  else {
204  mom.SetPtEtaPhiM(0, 0, 0, 0);
205  return kFALSE;
206  }
207 }
208 
209 //________________________________________________________________________
211 {
212  //Get momentum of the next accepted particle in array
213 
214  Double_t mass = fMassHypothesis;
215 
216  AliVParticle *vp = GetNextAcceptParticle();
217  if (vp) {
218  if (mass < 0) mass = vp->M();
219  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
220  return kTRUE;
221  }
222  else {
223  mom.SetPtEtaPhiM(0, 0, 0, 0);
224  return kFALSE;
225  }
226 }
227 
228 //________________________________________________________________________
229 Bool_t AliParticleContainer::AcceptParticle(const AliVParticle *vp)
230 {
231  // Return true if vp is accepted.
232  Bool_t r = ApplyParticleCuts(vp);
233  if (!r) return kFALSE;
234 
235  AliTLorentzVector mom;
236 
237  Int_t id = fClArray->IndexOf(vp);
238  if (id >= 0) {
239  GetMomentum(mom, id);
240  }
241  else {
242  GetMomentum(mom, vp);
243  }
244 
245  return ApplyKinematicCuts(mom);
246 }
247 
248 //________________________________________________________________________
250 {
251  // Return true if vp is accepted.
252  Bool_t r = ApplyParticleCuts(GetParticle(i));
253  if (!r) return kFALSE;
254 
255  AliTLorentzVector mom;
256  GetMomentum(mom, i);
257 
258  return ApplyKinematicCuts(mom);
259 }
260 
261 //________________________________________________________________________
262 Bool_t AliParticleContainer::ApplyParticleCuts(const AliVParticle* vp)
263 {
264  // Return true if i^th particle is accepted.
265 
266  fRejectionReason = 0;
267 
268  // Cuts on the particle properties
269 
270  if (!vp) {
272  return kFALSE;
273  }
274 
275  if (vp->TestBits(fBitMap) != (Int_t)fBitMap) {
277  return kFALSE;
278  }
279 
280  if (fMinMCLabel >= 0 && TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
282  return kFALSE;
283  }
284 
285  if (fMaxMCLabel >= 0 && TMath::Abs(vp->GetLabel()) < fMaxMCLabel) {
287  return kFALSE;
288  }
289 
290  if (fCharge>=0 && fCharge != vp->Charge()) {
292  return kFALSE;
293  }
294 
295  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
297  return kFALSE;
298  }
299 
300  return kTRUE;
301 }
302 
303 //________________________________________________________________________
304 Bool_t AliParticleContainer::ApplyKinematicCuts(const AliTLorentzVector& mom)
305 {
307  const Double_t pi = TMath::Pi();
308  const Double_t kSector = pi/9;
309  Double_t phiDist = TMath::Abs(mom.Phi() - TMath::FloorNint(mom.Phi()/kSector)*kSector);
310  if(phiDist<fMinDistanceTPCSectorEdge) {
312  return kFALSE;
313  }
314  }
315 
317 }
318 
319 //________________________________________________________________________
321 {
322  // Get number of accepted particles
323 
324  Int_t nPart = 0;
325  Int_t tempID = fCurrentID;
326  ResetCurrentID();
327 
328  AliVParticle *vp = GetNextAcceptParticle();
329  if(vp) nPart = 1;
330  while (GetNextAcceptParticle())
331  nPart++;
332 
333  fCurrentID = tempID;
334 
335  return nPart;
336 }
337 
338 //________________________________________________________________________
339 void AliParticleContainer::SetClassName(const char *clname)
340 {
341  // Set the class name
342 
343  TClass cls(clname);
344  if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
345  else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
346 }
347 
348 //________________________________________________________________________
350 {
351  static TString trackString;
352 
353  if (GetMinPt() == 0) {
354  trackString = TString::Format("%s_pT0000", GetArrayName().Data());
355  }
356  else if (GetMinPt() < 1.0) {
357  trackString = TString::Format("%s_pT0%3.0f", GetArrayName().Data(), GetMinPt()*1000.0);
358  }
359  else {
360  trackString = TString::Format("%s_pT%4.0f", GetArrayName().Data(), GetMinPt()*1000.0);
361  }
362 
363  return trackString.Data();
364 }
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
virtual AliVParticle * GetNextAcceptParticle()
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom)
const char * GetTitle() const
void SetClassName(const char *clname)
Double_t mass
UInt_t fBitMap
whether or not it is a particle level object collection
TString fClassName
name of branch
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp)
virtual Bool_t GetNextMomentum(TLorentzVector &mom)
Container for particles within the EMCAL framework.
virtual Bool_t GetNextAcceptMomentum(TLorentzVector &mom)
UInt_t fRejectionReason
!reject reason bit map for the last call to an accept object function
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 GetMomentum(TLorentzVector &mom, const AliVParticle *part, Double_t mass)
Base class for container structures within the EMCAL framework.
Short_t fCharge
require minimum distance to edge of TPC sector edge
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)
Int_t fMinMCLabel
cut on particle phi
const TString & GetArrayName() const
Double_t fMassHypothesis
maximum MC label
Short_t fGeneratorIndex
select particles with charge=fCharge
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom)
Int_t fMaxMCLabel
minimum MC label
TClonesArray * fClArray
if < 0 it will use a PID mass when available
Int_t GetNEntries() const
virtual AliVParticle * GetAcceptParticle(Int_t i=-1)
Int_t fCurrentID
!current ID for automatic loops
virtual Bool_t AcceptParticle(const AliVParticle *vp)
void ResetCurrentID(Int_t i=-1)
virtual AliVParticle * GetNextParticle()