Coverity bugs corrected.
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowTasks / AliFlowTrackCuts.cxx
CommitLineData
daf66719 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Id$ */
17
18// AliFlowTrackCuts:
19// ESD track cuts for flow framework
20//
21// origin: Mikolaj Krzewicki (mikolaj.krzewicki@cern.ch)
5559ce24 22//
23// This class gurantees consistency of cut methods, trackparameter
24// selection (global tracks, TPC only, etc..) and parameter mixing
25// in the flow framework. Transparently handles different input types:
26// ESD, MC, AOD.
27// This class works in 2 steps: first the requested track parameters are
28// constructed (to be set by SetParamType() ), then cuts are applied.
29// the constructed track can be requested AFTER checking the cuts by
30// calling GetTrack(), in this case the cut object stays in control,
31// caller does not have to delete the track.
32// Additionally caller can request an AliFlowTrack object to be constructed
33// according the parameter mixing scenario requested by SetParamMix().
34// AliFlowTrack is made using MakeFlowTrack() method, its an 'object factory'
35// so caller needs to take care of the freshly created object.
daf66719 36
37#include <limits.h>
38#include <float.h>
39#include "AliMCEvent.h"
40#include "AliVParticle.h"
41#include "AliMCParticle.h"
42#include "AliESDtrack.h"
43#include "AliAODTrack.h"
44#include "AliFlowTrack.h"
45#include "AliFlowTrackCuts.h"
46#include "AliLog.h"
47
48ClassImp(AliFlowTrackCuts)
49
50//-----------------------------------------------------------------------
51AliFlowTrackCuts::AliFlowTrackCuts():
52 AliFlowTrackSimpleCuts(),
53 fAliESDtrackCuts(new AliESDtrackCuts()),
54 fCutMCprocessType(kFALSE),
55 fMCprocessType(kPNoProcess),
56 fCutMCPID(kFALSE),
57 fMCPID(0),
58 fCutMCisPrimary(kFALSE),
59 fMCisPrimary(kFALSE),
60 fParamType(kESD_Global),
61 fParamMix(kPure),
62 fMCevent(NULL),
63 fCleanupTrack(kFALSE),
64 fTrack(NULL),
65 fMCparticle(NULL)
66{
67 //constructor
68}
69
70//-----------------------------------------------------------------------
71AliFlowTrackCuts::AliFlowTrackCuts(const AliFlowTrackCuts& someCuts):
72 AliFlowTrackSimpleCuts(someCuts),
73 fAliESDtrackCuts(new AliESDtrackCuts(*(someCuts.fAliESDtrackCuts))),
74 fCutMCprocessType(someCuts.fCutMCprocessType),
75 fMCprocessType(someCuts.fMCprocessType),
76 fCutMCPID(someCuts.fCutMCPID),
77 fMCPID(someCuts.fMCPID),
78 fCutMCisPrimary(someCuts.fCutMCisPrimary),
79 fMCisPrimary(someCuts.fMCisPrimary),
80 fParamType(someCuts.fParamType),
81 fParamMix(someCuts.fParamMix),
82 fMCevent(NULL),
83 fCleanupTrack(kFALSE),
84 fTrack(NULL),
85 fMCparticle(NULL)
86{
87 //copy constructor
88}
89
90//-----------------------------------------------------------------------
91AliFlowTrackCuts& AliFlowTrackCuts::operator=(const AliFlowTrackCuts& someCuts)
92{
93 //assignment
94 AliFlowTrackSimpleCuts::operator=(someCuts);
95 *fAliESDtrackCuts=*(someCuts.fAliESDtrackCuts);
96 fCutMCprocessType=someCuts.fCutMCprocessType;
97 fMCprocessType=someCuts.fMCprocessType;
98 fCutMCPID=someCuts.fCutMCPID;
99 fMCPID=someCuts.fMCPID;
100 fCutMCisPrimary=someCuts.fCutMCisPrimary;
101 fMCisPrimary=someCuts.fMCisPrimary;
102 fParamType=someCuts.fParamType;
103 fParamMix=someCuts.fParamMix;
104
105 fMCevent=NULL;
106 fCleanupTrack=kFALSE;
107 fTrack=NULL;
108 fMCparticle=NULL;
109
110 return *this;
111}
112
113//-----------------------------------------------------------------------
114AliFlowTrackCuts::~AliFlowTrackCuts()
115{
116 //dtor
117 if (fCleanupTrack) delete fTrack;
118 delete fAliESDtrackCuts;
119}
120
121//-----------------------------------------------------------------------
122Bool_t AliFlowTrackCuts::IsSelected(TObject* obj)
123{
124 //check cuts
125 AliVParticle* vparticle = dynamic_cast<AliVParticle*>(obj);
126 if (vparticle) return PassesCuts(vparticle);
127 AliFlowTrackSimple* flowtrack = dynamic_cast<AliFlowTrackSimple*>(obj);
128 if (flowtrack) return PassesCuts(flowtrack);
129 return kFALSE; //default when passed wrong type of object
130}
131
132//-----------------------------------------------------------------------
133Bool_t AliFlowTrackCuts::PassesCuts(AliFlowTrackSimple* track)
134{
135 //check cuts on a flowtracksimple
5559ce24 136
137 //clean up from last iteration
138 if (fCleanupTrack) delete fTrack; fTrack = NULL;
daf66719 139 return AliFlowTrackSimpleCuts::PassesCuts(track);
140}
141
142//-----------------------------------------------------------------------
143Bool_t AliFlowTrackCuts::PassesCuts(AliVParticle* vparticle)
144{
145 //check cuts for an ESD vparticle
146
5559ce24 147 //clean up from last iteration
148 if (fCleanupTrack) delete fTrack; fTrack=NULL;
149
daf66719 150 Int_t mcLabel = vparticle->GetLabel();
151 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(mcLabel));
152 else fMCparticle=NULL;
153
154 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*>(vparticle);
155 if (esdTrack)
156 HandleESDtrack(esdTrack);
157 else
158 HandleVParticle(vparticle);
159
160 //check the common cuts for the current particle (MC,AOD,ESD)
161 if (fCutPt) {if (fTrack->Pt() < fPtMin || fTrack->Pt() >= fPtMax ) return kFALSE;}
162 if (fCutEta) {if (fTrack->Eta() < fEtaMin || fTrack->Eta() >= fEtaMax ) return kFALSE;}
163 if (fCutPhi) {if (fTrack->Phi() < fPhiMin || fTrack->Phi() >= fPhiMax ) return kFALSE;}
164 if (fCutCharge) {if (fTrack->Charge() != fCharge) return kFALSE;}
165 //if(fCutPID) {if (fTrack->PID() != fPID) return kFALSE;}
166
167 //when MC info is required
168 if (fCutMCisPrimary)
169 {
170 if (!fMCevent) {AliError("no MC info"); return kFALSE;}
171 if (fMCevent->IsPhysicalPrimary(mcLabel) != fMCisPrimary) return kFALSE;
172 }
173 if (fCutMCPID)
174 {
175 if (!fMCparticle) {AliError("no MC info"); return kFALSE;}
176 Int_t pdgCode = fMCparticle->PdgCode();
177 if (fMCPID != pdgCode) return kFALSE;
178 }
179 if ( fCutMCprocessType )
180 {
181 if (!fMCparticle) {AliError("no MC info"); return kFALSE;}
182 TParticle* particle = fMCparticle->Particle();
183 Int_t processID = particle->GetUniqueID();
184 if (processID != fMCprocessType ) return kFALSE;
185 }
186
187 //check all else for ESDs using aliesdtrackcuts
188 if (esdTrack && (fParamType!=kMC) ) return fAliESDtrackCuts->IsSelected(static_cast<AliESDtrack*>(fTrack));
189
190 return kTRUE; //true by default, if we didn't set any cuts
191}
192
193//-----------------------------------------------------------------------
194void AliFlowTrackCuts::HandleVParticle(AliVParticle* track)
195{
196 //handle the general case
daf66719 197 switch (fParamType)
198 {
199 case kMC:
200 fCleanupTrack = kFALSE;
201 fTrack = fMCparticle;
202 break;
203 default:
204 fCleanupTrack = kFALSE;
205 fTrack = track;
206 }
207}
208
209//-----------------------------------------------------------------------
210void AliFlowTrackCuts::HandleESDtrack(AliESDtrack* track)
211{
212 //handle esd track
daf66719 213 switch (fParamType)
214 {
215 case kESD_Global:
216 fTrack = track;
217 fCleanupTrack = kFALSE;
218 break;
219 case kESD_TPConly:
220 fTrack = new AliESDtrack();
221 track->FillTPCOnlyTrack(*(static_cast<AliESDtrack*>(fTrack)));
222 fCleanupTrack = kTRUE;
223 break;
224 case kMC:
225 fCleanupTrack = kFALSE;
226 fTrack = fMCparticle;
227 break;
228 default:
229 fTrack = track;
230 fCleanupTrack = kFALSE;
231 }
232}
233
234//-----------------------------------------------------------------------
235AliFlowTrackCuts* AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts()
236{
237 //get standard cuts
238 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
5559ce24 239 cuts->SetName("standard TPConly cuts");
daf66719 240 delete cuts->fAliESDtrackCuts;
241 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
5559ce24 242 cuts->SetParamType(kESD_TPConly);
daf66719 243 return cuts;
244}
245
246//-----------------------------------------------------------------------
247AliFlowTrackCuts* AliFlowTrackCuts::GetStandardITSTPCTrackCuts2009(Bool_t selPrimaries)
248{
249 //get standard cuts
250 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
251 cuts->SetName("standard global track cuts 2009");
252 delete cuts->fAliESDtrackCuts;
253 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2009(selPrimaries);
5559ce24 254 cuts->SetParamType(kESD_Global);
daf66719 255 return cuts;
256}
257
258//-----------------------------------------------------------------------
259AliFlowTrack* AliFlowTrackCuts::MakeFlowTrack() const
260{
261 //get a flow track constructed from whatever we applied cuts on
262 //caller is resposible for deletion
263 AliFlowTrack* flowtrack=NULL;
264 switch(fParamMix)
265 {
266 case kPure:
267 flowtrack = new AliFlowTrack(fTrack);
268 break;
269 case kTrackWithMCkine:
270 flowtrack = new AliFlowTrack(fMCparticle);
271 break;
272 case kTrackWithMCPID:
273 flowtrack = new AliFlowTrack(fTrack);
274 break;
275 default:
276 flowtrack = new AliFlowTrack(fTrack);
277 }
278 if (fParamType==kMC) flowtrack->SetSource(AliFlowTrack::kFromMC);
279 else if (dynamic_cast<AliMCParticle*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromMC);
280 else if (dynamic_cast<AliESDtrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromESD);
281 else if (dynamic_cast<AliAODTrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromAOD);
282 return flowtrack;
283}