AliPhysics  fe039ad (fe039ad)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliTrackContainer.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 #include <bitset>
16 #include <iostream>
17 #include <TClonesArray.h>
18 
19 #include "AliAODEvent.h"
20 #include "AliESDEvent.h"
21 #include "AliVEvent.h"
22 #include "AliLog.h"
23 #include "AliVCuts.h"
24 #include "AliESDtrack.h"
25 
26 #include "AliTLorentzVector.h"
29 #include "AliTrackContainer.h"
30 
32 ClassImp(AliTrackContainer);
34 
36 
42  fTrackFilterType(AliEmcalTrackSelection::kHybridTracks),
43  fListOfCuts(0),
44  fSelectionModeAny(kFALSE),
45  fITSHybridTrackDistinction(kFALSE),
46  fAODFilterBits(0),
47  fTrackCutsPeriod(),
48  fEmcalTrackSelection(0),
49  fFilteredTracks(0),
50  fTrackTypes(5000)
51 {
52  fBaseClassName = "AliVTrack";
53  SetClassName("AliVTrack");
54  fMassHypothesis = 0.139;
55 }
56 
62 AliTrackContainer::AliTrackContainer(const char *name, const char *period):
64  fTrackFilterType(AliEmcalTrackSelection::kHybridTracks),
65  fListOfCuts(0),
66  fSelectionModeAny(kFALSE),
67  fITSHybridTrackDistinction(kFALSE),
68  fAODFilterBits(0),
69  fTrackCutsPeriod(period),
70  fEmcalTrackSelection(0),
71  fFilteredTracks(0),
72  fTrackTypes(5000)
73 {
74  fBaseClassName = "AliVTrack";
75  SetClassName("AliVTrack");
76 
77  if (fTrackCutsPeriod.IsNull() && !AliTrackContainer::fgDefTrackCutsPeriod.IsNull()) {
78  AliInfo(Form("Default track cuts period is %s", AliTrackContainer::fgDefTrackCutsPeriod.Data()));
80  }
81  fMassHypothesis = 0.139;
82 }
83 
90 void AliTrackContainer::SetArray(const AliVEvent *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 
156 void AliTrackContainer::NextEvent(const AliVEvent * event)
157 {
158  AliParticleContainer::NextEvent(event);
159 
160  fTrackTypes.Reset(kUndefined);
161  if (fEmcalTrackSelection) {
163 
164  const TClonesArray* trackBitmaps = fEmcalTrackSelection->GetAcceptedTrackBitmaps();
165  AliDebugStream(1) << "AliTrackContainer: Found Array with " << trackBitmaps->GetEntries() << " Tracks" << std::endl;
166  int naccepted(0), nrejected(0), nhybridTracks1(0), nhybridTracks2(0), nhybridTracks3(0);
167  TIter nextBitmap(trackBitmaps);
168  TBits* bits = 0;
169  Int_t i = 0;
170  while ((bits = static_cast<TBits*>(nextBitmap()))) {
171  if (i >= fTrackTypes.GetSize()) fTrackTypes.Set((i+1)*2);
172  AliVTrack* vTrack = static_cast<AliVTrack*>(fFilteredTracks->At(i));
173  if (!vTrack) {
174  nrejected++;
175  fTrackTypes[i] = kRejected;
176  }
177  else{
178  // track is accepted;
179  naccepted++;
180  if (IsHybridTrackSelection()) {
181  // Use determination based on ITS information
183  std::bitset<8> itsbits(vTrack->GetITSClusterMap());
184  auto hasSPD = (itsbits.test(0) || itsbits.test(1));
185  if(hasSPD) {
187  nhybridTracks1++;
188  }
189  else {
190  if(vTrack->GetStatus() & AliVTrack::kITSrefit){
192  nhybridTracks2++;
193  }
194  else {
196  nhybridTracks3++;
197  }
198  }
199  } else {
200  // Legacy code - to be removed soon
201  if (bits->FirstSetBit() == 0) {
203  nhybridTracks1++;
204  }
205  else if (bits->FirstSetBit() == 1) {
206  if ((vTrack->GetStatus()&AliVTrack::kITSrefit) != 0) {
208  nhybridTracks2++;
209  }
210  else {
212  nhybridTracks3++;
213  }
214  }
215  }
216  }
217  }
218  i++;
219  }
220  AliDebugStream(1) << "Accepted: " << naccepted << ", Rejected: " << nrejected << ", hybrid: (" << nhybridTracks1 << " | " << nhybridTracks2 << " | " << nhybridTracks3 << ")" << std::endl;
221  }
222  else {
223  fFilteredTracks = fClArray;
224  }
225 }
226 
233 {
234  //Get i^th jet in array
235 
236  if (i < 0 || i >= fFilteredTracks->GetEntriesFast()) return 0;
237  AliVTrack *vp = static_cast<AliVTrack*>(fFilteredTracks->At(i));
238  return vp;
239 }
240 
247 {
248  UInt_t rejectionReason;
249  if (i == -1) i = fCurrentID;
250  if (AcceptTrack(i, rejectionReason)) {
251  return GetTrack(i);
252  }
253  else {
254  AliDebug(2,"Track not accepted.");
255  return 0;
256  }
257 }
258 
265 {
266  const Int_t n = GetNEntries();
267  AliVTrack *p = 0;
268  do {
269  fCurrentID++;
270  if (fCurrentID >= n) break;
271  p = GetAcceptTrack(fCurrentID);
272  } while (!p);
273 
274  return p;
275 }
276 
283 {
284  const Int_t n = GetNEntries();
285  AliVTrack *p = 0;
286  do {
287  fCurrentID++;
288  if (fCurrentID >= n) break;
289  p = GetTrack(fCurrentID);
290  } while (!p);
291 
292  return p;
293 }
294 
301 Char_t AliTrackContainer::GetTrackType(const AliVTrack* track) const
302 {
303  Int_t id = fFilteredTracks->IndexOf(track);
304  if (id >= 0) {
305  return fTrackTypes[id];
306  }
307  else {
308  return kUndefined;
309  }
310 }
311 
321 Bool_t AliTrackContainer::GetMomentumFromTrack(TLorentzVector &mom, const AliVTrack* track, Double_t mass) const
322 {
323  if (track) {
324  if (mass < 0) mass = track->M();
325 
326  Bool_t useConstrainedParams = kFALSE;
327  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection()) {
328  Char_t trackType = GetTrackType(track);
329  if (trackType == kHybridConstrained || trackType == kHybridConstrainedNoITSrefit) {
330  AliDebugStream(2) << "Found a constrained track" << std::endl;
331  useConstrainedParams = kTRUE;
332  }
333  }
334 
335  if (useConstrainedParams) {
336  const AliESDtrack *esdtrack = static_cast<const AliESDtrack*>(track);
337  mom.SetPtEtaPhiM(esdtrack->GetConstrainedParam()->Pt(), esdtrack->GetConstrainedParam()->Eta(), esdtrack->GetConstrainedParam()->Phi(), mass);
338  }
339  else {
340  mom.SetPtEtaPhiM(track->Pt(), track->Eta(), track->Phi(), mass);
341  }
342  return kTRUE;
343  }
344  else {
345  mom.SetPtEtaPhiM(0, 0, 0, 0);
346  return kFALSE;
347  }
348 }
349 
357 Bool_t AliTrackContainer::GetMomentumFromTrack(TLorentzVector &mom, const AliVTrack* part) const
358 {
359  return GetMomentumFromTrack(mom,part,fMassHypothesis);
360 }
361 
371 Bool_t AliTrackContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
372 {
373  Double_t mass = fMassHypothesis;
374 
375  if (i == -1) i = fCurrentID;
376  AliVTrack *vp = GetTrack(i);
377  if (vp) {
378  if (mass < 0) mass = vp->M();
379 
380  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection() &&
382  AliDebugStream(2) << "Found a constrained track" << std::endl;
383  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
384  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
385  }
386  else {
387  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
388  }
389  return kTRUE;
390  }
391  else {
392  mom.SetPtEtaPhiM(0, 0, 0, 0);
393  return kFALSE;
394  }
395 }
396 
407 {
408  Double_t mass = fMassHypothesis;
409 
410  AliVTrack *vp = GetNextTrack();
411  if (vp) {
412  if (mass < 0) mass = vp->M();
413 
414  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection() &&
415  (fTrackTypes[fCurrentID] == kHybridConstrained || fTrackTypes[fCurrentID] == kHybridConstrainedNoITSrefit)) {
416  AliDebugStream(2) << "Found a constrained track" << std::endl;
417  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
418  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
419  }
420  else {
421  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
422  }
423  return kTRUE;
424  }
425  else {
426  mom.SetPtEtaPhiM(0, 0, 0, 0);
427  return kFALSE;
428  }
429 }
430 
441 Bool_t AliTrackContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
442 {
443 
444  Double_t mass = fMassHypothesis;
445 
446  if (i == -1) i = fCurrentID;
447  AliVTrack *vp = GetAcceptTrack(i);
448  if (vp) {
449  if (mass < 0) mass = vp->M();
450 
451  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection() &&
453  AliDebugStream(2) << "Found a constrained track" << std::endl;
454  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
455  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
456  }
457  else {
458  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
459  }
460 
461  return kTRUE;
462  }
463  else {
464  mom.SetPtEtaPhiM(0, 0, 0, 0);
465  return kFALSE;
466  }
467 }
468 
479 {
480  Double_t mass = fMassHypothesis;
481 
482  AliVTrack *vp = GetNextAcceptTrack();
483  if (vp) {
484  if (mass < 0) mass = vp->M();
485 
486  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection() &&
487  (fTrackTypes[fCurrentID] == kHybridConstrained || fTrackTypes[fCurrentID] == kHybridConstrainedNoITSrefit)) {
488  AliDebugStream(2) << "Found a constrained track" << std::endl;
489  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
490  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
491  }
492  else {
493  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
494  }
495 
496  return kTRUE;
497  }
498  else {
499  mom.SetPtEtaPhiM(0, 0, 0, 0);
500  return kFALSE;
501  }
502 }
503 
514 Bool_t AliTrackContainer::AcceptTrack(const AliVTrack *vp, UInt_t &rejectionReason) const
515 {
516  Bool_t r = ApplyTrackCuts(vp, rejectionReason);
517  if (!r) return kFALSE;
518 
519  AliTLorentzVector mom;
520  if(!GetMomentumFromTrack(mom, vp)) return false;
521 
522  return ApplyKinematicCuts(mom, rejectionReason);
523 }
524 
537 {
538  Bool_t r = ApplyTrackCuts(GetTrack(i), rejectionReason);
539  if (!r) return kFALSE;
540 
541  AliTLorentzVector mom;
542  if(!GetMomentum(mom, i)) return false;
543 
544  return ApplyKinematicCuts(mom, rejectionReason);
545 }
546 
556 Bool_t AliTrackContainer::ApplyTrackCuts(const AliVTrack* vp, UInt_t &rejectionReason) const
557 {
558  return ApplyParticleCuts(vp, rejectionReason);
559 }
560 
566 {
567  if (!fListOfCuts) {
568  fListOfCuts = new TObjArray;
569  fListOfCuts->SetOwner(true);
570  }
571  fListOfCuts->Add(cuts);
572 }
573 
579 {
580  if (!fListOfCuts) return 0;
581  return fListOfCuts->GetEntries();
582 }
583 
590 {
591  if (!fListOfCuts) return NULL;
592  if (icut < fListOfCuts->GetEntries()) {
593  return static_cast<AliVCuts *>(fListOfCuts->At(icut));
594  }
595  return NULL;
596 }
597 
604 }
605 
612  return AliTrackIterableContainer(this, false);
613 }
614 
621  return AliTrackIterableContainer(this, true);
622 }
623 
630  return AliTrackIterableMomentumContainer(this, false);
631 }
632 
639  return AliTrackIterableMomentumContainer(this, true);
640 }
641 
648 const char* AliTrackContainer::GetTitle() const
649 {
650  static TString trackString;
651  trackString = TString::Format("%s_pT%04d", GetArrayName().Data(), static_cast<int>(GetMinPt()*1000.0));
652  return trackString.Data();
653 }
654 
655 TString AliTrackContainer::GetDefaultArrayName(const AliVEvent *const ev) const {
656  if(ev->IsA() == AliAODEvent::Class()) return "tracks";
657  else if(ev->IsA() == AliESDEvent::Class()) return "Tracks";
658  else return "";
659 }
Interface for virtual track selection.
double Double_t
Definition: External.C:58
TObjArray * fFilteredTracks
! tracks filtered using fEmcalTrackSelection
void SetArray(const AliVEvent *event)
static TString fgDefTrackCutsPeriod
! default period string used to generate track cuts
const AliTrackIterableContainer accepted() const
Double_t mass
Container with name, TClonesArray and cuts for particles.
EMCALIterableContainer::AliEmcalIterableContainerT< AliVTrack, EMCALIterableContainer::operator_star_object< AliVTrack > > AliTrackIterableContainer
Declaration of class AliTLorentzVector.
char Char_t
Definition: External.C:18
Track selected under the constrained hybrid track cuts.
virtual Bool_t ApplyParticleCuts(const AliVParticle *vp, UInt_t &rejectionReason) const
UInt_t fAODFilterBits
track filter bits
const TClonesArray * GetAcceptedTrackBitmaps() const
void NextEvent(const AliVEvent *event)
const AliTrackIterableContainer all() const
void SetSelectionModeAny()
Set selection mode to any.
AliVCuts * GetTrackCuts(Int_t icut)
virtual Bool_t GetNextMomentum(TLorentzVector &mom)
AliEmcalTrackSelection * fEmcalTrackSelection
! track selection object
virtual Bool_t GetMomentum(TLorentzVector &mom, Int_t i) const
ETrackFilterType_t fTrackFilterType
track filter type
TString fTrackCutsPeriod
period string used to generate track cuts
Container for particles within the EMCAL framework.
Track selected under the constrained hybrid track cuts without ITS refit.
Bool_t fITSHybridTrackDistinction
Distinct hybrid tracks via SPD information.
Hybrid tracks using the 2011 definition including NoITSrefit tracks (ESD-only)
virtual Bool_t GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
virtual Bool_t GetMomentumFromTrack(TLorentzVector &mom, const AliVTrack *track, Double_t mass) const
Hybrid tracks using the 2010 definition including NoITSrefit tracks (ESD-only)
virtual Bool_t ApplyTrackCuts(const AliVTrack *vp, UInt_t &rejectionReason) const
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
EMCALIterableContainer::AliEmcalIterableContainerT< AliVTrack, EMCALIterableContainer::operator_star_pair< AliVTrack > > AliTrackIterableMomentumContainer
virtual Bool_t AcceptTrack(const AliVTrack *vp, UInt_t &rejectionReason) const
Hybrid tracks using the 2010 definition excluding NoITSrefit tracks (ESD-only)
Int_t GetNumberOfCutObjects() const
TArrayC fTrackTypes
! track types
Hybrid tracks using the 2011 definition excluding NoITSrefit tracks (ESD-only)
TObjArray * fListOfCuts
list of track cut objects
void AddTrackCuts(AliVCuts *cuts)
Add new track cuts to the list of cuts.
Implement virtual track selection for AOD analysis.
virtual AliVTrack * GetNextTrack()
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)
Bool_t fSelectionModeAny
accept track if any of the cuts is fulfilled
virtual AliVTrack * GetTrack(Int_t i=-1) const
Track selected under the global hybrid track cuts.
TObjArray * GetAcceptedTracks(const TClonesArray *const tracks)
Select tracks from a TClonesArray of input tracks.
virtual AliVTrack * GetNextAcceptTrack()
Char_t GetTrackType(const AliVTrack *track) const
void AddTrackCuts(AliVCuts *cuts)
virtual TString GetDefaultArrayName(const AliVEvent *const ev) const
void SetArray(const AliVEvent *event)
virtual AliVTrack * GetAcceptTrack(Int_t i=-1) const
virtual Bool_t GetNextAcceptMomentum(TLorentzVector &mom)
void SetSelectionModeAll()
Set selection mode to all.
const AliTrackIterableMomentumContainer accepted_momentum() const
const char * GetTitle() const
virtual Bool_t ApplyKinematicCuts(const AliTLorentzVector &mom, UInt_t &rejectionReason) const
bool Bool_t
Definition: External.C:53
Implementation of virtual track selection for ESDs.
Track status undefined.
const AliTrackIterableMomentumContainer all_momentum() const
Bool_t IsHybridTrackSelection() const