AliPhysics  7dff9e1 (7dff9e1)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 #include "AliVCuts.h"
11 #include "AliVTrack.h"
12 #include "AliESDtrack.h"
13 
14 #include "AliTLorentzVector.h"
17 #include "AliParticleContainer.h"
18 
20 
21 
22 TString AliParticleContainer::fgDefTrackCutsPeriod = "";
23 
24 //________________________________________________________________________
27  fParticlePtCut(0.15),
28  fParticleMinEta(-0.9),
29  fParticleMaxEta(0.9),
30  fParticleMinPhi(-10),
31  fParticleMaxPhi(10),
32  fPhiOffset(0.),
33  fMinDistanceTPCSectorEdge(-1),
34  fTrackBitMap(0),
35  fMCTrackBitMap(0),
36  fMinMCLabel(0),
37  fMinMCLabelAccept(-1),
38  fMCFlag(0),
39  fGeneratorIndex(-1),
40  fCharge(-1),
41  fTrackFilterType(AliEmcalTrackSelection::kNoTrackFilter),
42  fListOfCuts(0),
43  fSelectionModeAny(kFALSE),
44  fAODFilterBits(0),
45  fTrackCutsPeriod(),
46  fEmcalTrackSelection(0),
47  fFilteredTracks(0),
48  fTrackTypes(5000)
49 {
50  // Default constructor.
51 
52  fClassName = "AliVParticle";
53 }
54 
55 //________________________________________________________________________
56 AliParticleContainer::AliParticleContainer(const char *name, const char *period):
57  AliEmcalContainer(name),
58  fParticlePtCut(0.15),
59  fParticleMinEta(-0.9),
60  fParticleMaxEta(0.9),
61  fParticleMinPhi(-10),
62  fParticleMaxPhi(10),
63  fPhiOffset(0.),
64  fMinDistanceTPCSectorEdge(-1),
65  fTrackBitMap(0),
66  fMCTrackBitMap(0),
67  fMinMCLabel(0),
68  fMinMCLabelAccept(-1),
69  fMCFlag(0),
70  fGeneratorIndex(-1),
71  fCharge(-1),
72  fTrackFilterType(AliEmcalTrackSelection::kNoTrackFilter),
73  fListOfCuts(0),
74  fSelectionModeAny(kFALSE),
75  fAODFilterBits(0),
76  fTrackCutsPeriod(period),
77  fEmcalTrackSelection(0),
78  fFilteredTracks(0),
79  fTrackTypes(5000)
80 {
81  // Standard constructor.
82 
83  fClassName = "AliVParticle";
84 
86  AliInfo(Form("Default track cuts period is %s", AliParticleContainer::fgDefTrackCutsPeriod.Data()));
88  }
89 }
90 
91 //________________________________________________________________________
92 void AliParticleContainer::SetArray(AliVEvent *event)
93 {
94  // Get array from event.
95 
97 
101  }
102  else {
104 
105  AliInfo("Using custom track cuts");
106 
107  if (fLoadedClass) {
108  if (fLoadedClass->InheritsFrom("AliAODTrack")) {
109  AliInfo(Form("Objects are of type %s: AOD track selection will be done.", fLoadedClass->GetName()));
111  }
112  else if (fLoadedClass->InheritsFrom("AliESDtrack")) {
113  AliInfo(Form("Objects are of type %s: ESD track selection will be done.", fLoadedClass->GetName()));
115  }
116  else {
117  AliWarning(Form("Objects are of type %s: no track filtering will be done!!", fLoadedClass->GetName()));
118  }
119  }
120 
121  if (fEmcalTrackSelection) {
122  if (fSelectionModeAny) {
124  }
125  else {
127  }
128 
130  }
131  }
132  else {
133  if (!fTrackCutsPeriod.IsNull()) {
134  AliInfo(Form("Using track cuts %d for period %s", fTrackFilterType, fTrackCutsPeriod.Data()));
135  }
136  else {
137  AliInfo(Form("Using track cuts %d (no data period was provided!)", fTrackFilterType));
138  }
139 
140  if (fLoadedClass->InheritsFrom("AliAODTrack")) {
141  AliInfo(Form("Objects are of type %s: AOD track selection will be done.", fLoadedClass->GetName()));
143  }
144  else if (fLoadedClass->InheritsFrom("AliESDtrack")) {
145  AliInfo(Form("Objects are of type %s: ESD track selection will be done.", fLoadedClass->GetName()));
147  }
148  else {
149  AliWarning(Form("Objects are of type %s: no track filtering will be done!!", fLoadedClass->GetName()));
150  }
151  }
152  }
153 }
154 
155 //________________________________________________________________________
157 {
158  fTrackTypes.Reset(kUndefined);
159  if (fEmcalTrackSelection) {
161 
162  const TClonesArray* trackBitmaps = fEmcalTrackSelection->GetAcceptedTrackBitmaps();
163  TIter nextBitmap(trackBitmaps);
164  TBits* bits = 0;
165  Int_t i = 0;
166  while ((bits = static_cast<TBits*>(nextBitmap()))) {
167  if (i >= fTrackTypes.GetSize()) fTrackTypes.Set((i+1)*2);
168  AliVTrack* vTrack = static_cast<AliVTrack*>(fFilteredTracks->At(i));
169  if (!vTrack) {
170  fTrackTypes[i] = kRejected;
171  }
173  if (bits->FirstSetBit() == 0) {
175  }
176  else if (bits->FirstSetBit() == 1) {
177  if ((vTrack->GetStatus()&AliVTrack::kITSrefit) != 0) {
179  }
180  else {
182  }
183  }
184  }
185  i++;
186  }
187  }
188  else {
190  }
191 }
192 
193 //________________________________________________________________________
194 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
195 {
196  // Get the leading particle; use p if "p" is contained in opt
197 
198  TString option(opt);
199  option.ToLower();
200 
201  Int_t tempID = fCurrentID;
202 
203  AliVParticle *partMax = GetNextAcceptParticle(0);
204  AliVParticle *part = 0;
205 
206  if (option.Contains("p")) {
207  while ((part = GetNextAcceptParticle())) {
208  if (part->P() > partMax->P()) partMax = part;
209  }
210  }
211  else {
212  while ((part = GetNextAcceptParticle())) {
213  if (part->Pt() > partMax->Pt()) partMax = part;
214  }
215  }
216 
217  fCurrentID = tempID;
218 
219  return partMax;
220 }
221 
222 //________________________________________________________________________
223 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const
224 {
225  //Get i^th jet in array
226 
227  if (i == -1) i = fCurrentID;
228  if (i < 0 || i >= fFilteredTracks->GetEntriesFast()) return 0;
229  AliVParticle *vp = static_cast<AliVParticle*>(fFilteredTracks->At(i));
230  return vp;
231 }
232 
233 //________________________________________________________________________
235 {
236  //return pointer to particle if particle is accepted
237 
238  if (i == -1) i = fCurrentID;
239  if (AcceptParticle(i)) {
240  return GetParticle(i);
241  }
242  else {
243  AliDebug(2,"Particle not accepted.");
244  return 0;
245  }
246 }
247 
248 //________________________________________________________________________
249 AliVParticle* AliParticleContainer::GetParticleWithLabel(Int_t lab) const
250 {
251  //Get particle with label lab in array
252 
253  Int_t i = GetIndexFromLabel(lab);
254  return GetParticle(i);
255 }
256 
257 //________________________________________________________________________
259 {
260  //Get particle with label lab in array
261 
262  Int_t i = GetIndexFromLabel(lab);
263  return GetAcceptParticle(i);
264 }
265 
266 
267 //________________________________________________________________________
269 {
270  //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
271 
272  if (i >= 0) fCurrentID = i;
273 
274  const Int_t n = GetNEntries();
275 
276  AliVParticle *p = 0;
277  do {
278  fCurrentID++;
279  if (fCurrentID >= n) break;
281  } while (!p);
282 
283  return p;
284 }
285 
286 //________________________________________________________________________
288 {
289  //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
290 
291  if (i >= 0) fCurrentID = i;
292 
293  const Int_t n = GetNEntries();
294  AliVParticle *p = 0;
295  do {
296  fCurrentID++;
297  if (fCurrentID >= n) break;
298  p = GetParticle(fCurrentID);
299  } while (!p);
300 
301  return p;
302 }
303 
304 //________________________________________________________________________
305 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i)
306 {
307  //Get momentum of the i^th particle in array
308 
309  if (i == -1) i = fCurrentID;
310  AliVParticle *vp = GetParticle(i);
311  if (vp) {
312  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
313  (fTrackTypes[i] == kHybridConstrained || fTrackTypes[i] == kHybridConstrainedNoITSrefit)) {
314  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
315  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), 0.139);
316  }
317  else {
318  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), 0.139);
319  }
320  return kTRUE;
321  }
322  else {
323  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
324  return kFALSE;
325  }
326 }
327 
328 //________________________________________________________________________
329 Bool_t AliParticleContainer::GetNextMomentum(TLorentzVector &mom, Int_t i)
330 {
331  //Get momentum of the i^th particle in array
332 
333  AliVParticle *vp = GetNextParticle(i);
334  if (vp) {
335  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
337  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
338  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), 0.139);
339  }
340  else {
341  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), 0.139);
342  }
343  return kTRUE;
344  }
345  else {
346  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
347  return kFALSE;
348  }
349 }
350 
351 //________________________________________________________________________
352 Bool_t AliParticleContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i)
353 {
354  //Get momentum of the i^th particle in array
355 
356  if (i == -1) i = fCurrentID;
357  AliVParticle *vp = GetAcceptParticle(i);
358  if (vp) {
359  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
360  (fTrackTypes[i] == kHybridConstrained || fTrackTypes[i] == kHybridConstrainedNoITSrefit)) {
361  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
362  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), 0.139);
363  }
364  else {
365  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), 0.139);
366  }
367 
368  return kTRUE;
369  }
370  else {
371  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
372  return kFALSE;
373  }
374 }
375 
376 //________________________________________________________________________
377 Bool_t AliParticleContainer::GetNextAcceptMomentum(TLorentzVector &mom, Int_t i)
378 {
379  //Get momentum of the i^th particle in array
380 
381  AliVParticle *vp = GetNextAcceptParticle(i);
382  if (vp) {
383  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
385  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
386  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), 0.139);
387  }
388  else {
389  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), 0.139);
390  }
391 
392  return kTRUE;
393  }
394  else {
395  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
396  return kFALSE;
397  }
398 }
399 
400 //________________________________________________________________________
401 Bool_t AliParticleContainer::AcceptParticle(AliVParticle *vp)
402 {
403  // Return true if vp is accepted.
404  Int_t id = fFilteredTracks->IndexOf(vp);
405  if (id >= 0) {
406  return AcceptParticle(id);
407  }
408  else {
409  return kFALSE;
410  }
411 }
412 
413 //________________________________________________________________________
415 {
416  // Return true if i^th particle is accepted.
417 
418  fRejectionReason = 0;
419 
420  // Cuts on the particle properties
421  AliVParticle* vp = GetParticle(i);
422 
423  if (!vp) {
425  return kFALSE;
426  }
427 
428  if (TMath::Abs(vp->GetLabel()) < fMinMCLabelAccept) {
429  AliDebug(2,"Particle not accepted because label too small.");
431  return kFALSE;
432  }
433 
434  if (TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
435  if(vp->TestBits(fMCTrackBitMap) != (Int_t)fMCTrackBitMap) {
436  AliDebug(2,"MC particle not accepted because of MC bit map.");
438  return kFALSE;
439  }
440  }
441  else {
442  if(vp->TestBits(fTrackBitMap) != (Int_t)fTrackBitMap) {
443  AliDebug(2,"Track not accepted because of bit map.");
445  return kFALSE;
446  }
447  }
448 
449  if ((vp->GetFlag() & fMCFlag) != fMCFlag) {
451  return kFALSE;
452  }
453 
454  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
456  return kFALSE;
457  }
458 
459  if (fCharge>=0 && fCharge != vp->Charge()) {
461  return kFALSE;
462  }
463 
464  // Cuts on the 4-momentum
465  AliTLorentzVector mom;
466  GetMomentum(mom, i);
467 
468  if (mom.Pt() < fParticlePtCut) {
470  return kFALSE;
471  }
472 
473  Double_t phi = mom.Phi_0_2pi() + fPhiOffset;
474 
475  if (mom.Eta() < fParticleMinEta || mom.Eta() > fParticleMaxEta ||
476  phi < fParticleMinPhi || phi > fParticleMaxPhi) {
478  return kFALSE;
479  }
480 
482  const Double_t pi = TMath::Pi();
483  const Double_t kSector = pi/9;
484  Double_t phiDist = TMath::Abs(mom.Phi() - TMath::FloorNint(mom.Phi()/kSector)*kSector);
485  if(phiDist<fMinDistanceTPCSectorEdge) {
487  return kFALSE;
488  }
489  }
490 
491  return kTRUE;
492 }
493 
494 //________________________________________________________________________
496 {
497  // Get number of accepted particles
498 
499  Int_t nPart = 0;
500 
501  AliVParticle *vp = GetNextAcceptParticle(0);
502  if(vp) nPart = 1;
503  while (GetNextAcceptParticle())
504  nPart++;
505 
506  return nPart;
507 }
508 
509 //________________________________________________________________________
510 void AliParticleContainer::SetClassName(const char *clname)
511 {
512  // Set the class name
513 
514  TClass cls(clname);
515  if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
516  else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
517 }
518 
519 //________________________________________________________________________
521 {
522  if (!fListOfCuts) {
523  fListOfCuts = new TObjArray;
524  fListOfCuts->SetOwner(true);
525  }
526  fListOfCuts->Add(cuts);
527 }
528 
529 //________________________________________________________________________
531 {
532  if (!fListOfCuts) return 0;
533  return fListOfCuts->GetEntries();
534 }
535 
536 //________________________________________________________________________
538 {
539  if (!fListOfCuts) return NULL;
540  if (icut < fListOfCuts->GetEntries()) {
541  return static_cast<AliVCuts *>(fListOfCuts->At(icut));
542  }
543  return NULL;
544 }
Interface for virtual track selection.
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
Bool_t GetNextMomentum(TLorentzVector &mom, Int_t i=-1)
Double_t fParticlePtCut
default period string used to generate track cuts
AliVParticle * GetParticleWithLabel(Int_t lab) const
Int_t GetIndexFromLabel(Int_t lab) const
void SetClassName(const char *clname)
ETrackFilterType_t fTrackFilterType
virtual void SetArray(AliVEvent *event)
const TClonesArray * GetAcceptedTrackBitmaps() const
Implement virtual track selection for AOD analysis.
Bool_t AcceptParticle(AliVParticle *vp)
TArrayC fTrackTypes
tracks filtered using fEmcalTrackSelection
TClass * fLoadedClass
reject reason bit map for the last call to an accept object function
static TString fgDefTrackCutsPeriod
AliVCuts * GetTrackCuts(Int_t icut)
AliVParticle * GetAcceptParticleWithLabel(Int_t lab)
UInt_t fRejectionReason
event vertex array
Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i)
void SetArray(AliVEvent *event)
Declaration of class AliEmcalTrackSelectionESD.
AliVParticle * GetLeadingParticle(const char *opt="")
AliVParticle * GetParticle(Int_t i=-1) const
Bool_t GetNextAcceptMomentum(TLorentzVector &mom, Int_t i=-1)
void AddTrackCuts(AliVCuts *cuts)
Bool_t GetMomentum(TLorentzVector &mom, Int_t i)
AliVParticle * GetNextAcceptParticle(Int_t i=-1)
void AddTrackCuts(AliVCuts *cuts)
Implement virtual track selection for AOD analysis.
Int_t GetNumberOfCutObjects() const
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)
AliVParticle * GetNextParticle(Int_t i=-1)
TObjArray * GetAcceptedTracks(const TClonesArray *const tracks)
TObjArray * fFilteredTracks
track selection object
AliEmcalTrackSelection * fEmcalTrackSelection
TClonesArray * fClArray
Int_t GetNEntries() const
AliVParticle * GetAcceptParticle(Int_t i=-1)
Int_t fCurrentID
TClonesArray.
Implementation of virtual track selection for ESDs.