]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/AliFlowTasks/AliFlowTrackCuts.cxx
more fixes
[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),
957517fa 60 fRequireCharge(kFALSE),
127a5825 61 fFakesAreOK(kTRUE),
daf66719 62 fParamType(kESD_Global),
63 fParamMix(kPure),
daf66719 64 fCleanupTrack(kFALSE),
65 fTrack(NULL),
127a5825 66 fTrackLabel(INT_MIN),
957517fa 67 fMCevent(NULL),
daf66719 68 fMCparticle(NULL)
69{
70 //constructor
71}
72
73//-----------------------------------------------------------------------
74AliFlowTrackCuts::AliFlowTrackCuts(const AliFlowTrackCuts& someCuts):
75 AliFlowTrackSimpleCuts(someCuts),
76 fAliESDtrackCuts(new AliESDtrackCuts(*(someCuts.fAliESDtrackCuts))),
77 fCutMCprocessType(someCuts.fCutMCprocessType),
78 fMCprocessType(someCuts.fMCprocessType),
79 fCutMCPID(someCuts.fCutMCPID),
80 fMCPID(someCuts.fMCPID),
81 fCutMCisPrimary(someCuts.fCutMCisPrimary),
82 fMCisPrimary(someCuts.fMCisPrimary),
957517fa 83 fRequireCharge(someCuts.fRequireCharge),
127a5825 84 fFakesAreOK(someCuts.fFakesAreOK),
daf66719 85 fParamType(someCuts.fParamType),
86 fParamMix(someCuts.fParamMix),
daf66719 87 fCleanupTrack(kFALSE),
88 fTrack(NULL),
127a5825 89 fTrackLabel(INT_MIN),
957517fa 90 fMCevent(NULL),
daf66719 91 fMCparticle(NULL)
92{
93 //copy constructor
94}
95
96//-----------------------------------------------------------------------
97AliFlowTrackCuts& AliFlowTrackCuts::operator=(const AliFlowTrackCuts& someCuts)
98{
99 //assignment
100 AliFlowTrackSimpleCuts::operator=(someCuts);
101 *fAliESDtrackCuts=*(someCuts.fAliESDtrackCuts);
102 fCutMCprocessType=someCuts.fCutMCprocessType;
103 fMCprocessType=someCuts.fMCprocessType;
104 fCutMCPID=someCuts.fCutMCPID;
105 fMCPID=someCuts.fMCPID;
106 fCutMCisPrimary=someCuts.fCutMCisPrimary;
107 fMCisPrimary=someCuts.fMCisPrimary;
957517fa 108 fRequireCharge=someCuts.fRequireCharge;
127a5825 109 fFakesAreOK=someCuts.fFakesAreOK;
daf66719 110 fParamType=someCuts.fParamType;
111 fParamMix=someCuts.fParamMix;
112
daf66719 113 fCleanupTrack=kFALSE;
114 fTrack=NULL;
127a5825 115 fTrackLabel=INT_MIN;
957517fa 116 fMCevent=NULL;
daf66719 117 fMCparticle=NULL;
118
119 return *this;
120}
121
122//-----------------------------------------------------------------------
123AliFlowTrackCuts::~AliFlowTrackCuts()
124{
125 //dtor
126 if (fCleanupTrack) delete fTrack;
127 delete fAliESDtrackCuts;
128}
129
130//-----------------------------------------------------------------------
131Bool_t AliFlowTrackCuts::IsSelected(TObject* obj)
132{
133 //check cuts
134 AliVParticle* vparticle = dynamic_cast<AliVParticle*>(obj);
135 if (vparticle) return PassesCuts(vparticle);
136 AliFlowTrackSimple* flowtrack = dynamic_cast<AliFlowTrackSimple*>(obj);
137 if (flowtrack) return PassesCuts(flowtrack);
138 return kFALSE; //default when passed wrong type of object
139}
140
141//-----------------------------------------------------------------------
142Bool_t AliFlowTrackCuts::PassesCuts(AliFlowTrackSimple* track)
143{
144 //check cuts on a flowtracksimple
5559ce24 145
146 //clean up from last iteration
147 if (fCleanupTrack) delete fTrack; fTrack = NULL;
daf66719 148 return AliFlowTrackSimpleCuts::PassesCuts(track);
149}
150
151//-----------------------------------------------------------------------
152Bool_t AliFlowTrackCuts::PassesCuts(AliVParticle* vparticle)
153{
154 //check cuts for an ESD vparticle
155
127a5825 156 ////////////////////////////////////////////////////////////////
157 // start by preparing the track parameters to cut on //////////
158 ////////////////////////////////////////////////////////////////
5559ce24 159 //clean up from last iteration
160 if (fCleanupTrack) delete fTrack; fTrack=NULL;
161
957517fa 162 //get the label and the mc particle
127a5825 163 fTrackLabel = (fFakesAreOK)?TMath::Abs(vparticle->GetLabel()):vparticle->GetLabel();
164 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
daf66719 165 else fMCparticle=NULL;
166
957517fa 167 Bool_t isMCparticle = kFALSE; //some things are different for MC particles, check!
daf66719 168 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*>(vparticle);
169 if (esdTrack)
170 HandleESDtrack(esdTrack);
171 else
957517fa 172 {
daf66719 173 HandleVParticle(vparticle);
957517fa 174 //now check if produced particle is MC
175 isMCparticle = (dynamic_cast<AliMCParticle*>(fTrack))!=NULL;
176 }
127a5825 177 ////////////////////////////////////////////////////////////////
178 ////////////////////////////////////////////////////////////////
179
daf66719 180 //check the common cuts for the current particle (MC,AOD,ESD)
181 if (fCutPt) {if (fTrack->Pt() < fPtMin || fTrack->Pt() >= fPtMax ) return kFALSE;}
182 if (fCutEta) {if (fTrack->Eta() < fEtaMin || fTrack->Eta() >= fEtaMax ) return kFALSE;}
183 if (fCutPhi) {if (fTrack->Phi() < fPhiMin || fTrack->Phi() >= fPhiMax ) return kFALSE;}
127a5825 184 if (fRequireCharge) {if (fTrack->Charge() == 0) return kFALSE;}
957517fa 185 if (fCutCharge && !isMCparticle) {if (fTrack->Charge() != fCharge) return kFALSE;}
186 if (fCutCharge && isMCparticle)
187 {
188 //in case of an MC particle the charge is stored in units of 1/3|e|
189 Int_t charge = TMath::Nint(fTrack->Charge()/3.0); //mc particles have charge in units of 1/3e
190 return (charge==fCharge);
191 }
daf66719 192 //if(fCutPID) {if (fTrack->PID() != fPID) return kFALSE;}
193
957517fa 194 //when additionally MC info is required
daf66719 195 if (fCutMCisPrimary)
196 {
197 if (!fMCevent) {AliError("no MC info"); return kFALSE;}
127a5825 198 if (fMCevent->IsPhysicalPrimary(fTrackLabel) != fMCisPrimary) return kFALSE;
daf66719 199 }
200 if (fCutMCPID)
201 {
202 if (!fMCparticle) {AliError("no MC info"); return kFALSE;}
203 Int_t pdgCode = fMCparticle->PdgCode();
204 if (fMCPID != pdgCode) return kFALSE;
205 }
206 if ( fCutMCprocessType )
207 {
208 if (!fMCparticle) {AliError("no MC info"); return kFALSE;}
209 TParticle* particle = fMCparticle->Particle();
210 Int_t processID = particle->GetUniqueID();
211 if (processID != fMCprocessType ) return kFALSE;
212 }
213
214 //check all else for ESDs using aliesdtrackcuts
215 if (esdTrack && (fParamType!=kMC) ) return fAliESDtrackCuts->IsSelected(static_cast<AliESDtrack*>(fTrack));
216
217 return kTRUE; //true by default, if we didn't set any cuts
218}
219
220//-----------------------------------------------------------------------
221void AliFlowTrackCuts::HandleVParticle(AliVParticle* track)
222{
223 //handle the general case
daf66719 224 switch (fParamType)
225 {
226 case kMC:
227 fCleanupTrack = kFALSE;
228 fTrack = fMCparticle;
229 break;
230 default:
231 fCleanupTrack = kFALSE;
232 fTrack = track;
233 }
234}
235
236//-----------------------------------------------------------------------
237void AliFlowTrackCuts::HandleESDtrack(AliESDtrack* track)
238{
239 //handle esd track
daf66719 240 switch (fParamType)
241 {
242 case kESD_Global:
243 fTrack = track;
244 fCleanupTrack = kFALSE;
245 break;
246 case kESD_TPConly:
247 fTrack = new AliESDtrack();
248 track->FillTPCOnlyTrack(*(static_cast<AliESDtrack*>(fTrack)));
249 fCleanupTrack = kTRUE;
957517fa 250 //recalculate the label and mc particle, they may differ as TPClabel != global label
127a5825 251 fTrackLabel = (fFakesAreOK)?TMath::Abs(fTrack->GetLabel()):fTrack->GetLabel();
252 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
957517fa 253 else fMCparticle=NULL;
daf66719 254 break;
255 case kMC:
256 fCleanupTrack = kFALSE;
257 fTrack = fMCparticle;
258 break;
259 default:
260 fTrack = track;
261 fCleanupTrack = kFALSE;
262 }
263}
264
265//-----------------------------------------------------------------------
266AliFlowTrackCuts* AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts()
267{
268 //get standard cuts
269 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
5559ce24 270 cuts->SetName("standard TPConly cuts");
daf66719 271 delete cuts->fAliESDtrackCuts;
272 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
5559ce24 273 cuts->SetParamType(kESD_TPConly);
daf66719 274 return cuts;
275}
276
277//-----------------------------------------------------------------------
278AliFlowTrackCuts* AliFlowTrackCuts::GetStandardITSTPCTrackCuts2009(Bool_t selPrimaries)
279{
280 //get standard cuts
281 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
282 cuts->SetName("standard global track cuts 2009");
283 delete cuts->fAliESDtrackCuts;
284 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2009(selPrimaries);
5559ce24 285 cuts->SetParamType(kESD_Global);
daf66719 286 return cuts;
287}
288
289//-----------------------------------------------------------------------
290AliFlowTrack* AliFlowTrackCuts::MakeFlowTrack() const
291{
292 //get a flow track constructed from whatever we applied cuts on
293 //caller is resposible for deletion
294 AliFlowTrack* flowtrack=NULL;
295 switch(fParamMix)
296 {
297 case kPure:
298 flowtrack = new AliFlowTrack(fTrack);
299 break;
300 case kTrackWithMCkine:
301 flowtrack = new AliFlowTrack(fMCparticle);
302 break;
303 case kTrackWithMCPID:
304 flowtrack = new AliFlowTrack(fTrack);
305 break;
306 default:
307 flowtrack = new AliFlowTrack(fTrack);
308 }
309 if (fParamType==kMC) flowtrack->SetSource(AliFlowTrack::kFromMC);
310 else if (dynamic_cast<AliMCParticle*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromMC);
311 else if (dynamic_cast<AliESDtrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromESD);
312 else if (dynamic_cast<AliAODTrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromAOD);
313 return flowtrack;
314}
127a5825 315
316//-----------------------------------------------------------------------
317Bool_t AliFlowTrackCuts::IsPhysicalPrimary() const
318{
319 //check if current particle is a physical primary
320 return fMCevent->IsPhysicalPrimary(fTrackLabel);
321}