AliPhysics  v5-06-11-01 (156c7f3)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEMCalPtTaskTrackSelectionESD.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2014, 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 /*
16  * Implementation of the track selection for the analysis on ESDs using
17  * AliESDtrackCuts as underlying structure
18  *
19  * Author:
20  * Markus Fasel
21  */
22 #include <TClonesArray.h>
24 #include <memory>
25 
26 #include "AliESDEvent.h"
27 #include "AliESDtrack.h"
28 #include "AliESDtrackCuts.h"
29 #include "AliLog.h"
30 #include "AliPicoTrack.h"
31 
32 
34 
35 namespace EMCalTriggerPtAnalysis {
36 
37 //______________________________________________________________________________
38 AliEMCalPtTaskTrackSelectionESD::AliEMCalPtTaskTrackSelectionESD():
39  AliEMCalPtTaskVTrackSelection(),
40  fTrackCuts(NULL)
41 {
42  /*
43  * Default constructor
44  */
45 }
46 
47 //______________________________________________________________________________
48 AliEMCalPtTaskTrackSelectionESD::AliEMCalPtTaskTrackSelectionESD(AliESDtrackCuts* cuts):
49  AliEMCalPtTaskVTrackSelection(),
50  fTrackCuts(cuts)
51 {
52  /*
53  * Constructor with cuts
54  */
55 }
56 
57 //______________________________________________________________________________
58 AliEMCalPtTaskTrackSelectionESD::AliEMCalPtTaskTrackSelectionESD(
59  const AliEMCalPtTaskTrackSelectionESD& ref):
60  AliEMCalPtTaskVTrackSelection(ref),
61  fTrackCuts(NULL)
62 {
63  /*
64  * Copy constructor, creating a new cut object
65  */
66  if(ref.fTrackCuts) fTrackCuts = new AliESDtrackCuts(*(ref.fTrackCuts));
67 }
68 
69 //______________________________________________________________________________
70 AliEMCalPtTaskTrackSelectionESD& AliEMCalPtTaskTrackSelectionESD::operator=(
71  const AliEMCalPtTaskTrackSelectionESD& ref)
72 {
73  /*
74  * Assignment operator
75  */
76  AliEMCalPtTaskVTrackSelection::operator=(ref);
77  if(&ref != this){
78  if(fTrackCuts) {
79  delete fTrackCuts;
80  fTrackCuts = NULL;
81  }
82  if(ref.fTrackCuts) fTrackCuts = new AliESDtrackCuts(*(ref.fTrackCuts));
83  }
84  return *this;
85 }
86 
87 //______________________________________________________________________________
88 AliEMCalPtTaskTrackSelectionESD::~AliEMCalPtTaskTrackSelectionESD() {
89  /*
90  * Destructor, deleting track cuts
91  */
92  if(fTrackCuts) delete fTrackCuts;
93 }
94 
95 //______________________________________________________________________________
96 TObjArray* AliEMCalPtTaskTrackSelectionESD::GetAcceptedTracks(
97  const TClonesArray* const tracks) {
98  /*
99  * Select tracks from a TClonesArray of input tracks
100  *
101  * @param tracks: TClonesArray of tracks (must not be null)
102  * @return: TObjArray of selected tracks
103  */
104  if(!fListOfTracks) fListOfTracks = new TObjArray;
105  else fListOfTracks->Clear();
106  if(!fTrackCuts){
107  AliError("Track cuts not provided");
108  return fListOfTracks;
109  }
110  TIter trackIter(tracks);
111  AliESDtrack *track(NULL);
112  AliPicoTrack *picoTrack(NULL);
113  TObject *containerObject(NULL);
114  while((containerObject = dynamic_cast<TObject *>(trackIter()))){
115  // Handle pico tracks
116  if((picoTrack = dynamic_cast<AliPicoTrack *>(containerObject)))
117  track = dynamic_cast<AliESDtrack *>(picoTrack->GetTrack());
118  else
119  track = dynamic_cast<AliESDtrack *>(containerObject);
120  if(fTrackCuts->AcceptTrack(track)) fListOfTracks->AddLast(track);
121  }
122  return fListOfTracks;
123 }
124 
125 
126 
127 //______________________________________________________________________________
128 TObjArray* AliEMCalPtTaskTrackSelectionESD::GetAcceptedTracks(const AliVEvent* const event) {
129  /*
130  * Select tracks from a virtual event
131  *
132  * @param event: AliESDEvent, via interface of virtual event (must not be null)
133  * @return: TObjArray of selected tracks
134  */
135  if(!fListOfTracks) fListOfTracks = new TObjArray;
136  else fListOfTracks->Clear();
137  if(!fTrackCuts){
138  AliError("Track cuts not provided");
139  return fListOfTracks;
140  }
141  const AliESDEvent *esd = dynamic_cast<const AliESDEvent *>(event);
142  if(!esd){
143  AliError("Event not of type AliESDEvent");
144  return fListOfTracks;
145  }
146  std::auto_ptr<TObjArray> accepted(fTrackCuts->GetAcceptedTracks(esd));
147  TIter trackIter(accepted.get());
148  AliESDtrack *track(NULL);
149  while((track = dynamic_cast<AliESDtrack *>(trackIter()))){
150  fListOfTracks->AddLast(track);
151  }
152  return fListOfTracks;
153 }
154 
155 //______________________________________________________________________________
156 bool AliEMCalPtTaskTrackSelectionESD::IsTrackAccepted(AliVTrack* const trk) {
157  /*
158  * Check whether track is accepted
159  *
160  * @param trk: Track to check
161  * @return: true if selected, false otherwise
162  */
163  AliESDtrack *esdt = dynamic_cast<AliESDtrack *>(trk);
164  if(!esdt){
165  AliPicoTrack *picoTrack = dynamic_cast<AliPicoTrack *>(trk);
166  if(picoTrack)
167  esdt = dynamic_cast<AliESDtrack*>(picoTrack->GetTrack());
168  else{
169  AliError("Neither Pico nor ESD track");
170  return kFALSE;
171  }
172  }
173  return fTrackCuts->AcceptTrack(esdt);
174 }
175 
176 } /* namespace EMCalTriggerPtAnalysis */
177 
ClassImp(EMCalTriggerPtAnalysis::AliEMCalPtTaskTrackSelectionESD) namespace EMCalTriggerPtAnalysis