AliPhysics  4ef2867 (4ef2867)
 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 <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  }
140  else {
141  fListOfTracks->Clear();
142  }
143 
144  for(auto mytrack : *tracks) {
145  AliVTrack *track = static_cast<AliVTrack *>(mytrack);
147  if(selectionResult) {
148  fListOfTracks->AddLast(new PWG::EMCAL::AliEmcalTrackSelResultPtr(selectionResult));
149  }
150  }
151  return fListOfTracks;
152 }
153 
155 {
156  if (!fListOfTracks) {
157  fListOfTracks = new TObjArray;
158  }
159  else {
160  fListOfTracks->Clear();
161  }
162 
163  for(int itrk = 0; itrk < event->GetNumberOfTracks(); itrk++){
164  AliVTrack *trk = static_cast<AliVTrack*>(event->GetTrack(itrk));
166  if(selectionStatus)
167  fListOfTracks->AddLast(new PWG::EMCAL::AliEmcalTrackSelResultPtr(selectionStatus));
168  }
169  return fListOfTracks;
170 }
171 
173  TObject(),
174  fOwner(false),
175  fManagedObject(nullptr)
176 {
177 
178 }
179 
181  TObject(),
182  fOwner(owner),
183  fManagedObject(managedObject)
184 {
185 }
186 
188  TObject(ref),
189  fOwner(false),
190  fManagedObject(ref.fManagedObject)
191 {
192 }
193 
195  TObject::operator=(ref);
196 
197  if(this != &ref){
198  Cleanup();
199  fOwner = false;
201  }
202  return *this;
203 }
204 
206  if(fManagedObject && fOwner) delete fManagedObject;
207  fManagedObject = nullptr;
208 }
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