Obsolete code filling PHOS trigger into ESD is removed
[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"
12b2b8bc 43#include "AliMultiplicity.h"
daf66719 44#include "AliAODTrack.h"
45#include "AliFlowTrack.h"
46#include "AliFlowTrackCuts.h"
47#include "AliLog.h"
48
49ClassImp(AliFlowTrackCuts)
50
51//-----------------------------------------------------------------------
52AliFlowTrackCuts::AliFlowTrackCuts():
53 AliFlowTrackSimpleCuts(),
54 fAliESDtrackCuts(new AliESDtrackCuts()),
924b02b0 55 fQA(kFALSE),
daf66719 56 fCutMCprocessType(kFALSE),
57 fMCprocessType(kPNoProcess),
58 fCutMCPID(kFALSE),
59 fMCPID(0),
60 fCutMCisPrimary(kFALSE),
61 fMCisPrimary(kFALSE),
957517fa 62 fRequireCharge(kFALSE),
127a5825 63 fFakesAreOK(kTRUE),
12b2b8bc 64 fParamType(kGlobal),
daf66719 65 fParamMix(kPure),
daf66719 66 fCleanupTrack(kFALSE),
67 fTrack(NULL),
12b2b8bc 68 fTrackPhi(0.),
69 fTrackEta(0.),
70 fTrackWeight(0.),
127a5825 71 fTrackLabel(INT_MIN),
957517fa 72 fMCevent(NULL),
daf66719 73 fMCparticle(NULL)
74{
75 //constructor
76}
77
78//-----------------------------------------------------------------------
79AliFlowTrackCuts::AliFlowTrackCuts(const AliFlowTrackCuts& someCuts):
80 AliFlowTrackSimpleCuts(someCuts),
81 fAliESDtrackCuts(new AliESDtrackCuts(*(someCuts.fAliESDtrackCuts))),
924b02b0 82 fQA(someCuts.fQA),
daf66719 83 fCutMCprocessType(someCuts.fCutMCprocessType),
84 fMCprocessType(someCuts.fMCprocessType),
85 fCutMCPID(someCuts.fCutMCPID),
86 fMCPID(someCuts.fMCPID),
87 fCutMCisPrimary(someCuts.fCutMCisPrimary),
88 fMCisPrimary(someCuts.fMCisPrimary),
957517fa 89 fRequireCharge(someCuts.fRequireCharge),
127a5825 90 fFakesAreOK(someCuts.fFakesAreOK),
daf66719 91 fParamType(someCuts.fParamType),
92 fParamMix(someCuts.fParamMix),
daf66719 93 fCleanupTrack(kFALSE),
94 fTrack(NULL),
12b2b8bc 95 fTrackPhi(someCuts.fTrackPhi),
96 fTrackEta(someCuts.fTrackEta),
97 fTrackWeight(someCuts.fTrackWeight),
127a5825 98 fTrackLabel(INT_MIN),
957517fa 99 fMCevent(NULL),
daf66719 100 fMCparticle(NULL)
101{
102 //copy constructor
103}
104
105//-----------------------------------------------------------------------
106AliFlowTrackCuts& AliFlowTrackCuts::operator=(const AliFlowTrackCuts& someCuts)
107{
108 //assignment
109 AliFlowTrackSimpleCuts::operator=(someCuts);
110 *fAliESDtrackCuts=*(someCuts.fAliESDtrackCuts);
924b02b0 111 fQA=someCuts.fQA;
daf66719 112 fCutMCprocessType=someCuts.fCutMCprocessType;
113 fMCprocessType=someCuts.fMCprocessType;
114 fCutMCPID=someCuts.fCutMCPID;
115 fMCPID=someCuts.fMCPID;
116 fCutMCisPrimary=someCuts.fCutMCisPrimary;
117 fMCisPrimary=someCuts.fMCisPrimary;
957517fa 118 fRequireCharge=someCuts.fRequireCharge;
127a5825 119 fFakesAreOK=someCuts.fFakesAreOK;
daf66719 120 fParamType=someCuts.fParamType;
121 fParamMix=someCuts.fParamMix;
122
daf66719 123 fCleanupTrack=kFALSE;
124 fTrack=NULL;
12b2b8bc 125 fTrackPhi=someCuts.fTrackPhi;
126 fTrackPhi=someCuts.fTrackPhi;
127 fTrackWeight=someCuts.fTrackWeight;
127a5825 128 fTrackLabel=INT_MIN;
957517fa 129 fMCevent=NULL;
daf66719 130 fMCparticle=NULL;
131
132 return *this;
133}
134
135//-----------------------------------------------------------------------
136AliFlowTrackCuts::~AliFlowTrackCuts()
137{
138 //dtor
139 if (fCleanupTrack) delete fTrack;
140 delete fAliESDtrackCuts;
141}
142
143//-----------------------------------------------------------------------
12b2b8bc 144Bool_t AliFlowTrackCuts::IsSelected(TObject* obj, Int_t id)
daf66719 145{
146 //check cuts
147 AliVParticle* vparticle = dynamic_cast<AliVParticle*>(obj);
148 if (vparticle) return PassesCuts(vparticle);
149 AliFlowTrackSimple* flowtrack = dynamic_cast<AliFlowTrackSimple*>(obj);
150 if (flowtrack) return PassesCuts(flowtrack);
12b2b8bc 151 AliMultiplicity* tracklets = dynamic_cast<AliMultiplicity*>(obj);
152 if (tracklets) return PassesCuts(tracklets,id);
daf66719 153 return kFALSE; //default when passed wrong type of object
154}
155
156//-----------------------------------------------------------------------
157Bool_t AliFlowTrackCuts::PassesCuts(AliFlowTrackSimple* track)
158{
159 //check cuts on a flowtracksimple
5559ce24 160
161 //clean up from last iteration
162 if (fCleanupTrack) delete fTrack; fTrack = NULL;
daf66719 163 return AliFlowTrackSimpleCuts::PassesCuts(track);
164}
165
166//-----------------------------------------------------------------------
12b2b8bc 167Bool_t AliFlowTrackCuts::PassesCuts(AliMultiplicity* tracklet, Int_t id)
168{
169 //check cuts on a tracklets
170
171 //clean up from last iteration
172 if (fCleanupTrack) delete fTrack; fTrack = NULL;
173 fMCparticle=NULL;
174
175 fTrackPhi = tracklet->GetPhi(id);
176 fTrackEta = tracklet->GetEta(id);
177 fTrackWeight = 1.0;
178 if (fCutEta) {if ( fTrackEta < fEtaMin || fTrackEta >= fEtaMax ) return kFALSE;}
179 if (fCutPhi) {if ( fTrackPhi < fPhiMin || fTrackPhi >= fPhiMax ) return kFALSE;}
180
181 //check MC info if available
182 fTrackLabel = tracklet->GetLabel(id,1); //TODO: this can be improved
183 if (!PassesMCcuts()) return kFALSE;
184 return kTRUE;
185}
186
187//-----------------------------------------------------------------------
188Bool_t AliFlowTrackCuts::PassesMCcuts()
189{
190 //check the MC info
191 if (!fMCevent) {AliError("no MC info"); return kFALSE;}
192 fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
193 if (!fMCparticle) {AliError("no MC info"); return kFALSE;}
194
195 if (fCutMCisPrimary)
196 {
197 if (IsPhysicalPrimary() != fMCisPrimary) return kFALSE;
198 }
199 if (fCutMCPID)
200 {
201 Int_t pdgCode = fMCparticle->PdgCode();
202 if (fMCPID != pdgCode) return kFALSE;
203 }
204 if ( fCutMCprocessType )
205 {
206 TParticle* particle = fMCparticle->Particle();
207 Int_t processID = particle->GetUniqueID();
208 if (processID != fMCprocessType ) return kFALSE;
209 }
210 return kTRUE;
211}
212
213//-----------------------------------------------------------------------
daf66719 214Bool_t AliFlowTrackCuts::PassesCuts(AliVParticle* vparticle)
215{
216 //check cuts for an ESD vparticle
217
127a5825 218 ////////////////////////////////////////////////////////////////
219 // start by preparing the track parameters to cut on //////////
220 ////////////////////////////////////////////////////////////////
5559ce24 221 //clean up from last iteration
222 if (fCleanupTrack) delete fTrack; fTrack=NULL;
223
957517fa 224 //get the label and the mc particle
127a5825 225 fTrackLabel = (fFakesAreOK)?TMath::Abs(vparticle->GetLabel()):vparticle->GetLabel();
226 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
daf66719 227 else fMCparticle=NULL;
228
957517fa 229 Bool_t isMCparticle = kFALSE; //some things are different for MC particles, check!
daf66719 230 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*>(vparticle);
231 if (esdTrack)
232 HandleESDtrack(esdTrack);
233 else
957517fa 234 {
daf66719 235 HandleVParticle(vparticle);
957517fa 236 //now check if produced particle is MC
237 isMCparticle = (dynamic_cast<AliMCParticle*>(fTrack))!=NULL;
238 }
127a5825 239 ////////////////////////////////////////////////////////////////
240 ////////////////////////////////////////////////////////////////
241
924b02b0 242 Bool_t pass=kTRUE;
daf66719 243 //check the common cuts for the current particle (MC,AOD,ESD)
924b02b0 244 if (fCutPt) {if (fTrack->Pt() < fPtMin || fTrack->Pt() >= fPtMax ) pass=kFALSE;}
245 if (fCutEta) {if (fTrack->Eta() < fEtaMin || fTrack->Eta() >= fEtaMax ) pass=kFALSE;}
246 if (fCutPhi) {if (fTrack->Phi() < fPhiMin || fTrack->Phi() >= fPhiMax ) pass=kFALSE;}
247 if (fRequireCharge) {if (fTrack->Charge() == 0) pass=kFALSE;}
248 if (fCutCharge && !isMCparticle) {if (fTrack->Charge() != fCharge) pass=kFALSE;}
957517fa 249 if (fCutCharge && isMCparticle)
250 {
251 //in case of an MC particle the charge is stored in units of 1/3|e|
252 Int_t charge = TMath::Nint(fTrack->Charge()/3.0); //mc particles have charge in units of 1/3e
253 return (charge==fCharge);
254 }
924b02b0 255 //if(fCutPID) {if (fTrack->PID() != fPID) pass=kFALSE;}
daf66719 256
957517fa 257 //when additionally MC info is required
924b02b0 258 if (!PassesMCcuts()) pass=kFALSE;
daf66719 259
260 //check all else for ESDs using aliesdtrackcuts
924b02b0 261 if (esdTrack && (fParamType!=kMC) )
262 if (!fAliESDtrackCuts->IsSelected(static_cast<AliESDtrack*>(fTrack))) pass=kFALSE;
daf66719 263
924b02b0 264 return pass; //true by default, if we didn't set any cuts
daf66719 265}
266
267//-----------------------------------------------------------------------
268void AliFlowTrackCuts::HandleVParticle(AliVParticle* track)
269{
270 //handle the general case
daf66719 271 switch (fParamType)
272 {
daf66719 273 default:
274 fCleanupTrack = kFALSE;
275 fTrack = track;
276 }
277}
278
279//-----------------------------------------------------------------------
280void AliFlowTrackCuts::HandleESDtrack(AliESDtrack* track)
281{
282 //handle esd track
daf66719 283 switch (fParamType)
284 {
12b2b8bc 285 case kGlobal:
daf66719 286 fTrack = track;
287 fCleanupTrack = kFALSE;
288 break;
289 case kESD_TPConly:
290 fTrack = new AliESDtrack();
291 track->FillTPCOnlyTrack(*(static_cast<AliESDtrack*>(fTrack)));
292 fCleanupTrack = kTRUE;
957517fa 293 //recalculate the label and mc particle, they may differ as TPClabel != global label
127a5825 294 fTrackLabel = (fFakesAreOK)?TMath::Abs(fTrack->GetLabel()):fTrack->GetLabel();
295 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
957517fa 296 else fMCparticle=NULL;
daf66719 297 break;
daf66719 298 default:
299 fTrack = track;
300 fCleanupTrack = kFALSE;
301 }
302}
303
304//-----------------------------------------------------------------------
305AliFlowTrackCuts* AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts()
306{
307 //get standard cuts
308 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
5559ce24 309 cuts->SetName("standard TPConly cuts");
daf66719 310 delete cuts->fAliESDtrackCuts;
311 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
5559ce24 312 cuts->SetParamType(kESD_TPConly);
daf66719 313 return cuts;
314}
315
316//-----------------------------------------------------------------------
317AliFlowTrackCuts* AliFlowTrackCuts::GetStandardITSTPCTrackCuts2009(Bool_t selPrimaries)
318{
319 //get standard cuts
320 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
321 cuts->SetName("standard global track cuts 2009");
322 delete cuts->fAliESDtrackCuts;
323 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2009(selPrimaries);
12b2b8bc 324 cuts->SetParamType(kGlobal);
daf66719 325 return cuts;
326}
327
328//-----------------------------------------------------------------------
329AliFlowTrack* AliFlowTrackCuts::MakeFlowTrack() const
330{
331 //get a flow track constructed from whatever we applied cuts on
332 //caller is resposible for deletion
333 AliFlowTrack* flowtrack=NULL;
12b2b8bc 334 if (fParamType==kESD_SPDtracklet)
daf66719 335 {
12b2b8bc 336 flowtrack = new AliFlowTrack();
337 flowtrack->SetPhi(fTrackPhi);
338 flowtrack->SetEta(fTrackEta);
339 flowtrack->SetSource(AliFlowTrack::kFromTracklet);
340 }
341 else
342 {
343 switch(fParamMix)
344 {
345 case kPure:
346 flowtrack = new AliFlowTrack(fTrack);
347 break;
348 case kTrackWithMCkine:
349 flowtrack = new AliFlowTrack(fMCparticle);
350 break;
351 case kTrackWithMCPID:
352 flowtrack = new AliFlowTrack(fTrack);
353 break;
354 default:
355 flowtrack = new AliFlowTrack(fTrack);
356 }
357 if (fParamType==kMC) flowtrack->SetSource(AliFlowTrack::kFromMC);
358 else if (dynamic_cast<AliESDtrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromESD);
359 else if (dynamic_cast<AliAODTrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromAOD);
360 else if (dynamic_cast<AliMCParticle*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromMC);
daf66719 361 }
daf66719 362 return flowtrack;
363}
127a5825 364
365//-----------------------------------------------------------------------
366Bool_t AliFlowTrackCuts::IsPhysicalPrimary() const
367{
368 //check if current particle is a physical primary
369 return fMCevent->IsPhysicalPrimary(fTrackLabel);
370}
12b2b8bc 371
372//-----------------------------------------------------------------------
373const char* AliFlowTrackCuts::GetParamTypeName(trackParameterType type)
374{
375 //return the name of the selected parameter type
376 switch (type)
377 {
378 case kMC:
379 return "MC";
380 case kGlobal:
381 return "ESD global";
382 case kESD_TPConly:
383 return "TPC only";
384 case kESD_SPDtracklet:
385 return "SPD tracklet";
386 default:
387 return "unknown";
388 }
389 return "unknown";
390}
924b02b0 391
392//-----------------------------------------------------------------------
393void AliFlowTrackCuts::DefineHistograms()
394{
395}