AliPhysics  58f3d52 (58f3d52)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <AliEmcalTrackSelection.h>
16 #include <TObjArray.h>
17 #include <TClonesArray.h>
18 #include <AliESDtrackCuts.h>
20 #include <AliLog.h>
21 #include <AliVCuts.h>
22 #include <AliVTrack.h>
23 #include <AliVEvent.h>
24 #include <iostream>
25 
27 ClassImp(AliEmcalManagedObject)
28 ClassImp(AliEmcalTrackSelection)
30 
32  TObject(),
33  fListOfTracks(NULL),
34  fListOfTrackBitmaps(NULL),
35  fTrackBitmap(64),
36  fListOfCuts(NULL),
37  fSelectionModeAny(kFALSE)
38 {
39 }
40 
42  TObject(ref),
43  fListOfTracks(NULL),
44  fListOfTrackBitmaps(NULL),
45  fTrackBitmap(64),
46  fListOfCuts(NULL),
47  fSelectionModeAny(kFALSE)
48 {
49  if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
50  if(ref.fListOfTrackBitmaps) fListOfTrackBitmaps = new TClonesArray(*(ref.fListOfTrackBitmaps));
51  if(ref.fListOfCuts){
52  fListOfCuts = new TObjArray;
53  fListOfCuts->SetOwner(true); // Ownership handled object-by-object by the smart pointer
54  for(auto cutIter : *(ref.fListOfCuts))
55  fListOfCuts->Add(new AliEmcalManagedObject(*(static_cast<AliEmcalManagedObject *>(cutIter))));
56  }
57 }
58 
60  TObject::operator=(ref);
61  if(this != &ref){
63  if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
64  if(ref.fListOfTrackBitmaps) fListOfTrackBitmaps = new TClonesArray(*(ref.fListOfTrackBitmaps));
65  if(ref.fListOfCuts){
66  fListOfCuts = new TObjArray;
67  fListOfCuts->SetOwner(true); // Ownership handled object-by-object by the smart pointer
68  for(auto cutIter : *(ref.fListOfCuts))
69  fListOfCuts->Add(new AliEmcalManagedObject(*(static_cast<AliEmcalManagedObject *>(cutIter))));
70  } else fListOfCuts = NULL;
71  }
72  return *this;
73 }
74 
76  if(fListOfTracks) delete fListOfTracks;
78  if(fListOfCuts) delete fListOfCuts;
79 }
80 
82  AliInfoStream() << "Adding trackc cuts " << cuts->GetName() << " of type " << cuts->IsA()->GetName() << std::endl;
83  if(!fListOfCuts){
84  fListOfCuts = new TObjArray;
85  fListOfCuts->SetOwner(true);
86  }
87  if(cuts) {
88  // Special treatment for AliESDtrackCuts:
89  // As the function IsSelected is not properly implemented for AliAODTracks
90  // a wrapper needs to be used, which handles the expected behaviour for
91  // both AliESDtracks and AliAODTracks
92  AliVCuts *mycuts = cuts;
93  if(AliESDtrackCuts *esdcuts = dynamic_cast<AliESDtrackCuts *>(cuts)) mycuts = new PWG::EMCAL::AliEmcalESDtrackCutsWrapper(esdcuts->GetName(), esdcuts);
94  fListOfCuts->Add(new AliEmcalManagedObject(mycuts, true));
95  }
96 }
97 
99  for(auto c : *cuts){
100  AliVCuts *cuts = dynamic_cast<AliVCuts*>(c);
101  if(cuts){
102  AddTrackCuts(cuts);
103  } else {
104  AliErrorStream() << "Object not inheriting from AliVCuts - not added to track selection" << std::endl;
105  }
106  }
107 }
108 
110  if(!fListOfCuts) return 0;
111  return fListOfCuts->GetEntries();
112 }
113 
115  if(!fListOfCuts) return NULL;
116  if(icut < fListOfCuts->GetEntries()){
117  AliEmcalManagedObject *ptr = static_cast<AliEmcalManagedObject *>(fListOfCuts->At(icut));
118  return static_cast<AliVCuts *>(ptr->GetObject());
119  }
120 
121  return NULL;
122 }
123 
124 TObjArray* AliEmcalTrackSelection::GetAcceptedTracks(const TClonesArray* const tracks)
125 {
126  if (!fListOfTracks) {
127  fListOfTracks = new TObjArray;
128  }
129  else {
130  fListOfTracks->Clear();
131  }
132 
133  if (!fListOfTrackBitmaps) {
134  fListOfTrackBitmaps = new TClonesArray("TBits", 1000);
135  fListOfTrackBitmaps->SetOwner(kTRUE);
136  }
137  else {
138  fListOfTrackBitmaps->Delete();
139  }
140 
141  TIter next(tracks);
142  AliVTrack* track = 0;
143  Int_t i = 0;
144  while((track = static_cast<AliVTrack*>(next()))) {
145  if (IsTrackAccepted(track)) {
146  fListOfTracks->AddLast(track);
147  }
148  else {
149  fListOfTracks->AddLast(0);
150  }
151  new ((*fListOfTrackBitmaps)[i]) TBits(fTrackBitmap);
152  i++;
153  }
154  return fListOfTracks;
155 }
156 
158 {
159  if (!fListOfTracks) {
160  fListOfTracks = new TObjArray;
161  }
162  else {
163  fListOfTracks->Clear();
164  }
165 
166  if (!fListOfTrackBitmaps) {
167  fListOfTrackBitmaps = new TClonesArray("TBits", 1000);
168  fListOfTrackBitmaps->SetOwner(kTRUE);
169  }
170  else {
171  fListOfTrackBitmaps->Delete();
172  }
173 
174  for(int itrk = 0; itrk < event->GetNumberOfTracks(); itrk++){
175  AliVTrack *trk = static_cast<AliVTrack*>(event->GetTrack(itrk));
176  if (IsTrackAccepted(trk)) {
177  fListOfTracks->AddLast(trk);
178  }
179  else {
180  fListOfTracks->AddLast(trk);
181  }
182  new ((*fListOfTrackBitmaps)[itrk]) TBits(fTrackBitmap);
183  }
184  return fListOfTracks;
185 }
186 
188  TObject(),
189  fOwner(false),
190  fManagedObject(nullptr)
191 {
192 
193 }
194 
196  TObject(),
197  fOwner(owner),
198  fManagedObject(managedObject)
199 {
200 }
201 
203  TObject(ref),
204  fOwner(false),
205  fManagedObject(ref.fManagedObject)
206 {
207 }
208 
210  TObject::operator=(ref);
211 
212  if(this != &ref){
213  Cleanup();
214  fOwner = false;
216  }
217  return *this;
218 }
219 
221  if(fManagedObject && fOwner) delete fManagedObject;
222  fManagedObject = nullptr;
223 }
Interface for virtual track selection.
AliEmcalTrackSelection & operator=(const AliEmcalTrackSelection &ref)
Assingment operator.
TObject * GetObject()
Providing access to managed object.
Int_t GetNumberOfCutObjects() const
Get the number of cut objects assigned.
TObjArray * fListOfCuts
List of track cut objects.
TCanvas * c
Definition: TestFitELoss.C:172
TObject * fManagedObject
Pointer to object handled by the smart pointer.
AliEmcalManagedObject()
Dummy constructor.
TClonesArray * fListOfTrackBitmaps
TClonesArray with accepted tracks' bit maps.
Bool_t fOwner
Switch defining ownership over object.
AliEmcalManagedObject & operator=(const AliEmcalManagedObject &ref)
int Int_t
Definition: External.C:63
AliVCuts * GetTrackCuts(Int_t icut)
Access to track cuts at a given position.
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.
TBits fTrackBitmap
Bitmap of last accepted/rejected track.
virtual ~AliEmcalTrackSelection()
Destructor.
Smart pointer implementation for objects inheriting from TObject.
bool Bool_t
Definition: External.C:53
virtual bool IsTrackAccepted(AliVTrack *const trk)=0
Interface for track selection code.