parameters for Lorentz angle correc tion in SPD and SSD
[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>
9a0783cc 39#include "TParticle.h"
40#include "AliStack.h"
daf66719 41#include "AliMCEvent.h"
9a0783cc 42#include "AliESDEvent.h"
daf66719 43#include "AliVParticle.h"
44#include "AliMCParticle.h"
45#include "AliESDtrack.h"
12b2b8bc 46#include "AliMultiplicity.h"
daf66719 47#include "AliAODTrack.h"
48#include "AliFlowTrack.h"
49#include "AliFlowTrackCuts.h"
50#include "AliLog.h"
51
52ClassImp(AliFlowTrackCuts)
53
54//-----------------------------------------------------------------------
55AliFlowTrackCuts::AliFlowTrackCuts():
56 AliFlowTrackSimpleCuts(),
57 fAliESDtrackCuts(new AliESDtrackCuts()),
924b02b0 58 fQA(kFALSE),
daf66719 59 fCutMCprocessType(kFALSE),
60 fMCprocessType(kPNoProcess),
61 fCutMCPID(kFALSE),
62 fMCPID(0),
63 fCutMCisPrimary(kFALSE),
64 fMCisPrimary(kFALSE),
957517fa 65 fRequireCharge(kFALSE),
127a5825 66 fFakesAreOK(kTRUE),
9a0783cc 67 fCutSPDtrackletDeltaPhi(kFALSE),
68 fSPDtrackletDeltaPhiMax(FLT_MAX),
69 fSPDtrackletDeltaPhiMin(-FLT_MAX),
12b2b8bc 70 fParamType(kGlobal),
daf66719 71 fParamMix(kPure),
daf66719 72 fCleanupTrack(kFALSE),
73 fTrack(NULL),
12b2b8bc 74 fTrackPhi(0.),
75 fTrackEta(0.),
76 fTrackWeight(0.),
127a5825 77 fTrackLabel(INT_MIN),
957517fa 78 fMCevent(NULL),
9a0783cc 79 fMCparticle(NULL),
80 fEvent(NULL)
daf66719 81{
82 //constructor
83}
84
85//-----------------------------------------------------------------------
86AliFlowTrackCuts::AliFlowTrackCuts(const AliFlowTrackCuts& someCuts):
87 AliFlowTrackSimpleCuts(someCuts),
88 fAliESDtrackCuts(new AliESDtrackCuts(*(someCuts.fAliESDtrackCuts))),
924b02b0 89 fQA(someCuts.fQA),
daf66719 90 fCutMCprocessType(someCuts.fCutMCprocessType),
91 fMCprocessType(someCuts.fMCprocessType),
92 fCutMCPID(someCuts.fCutMCPID),
93 fMCPID(someCuts.fMCPID),
94 fCutMCisPrimary(someCuts.fCutMCisPrimary),
95 fMCisPrimary(someCuts.fMCisPrimary),
957517fa 96 fRequireCharge(someCuts.fRequireCharge),
127a5825 97 fFakesAreOK(someCuts.fFakesAreOK),
9a0783cc 98 fCutSPDtrackletDeltaPhi(someCuts.fCutSPDtrackletDeltaPhi),
99 fSPDtrackletDeltaPhiMax(someCuts.fSPDtrackletDeltaPhiMax),
100 fSPDtrackletDeltaPhiMin(someCuts.fSPDtrackletDeltaPhiMin),
daf66719 101 fParamType(someCuts.fParamType),
102 fParamMix(someCuts.fParamMix),
daf66719 103 fCleanupTrack(kFALSE),
104 fTrack(NULL),
12b2b8bc 105 fTrackPhi(someCuts.fTrackPhi),
106 fTrackEta(someCuts.fTrackEta),
107 fTrackWeight(someCuts.fTrackWeight),
127a5825 108 fTrackLabel(INT_MIN),
957517fa 109 fMCevent(NULL),
9a0783cc 110 fMCparticle(NULL),
111 fEvent(NULL)
daf66719 112{
113 //copy constructor
114}
115
116//-----------------------------------------------------------------------
117AliFlowTrackCuts& AliFlowTrackCuts::operator=(const AliFlowTrackCuts& someCuts)
118{
119 //assignment
120 AliFlowTrackSimpleCuts::operator=(someCuts);
121 *fAliESDtrackCuts=*(someCuts.fAliESDtrackCuts);
924b02b0 122 fQA=someCuts.fQA;
daf66719 123 fCutMCprocessType=someCuts.fCutMCprocessType;
124 fMCprocessType=someCuts.fMCprocessType;
125 fCutMCPID=someCuts.fCutMCPID;
126 fMCPID=someCuts.fMCPID;
127 fCutMCisPrimary=someCuts.fCutMCisPrimary;
128 fMCisPrimary=someCuts.fMCisPrimary;
957517fa 129 fRequireCharge=someCuts.fRequireCharge;
127a5825 130 fFakesAreOK=someCuts.fFakesAreOK;
9a0783cc 131 fCutSPDtrackletDeltaPhi=someCuts.fCutSPDtrackletDeltaPhi;
132 fSPDtrackletDeltaPhiMax=someCuts.fSPDtrackletDeltaPhiMax;
133 fSPDtrackletDeltaPhiMin=someCuts.fSPDtrackletDeltaPhiMin;
daf66719 134 fParamType=someCuts.fParamType;
135 fParamMix=someCuts.fParamMix;
136
daf66719 137 fCleanupTrack=kFALSE;
138 fTrack=NULL;
12b2b8bc 139 fTrackPhi=someCuts.fTrackPhi;
140 fTrackPhi=someCuts.fTrackPhi;
141 fTrackWeight=someCuts.fTrackWeight;
127a5825 142 fTrackLabel=INT_MIN;
957517fa 143 fMCevent=NULL;
daf66719 144 fMCparticle=NULL;
9a0783cc 145 fEvent=NULL;
daf66719 146
147 return *this;
148}
149
150//-----------------------------------------------------------------------
151AliFlowTrackCuts::~AliFlowTrackCuts()
152{
153 //dtor
154 if (fCleanupTrack) delete fTrack;
155 delete fAliESDtrackCuts;
156}
157
158//-----------------------------------------------------------------------
12b2b8bc 159Bool_t AliFlowTrackCuts::IsSelected(TObject* obj, Int_t id)
daf66719 160{
161 //check cuts
162 AliVParticle* vparticle = dynamic_cast<AliVParticle*>(obj);
163 if (vparticle) return PassesCuts(vparticle);
164 AliFlowTrackSimple* flowtrack = dynamic_cast<AliFlowTrackSimple*>(obj);
165 if (flowtrack) return PassesCuts(flowtrack);
12b2b8bc 166 AliMultiplicity* tracklets = dynamic_cast<AliMultiplicity*>(obj);
167 if (tracklets) return PassesCuts(tracklets,id);
daf66719 168 return kFALSE; //default when passed wrong type of object
169}
170
171//-----------------------------------------------------------------------
172Bool_t AliFlowTrackCuts::PassesCuts(AliFlowTrackSimple* track)
173{
174 //check cuts on a flowtracksimple
5559ce24 175
176 //clean up from last iteration
177 if (fCleanupTrack) delete fTrack; fTrack = NULL;
daf66719 178 return AliFlowTrackSimpleCuts::PassesCuts(track);
179}
180
181//-----------------------------------------------------------------------
12b2b8bc 182Bool_t AliFlowTrackCuts::PassesCuts(AliMultiplicity* tracklet, Int_t id)
183{
184 //check cuts on a tracklets
185
9a0783cc 186 //clean up from last iteration, and init label
12b2b8bc 187 if (fCleanupTrack) delete fTrack; fTrack = NULL;
188 fMCparticle=NULL;
9a0783cc 189 fTrackLabel=-1;
12b2b8bc 190
191 fTrackPhi = tracklet->GetPhi(id);
192 fTrackEta = tracklet->GetEta(id);
193 fTrackWeight = 1.0;
194 if (fCutEta) {if ( fTrackEta < fEtaMin || fTrackEta >= fEtaMax ) return kFALSE;}
195 if (fCutPhi) {if ( fTrackPhi < fPhiMin || fTrackPhi >= fPhiMax ) return kFALSE;}
196
197 //check MC info if available
9a0783cc 198 //if the 2 clusters have different label track cannot be good
199 //and should therefore not pass the mc cuts
200 Int_t label0 = tracklet->GetLabel(id,0);
201 Int_t label1 = tracklet->GetLabel(id,1);
202 fTrackLabel = (label0==label1)?tracklet->GetLabel(id,1):-1;
12b2b8bc 203 if (!PassesMCcuts()) return kFALSE;
204 return kTRUE;
205}
206
207//-----------------------------------------------------------------------
208Bool_t AliFlowTrackCuts::PassesMCcuts()
209{
210 //check the MC info
03d364db 211 if (!fMCevent) return kFALSE;
9a0783cc 212 if (fTrackLabel<0) return kFALSE;//otherwise AliCMevent prints a warning before returning NULL
12b2b8bc 213 fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
03d364db 214 if (!fMCparticle) {AliError("no MC track"); return kFALSE;}
12b2b8bc 215
216 if (fCutMCisPrimary)
217 {
9a0783cc 218 if (IsPhysicalPrimary(fMCevent,fTrackLabel) != fMCisPrimary) return kFALSE;
12b2b8bc 219 }
220 if (fCutMCPID)
221 {
222 Int_t pdgCode = fMCparticle->PdgCode();
223 if (fMCPID != pdgCode) return kFALSE;
224 }
225 if ( fCutMCprocessType )
226 {
227 TParticle* particle = fMCparticle->Particle();
228 Int_t processID = particle->GetUniqueID();
229 if (processID != fMCprocessType ) return kFALSE;
230 }
231 return kTRUE;
232}
233
234//-----------------------------------------------------------------------
daf66719 235Bool_t AliFlowTrackCuts::PassesCuts(AliVParticle* vparticle)
236{
237 //check cuts for an ESD vparticle
238
127a5825 239 ////////////////////////////////////////////////////////////////
240 // start by preparing the track parameters to cut on //////////
241 ////////////////////////////////////////////////////////////////
5559ce24 242 //clean up from last iteration
243 if (fCleanupTrack) delete fTrack; fTrack=NULL;
244
957517fa 245 //get the label and the mc particle
127a5825 246 fTrackLabel = (fFakesAreOK)?TMath::Abs(vparticle->GetLabel()):vparticle->GetLabel();
247 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
daf66719 248 else fMCparticle=NULL;
249
957517fa 250 Bool_t isMCparticle = kFALSE; //some things are different for MC particles, check!
daf66719 251 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*>(vparticle);
252 if (esdTrack)
253 HandleESDtrack(esdTrack);
254 else
957517fa 255 {
daf66719 256 HandleVParticle(vparticle);
957517fa 257 //now check if produced particle is MC
258 isMCparticle = (dynamic_cast<AliMCParticle*>(fTrack))!=NULL;
259 }
127a5825 260 ////////////////////////////////////////////////////////////////
261 ////////////////////////////////////////////////////////////////
262
924b02b0 263 Bool_t pass=kTRUE;
9a0783cc 264 //check the common cuts for the current particle fTrack (MC,AOD,ESD)
924b02b0 265 if (fCutPt) {if (fTrack->Pt() < fPtMin || fTrack->Pt() >= fPtMax ) pass=kFALSE;}
266 if (fCutEta) {if (fTrack->Eta() < fEtaMin || fTrack->Eta() >= fEtaMax ) pass=kFALSE;}
267 if (fCutPhi) {if (fTrack->Phi() < fPhiMin || fTrack->Phi() >= fPhiMax ) pass=kFALSE;}
268 if (fRequireCharge) {if (fTrack->Charge() == 0) pass=kFALSE;}
269 if (fCutCharge && !isMCparticle) {if (fTrack->Charge() != fCharge) pass=kFALSE;}
957517fa 270 if (fCutCharge && isMCparticle)
271 {
272 //in case of an MC particle the charge is stored in units of 1/3|e|
273 Int_t charge = TMath::Nint(fTrack->Charge()/3.0); //mc particles have charge in units of 1/3e
274 return (charge==fCharge);
275 }
924b02b0 276 //if(fCutPID) {if (fTrack->PID() != fPID) pass=kFALSE;}
daf66719 277
957517fa 278 //when additionally MC info is required
924b02b0 279 if (!PassesMCcuts()) pass=kFALSE;
daf66719 280
281 //check all else for ESDs using aliesdtrackcuts
924b02b0 282 if (esdTrack && (fParamType!=kMC) )
283 if (!fAliESDtrackCuts->IsSelected(static_cast<AliESDtrack*>(fTrack))) pass=kFALSE;
daf66719 284
924b02b0 285 return pass; //true by default, if we didn't set any cuts
daf66719 286}
287
288//-----------------------------------------------------------------------
289void AliFlowTrackCuts::HandleVParticle(AliVParticle* track)
290{
291 //handle the general case
daf66719 292 switch (fParamType)
293 {
daf66719 294 default:
295 fCleanupTrack = kFALSE;
296 fTrack = track;
297 }
298}
299
300//-----------------------------------------------------------------------
301void AliFlowTrackCuts::HandleESDtrack(AliESDtrack* track)
302{
303 //handle esd track
daf66719 304 switch (fParamType)
305 {
12b2b8bc 306 case kGlobal:
daf66719 307 fTrack = track;
308 fCleanupTrack = kFALSE;
309 break;
310 case kESD_TPConly:
311 fTrack = new AliESDtrack();
312 track->FillTPCOnlyTrack(*(static_cast<AliESDtrack*>(fTrack)));
313 fCleanupTrack = kTRUE;
957517fa 314 //recalculate the label and mc particle, they may differ as TPClabel != global label
127a5825 315 fTrackLabel = (fFakesAreOK)?TMath::Abs(fTrack->GetLabel()):fTrack->GetLabel();
316 if (fMCevent) fMCparticle = static_cast<AliMCParticle*>(fMCevent->GetTrack(fTrackLabel));
957517fa 317 else fMCparticle=NULL;
daf66719 318 break;
daf66719 319 default:
320 fTrack = track;
321 fCleanupTrack = kFALSE;
322 }
323}
324
325//-----------------------------------------------------------------------
326AliFlowTrackCuts* AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts()
327{
328 //get standard cuts
329 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
5559ce24 330 cuts->SetName("standard TPConly cuts");
daf66719 331 delete cuts->fAliESDtrackCuts;
332 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
5559ce24 333 cuts->SetParamType(kESD_TPConly);
daf66719 334 return cuts;
335}
336
337//-----------------------------------------------------------------------
338AliFlowTrackCuts* AliFlowTrackCuts::GetStandardITSTPCTrackCuts2009(Bool_t selPrimaries)
339{
340 //get standard cuts
341 AliFlowTrackCuts* cuts = new AliFlowTrackCuts();
342 cuts->SetName("standard global track cuts 2009");
343 delete cuts->fAliESDtrackCuts;
344 cuts->fAliESDtrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2009(selPrimaries);
12b2b8bc 345 cuts->SetParamType(kGlobal);
daf66719 346 return cuts;
347}
348
349//-----------------------------------------------------------------------
350AliFlowTrack* AliFlowTrackCuts::MakeFlowTrack() const
351{
352 //get a flow track constructed from whatever we applied cuts on
353 //caller is resposible for deletion
9a0783cc 354 //if construction fails return NULL
daf66719 355 AliFlowTrack* flowtrack=NULL;
12b2b8bc 356 if (fParamType==kESD_SPDtracklet)
daf66719 357 {
12b2b8bc 358 flowtrack = new AliFlowTrack();
9a0783cc 359 switch (fParamMix)
360 {
361 case kPure:
362 flowtrack->SetPhi(fTrackPhi);
363 flowtrack->SetEta(fTrackEta);
364 break;
365 case kTrackWithMCkine:
366 if (!fMCparticle) return NULL;
367 flowtrack->SetPhi( fMCparticle->Phi() );
368 flowtrack->SetEta( fMCparticle->Eta() );
369 flowtrack->SetPt( fMCparticle->Pt() );
370 break;
371 case kTrackWithMCpt:
372 if (!fMCparticle) return NULL;
373 flowtrack->SetPhi(fTrackPhi);
374 flowtrack->SetEta(fTrackEta);
375 flowtrack->SetPt(fMCparticle->Pt());
376 break;
377 default:
378 flowtrack->SetPhi(fTrackPhi);
379 flowtrack->SetEta(fTrackEta);
380 }
12b2b8bc 381 flowtrack->SetSource(AliFlowTrack::kFromTracklet);
382 }
383 else
384 {
385 switch(fParamMix)
386 {
387 case kPure:
388 flowtrack = new AliFlowTrack(fTrack);
389 break;
390 case kTrackWithMCkine:
391 flowtrack = new AliFlowTrack(fMCparticle);
392 break;
393 case kTrackWithMCPID:
394 flowtrack = new AliFlowTrack(fTrack);
9a0783cc 395 //flowtrack->setPID(...) from mc, when implemented
12b2b8bc 396 break;
9a0783cc 397 case kTrackWithMCpt:
398 if (!fMCparticle) return NULL;
399 flowtrack = new AliFlowTrack(fTrack);
400 flowtrack->SetPt(fMCparticle->Pt());
12b2b8bc 401 default:
402 flowtrack = new AliFlowTrack(fTrack);
403 }
404 if (fParamType==kMC) flowtrack->SetSource(AliFlowTrack::kFromMC);
405 else if (dynamic_cast<AliESDtrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromESD);
406 else if (dynamic_cast<AliAODTrack*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromAOD);
407 else if (dynamic_cast<AliMCParticle*>(fTrack)) flowtrack->SetSource(AliFlowTrack::kFromMC);
daf66719 408 }
daf66719 409 return flowtrack;
410}
127a5825 411
412//-----------------------------------------------------------------------
413Bool_t AliFlowTrackCuts::IsPhysicalPrimary() const
414{
415 //check if current particle is a physical primary
9a0783cc 416 if (!fMCevent) return kFALSE;
417 if (fTrackLabel<0) return kFALSE;
418 return IsPhysicalPrimary(fMCevent, fTrackLabel);
419}
420
421//-----------------------------------------------------------------------
422Bool_t AliFlowTrackCuts::IsPhysicalPrimary(AliMCEvent* mcEvent, Int_t label)
423{
424 //check if current particle is a physical primary
425 Bool_t physprim=mcEvent->IsPhysicalPrimary(label);
426 if (!physprim) return kFALSE;
427 AliMCParticle* track = static_cast<AliMCParticle*>(mcEvent->GetTrack(label));
428 if (!track) return kFALSE;
429 TParticle* particle = track->Particle();
430 Bool_t transported = particle->TestBit(kTransportBit);
431 //printf("prim: %s, transp: %s\n",(physprim)?"YES":"NO ",(transported)?"YES":"NO ");
432 return (physprim && transported);
127a5825 433}
12b2b8bc 434
435//-----------------------------------------------------------------------
436const char* AliFlowTrackCuts::GetParamTypeName(trackParameterType type)
437{
438 //return the name of the selected parameter type
439 switch (type)
440 {
441 case kMC:
442 return "MC";
443 case kGlobal:
444 return "ESD global";
445 case kESD_TPConly:
446 return "TPC only";
447 case kESD_SPDtracklet:
448 return "SPD tracklet";
449 default:
450 return "unknown";
451 }
452 return "unknown";
453}
924b02b0 454
455//-----------------------------------------------------------------------
456void AliFlowTrackCuts::DefineHistograms()
457{
458}
9a0783cc 459
460//-----------------------------------------------------------------------
461Int_t AliFlowTrackCuts::GetNumberOfInputObjects() const
462{
463 //get the number of tracks in the input event according source
464 //selection (ESD tracks, tracklets, MC particles etc.)
465 AliESDEvent* esd=NULL;
466 switch (fParamType)
467 {
468 case kESD_SPDtracklet:
469 esd = dynamic_cast<AliESDEvent*>(fEvent);
470 if (!esd) return 0;
471 return esd->GetMultiplicity()->GetNumberOfTracklets();
472 case kMC:
473 if (!fMCevent) return 0;
474 return fMCevent->GetNumberOfTracks();
475 default:
476 if (!fEvent) return 0;
477 return fEvent->GetNumberOfTracks();
478 }
479 return 0;
480}
481
482//-----------------------------------------------------------------------
483TObject* AliFlowTrackCuts::GetInputObject(Int_t i)
484{
485 //get the input object according the data source selection:
486 //(esd tracks, traclets, mc particles,etc...)
487 AliESDEvent* esd=NULL;
488 switch (fParamType)
489 {
490 case kESD_SPDtracklet:
491 esd = dynamic_cast<AliESDEvent*>(fEvent);
492 if (!esd) return NULL;
493 return const_cast<AliMultiplicity*>(esd->GetMultiplicity());
494 case kMC:
495 if (!fMCevent) return NULL;
496 return fMCevent->GetTrack(i);
497 default:
498 if (!fEvent) return NULL;
499 return fEvent->GetTrack(i);
500 }
501}