AliPhysics  63e47e1 (63e47e1)
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  for(auto c : *cuts){
120  PWG::EMCAL::AliEmcalCutBase *emccuts = dynamic_cast<PWG::EMCAL::AliEmcalCutBase*>(c);
121  if(emccuts){
122  AddTrackCuts(emccuts);
123  } else {
124  AliVCuts *vcuts = dynamic_cast<AliVCuts *>(c);
125  if(vcuts) {
126  AddTrackCuts(vcuts);
127  } else {
128  AliErrorStream() << "Object not inheriting from AliVCuts - not added to track selection" << std::endl;
129  }
130  }
131  }
132 }
133 
135  if(!fListOfCuts) return 0;
136  return fListOfCuts->GetEntries();
137 }
138 
140  if(!fListOfCuts) return NULL;
141  if(icut < fListOfCuts->GetEntries()){
142  AliEmcalManagedObject *ptr = static_cast<AliEmcalManagedObject *>(fListOfCuts->At(icut));
143  return static_cast<PWG::EMCAL::AliEmcalCutBase *>(ptr->GetObject());
144  }
145 
146  return NULL;
147 }
148 
149 TObjArray* AliEmcalTrackSelection::GetAcceptedTracks(const TClonesArray* const tracks)
150 {
151  if (!fListOfTracks) {
152  fListOfTracks = new TObjArray;
153  fListOfTracks->SetOwner(kTRUE);
154  }
155  else {
156  fListOfTracks->Clear();
157  }
158 
159  for(auto mytrack : *tracks) {
160  fListOfTracks->AddLast(new PWG::EMCAL::AliEmcalTrackSelResultPtr(IsTrackAccepted(static_cast<AliVTrack *>(mytrack))));
161  }
162  return fListOfTracks;
163 }
164 
166 {
167  if (!fListOfTracks) {
168  fListOfTracks = new TObjArray;
169  fListOfTracks->SetOwner(kTRUE);
170  }
171  else {
172  fListOfTracks->Clear();
173  }
174 
175  for(int itrk = 0; itrk < event->GetNumberOfTracks(); itrk++){
176  fListOfTracks->AddLast(new PWG::EMCAL::AliEmcalTrackSelResultPtr(IsTrackAccepted(static_cast<AliVTrack*>(event->GetTrack(itrk)))));
177  }
178  return fListOfTracks;
179 }
180 
182  TObject(),
183  fOwner(false),
184  fManagedObject(nullptr)
185 {
186 
187 }
188 
190  TObject(),
191  fOwner(owner),
192  fManagedObject(managedObject)
193 {
194 }
195 
197  TObject(ref),
198  fOwner(false),
200 {
201 }
202 
204  TObject::operator=(ref);
205 
206  if(this != &ref){
207  Cleanup();
208  fOwner = false;
210  }
211  return *this;
212 }
213 
215  if(fManagedObject && fOwner) delete fManagedObject;
216  fManagedObject = nullptr;
217 }
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