AliPhysics  608b256 (608b256)
AliEmcalTrackSelection.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 <TObjArray.h>
28 #include <TClonesArray.h>
29 #include "AliESDtrackCuts.h"
31 #include "AliEmcalVCutsWrapper.h"
32 #include "AliEmcalTrackSelection.h"
33 #include "AliLog.h"
34 #include "AliVCuts.h"
35 #include "AliVTrack.h"
36 #include "AliVEvent.h"
37 #include <iostream>
38 
40 ClassImp(AliEmcalManagedObject)
41 ClassImp(AliEmcalTrackSelection)
43 
44 using namespace PWG::EMCAL;
45 
47  TObject(),
48  fListOfTracks(NULL),
49  fListOfCuts(NULL),
50  fSelectionModeAny(kFALSE)
51 {
52 }
53 
55  TObject(ref),
56  fListOfTracks(NULL),
57  fListOfCuts(NULL),
58  fSelectionModeAny(kFALSE)
59 {
60  if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
61  if(ref.fListOfCuts){
62  fListOfCuts = new TObjArray;
63  fListOfCuts->SetOwner(true); // Ownership handled object-by-object by the smart pointer
64  for(auto cutIter : *(ref.fListOfCuts))
65  fListOfCuts->Add(new AliEmcalManagedObject(*(static_cast<AliEmcalManagedObject *>(cutIter))));
66  }
67 }
68 
70  TObject::operator=(ref);
71  if(this != &ref){
73  if(ref.fListOfTracks) fListOfTracks = new TObjArray(*(ref.fListOfTracks));
74  if(ref.fListOfCuts){
75  fListOfCuts = new TObjArray;
76  fListOfCuts->SetOwner(true); // Ownership handled object-by-object by the smart pointer
77  for(auto cutIter : *(ref.fListOfCuts))
78  fListOfCuts->Add(new AliEmcalManagedObject(*(static_cast<AliEmcalManagedObject *>(cutIter))));
79  } else fListOfCuts = NULL;
80  }
81  return *this;
82 }
83 
85  if(fListOfTracks) delete fListOfTracks;
86  if(fListOfCuts) delete fListOfCuts;
87 }
88 
90  AliInfoStream() << "Adding track cuts " << cuts->GetName() << " of type " << cuts->IsA()->GetName() << std::endl;
91  if(!fListOfCuts){
92  fListOfCuts = new TObjArray;
93  fListOfCuts->SetOwner(true);
94  }
95  if(cuts) {
96  // Special treatment for AliESDtrackCuts:
97  // As the function IsSelected is not properly implemented for AliAODTracks
98  // a wrapper needs to be used, which handles the expected behaviour for
99  // both AliESDtracks and AliAODTracks
100  AliVCuts *mycuts = cuts;
101  if(AliESDtrackCuts *esdcuts = dynamic_cast<AliESDtrackCuts *>(cuts)) mycuts = new PWG::EMCAL::AliEmcalESDtrackCutsWrapper(esdcuts->GetName(), esdcuts);
102  // Convert to AliEmcalCutBase
104  }
105 }
106 
108  AliInfoStream() << "Adding track cuts " << cuts->GetName() << " of type " << cuts->IsA()->GetName() << std::endl;
109  if(!fListOfCuts){
110  fListOfCuts = new TObjArray;
111  fListOfCuts->SetOwner(true);
112  }
113  if(cuts) {
114  fListOfCuts->Add(new AliEmcalManagedObject(cuts));
115  }
116 }
117 
119  if(!cuts) {
120  AliErrorStream() << "Not setting cuts since cut array is null" << std::endl;
121  return;
122  }
123  for(auto c : *cuts){
124  PWG::EMCAL::AliEmcalCutBase *emccuts = dynamic_cast<PWG::EMCAL::AliEmcalCutBase*>(c);
125  if(emccuts){
126  AddTrackCuts(emccuts);
127  } else {
128  AliVCuts *vcuts = dynamic_cast<AliVCuts *>(c);
129  if(vcuts) {
130  AddTrackCuts(vcuts);
131  } else {
132  AliErrorStream() << "Object not inheriting from AliVCuts - not added to track selection" << std::endl;
133  }
134  }
135  }
136 }
137 
139  if(!fListOfCuts) return 0;
140  return fListOfCuts->GetEntries();
141 }
142 
144  if(!fListOfCuts) return NULL;
145  if(icut < fListOfCuts->GetEntries()){
146  AliEmcalManagedObject *ptr = static_cast<AliEmcalManagedObject *>(fListOfCuts->At(icut));
147  return static_cast<PWG::EMCAL::AliEmcalCutBase *>(ptr->GetObject());
148  }
149 
150  return NULL;
151 }
152 
153 TObjArray* AliEmcalTrackSelection::GetAcceptedTracks(const TClonesArray* const tracks)
154 {
155  if (!fListOfTracks) {
156  fListOfTracks = new TObjArray;
157  fListOfTracks->SetOwner(kTRUE);
158  }
159  else {
160  fListOfTracks->Clear();
161  }
162 
163  for(auto mytrack : *tracks) {
164  fListOfTracks->AddLast(new PWG::EMCAL::AliEmcalTrackSelResultPtr(IsTrackAccepted(static_cast<AliVTrack *>(mytrack))));
165  }
166  return fListOfTracks;
167 }
168 
170 {
171  if (!fListOfTracks) {
172  fListOfTracks = new TObjArray;
173  fListOfTracks->SetOwner(kTRUE);
174  }
175  else {
176  fListOfTracks->Clear();
177  }
178 
179  for(int itrk = 0; itrk < event->GetNumberOfTracks(); itrk++){
180  fListOfTracks->AddLast(new PWG::EMCAL::AliEmcalTrackSelResultPtr(IsTrackAccepted(static_cast<AliVTrack*>(event->GetTrack(itrk)))));
181  }
182  return fListOfTracks;
183 }
184 
186  TObject(),
187  fOwner(false),
188  fManagedObject(nullptr)
189 {
190 
191 }
192 
194  TObject(),
195  fOwner(owner),
196  fManagedObject(managedObject)
197 {
198 }
199 
201  TObject(ref),
202  fOwner(false),
204 {
205 }
206 
208  TObject::operator=(ref);
209 
210  if(this != &ref){
211  Cleanup();
212  fOwner = false;
214  }
215  return *this;
216 }
217 
219  if(fManagedObject && fOwner) delete fManagedObject;
220  fManagedObject = nullptr;
221 }
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.
Namespace for EMCAL framework classes and task.
AliEmcalManagedObject & operator=(const AliEmcalManagedObject &ref)
int Int_t
Definition: External.C:63
Namespace for PWG framework classes.
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