AliPhysics  1168478 (1168478)
 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 <AliLog.h>
19 #include <AliVCuts.h>
20 #include <AliVTrack.h>
21 #include <AliVEvent.h>
22 #include <iostream>
23 
28 
30  TObject(),
31  fListOfTracks(NULL),
32  fListOfTrackBitmaps(NULL),
33  fTrackBitmap(64),
34  fListOfCuts(NULL),
35  fSelectionModeAny(kFALSE)
36 {
37 }
38 
40  TObject(ref),
41  fListOfTracks(NULL),
42  fListOfTrackBitmaps(NULL),
43  fTrackBitmap(64),
44  fListOfCuts(NULL),
45  fSelectionModeAny(kFALSE)
46 {
47  if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
48  if(ref.fListOfTrackBitmaps) fListOfTrackBitmaps = new TClonesArray(*(ref.fListOfTrackBitmaps));
49  if(ref.fListOfCuts){
50  fListOfCuts = new TObjArray;
51  fListOfCuts->SetOwner(true); // Ownership handled object-by-object by the smart pointer
52  for(auto cutIter : *(ref.fListOfCuts))
53  fListOfCuts->Add(new AliEmcalManagedObject(*(static_cast<AliEmcalManagedObject *>(cutIter))));
54  }
55 }
56 
58  TObject::operator=(ref);
59  if(this != &ref){
61  if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
62  if(ref.fListOfTrackBitmaps) fListOfTrackBitmaps = new TClonesArray(*(ref.fListOfTrackBitmaps));
63  if(ref.fListOfCuts){
64  fListOfCuts = new TObjArray;
65  fListOfCuts->SetOwner(true); // Ownership handled object-by-object by the smart pointer
66  for(auto cutIter : *(ref.fListOfCuts))
67  fListOfCuts->Add(new AliEmcalManagedObject(*(static_cast<AliEmcalManagedObject *>(cutIter))));
68  } else fListOfCuts = NULL;
69  }
70  return *this;
71 }
72 
74  if(fListOfTracks) delete fListOfTracks;
76  if(fListOfCuts) delete fListOfCuts;
77 }
78 
80  if(!fListOfCuts){
81  fListOfCuts = new TObjArray;
82  fListOfCuts->SetOwner(true);
83  }
84  if(cuts) fListOfCuts->Add(new AliEmcalManagedObject(cuts, true));
85 }
86 
88  for(auto c : *cuts){
89  AliVCuts *cuts = dynamic_cast<AliVCuts*>(c);
90  if(cuts){
91  AddTrackCuts(cuts);
92  } else {
93  AliErrorStream() << "Object not inheriting from AliVCuts - not added to track selection" << std::endl;
94  }
95  }
96 }
97 
99  if(!fListOfCuts) return 0;
100  return fListOfCuts->GetEntries();
101 }
102 
104  if(!fListOfCuts) return NULL;
105  if(icut < fListOfCuts->GetEntries()){
106  AliEmcalManagedObject *ptr = static_cast<AliEmcalManagedObject *>(fListOfCuts->At(icut));
107  return static_cast<AliVCuts *>(ptr->GetObject());
108  }
109 
110  return NULL;
111 }
112 
113 TObjArray* AliEmcalTrackSelection::GetAcceptedTracks(const TClonesArray* const tracks)
114 {
115  if (!fListOfTracks) {
116  fListOfTracks = new TObjArray;
117  }
118  else {
119  fListOfTracks->Clear();
120  }
121 
122  if (!fListOfTrackBitmaps) {
123  fListOfTrackBitmaps = new TClonesArray("TBits", 1000);
124  fListOfTrackBitmaps->SetOwner(kTRUE);
125  }
126  else {
127  fListOfTrackBitmaps->Delete();
128  }
129 
130  TIter next(tracks);
131  AliVTrack* track = 0;
132  Int_t i = 0;
133  while((track = static_cast<AliVTrack*>(next()))) {
134  if (IsTrackAccepted(track)) {
135  fListOfTracks->AddLast(track);
136  }
137  else {
138  fListOfTracks->AddLast(0);
139  }
140  new ((*fListOfTrackBitmaps)[i]) TBits(fTrackBitmap);
141  i++;
142  }
143  return fListOfTracks;
144 }
145 
147 {
148  if (!fListOfTracks) {
149  fListOfTracks = new TObjArray;
150  }
151  else {
152  fListOfTracks->Clear();
153  }
154 
155  if (!fListOfTrackBitmaps) {
156  fListOfTrackBitmaps = new TClonesArray("TBits", 1000);
157  fListOfTrackBitmaps->SetOwner(kTRUE);
158  }
159  else {
160  fListOfTrackBitmaps->Delete();
161  }
162 
163  for(int itrk = 0; itrk < event->GetNumberOfTracks(); itrk++){
164  AliVTrack *trk = static_cast<AliVTrack*>(event->GetTrack(itrk));
165  if (IsTrackAccepted(trk)) {
166  fListOfTracks->AddLast(trk);
167  }
168  else {
169  fListOfTracks->AddLast(trk);
170  }
171  new ((*fListOfTrackBitmaps)[itrk]) TBits(fTrackBitmap);
172  }
173  return fListOfTracks;
174 }
175 
177  TObject(),
178  fOwner(false),
179  fManagedObject(nullptr)
180 {
181 
182 }
183 
185  TObject(),
186  fOwner(owner),
187  fManagedObject(managedObject)
188 {
189 }
190 
192  TObject(ref),
193  fOwner(false),
194  fManagedObject(ref.fManagedObject)
195 {
196 }
197 
199  TObject::operator=(ref);
200 
201  if(this != &ref){
202  Cleanup();
203  fOwner = false;
205  }
206  return *this;
207 }
208 
210  if(fManagedObject && fOwner) delete fManagedObject;
211  fManagedObject = nullptr;
212 }
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.
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
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.