AliPhysics  32e057f (32e057f)
AliEmcalTrackSelection.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2015, 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 <TObjArray.h>
16 #include <TClonesArray.h>
17 #include "AliESDtrackCuts.h"
19 #include "AliEmcalVCutsWrapper.h"
20 #include "AliEmcalTrackSelection.h"
21 #include "AliLog.h"
22 #include "AliVCuts.h"
23 #include "AliVTrack.h"
24 #include "AliVEvent.h"
25 #include "iostream"
26 
28 ClassImp(AliEmcalManagedObject)
29 ClassImp(AliEmcalTrackSelection)
31 
33  TObject(),
34  fListOfTracks(NULL),
35  fListOfCuts(NULL),
36  fSelectionModeAny(kFALSE)
37 {
38 }
39 
41  TObject(ref),
42  fListOfTracks(NULL),
43  fListOfCuts(NULL),
44  fSelectionModeAny(kFALSE)
45 {
46  if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
47  if(ref.fListOfCuts){
48  fListOfCuts = new TObjArray;
49  fListOfCuts->SetOwner(true); // Ownership handled object-by-object by the smart pointer
50  for(auto cutIter : *(ref.fListOfCuts))
51  fListOfCuts->Add(new AliEmcalManagedObject(*(static_cast<AliEmcalManagedObject *>(cutIter))));
52  }
53 }
54 
56  TObject::operator=(ref);
57  if(this != &ref){
59  if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
60  if(ref.fListOfCuts){
61  fListOfCuts = new TObjArray;
62  fListOfCuts->SetOwner(true); // Ownership handled object-by-object by the smart pointer
63  for(auto cutIter : *(ref.fListOfCuts))
64  fListOfCuts->Add(new AliEmcalManagedObject(*(static_cast<AliEmcalManagedObject *>(cutIter))));
65  } else fListOfCuts = NULL;
66  }
67  return *this;
68 }
69 
71  if(fListOfTracks) delete fListOfTracks;
72  if(fListOfCuts) delete fListOfCuts;
73 }
74 
76  AliInfoStream() << "Adding trackc cuts " << cuts->GetName() << " of type " << cuts->IsA()->GetName() << std::endl;
77  if(!fListOfCuts){
78  fListOfCuts = new TObjArray;
79  fListOfCuts->SetOwner(true);
80  }
81  if(cuts) {
82  // Special treatment for AliESDtrackCuts:
83  // As the function IsSelected is not properly implemented for AliAODTracks
84  // a wrapper needs to be used, which handles the expected behaviour for
85  // both AliESDtracks and AliAODTracks
86  AliVCuts *mycuts = cuts;
87  if(AliESDtrackCuts *esdcuts = dynamic_cast<AliESDtrackCuts *>(cuts)) mycuts = new PWG::EMCAL::AliEmcalESDtrackCutsWrapper(esdcuts->GetName(), esdcuts);
88  // Convert to AliEmcalCutBase
90  }
91 }
92 
94  AliInfoStream() << "Adding trackc cuts " << cuts->GetName() << " of type " << cuts->IsA()->GetName() << std::endl;
95  if(!fListOfCuts){
96  fListOfCuts = new TObjArray;
97  fListOfCuts->SetOwner(true);
98  }
99  if(cuts) {
100  fListOfCuts->Add(new AliEmcalManagedObject(cuts));
101  }
102 }
103 
105  for(auto c : *cuts){
106  PWG::EMCAL::AliEmcalCutBase *emccuts = dynamic_cast<PWG::EMCAL::AliEmcalCutBase*>(c);
107  if(emccuts){
108  AddTrackCuts(emccuts);
109  } else {
110  AliVCuts *vcuts = dynamic_cast<AliVCuts *>(c);
111  if(vcuts) {
112  AddTrackCuts(vcuts);
113  } else {
114  AliErrorStream() << "Object not inheriting from AliVCuts - not added to track selection" << std::endl;
115  }
116  }
117  }
118 }
119 
121  if(!fListOfCuts) return 0;
122  return fListOfCuts->GetEntries();
123 }
124 
126  if(!fListOfCuts) return NULL;
127  if(icut < fListOfCuts->GetEntries()){
128  AliEmcalManagedObject *ptr = static_cast<AliEmcalManagedObject *>(fListOfCuts->At(icut));
129  return static_cast<PWG::EMCAL::AliEmcalCutBase *>(ptr->GetObject());
130  }
131 
132  return NULL;
133 }
134 
135 TObjArray* AliEmcalTrackSelection::GetAcceptedTracks(const TClonesArray* const tracks)
136 {
137  if (!fListOfTracks) {
138  fListOfTracks = new TObjArray;
139  fListOfTracks->SetOwner(kTRUE);
140  }
141  else {
142  fListOfTracks->Clear();
143  }
144 
145  for(auto mytrack : *tracks) {
146  fListOfTracks->AddLast(new PWG::EMCAL::AliEmcalTrackSelResultPtr(IsTrackAccepted(static_cast<AliVTrack *>(mytrack))));
147  }
148  return fListOfTracks;
149 }
150 
152 {
153  if (!fListOfTracks) {
154  fListOfTracks = new TObjArray;
155  fListOfTracks->SetOwner(kTRUE);
156  }
157  else {
158  fListOfTracks->Clear();
159  }
160 
161  for(int itrk = 0; itrk < event->GetNumberOfTracks(); itrk++){
162  fListOfTracks->AddLast(new PWG::EMCAL::AliEmcalTrackSelResultPtr(IsTrackAccepted(static_cast<AliVTrack*>(event->GetTrack(itrk)))));
163  }
164  return fListOfTracks;
165 }
166 
168  TObject(),
169  fOwner(false),
170  fManagedObject(nullptr)
171 {
172 
173 }
174 
176  TObject(),
177  fOwner(owner),
178  fManagedObject(managedObject)
179 {
180 }
181 
183  TObject(ref),
184  fOwner(false),
186 {
187 }
188 
190  TObject::operator=(ref);
191 
192  if(this != &ref){
193  Cleanup();
194  fOwner = false;
196  }
197  return *this;
198 }
199 
201  if(fManagedObject && fOwner) delete fManagedObject;
202  fManagedObject = nullptr;
203 }
Interface for virtual track selection.
AliEmcalTrackSelection & operator=(const AliEmcalTrackSelection &ref)
Assingment operator.
TObject * GetObject()
Providing access to managed object.
PWG::EMCAL::AliEmcalCutBase * GetTrackCuts(Int_t icut)
Access to track cuts at a given position.
Wrapper class handling AliVCuts as AliEmcalCutBase.
Int_t GetNumberOfCutObjects() const
Get the number of cut objects assigned.
TObjArray * fListOfCuts
List of track cut objects.
TCanvas * c
Definition: TestFitELoss.C:172
Structure containing the result of a given track selection step.
TObject * fManagedObject
Pointer to object handled by the smart pointer.
AliEmcalManagedObject()
Dummy constructor.
Bool_t fOwner
Switch defining ownership over object.
AliEmcalManagedObject & operator=(const AliEmcalManagedObject &ref)
int Int_t
Definition: External.C:63
AliEmcalTrackSelection()
Default consturctor.
void AddTrackCuts(AliVCuts *cuts)
Add new track cuts to the list of cuts.
TObjArray * fListOfTracks
TObjArray with accepted tracks.
TObjArray * GetAcceptedTracks(const TClonesArray *const tracks)
Select tracks from a TClonesArray of input tracks.
virtual PWG::EMCAL::AliEmcalTrackSelResultPtr IsTrackAccepted(AliVTrack *const trk)=0
Interface for track selection code.
virtual ~AliEmcalTrackSelection()
Destructor.
Smart pointer implementation for objects inheriting from TObject.
Interface for a cut class returning selection status and user information.
bool Bool_t
Definition: External.C:53