AliPhysics  4ef2867 (4ef2867)
 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) 2017, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
27 #include <bitset>
28 #include <iostream>
29 #include <TClonesArray.h>
30 
31 #include "AliAODEvent.h"
32 #include "AliESDEvent.h"
33 #include "AliVEvent.h"
34 #include "AliLog.h"
35 #include "AliVCuts.h"
36 #include "AliESDtrack.h"
37 
38 #include "AliTLorentzVector.h"
44 #include "AliTrackContainer.h"
45 
47 ClassImp(AliTrackContainer);
49 
51 
57  fTrackFilterType(AliEmcalTrackSelection::kHybridTracks),
58  fListOfCuts(0),
59  fSelectionModeAny(kFALSE),
60  fITSHybridTrackDistinction(kFALSE),
61  fAODFilterBits(0),
62  fTrackCutsPeriod(),
63  fEmcalTrackSelection(0),
64  fFilteredTracks(),
65  fTrackTypes(5000)
66 {
67  fBaseClassName = "AliVTrack";
68  SetClassName("AliVTrack");
69  fMassHypothesis = 0.139;
70 }
71 
77 AliTrackContainer::AliTrackContainer(const char *name, const char *period):
79  fTrackFilterType(AliEmcalTrackSelection::kHybridTracks),
80  fListOfCuts(0),
81  fSelectionModeAny(kFALSE),
82  fITSHybridTrackDistinction(kFALSE),
83  fAODFilterBits(0),
84  fTrackCutsPeriod(period),
85  fEmcalTrackSelection(0),
86  fFilteredTracks(),
87  fTrackTypes(5000)
88 {
89  fBaseClassName = "AliVTrack";
90  SetClassName("AliVTrack");
91 
92  if (fTrackCutsPeriod.IsNull() && !AliTrackContainer::fgDefTrackCutsPeriod.IsNull()) {
93  AliInfo(Form("Default track cuts period is %s", AliTrackContainer::fgDefTrackCutsPeriod.Data()));
95  }
96  fMassHypothesis = 0.139;
97 }
98 
105 void AliTrackContainer::SetArray(const AliVEvent *event)
106 {
108 
112  }
113  else {
115 
116  AliInfo("Using custom track cuts");
117 
118  if (fLoadedClass) {
119  if (fLoadedClass->InheritsFrom("AliAODTrack")) {
120  AliInfo(Form("Objects are of type %s: AOD track selection will be done.", fLoadedClass->GetName()));
122  }
123  else if (fLoadedClass->InheritsFrom("AliESDtrack")) {
124  AliInfo(Form("Objects are of type %s: ESD track selection will be done.", fLoadedClass->GetName()));
126  }
127  else {
128  AliWarning(Form("Objects are of type %s: no track filtering will be done!!", fLoadedClass->GetName()));
129  }
130  }
131 
132  if (fEmcalTrackSelection) {
133  if (fSelectionModeAny) {
135  }
136  else {
138  }
139 
141  }
142  }
143  else {
144  if (!fTrackCutsPeriod.IsNull()) {
145  AliInfo(Form("Using track cuts %d for period %s", fTrackFilterType, fTrackCutsPeriod.Data()));
146  }
147  else {
148  AliInfo(Form("Using track cuts %d (no data period was provided!)", fTrackFilterType));
149  }
150 
151  if (fLoadedClass->InheritsFrom("AliAODTrack")) {
152  AliInfo(Form("Objects are of type %s: AOD track selection will be done.", fLoadedClass->GetName()));
154  }
155  else if (fLoadedClass->InheritsFrom("AliESDtrack")) {
156  AliInfo(Form("Objects are of type %s: ESD track selection will be done.", fLoadedClass->GetName()));
158  }
159  else {
160  AliWarning(Form("Objects are of type %s: no track filtering will be done!!", fLoadedClass->GetName()));
161  }
162  }
163  }
164 }
165 
171 void AliTrackContainer::NextEvent(const AliVEvent * event)
172 {
173  AliParticleContainer::NextEvent(event);
174 
175  fTrackTypes.Reset(kUndefined);
176  if (fEmcalTrackSelection) {
177  auto acceptedTracks = fEmcalTrackSelection->GetAcceptedTracks(fClArray);
178 
179  TObjArray *trackarray(fFilteredTracks.GetData());
180  if(!trackarray){
181  trackarray = new TObjArray;
182  trackarray->SetOwner(false);
183  fFilteredTracks.SetObject(trackarray);
185  } else {
186  trackarray->Clear();
187  }
188 
189  int naccepted(0), nrejected(0), nhybridTracks1(0), nhybridTracks2(0), nhybridTracks3(0);
190  Int_t i = 0;
191  for(auto accresult : *acceptedTracks) {
192  if (i >= fTrackTypes.GetSize()) fTrackTypes.Set((i+1)*2);
193  PWG::EMCAL::AliEmcalTrackSelResultPtr *selectionResult = static_cast<PWG::EMCAL::AliEmcalTrackSelResultPtr *>(accresult);
194  AliVTrack *vTrack = selectionResult->GetTrack();
195  trackarray->AddLast(vTrack);
196  if (!(*selectionResult) || !vTrack) {
197  nrejected++;
198  fTrackTypes[i] = kRejected;
199  }
200  else{
201  // track is accepted;
202  naccepted++;
203  if (IsHybridTrackSelection()) {
204  switch(GetHybridDefinition(*selectionResult)) {
207  nhybridTracks1++;
208  break;
211  nhybridTracks2++;
212  break;
215  nhybridTracks3++;
216  break;
218  fTrackTypes[i] = kRejected; // should in principle never happen
219  break;
220  };
221  }
222  }
223  i++;
224  }
225  AliDebugStream(1) << "Accepted: " << naccepted << ", Rejected: " << nrejected << ", hybrid: (" << nhybridTracks1 << " | " << nhybridTracks2 << " | " << nhybridTracks3 << ")" << std::endl;
226  }
227  else {
228  fFilteredTracks.SetOwner(false);
229  fFilteredTracks.SetObject(fClArray);
230  }
231 }
232 
239 {
240  //Get i^th jet in array
241 
242  if (i < 0 || i >= fFilteredTracks.GetData()->GetEntriesFast()) return 0;
243  AliVTrack *vp = static_cast<AliVTrack*>(fFilteredTracks.GetData()->At(i));
244  return vp;
245 }
246 
253 {
254  UInt_t rejectionReason;
255  if (i == -1) i = fCurrentID;
256  if (AcceptTrack(i, rejectionReason)) {
257  return GetTrack(i);
258  }
259  else {
260  AliDebug(2,"Track not accepted.");
261  return 0;
262  }
263 }
264 
271 {
272  const Int_t n = GetNEntries();
273  AliVTrack *p = 0;
274  do {
275  fCurrentID++;
276  if (fCurrentID >= n) break;
277  p = GetAcceptTrack(fCurrentID);
278  } while (!p);
279 
280  return p;
281 }
282 
289 {
290  const Int_t n = GetNEntries();
291  AliVTrack *p = 0;
292  do {
293  fCurrentID++;
294  if (fCurrentID >= n) break;
295  p = GetTrack(fCurrentID);
296  } while (!p);
297 
298  return p;
299 }
300 
307 Char_t AliTrackContainer::GetTrackType(const AliVTrack* track) const
308 {
309  Int_t id = fFilteredTracks.GetData()->IndexOf(track);
310  if (id >= 0) {
311  return fTrackTypes[id];
312  }
313  else {
314  return kUndefined;
315  }
316 }
317 
327 Bool_t AliTrackContainer::GetMomentumFromTrack(TLorentzVector &mom, const AliVTrack* track, Double_t mass) const
328 {
329  if (track) {
330  if (mass < 0) mass = track->M();
331 
332  Bool_t useConstrainedParams = kFALSE;
333  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection()) {
334  Char_t trackType = GetTrackType(track);
335  if (trackType == kHybridConstrained || trackType == kHybridConstrainedNoITSrefit) {
336  AliDebugStream(2) << "Found a constrained track" << std::endl;
337  useConstrainedParams = kTRUE;
338  }
339  }
340 
341  if (useConstrainedParams) {
342  const AliESDtrack *esdtrack = static_cast<const AliESDtrack*>(track);
343  mom.SetPtEtaPhiM(esdtrack->GetConstrainedParam()->Pt(), esdtrack->GetConstrainedParam()->Eta(), esdtrack->GetConstrainedParam()->Phi(), mass);
344  }
345  else {
346  mom.SetPtEtaPhiM(track->Pt(), track->Eta(), track->Phi(), mass);
347  }
348  return kTRUE;
349  }
350  else {
351  mom.SetPtEtaPhiM(0, 0, 0, 0);
352  return kFALSE;
353  }
354 }
355 
363 Bool_t AliTrackContainer::GetMomentumFromTrack(TLorentzVector &mom, const AliVTrack* part) const
364 {
365  return GetMomentumFromTrack(mom,part,fMassHypothesis);
366 }
367 
377 Bool_t AliTrackContainer::GetMomentum(TLorentzVector &mom, Int_t i) const
378 {
379  Double_t mass = fMassHypothesis;
380 
381  if (i == -1) i = fCurrentID;
382  AliVTrack *vp = GetTrack(i);
383  if (vp) {
384  if (mass < 0) mass = vp->M();
385 
386  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection() &&
388  AliDebugStream(2) << "Found a constrained track" << std::endl;
389  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
390  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
391  }
392  else {
393  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
394  }
395  return kTRUE;
396  }
397  else {
398  mom.SetPtEtaPhiM(0, 0, 0, 0);
399  return kFALSE;
400  }
401 }
402 
413 {
414  Double_t mass = fMassHypothesis;
415 
416  AliVTrack *vp = GetNextTrack();
417  if (vp) {
418  if (mass < 0) mass = vp->M();
419 
420  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection() &&
421  (fTrackTypes[fCurrentID] == kHybridConstrained || fTrackTypes[fCurrentID] == kHybridConstrainedNoITSrefit)) {
422  AliDebugStream(2) << "Found a constrained track" << std::endl;
423  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
424  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
425  }
426  else {
427  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
428  }
429  return kTRUE;
430  }
431  else {
432  mom.SetPtEtaPhiM(0, 0, 0, 0);
433  return kFALSE;
434  }
435 }
436 
447 Bool_t AliTrackContainer::GetAcceptMomentum(TLorentzVector &mom, Int_t i) const
448 {
449 
450  Double_t mass = fMassHypothesis;
451 
452  if (i == -1) i = fCurrentID;
453  AliVTrack *vp = GetAcceptTrack(i);
454  if (vp) {
455  if (mass < 0) mass = vp->M();
456 
457  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection() &&
459  AliDebugStream(2) << "Found a constrained track" << std::endl;
460  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
461  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
462  }
463  else {
464  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
465  }
466 
467  return kTRUE;
468  }
469  else {
470  mom.SetPtEtaPhiM(0, 0, 0, 0);
471  return kFALSE;
472  }
473 }
474 
485 {
486  Double_t mass = fMassHypothesis;
487 
488  AliVTrack *vp = GetNextAcceptTrack();
489  if (vp) {
490  if (mass < 0) mass = vp->M();
491 
492  if (fLoadedClass->InheritsFrom("AliESDtrack") && IsHybridTrackSelection() &&
493  (fTrackTypes[fCurrentID] == kHybridConstrained || fTrackTypes[fCurrentID] == kHybridConstrainedNoITSrefit)) {
494  AliDebugStream(2) << "Found a constrained track" << std::endl;
495  AliESDtrack *track = static_cast<AliESDtrack*>(vp);
496  mom.SetPtEtaPhiM(track->GetConstrainedParam()->Pt(), track->GetConstrainedParam()->Eta(), track->GetConstrainedParam()->Phi(), mass);
497  }
498  else {
499  mom.SetPtEtaPhiM(vp->Pt(), vp->Eta(), vp->Phi(), mass);
500  }
501 
502  return kTRUE;
503  }
504  else {
505  mom.SetPtEtaPhiM(0, 0, 0, 0);
506  return kFALSE;
507  }
508 }
509 
520 Bool_t AliTrackContainer::AcceptTrack(const AliVTrack *vp, UInt_t &rejectionReason) const
521 {
522  Bool_t r = ApplyTrackCuts(vp, rejectionReason);
523  if (!r) return kFALSE;
524 
525  AliTLorentzVector mom;
526  if(!GetMomentumFromTrack(mom, vp)) return false;
527 
528  return ApplyKinematicCuts(mom, rejectionReason);
529 }
530 
543 {
544  Bool_t r = ApplyTrackCuts(GetTrack(i), rejectionReason);
545  if (!r) return kFALSE;
546 
547  AliTLorentzVector mom;
548  if(!GetMomentum(mom, i)) return false;
549 
550  return ApplyKinematicCuts(mom, rejectionReason);
551 }
552 
562 Bool_t AliTrackContainer::ApplyTrackCuts(const AliVTrack* vp, UInt_t &rejectionReason) const
563 {
564  return ApplyParticleCuts(vp, rejectionReason);
565 }
566 
572 {
573  if (!fListOfCuts) {
574  fListOfCuts = new TObjArray;
575  fListOfCuts->SetOwner(true);
576  }
577  fListOfCuts->Add(cuts);
578 }
579 
585 {
586  if (!fListOfCuts) return 0;
587  return fListOfCuts->GetEntries();
588 }
589 
596 {
597  if (!fListOfCuts) return NULL;
598  if (icut < fListOfCuts->GetEntries()) {
599  return static_cast<AliVCuts *>(fListOfCuts->At(icut));
600  }
601  return NULL;
602 }
603 
610 }
611 
614  if(auto hybriddata = dynamic_cast<const PWG::EMCAL::AliEmcalTrackSelResultHybrid *>(selectionResult.GetUserInfo())) {
615  hybridDefinition = hybriddata->GetHybridTrackType();
616  } else {
617  if(auto combineddata = dynamic_cast<const PWG::EMCAL::AliEmcalTrackSelResultCombined *>(selectionResult.GetUserInfo())){
618  for(int icut = 0; icut < combineddata->GetNumberOfSelectionResults(); icut++){
619  auto cutresult = GetHybridDefinition((*combineddata)[icut]);
620  if(cutresult != PWG::EMCAL::AliEmcalTrackSelResultHybrid::kUndefined) hybridDefinition = cutresult;
621  }
622  }
623  }
624  return hybridDefinition;
625 }
626 
633  return AliTrackIterableContainer(this, false);
634 }
635 
642  return AliTrackIterableContainer(this, true);
643 }
644 
651  return AliTrackIterableMomentumContainer(this, false);
652 }
653 
660  return AliTrackIterableMomentumContainer(this, true);
661 }
662 
669 const char* AliTrackContainer::GetTitle() const
670 {
671  static TString trackString;
672  trackString = TString::Format("%s_pT%04d", GetArrayName().Data(), static_cast<int>(GetMinPt()*1000.0));
673  return trackString.Data();
674 }
675 
676 TString AliTrackContainer::GetDefaultArrayName(const AliVEvent *const ev) const {
677  if(ev->IsA() == AliAODEvent::Class()) return "tracks";
678  else if(ev->IsA() == AliESDEvent::Class()) return "Tracks";
679  else return "";
680 }
681 
683  TObject(),
684  fManagedObject(nullptr),
685  fOwnership(false)
686 {
687 
688 }
689 
691  TObject(),
692  fManagedObject(managedobject),
693  fOwnership(ownership)
694 {
695 
696 }
697 
699  TObject(other),
700  fManagedObject(other.fManagedObject),
701  fOwnership(false)
702 {
703 
704 }
705 
707  TObject::operator=(other);
708  if(this != &other) {
709  if(fOwnership && fManagedObject) delete fManagedObject;
710  fManagedObject = other.fManagedObject;
711  fOwnership = false;
712  }
713  return *this;
714 }
715 
717  if(fOwnership && fManagedObject) delete fManagedObject;
718 }
719 
721  if(fOwnership && fManagedObject) delete fManagedObject;
722  fManagedObject = obj;
723 }
724 
726  fOwnership = owner;
727 }
728 
730  if(fOwnership) target.SetOwner(fOwnership);
731  fOwnership = false;
732 }
733 
735  if(source.IsOwner()) {
736  fOwnership = true;
737  source.SetOwner(false);
738  }
739 }
Interface for virtual track selection.
double Double_t
Definition: External.C:58
void SetArray(const AliVEvent *event)
static TString fgDefTrackCutsPeriod
! default period string used to generate track cuts
const AliTrackIterableContainer accepted() const
Double_t mass
TrackOwnerHandler & operator=(const TrackOwnerHandler &other)
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
void NextEvent(const AliVEvent *event)
Structure containing the result of a given track selection step.
const AliTrackIterableContainer all() const
void ReceiveOwnershipFrom(TrackOwnerHandler &source)
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.
PWG::EMCAL::AliEmcalTrackSelResultHybrid::HybridType_t GetHybridDefinition(const PWG::EMCAL::AliEmcalTrackSelResultPtr &selectionResult) const
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)
TrackOwnerHandler fFilteredTracks
! tracks filtered using fEmcalTrackSelection
virtual Bool_t ApplyTrackCuts(const AliVTrack *vp, UInt_t &rejectionReason) const
int Int_t
Definition: External.C:63
TObjArray * fManagedObject
Object managed by the handler.
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
void TransferOwnershipTo(TrackOwnerHandler &target)
Unique_ptr implementation for ROOT5 compatibility.
Implementation of virtual track selection for ESDs.
Track status undefined.
const AliTrackIterableMomentumContainer all_momentum() const
Bool_t IsHybridTrackSelection() const