AliPhysics  f2694b8 (f2694b8)
 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  fMinMCLabel(-1),
35  fMaxMCLabel(-1),
36  fMCFlag(0),
37  fGeneratorIndex(-1),
38  fCharge(-1),
39  fTrackFilterType(AliEmcalTrackSelection::kNoTrackFilter),
40  fListOfCuts(0),
41  fSelectionModeAny(kFALSE),
42  fAODFilterBits(0),
43  fTrackCutsPeriod(),
44  fEmcalTrackSelection(0),
45  fFilteredTracks(0),
46  fTrackTypes(5000)
47 {
48  // Default constructor.
49 
50  fClassName = "AliVParticle";
51 }
52 
53 //________________________________________________________________________
54 AliParticleContainer::AliParticleContainer(const char *name, const char *period):
55  AliEmcalContainer(name),
56  fParticlePtCut(0.15),
57  fParticleMinEta(-0.9),
58  fParticleMaxEta(0.9),
59  fParticleMinPhi(-10),
60  fParticleMaxPhi(10),
61  fPhiOffset(0.),
62  fMinDistanceTPCSectorEdge(-1),
63  fMinMCLabel(-1),
64  fMaxMCLabel(-1),
65  fMCFlag(0),
66  fGeneratorIndex(-1),
67  fCharge(-1),
68  fTrackFilterType(AliEmcalTrackSelection::kNoTrackFilter),
69  fListOfCuts(0),
70  fSelectionModeAny(kFALSE),
71  fAODFilterBits(0),
72  fTrackCutsPeriod(period),
73  fEmcalTrackSelection(0),
74  fFilteredTracks(0),
75  fTrackTypes(5000)
76 {
77  // Standard constructor.
78 
79  fClassName = "AliVParticle";
80 
82  AliInfo(Form("Default track cuts period is %s", AliParticleContainer::fgDefTrackCutsPeriod.Data()));
84  }
85 }
86 
87 //________________________________________________________________________
88 void AliParticleContainer::SetArray(AliVEvent *event)
89 {
90  // Get array from event.
91 
93 
97  }
98  else {
100 
101  AliInfo("Using custom track cuts");
102 
103  if (fLoadedClass) {
104  if (fLoadedClass->InheritsFrom("AliAODTrack")) {
105  AliInfo(Form("Objects are of type %s: AOD track selection will be done.", fLoadedClass->GetName()));
107  }
108  else if (fLoadedClass->InheritsFrom("AliESDtrack")) {
109  AliInfo(Form("Objects are of type %s: ESD track selection will be done.", fLoadedClass->GetName()));
111  }
112  else {
113  AliWarning(Form("Objects are of type %s: no track filtering will be done!!", fLoadedClass->GetName()));
114  }
115  }
116 
117  if (fEmcalTrackSelection) {
118  if (fSelectionModeAny) {
120  }
121  else {
123  }
124 
126  }
127  }
128  else {
129  if (!fTrackCutsPeriod.IsNull()) {
130  AliInfo(Form("Using track cuts %d for period %s", fTrackFilterType, fTrackCutsPeriod.Data()));
131  }
132  else {
133  AliInfo(Form("Using track cuts %d (no data period was provided!)", fTrackFilterType));
134  }
135 
136  if (fLoadedClass->InheritsFrom("AliAODTrack")) {
137  AliInfo(Form("Objects are of type %s: AOD track selection will be done.", fLoadedClass->GetName()));
139  }
140  else if (fLoadedClass->InheritsFrom("AliESDtrack")) {
141  AliInfo(Form("Objects are of type %s: ESD track selection will be done.", fLoadedClass->GetName()));
143  }
144  else {
145  AliWarning(Form("Objects are of type %s: no track filtering will be done!!", fLoadedClass->GetName()));
146  }
147  }
148  }
149 }
150 
151 //________________________________________________________________________
153 {
154  fTrackTypes.Reset(kUndefined);
155  if (fEmcalTrackSelection) {
157 
158  const TClonesArray* trackBitmaps = fEmcalTrackSelection->GetAcceptedTrackBitmaps();
159  TIter nextBitmap(trackBitmaps);
160  TBits* bits = 0;
161  Int_t i = 0;
162  while ((bits = static_cast<TBits*>(nextBitmap()))) {
163  if (i >= fTrackTypes.GetSize()) fTrackTypes.Set((i+1)*2);
164  AliVTrack* vTrack = static_cast<AliVTrack*>(fFilteredTracks->At(i));
165  if (!vTrack) {
166  fTrackTypes[i] = kRejected;
167  }
169  if (bits->FirstSetBit() == 0) {
171  }
172  else if (bits->FirstSetBit() == 1) {
173  if ((vTrack->GetStatus()&AliVTrack::kITSrefit) != 0) {
175  }
176  else {
178  }
179  }
180  }
181  i++;
182  }
183  }
184  else {
186  }
187 }
188 
189 //________________________________________________________________________
190 AliVParticle* AliParticleContainer::GetLeadingParticle(const char* opt)
191 {
192  // Get the leading particle; use p if "p" is contained in opt
193 
194  TString option(opt);
195  option.ToLower();
196 
197  Int_t tempID = fCurrentID;
198 
199  AliVParticle *partMax = GetNextAcceptParticle(0);
200  AliVParticle *part = 0;
201 
202  if (option.Contains("p")) {
203  while ((part = GetNextAcceptParticle())) {
204  if (part->P() > partMax->P()) partMax = part;
205  }
206  }
207  else {
208  while ((part = GetNextAcceptParticle())) {
209  if (part->Pt() > partMax->Pt()) partMax = part;
210  }
211  }
212 
213  fCurrentID = tempID;
214 
215  return partMax;
216 }
217 
218 //________________________________________________________________________
219 AliVParticle* AliParticleContainer::GetParticle(Int_t i) const
220 {
221  //Get i^th jet in array
222 
223  if (i == -1) i = fCurrentID;
224  if (i < 0 || i >= fFilteredTracks->GetEntriesFast()) return 0;
225  AliVParticle *vp = static_cast<AliVParticle*>(fFilteredTracks->At(i));
226  return vp;
227 }
228 
229 //________________________________________________________________________
231 {
232  //return pointer to particle if particle is accepted
233 
234  if (i == -1) i = fCurrentID;
235  if (AcceptParticle(i)) {
236  return GetParticle(i);
237  }
238  else {
239  AliDebug(2,"Particle not accepted.");
240  return 0;
241  }
242 }
243 
244 //________________________________________________________________________
245 AliVParticle* AliParticleContainer::GetParticleWithLabel(Int_t lab) const
246 {
247  //Get particle with label lab in array
248 
249  Int_t i = GetIndexFromLabel(lab);
250  return GetParticle(i);
251 }
252 
253 //________________________________________________________________________
255 {
256  //Get particle with label lab in array
257 
258  Int_t i = GetIndexFromLabel(lab);
259  return GetAcceptParticle(i);
260 }
261 
262 
263 //________________________________________________________________________
265 {
266  //Get next accepted particle; if i >= 0 (re)start counter from i; return 0 if no accepted particle could be found
267 
268  if (i >= 0) fCurrentID = i;
269 
270  const Int_t n = GetNEntries();
271 
272  AliVParticle *p = 0;
273  do {
274  fCurrentID++;
275  if (fCurrentID >= n) break;
277  } while (!p);
278 
279  return p;
280 }
281 
282 //________________________________________________________________________
284 {
285  //Get next particle; if i >= 0 (re)start counter from i; return 0 if no particle could be found
286 
287  if (i >= 0) fCurrentID = i;
288 
289  const Int_t n = GetNEntries();
290  AliVParticle *p = 0;
291  do {
292  fCurrentID++;
293  if (fCurrentID >= n) break;
294  p = GetParticle(fCurrentID);
295  } while (!p);
296 
297  return p;
298 }
299 
300 //________________________________________________________________________
301 Bool_t AliParticleContainer::GetMomentum(TLorentzVector &mom, Int_t i)
302 {
303  //Get momentum of the i^th particle in array
304 
305  if (i == -1) i = fCurrentID;
306  AliVParticle *vp = GetParticle(i);
307  if (vp) {
308  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
309  (fTrackTypes[i] == kHybridConstrained || fTrackTypes[i] == kHybridConstrainedNoITSrefit)) {
310  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
311  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), 0.139);
312  }
313  else {
314  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), 0.139);
315  }
316  return kTRUE;
317  }
318  else {
319  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
320  return kFALSE;
321  }
322 }
323 
324 //________________________________________________________________________
325 Bool_t AliParticleContainer::GetNextMomentum(TLorentzVector &mom, Int_t i)
326 {
327  //Get momentum of the i^th particle in array
328 
329  AliVParticle *vp = GetNextParticle(i);
330  if (vp) {
331  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
333  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
334  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), 0.139);
335  }
336  else {
337  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), 0.139);
338  }
339  return kTRUE;
340  }
341  else {
342  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
343  return kFALSE;
344  }
345 }
346 
347 //________________________________________________________________________
348 Bool_t AliParticleContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i)
349 {
350  //Get momentum of the i^th particle in array
351 
352  if (i == -1) i = fCurrentID;
353  AliVParticle *vp = GetAcceptParticle(i);
354  if (vp) {
355  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
356  (fTrackTypes[i] == kHybridConstrained || fTrackTypes[i] == kHybridConstrainedNoITSrefit)) {
357  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
358  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), 0.139);
359  }
360  else {
361  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), 0.139);
362  }
363 
364  return kTRUE;
365  }
366  else {
367  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
368  return kFALSE;
369  }
370 }
371 
372 //________________________________________________________________________
373 Bool_t AliParticleContainer::GetNextAcceptMomentum(TLorentzVector &mom, Int_t i)
374 {
375  //Get momentum of the i^th particle in array
376 
377  AliVParticle *vp = GetNextAcceptParticle(i);
378  if (vp) {
379  if (fLoadedClass->InheritsFrom("AliESDtrack") && fTrackFilterType == AliEmcalTrackSelection::kHybridTracks &&
381  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
382  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), 0.139);
383  }
384  else {
385  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), 0.139);
386  }
387 
388  return kTRUE;
389  }
390  else {
391  mom.SetPtEtaPhiM(0, 0, 0, 0.139);
392  return kFALSE;
393  }
394 }
395 
396 //________________________________________________________________________
397 Bool_t AliParticleContainer::AcceptParticle(AliVParticle *vp)
398 {
399  // Return true if vp is accepted.
400  Int_t id = fFilteredTracks->IndexOf(vp);
401  if (id >= 0) {
402  return AcceptParticle(id);
403  }
404  else {
405  return kFALSE;
406  }
407 }
408 
409 //________________________________________________________________________
411 {
412  // Return true if i^th particle is accepted.
413 
414  fRejectionReason = 0;
415 
416  // Cuts on the particle properties
417  AliVParticle* vp = GetParticle(i);
418 
419  if (!vp) {
421  return kFALSE;
422  }
423 
424  if (vp->TestBits(fBitMap) != (Int_t)fBitMap) {
426  return kFALSE;
427  }
428 
429  if (fMinMCLabel >= 0 && TMath::Abs(vp->GetLabel()) > fMinMCLabel) {
431  return kFALSE;
432  }
433 
434  if (fMaxMCLabel >= 0 && TMath::Abs(vp->GetLabel()) < fMaxMCLabel) {
436  return kFALSE;
437  }
438 
439  if ((vp->GetFlag() & fMCFlag) != fMCFlag) {
441  return kFALSE;
442  }
443 
444  if (fGeneratorIndex >= 0 && fGeneratorIndex != vp->GetGeneratorIndex()) {
446  return kFALSE;
447  }
448 
449  if (fCharge>=0 && fCharge != vp->Charge()) {
451  return kFALSE;
452  }
453 
454  // Cuts on the 4-momentum
455  AliTLorentzVector mom;
456  GetMomentum(mom, i);
457 
458  return ApplyKinematicCuts(mom);
459 }
460 
461 //________________________________________________________________________
462 Bool_t AliParticleContainer::ApplyKinematicCuts(const AliTLorentzVector& mom)
463 {
464  if (mom.Pt() < fParticlePtCut) {
466  return kFALSE;
467  }
468 
469  Double_t phi = mom.Phi_0_2pi() + fPhiOffset;
470 
471  if (mom.Eta() < fParticleMinEta || mom.Eta() > fParticleMaxEta ||
472  phi < fParticleMinPhi || phi > fParticleMaxPhi) {
474  return kFALSE;
475  }
476 
478  const Double_t pi = TMath::Pi();
479  const Double_t kSector = pi/9;
480  Double_t phiDist = TMath::Abs(mom.Phi() - TMath::FloorNint(mom.Phi()/kSector)*kSector);
481  if(phiDist<fMinDistanceTPCSectorEdge) {
483  return kFALSE;
484  }
485  }
486 
487  return kTRUE;
488 }
489 
490 //________________________________________________________________________
492 {
493  // Get number of accepted particles
494 
495  Int_t nPart = 0;
496 
497  AliVParticle *vp = GetNextAcceptParticle(0);
498  if(vp) nPart = 1;
499  while (GetNextAcceptParticle())
500  nPart++;
501 
502  return nPart;
503 }
504 
505 //________________________________________________________________________
506 void AliParticleContainer::SetClassName(const char *clname)
507 {
508  // Set the class name
509 
510  TClass cls(clname);
511  if (cls.InheritsFrom("AliVParticle")) fClassName = clname;
512  else AliError(Form("Unable to set class name %s for a AliParticleContainer, it must inherits from AliVParticle!",clname));
513 }
514 
515 //________________________________________________________________________
517 {
518  if (!fListOfCuts) {
519  fListOfCuts = new TObjArray;
520  fListOfCuts->SetOwner(true);
521  }
522  fListOfCuts->Add(cuts);
523 }
524 
525 //________________________________________________________________________
527 {
528  if (!fListOfCuts) return 0;
529  return fListOfCuts->GetEntries();
530 }
531 
532 //________________________________________________________________________
534 {
535  if (!fListOfCuts) return NULL;
536  if (icut < fListOfCuts->GetEntries()) {
537  return static_cast<AliVCuts *>(fListOfCuts->At(icut));
538  }
539  return NULL;
540 }
541 
542 //________________________________________________________________________
544 {
545  static TString trackString;
546 
547  if (GetParticlePtCut() == 0) {
548  trackString = TString::Format("%s_pT0000", GetArrayName().Data());
549  }
550  else if (GetParticlePtCut() < 1.0) {
551  trackString = TString::Format("%s_pT0%3.0f", GetArrayName().Data(), GetParticlePtCut()*1000.0);
552  }
553  else {
554  trackString = TString::Format("%s_pT%4.0f", GetArrayName().Data(), GetParticlePtCut()*1000.0);
555  }
556 
557  return trackString.Data();
558 }
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
const char * GetTitle() 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.
virtual 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)
Double_t GetParticlePtCut() const
const TString & GetArrayName() const
AliVParticle * GetNextParticle(Int_t i=-1)
TObjArray * GetAcceptedTracks(const TClonesArray *const tracks)
TObjArray * fFilteredTracks
track selection object
Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom)
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.