tracklets accessible from ESD and AOD events via virtual class: https://alice.its...
[u/mrichter/AliRoot.git] / ANALYSIS / ESDfilter / AliAnalysisTaskESDfilter.cxx
CommitLineData
c82bb898 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
63825dc4 18#include <Riostream.h>
c82bb898 19#include <TChain.h>
20#include <TTree.h>
21#include <TList.h>
22#include <TArrayI.h>
23#include <TParameter.h>
24#include <TRandom.h>
25#include <TParticle.h>
26#include <TFile.h>
63825dc4 27#include <TVector3.h>
c82bb898 28
29#include "AliAnalysisTaskESDfilter.h"
30#include "AliAnalysisManager.h"
31#include "AliESDEvent.h"
32#include "AliESDRun.h"
33#include "AliStack.h"
34#include "AliAODEvent.h"
35#include "AliMCEvent.h"
36#include "AliMCEventHandler.h"
37#include "AliESDInputHandler.h"
38#include "AliAODHandler.h"
39#include "AliAODMCParticle.h"
40#include "AliAnalysisFilter.h"
41#include "AliESDMuonTrack.h"
42#include "AliESDVertex.h"
43#include "AliCentrality.h"
44#include "AliEventplane.h"
45#include "AliESDv0.h"
46#include "AliESDkink.h"
47#include "AliESDcascade.h"
48#include "AliESDPmdTrack.h"
49#include "AliESDCaloCluster.h"
50#include "AliESDCaloCells.h"
51#include "AliMultiplicity.h"
52#include "AliLog.h"
53#include "AliCodeTimer.h"
54#include "AliESDtrackCuts.h"
55#include "AliESDpid.h"
08b38f3f 56#include "AliAODHMPIDrings.h"
c82bb898 57#include "AliV0vertexer.h"
58#include "AliCascadeVertexer.h"
c82bb898 59#include "AliExternalTrackParam.h"
60#include "AliTrackerBase.h"
c82bb898 61#include "AliTPCdEdxInfo.h"
62
b2b65de9 63#include "AliESDTrdTrack.h"
64#include "AliESDTrdTracklet.h"
65#include "AliAODTrdTrack.h"
66#include "AliAODTrdTracklet.h"
63825dc4 67#include "AliEMCALRecoUtils.h"
db47bd9e 68#include "AliESDUtils.h"
b2b65de9 69
c82bb898 70using std::cout;
71using std::endl;
72ClassImp(AliAnalysisTaskESDfilter)
73
74////////////////////////////////////////////////////////////////////////
75
76AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter():
77 AliAnalysisTaskSE(),
78 fTrackFilter(0x0),
79 fKinkFilter(0x0),
80 fV0Filter(0x0),
81 fCascadeFilter(0x0),
82 fHighPthreshold(0),
83 fPtshape(0x0),
84 fEnableFillAOD(kTRUE),
85 fUsedTrack(0x0),
b2b65de9 86 fUsedTrackCopy(0x0),
c82bb898 87 fUsedKink(0x0),
88 fUsedV0(0x0),
89 fAODTrackRefs(0x0),
90 fAODV0VtxRefs(0x0),
91 fAODV0Refs(0x0),
92 fMChandler(0x0),
93 fNumberOfTracks(0),
94 fNumberOfPositiveTracks(0),
95 fNumberOfV0s(0),
96 fNumberOfVertices(0),
97 fNumberOfCascades(0),
98 fNumberOfKinks(0),
99 fOldESDformat(kFALSE),
100 fPrimaryVertex(0x0),
101 fTPCConstrainedFilterMask(0),
102 fHybridFilterMaskTPCCG(0),
103 fWriteHybridTPCCOnly(kFALSE),
104 fGlobalConstrainedFilterMask(0),
105 fHybridFilterMaskGCG(0),
106 fWriteHybridGCOnly(kFALSE),
107 fIsVZEROEnabled(kTRUE),
108 fIsTZEROEnabled(kTRUE),
109 fIsZDCEnabled(kTRUE),
08b38f3f 110 fIsHMPIDEnabled(kTRUE),
c82bb898 111 fIsV0CascadeRecoEnabled(kFALSE),
112 fAreCascadesEnabled(kTRUE),
113 fAreV0sEnabled(kTRUE),
114 fAreKinksEnabled(kTRUE),
115 fAreTracksEnabled(kTRUE),
116 fArePmdClustersEnabled(kTRUE),
117 fAreCaloClustersEnabled(kTRUE),
118 fAreEMCALCellsEnabled(kTRUE),
119 fArePHOSCellsEnabled(kTRUE),
120 fAreEMCALTriggerEnabled(kTRUE),
121 fArePHOSTriggerEnabled(kTRUE),
122 fAreTrackletsEnabled(kTRUE),
b2b65de9 123 fIsTRDEnabled(kTRUE),
c82bb898 124 fESDpid(0x0),
125 fIsPidOwner(kFALSE),
c82bb898 126 fTPCaloneTrackCuts(0),
a29b2a8a 127 fDoPropagateTrackToEMCal(kTRUE),
db47bd9e 128 fEMCalSurfaceDistance(440),
129 fRefitVertexTracks(-1),
ca77219c 130 fRefitVertexTracksNCuts(0),
db47bd9e 131 fRefitVertexTracksCuts(0)
c82bb898 132{
133 // Default constructor
5059e451 134 fV0Cuts[0] = 33. ; // max allowed chi2
135 fV0Cuts[1] = 0.1 ; // min allowed impact parameter for the 1st daughter
136 fV0Cuts[2] = 0.1 ; // min allowed impact parameter for the 2nd daughter
137 fV0Cuts[3] = 1. ; // max allowed DCA between the daughter tracks
138 fV0Cuts[4] = .998; // min allowed cosine of V0's pointing angle
139 fV0Cuts[5] = 0.9 ; // min radius of the fiducial volume
140 fV0Cuts[6] = 100. ; // max radius of the fiducial volume
141
142 fCascadeCuts[0] = 33. ; // max allowed chi2 (same as PDC07)
143 fCascadeCuts[1] = 0.05 ; // min allowed V0 impact parameter
144 fCascadeCuts[2] = 0.008; // "window" around the Lambda mass
145 fCascadeCuts[3] = 0.03 ; // min allowed bachelor's impact parameter
146 fCascadeCuts[4] = 0.3 ; // max allowed DCA between the V0 and the bachelor
147 fCascadeCuts[5] = 0.999; // min allowed cosine of the cascade pointing angle
148 fCascadeCuts[6] = 0.9 ; // min radius of the fiducial volume
149 fCascadeCuts[7] = 100. ; // max radius of the fiducial volume
c82bb898 150}
151
152//______________________________________________________________________________
153AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter(const char* name):
5059e451 154 AliAnalysisTaskSE(name),
155 fTrackFilter(0x0),
156 fKinkFilter(0x0),
157 fV0Filter(0x0),
158 fCascadeFilter(0x0),
159 fHighPthreshold(0),
160 fPtshape(0x0),
161 fEnableFillAOD(kTRUE),
162 fUsedTrack(0x0),
163 fUsedTrackCopy(0x0),
164 fUsedKink(0x0),
165 fUsedV0(0x0),
166 fAODTrackRefs(0x0),
167 fAODV0VtxRefs(0x0),
168 fAODV0Refs(0x0),
169 fMChandler(0x0),
170 fNumberOfTracks(0),
171 fNumberOfPositiveTracks(0),
172 fNumberOfV0s(0),
173 fNumberOfVertices(0),
174 fNumberOfCascades(0),
175 fNumberOfKinks(0),
176 fOldESDformat(kFALSE),
177 fPrimaryVertex(0x0),
c82bb898 178 fTPCConstrainedFilterMask(0),
179 fHybridFilterMaskTPCCG(0),
180 fWriteHybridTPCCOnly(kFALSE),
181 fGlobalConstrainedFilterMask(0),
182 fHybridFilterMaskGCG(0),
183 fWriteHybridGCOnly(kFALSE),
5059e451 184 fIsVZEROEnabled(kTRUE),
185 fIsTZEROEnabled(kTRUE),
186 fIsZDCEnabled(kTRUE),
187 fIsHMPIDEnabled(kTRUE),
188 fIsV0CascadeRecoEnabled(kFALSE),
189 fAreCascadesEnabled(kTRUE),
190 fAreV0sEnabled(kTRUE),
191 fAreKinksEnabled(kTRUE),
192 fAreTracksEnabled(kTRUE),
193 fArePmdClustersEnabled(kTRUE),
194 fAreCaloClustersEnabled(kTRUE),
195 fAreEMCALCellsEnabled(kTRUE),
196 fArePHOSCellsEnabled(kTRUE),
197 fAreEMCALTriggerEnabled(kTRUE),
198 fArePHOSTriggerEnabled(kTRUE),
199 fAreTrackletsEnabled(kTRUE),
200 fIsTRDEnabled(kTRUE),
201 fESDpid(0x0),
202 fIsPidOwner(kFALSE),
203 fTPCaloneTrackCuts(0),
204 fDoPropagateTrackToEMCal(kTRUE),
205 fEMCalSurfaceDistance(440),
206 fRefitVertexTracks(-1),
207 fRefitVertexTracksNCuts(0),
208 fRefitVertexTracksCuts(0)
c82bb898 209{
210 // Constructor
211
5059e451 212 fV0Cuts[0] = 33. ; // max allowed chi2
213 fV0Cuts[1] = 0.1 ; // min allowed impact parameter for the 1st daughter
214 fV0Cuts[2] = 0.1 ; // min allowed impact parameter for the 2nd daughter
215 fV0Cuts[3] = 1. ; // max allowed DCA between the daughter tracks
216 fV0Cuts[4] = .998; // min allowed cosine of V0's pointing angle
217 fV0Cuts[5] = 0.9 ; // min radius of the fiducial volume
218 fV0Cuts[6] = 100. ; // max radius of the fiducial volume
219
220 fCascadeCuts[0] = 33. ; // max allowed chi2 (same as PDC07)
221 fCascadeCuts[1] = 0.05 ; // min allowed V0 impact parameter
222 fCascadeCuts[2] = 0.008; // "window" around the Lambda mass
223 fCascadeCuts[3] = 0.03 ; // min allowed bachelor's impact parameter
224 fCascadeCuts[4] = 0.3 ; // max allowed DCA between the V0 and the bachelor
225 fCascadeCuts[5] = 0.999; // min allowed cosine of the cascade pointing angle
226 fCascadeCuts[6] = 0.9 ; // min radius of the fiducial volume
227 fCascadeCuts[7] = 100. ; // max radius of the fiducial volume
c82bb898 228}
5059e451 229
230AliAnalysisTaskESDfilter::~AliAnalysisTaskESDfilter()
231{
232 if(fIsPidOwner) delete fESDpid;
233 delete[] fRefitVertexTracksCuts;
c82bb898 234}
db47bd9e 235
c82bb898 236//______________________________________________________________________________
237void AliAnalysisTaskESDfilter::UserCreateOutputObjects()
238{
239 //
240 // Create Output Objects conenct filter to outputtree
241 //
242 if(OutputTree())
243 {
244 OutputTree()->GetUserInfo()->Add(fTrackFilter);
245 }
246 else
247 {
248 AliError("No OutputTree() for adding the track filter");
249 }
250 fTPCaloneTrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
251}
252
253//______________________________________________________________________________
254void AliAnalysisTaskESDfilter::Init()
255{
256 // Initialization
257 if (fDebug > 1) AliInfo("Init() \n");
c82bb898 258}
259
260//______________________________________________________________________________
dc893135 261Bool_t AliAnalysisTaskESDfilter::Notify()
262{
5059e451 263 // Notify method.
264 AddMetadataToUserInfo();
265 return kTRUE;
dc893135 266}
267
268//______________________________________________________________________________
269Bool_t AliAnalysisTaskESDfilter::AddMetadataToUserInfo()
270{
5059e451 271 // Copy metadata to AOD user info.
dc893135 272 static Bool_t copyFirst = kFALSE;
273 if (!copyFirst) {
274 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
275 if (!mgr) {
5059e451 276 AliError("AliAnalysisTaskESDfilter::AddMetadataToUserInfo() : No analysis manager !");
277 return kFALSE;
dc893135 278 }
279 TTree *esdTree = mgr->GetTree()->GetTree();
280 if (!esdTree) return kFALSE;
281 TNamed *alirootVersion = (TNamed*)esdTree->GetUserInfo()->FindObject("alirootVersion");
282 if (!alirootVersion) return kFALSE;
283 AliAODHandler *aodHandler = dynamic_cast<AliAODHandler*>(mgr->GetOutputEventHandler());
5059e451 284 if (!aodHandler) return kFALSE;
dc893135 285 TTree *aodTree = aodHandler->GetTree();
286 if (!aodTree) return kFALSE;
287 aodTree->GetUserInfo()->Add(new TNamed(*alirootVersion));
288 copyFirst = kTRUE;
289 }
290 return kTRUE;
291}
292
293//______________________________________________________________________________
c82bb898 294void AliAnalysisTaskESDfilter::PrintTask(Option_t *option, Int_t indent) const
295{
5059e451 296 // Print selection task information
c82bb898 297 AliInfo("");
298
299 AliAnalysisTaskSE::PrintTask(option,indent);
300
301 TString spaces(' ',indent+3);
302
5059e451 303 cout << spaces.Data() << Form("Cascades are %s",fAreCascadesEnabled ? "ENABLED":"DISABLED") << endl;
304 cout << spaces.Data() << Form("V0s are %s",fAreV0sEnabled ? "ENABLED":"DISABLED") << endl;
305 cout << spaces.Data() << Form("Kinks are %s",fAreKinksEnabled ? "ENABLED":"DISABLED") << endl;
306 cout << spaces.Data() << Form("Tracks are %s",fAreTracksEnabled ? "ENABLED":"DISABLED") << endl;
307 cout << spaces.Data() << Form("PmdClusters are %s",fArePmdClustersEnabled ? "ENABLED":"DISABLED") << endl;
308 cout << spaces.Data() << Form("CaloClusters are %s",fAreCaloClustersEnabled ? "ENABLED":"DISABLED") << endl;
c82bb898 309 cout << spaces.Data() << Form("EMCAL cells are %s",fAreEMCALCellsEnabled ? "ENABLED":"DISABLED") << endl;
5059e451 310 cout << spaces.Data() << Form("EMCAL triggers are %s",fAreEMCALTriggerEnabled ? "ENABLED":"DISABLED") << endl;
311 cout << spaces.Data() << Form("PHOS triggers are %s",fArePHOSTriggerEnabled ? "ENABLED":"DISABLED") << endl;
312 cout << spaces.Data() << Form("Tracklets are %s",fAreTrackletsEnabled ? "ENABLED":"DISABLED") << endl;
313 cout << spaces.Data() << Form("PropagateTrackToEMCal is %s", fDoPropagateTrackToEMCal ? "ENABLED":"DISABLED") << endl;
314 if (fRefitVertexTracks<0) cout << spaces.Data() << Form("RefitVerteTracks is DISABLED") << endl;
315 else cout << spaces.Data() << Form("RefitVerteTracks is ENABLED to %d",fRefitVertexTracks) << endl;
c82bb898 316}
317
318//______________________________________________________________________________
319void AliAnalysisTaskESDfilter::UserExec(Option_t */*option*/)
320{
5059e451 321 // Execute analysis for current event
c82bb898 322
323 Long64_t ientry = Entry();
c82bb898 324 if (fDebug > 0) {
5059e451 325 printf("Filter: Analysing event # %5d\n", (Int_t) ientry);
326 if (fHighPthreshold == 0) AliInfo("detector PID signals are stored in each track");
327 if (!fPtshape) AliInfo("detector PID signals are not stored below the pt threshold");
c82bb898 328 }
329 // Filters must explicitely enable AOD filling in their UserExec (AG)
5059e451 330 if (!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler())
331 AliFatal("Cannot run ESD filter without an output event handler");
c82bb898 332 if(fEnableFillAOD) {
5059e451 333 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);
334 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillExtension(kTRUE);
c82bb898 335 }
336 ConvertESDtoAOD();
337}
338
339//______________________________________________________________________________
340TClonesArray& AliAnalysisTaskESDfilter::Cascades()
341{
342 return *(AODEvent()->GetCascades());
343}
344
345//______________________________________________________________________________
346TClonesArray& AliAnalysisTaskESDfilter::Tracks()
347{
348 return *(AODEvent()->GetTracks());
349}
350
351//______________________________________________________________________________
352TClonesArray& AliAnalysisTaskESDfilter::V0s()
353{
354 return *(AODEvent()->GetV0s());
355}
356
357//______________________________________________________________________________
358TClonesArray& AliAnalysisTaskESDfilter::Vertices()
359{
360 return *(AODEvent()->GetVertices());
361}
362
363//______________________________________________________________________________
364AliAODHeader* AliAnalysisTaskESDfilter::ConvertHeader(const AliESDEvent& esd)
365{
5059e451 366 // Convert header information
c82bb898 367
368 AliCodeTimerAuto("",0);
369
370 AliAODHeader* header = AODEvent()->GetHeader();
371
372 header->SetRunNumber(esd.GetRunNumber());
373 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
ef7661fd 374 header->SetNumberOfESDTracks(esd.GetNumberOfTracks());
c82bb898 375
376 TTree* tree = fInputHandler->GetTree();
377 if (tree) {
378 TFile* file = tree->GetCurrentFile();
379 if (file) header->SetESDFileName(file->GetName());
380 }
381
382 if (fOldESDformat) {
383 header->SetBunchCrossNumber(0);
384 header->SetOrbitNumber(0);
385 header->SetPeriodNumber(0);
386 header->SetEventType(0);
387 header->SetMuonMagFieldScale(-999.);
388 header->SetCentrality(0);
389 header->SetEventplane(0);
390 } else {
391 header->SetBunchCrossNumber(esd.GetBunchCrossNumber());
392 header->SetOrbitNumber(esd.GetOrbitNumber());
393 header->SetPeriodNumber(esd.GetPeriodNumber());
394 header->SetEventType(esd.GetEventType());
395
396 header->SetEventNumberESDFile(esd.GetHeader()->GetEventNumberInFile());
397 if(const_cast<AliESDEvent&>(esd).GetCentrality()){
398 header->SetCentrality(const_cast<AliESDEvent&>(esd).GetCentrality());
399 }
400 else{
401 header->SetCentrality(0);
402 }
403 if(const_cast<AliESDEvent&>(esd).GetEventplane()){
404 header->SetEventplane(const_cast<AliESDEvent&>(esd).GetEventplane());
405 }
406 else{
407 header->SetEventplane(0);
408 }
409 }
410
411 // Trigger
412 header->SetFiredTriggerClasses(esd.GetFiredTriggerClasses());
413 header->SetTriggerMask(esd.GetTriggerMask());
414 header->SetTriggerCluster(esd.GetTriggerCluster());
415 header->SetL0TriggerInputs(esd.GetHeader()->GetL0TriggerInputs());
416 header->SetL1TriggerInputs(esd.GetHeader()->GetL1TriggerInputs());
417 header->SetL2TriggerInputs(esd.GetHeader()->GetL2TriggerInputs());
418
419 header->SetMagneticField(esd.GetMagneticField());
420 header->SetMuonMagFieldScale(esd.GetCurrentDip()/6000.);
421 header->SetZDCN1Energy(esd.GetZDCN1Energy());
422 header->SetZDCP1Energy(esd.GetZDCP1Energy());
423 header->SetZDCN2Energy(esd.GetZDCN2Energy());
424 header->SetZDCP2Energy(esd.GetZDCP2Energy());
425 header->SetZDCEMEnergy(esd.GetZDCEMEnergy(0),esd.GetZDCEMEnergy(1));
4ccebdba 426
427 header->SetIRInt2InteractionMap(esd.GetHeader()->GetIRInt2InteractionMap());
428 header->SetIRInt1InteractionMap(esd.GetHeader()->GetIRInt1InteractionMap());
c82bb898 429
430 // ITS Cluster Multiplicty
431 const AliMultiplicity *mult = esd.GetMultiplicity();
432 for (Int_t ilay = 0; ilay < 6; ilay++) header->SetITSClusters(ilay, mult->GetNumberOfITSClusters(ilay));
433
434 // TPC only Reference Multiplicty
435 Int_t refMult = fTPCaloneTrackCuts ? (Short_t)fTPCaloneTrackCuts->GetReferenceMultiplicity(&esd, kTRUE) : -1;
436 header->SetTPConlyRefMultiplicity(refMult);
e9f4e33d 437 //
4200e13b 438 AliESDtrackCuts::MultEstTrackType estType = esd.GetPrimaryVertexTracks()->GetStatus() ? AliESDtrackCuts::kTrackletsITSTPC : AliESDtrackCuts::kTracklets;
439 header->SetRefMultiplicityComb05(AliESDtrackCuts::GetReferenceMultiplicity(&esd,estType,0.5));
440 header->SetRefMultiplicityComb08(AliESDtrackCuts::GetReferenceMultiplicity(&esd,estType,0.8));
c82bb898 441 //
fca98851 442 Float_t diamxy[2]={(Float_t)esd.GetDiamondX(),(Float_t)esd.GetDiamondY()};
c82bb898 443 Float_t diamcov[3];
444 esd.GetDiamondCovXY(diamcov);
445 header->SetDiamond(diamxy,diamcov);
446 header->SetDiamondZ(esd.GetDiamondZ(),esd.GetSigma2DiamondZ());
447
448 // VZERO channel equalization factors for event-plane reconstruction
449 header->SetVZEROEqFactors(esd.GetVZEROEqFactors());
450
602fd73e 451 // T0 Resolution information
452 const AliESDRun* esdRun = esd.GetESDRun();
453 for (Int_t i=0;i<AliESDRun::kT0spreadSize;i++) header->SetT0spread(i,esdRun->GetT0spread(i));
454
c82bb898 455 return header;
456}
457
458//______________________________________________________________________________
459void AliAnalysisTaskESDfilter::ConvertCascades(const AliESDEvent& esd)
460{
c82bb898 461 // Convert the cascades part of the ESD.
462 // Return the number of cascades
463
464 AliCodeTimerAuto("",0);
465
466 // Create vertices starting from the most complex objects
467 Double_t chi2 = 0.;
468
469 const AliESDVertex* vtx = esd.GetPrimaryVertex();
470 Double_t pos[3] = { 0. };
471 Double_t covVtx[6] = { 0. };
472 Double_t momBach[3]={0.};
473 Double_t covTr[21]={0.};
76b98553 474 // Double_t pid[10]={0.};
c82bb898 475 AliAODPid* detpid(0x0);
476 AliAODVertex* vV0FromCascade(0x0);
477 AliAODv0* aodV0(0x0);
478 AliAODcascade* aodCascade(0x0);
479 AliAODTrack* aodTrack(0x0);
480 Double_t momPos[3]={0.};
481 Double_t momNeg[3] = { 0. };
482 Double_t momPosAtV0vtx[3]={0.};
483 Double_t momNegAtV0vtx[3]={0.};
339288ed 484 Int_t tofLabel[3] = {0};
c82bb898 485 TClonesArray& verticesArray = Vertices();
486 TClonesArray& tracksArray = Tracks();
487 TClonesArray& cascadesArray = Cascades();
488
489 // Cascades (Modified by A.Maire - February 2009)
490 for (Int_t nCascade = 0; nCascade < esd.GetNumberOfCascades(); ++nCascade) {
491
492 // 0- Preparation
493 //
494 AliESDcascade *esdCascade = esd.GetCascade(nCascade);
495 Int_t idxPosFromV0Dghter = esdCascade->GetPindex();
496 Int_t idxNegFromV0Dghter = esdCascade->GetNindex();
497 Int_t idxBachFromCascade = esdCascade->GetBindex();
498
499 AliESDtrack *esdCascadePos = esd.GetTrack( idxPosFromV0Dghter);
500 AliESDtrack *esdCascadeNeg = esd.GetTrack( idxNegFromV0Dghter);
501 AliESDtrack *esdCascadeBach = esd.GetTrack( idxBachFromCascade);
502
503 // Identification of the V0 within the esdCascade (via both daughter track indices)
504 AliESDv0 * currentV0 = 0x0;
505 Int_t idxV0FromCascade = -1;
506
507 for (Int_t iV0=0; iV0<esd.GetNumberOfV0s(); ++iV0) {
508
509 currentV0 = esd.GetV0(iV0);
510 Int_t posCurrentV0 = currentV0->GetPindex();
511 Int_t negCurrentV0 = currentV0->GetNindex();
512
513 if (posCurrentV0==idxPosFromV0Dghter && negCurrentV0==idxNegFromV0Dghter) {
514 idxV0FromCascade = iV0;
515 break;
516 }
517 }
518
519 if(idxV0FromCascade < 0){
520 printf("Cascade - no matching for the V0 (index V0 = -1) ! Skip ... \n");
521 continue;
522 }// a priori, useless check, but safer ... in case of pb with tracks "out of bounds"
523
524 AliESDv0 *esdV0FromCascade = esd.GetV0(idxV0FromCascade);
525
526 // 1 - Cascade selection
527
528 // AliESDVertex *esdPrimVtx = new AliESDVertex(*(esd.GetPrimaryVertex()));
529 // TList cascadeObjects;
530 // cascadeObjects.AddAt(esdV0FromCascade, 0);
531 // cascadeObjects.AddAt(esdCascadePos, 1);
532 // cascadeObjects.AddAt(esdCascadeNeg, 2);
533 // cascadeObjects.AddAt(esdCascade, 3);
534 // cascadeObjects.AddAt(esdCascadeBach, 4);
535 // cascadeObjects.AddAt(esdPrimVtx, 5);
536 //
537 // UInt_t selectCascade = 0;
538 // if (fCascadeFilter) {
539 // // selectCascade = fCascadeFilter->IsSelected(&cascadeObjects);
540 // // FIXME AliESDCascadeCuts to be implemented ...
541 //
542 // // Here we may encounter a moot point at the V0 level
543 // // between the cascade selections and the V0 ones :
544 // // the V0 selected along with the cascade (secondary V0) may
545 // // usually be removed from the dedicated V0 selections (prim V0) ...
546 // // -> To be discussed !
547 //
548 // // this is a little awkward but otherwise the
549 // // list wants to access the pointer (delete it)
550 // // again when going out of scope
551 // delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct
552 // esdPrimVtx = 0;
553 // if (!selectCascade)
554 // continue;
555 // }
556 // else{
557 // delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct
558 // esdPrimVtx = 0;
559 // }
560
561 // 2 - Add the cascade vertex
562
563 esdCascade->GetXYZcascade(pos[0], pos[1], pos[2]);
564 esdCascade->GetPosCovXi(covVtx);
565 chi2 = esdCascade->GetChi2Xi();
566
5059e451 567 AliAODVertex *vCascade = new(verticesArray[fNumberOfVertices++]) AliAODVertex(pos,
568 covVtx,
569 chi2, // FIXME = Chi2/NDF will be needed
570 fPrimaryVertex,
571 nCascade, // id
572 AliAODVertex::kCascade);
c82bb898 573 fPrimaryVertex->AddDaughter(vCascade);
574
c82bb898 575 // 3 - Add the bachelor track from the cascade
576
577 if (!fUsedTrack[idxBachFromCascade]) {
578
579 esdCascadeBach->GetPxPyPz(momBach);
580 esdCascadeBach->GetXYZ(pos);
581 esdCascadeBach->GetCovarianceXYZPxPyPz(covTr);
76b98553 582 // esdCascadeBach->GetESDpid(pid);
339288ed 583 esdCascadeBach->GetTOFLabel(tofLabel);
584
5059e451 585 fUsedTrack[idxBachFromCascade] = kTRUE;
586 UInt_t selectInfo = 0;
587 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeBach);
588 if (fMChandler) fMChandler->SelectParticle(esdCascadeBach->GetLabel());
589 aodTrack = new(tracksArray[fNumberOfTracks++]) AliAODTrack(esdCascadeBach->GetID(),
590 esdCascadeBach->GetLabel(),
591 momBach,
592 kTRUE,
593 pos,
594 kFALSE, // Why kFALSE for "isDCA" ? FIXME
595 covTr,
596 (Short_t)esdCascadeBach->GetSign(),
597 esdCascadeBach->GetITSClusterMap(),
76b98553 598 // pid,
5059e451 599 vCascade,
600 kTRUE, // usedForVtxFit = kFALSE ? FIXME
601 vtx->UsesTrack(esdCascadeBach->GetID()),
602 AliAODTrack::kSecondary,
603 selectInfo);
76b98553 604 aodTrack->SetPIDForTracking(esdCascadeBach->GetPIDForTracking());
5059e451 605 aodTrack->SetTPCFitMap(esdCascadeBach->GetTPCFitMap());
606 aodTrack->SetTPCClusterMap(esdCascadeBach->GetTPCClusterMap());
607 aodTrack->SetTPCSharedMap (esdCascadeBach->GetTPCSharedMap());
608 aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeBach));
609 aodTrack->SetTPCPointsF(esdCascadeBach->GetTPCNclsF());
610 aodTrack->SetTPCNCrossedRows(UShort_t(esdCascadeBach->GetTPCCrossedRows()));
611 aodTrack->SetIntegratedLength(esdCascadeBach->GetIntegratedLength());
612 aodTrack->SetTOFLabel(tofLabel);
613 CopyCaloProps(esdCascadeBach,aodTrack);
614 fAODTrackRefs->AddAt(aodTrack,idxBachFromCascade);
c82bb898 615
5059e451 616 if (esdCascadeBach->GetSign() > 0) ++fNumberOfPositiveTracks;
617 aodTrack->ConvertAliPIDtoAODPID();
618 aodTrack->SetFlags(esdCascadeBach->GetStatus());
619 SetAODPID(esdCascadeBach,aodTrack,detpid);
c82bb898 620 }
621 else {
5059e451 622 aodTrack = static_cast<AliAODTrack*>( fAODTrackRefs->At(idxBachFromCascade) );
c82bb898 623 }
624
625 vCascade->AddDaughter(aodTrack);
626
c82bb898 627 // 4 - Add the V0 from the cascade.
628 // = V0vtx + both pos and neg daughter tracks + the aodV0 itself
629 //
630
631 if ( !fUsedV0[idxV0FromCascade] ) {
632 // 4.A - if VO structure hasn't been created yet
633
634 // 4.A.1 - Create the V0 vertex of the cascade
c82bb898 635 esdV0FromCascade->GetXYZ(pos[0], pos[1], pos[2]);
636 esdV0FromCascade->GetPosCov(covVtx);
637 chi2 = esdV0FromCascade->GetChi2V0(); // = chi2/NDF since NDF = 2*2-3 ?
638
639 vV0FromCascade = new(verticesArray[fNumberOfVertices++]) AliAODVertex(pos,
5059e451 640 covVtx,
641 chi2,
642 vCascade,
643 idxV0FromCascade, //id of ESDv0
644 AliAODVertex::kV0);
c82bb898 645 // Note:
646 // one V0 can be used by several cascades.
647 // So, one AOD V0 vtx can have several parent vtx.
648 // This is not directly allowed by AliAODvertex.
649 // Setting the parent vtx (here = param "vCascade") doesn't lead to a crash
650 // but to a problem of consistency within AODEvent.
651 // -> See below paragraph 4.B, for the proposed treatment of such a case.
652
653 // Add the vV0FromCascade to the aodVOVtxRefs
654 fAODV0VtxRefs->AddAt(vV0FromCascade,idxV0FromCascade);
655
c82bb898 656 // 4.A.2 - Add the positive tracks from the V0
657
658 esdCascadePos->GetPxPyPz(momPos);
659 esdCascadePos->GetXYZ(pos);
660 esdCascadePos->GetCovarianceXYZPxPyPz(covTr);
76b98553 661 // esdCascadePos->GetESDpid(pid);
339288ed 662 esdCascadePos->GetTOFLabel(tofLabel);
c82bb898 663
664 if (!fUsedTrack[idxPosFromV0Dghter]) {
665 fUsedTrack[idxPosFromV0Dghter] = kTRUE;
666
667 UInt_t selectInfo = 0;
668 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadePos);
669 if(fMChandler) fMChandler->SelectParticle(esdCascadePos->GetLabel());
5059e451 670 aodTrack = new(tracksArray[fNumberOfTracks++]) AliAODTrack(esdCascadePos->GetID(),
671 esdCascadePos->GetLabel(),
672 momPos,
673 kTRUE,
674 pos,
675 kFALSE, // Why kFALSE for "isDCA" ? FIXME
676 covTr,
677 (Short_t)esdCascadePos->GetSign(),
678 esdCascadePos->GetITSClusterMap(),
76b98553 679 //pid,
5059e451 680 vV0FromCascade,
681 kTRUE, // usedForVtxFit = kFALSE ? FIXME
682 vtx->UsesTrack(esdCascadePos->GetID()),
683 AliAODTrack::kSecondary,
684 selectInfo);
76b98553 685 aodTrack->SetPIDForTracking(esdCascadePos->GetPIDForTracking());
c82bb898 686 aodTrack->SetTPCFitMap(esdCascadePos->GetTPCFitMap());
687 aodTrack->SetTPCClusterMap(esdCascadePos->GetTPCClusterMap());
688 aodTrack->SetTPCSharedMap (esdCascadePos->GetTPCSharedMap());
689 aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadePos));
690 aodTrack->SetTPCPointsF(esdCascadePos->GetTPCNclsF());
820214a7 691 aodTrack->SetTPCNCrossedRows(UShort_t(esdCascadePos->GetTPCCrossedRows()));
9b5c8b95 692 aodTrack->SetIntegratedLength(esdCascadePos->GetIntegratedLength());
339288ed 693 aodTrack->SetTOFLabel(tofLabel);
fca98851 694 CopyCaloProps(esdCascadePos,aodTrack);
c82bb898 695 fAODTrackRefs->AddAt(aodTrack,idxPosFromV0Dghter);
696
697 if (esdCascadePos->GetSign() > 0) ++fNumberOfPositiveTracks;
698 aodTrack->ConvertAliPIDtoAODPID();
699 aodTrack->SetFlags(esdCascadePos->GetStatus());
700 SetAODPID(esdCascadePos,aodTrack,detpid);
701 }
702 else {
703 aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(idxPosFromV0Dghter));
704 }
705 vV0FromCascade->AddDaughter(aodTrack);
706
c82bb898 707 // 4.A.3 - Add the negative tracks from the V0
708
709 esdCascadeNeg->GetPxPyPz(momNeg);
710 esdCascadeNeg->GetXYZ(pos);
711 esdCascadeNeg->GetCovarianceXYZPxPyPz(covTr);
76b98553 712 // esdCascadeNeg->GetESDpid(pid);
339288ed 713 esdCascadeNeg->GetTOFLabel(tofLabel);
c82bb898 714
c82bb898 715 if (!fUsedTrack[idxNegFromV0Dghter]) {
716 fUsedTrack[idxNegFromV0Dghter] = kTRUE;
717
718 UInt_t selectInfo = 0;
719 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeNeg);
5059e451 720 if (fMChandler)
721 fMChandler->SelectParticle(esdCascadeNeg->GetLabel());
722 aodTrack = new(tracksArray[fNumberOfTracks++]) AliAODTrack(esdCascadeNeg->GetID(),
723 esdCascadeNeg->GetLabel(),
724 momNeg,
725 kTRUE,
726 pos,
727 kFALSE, // Why kFALSE for "isDCA" ? FIXME
728 covTr,
729 (Short_t)esdCascadeNeg->GetSign(),
730 esdCascadeNeg->GetITSClusterMap(),
76b98553 731 // pid,
5059e451 732 vV0FromCascade,
733 kTRUE, // usedForVtxFit = kFALSE ? FIXME
734 vtx->UsesTrack(esdCascadeNeg->GetID()),
735 AliAODTrack::kSecondary,
736 selectInfo);
76b98553 737 aodTrack->SetPIDForTracking(esdCascadeNeg->GetPIDForTracking());
c82bb898 738 aodTrack->SetTPCFitMap(esdCascadeNeg->GetTPCFitMap());
739 aodTrack->SetTPCClusterMap(esdCascadeNeg->GetTPCClusterMap());
740 aodTrack->SetTPCSharedMap (esdCascadeNeg->GetTPCSharedMap());
741 aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeNeg));
742 aodTrack->SetTPCPointsF(esdCascadeNeg->GetTPCNclsF());
820214a7 743 aodTrack->SetTPCNCrossedRows(UShort_t(esdCascadeNeg->GetTPCCrossedRows()));
9b5c8b95 744 aodTrack->SetIntegratedLength(esdCascadeNeg->GetIntegratedLength());
339288ed 745 aodTrack->SetTOFLabel(tofLabel);
fca98851 746 CopyCaloProps(esdCascadeNeg,aodTrack);
c82bb898 747 fAODTrackRefs->AddAt(aodTrack,idxNegFromV0Dghter);
748
749 if (esdCascadeNeg->GetSign() > 0) ++fNumberOfPositiveTracks;
750 aodTrack->ConvertAliPIDtoAODPID();
751 aodTrack->SetFlags(esdCascadeNeg->GetStatus());
752 SetAODPID(esdCascadeNeg,aodTrack,detpid);
753 }
754 else {
755 aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(idxNegFromV0Dghter));
756 }
757
758 vV0FromCascade->AddDaughter(aodTrack);
c82bb898 759
760 // 4.A.4 - Add the V0 from cascade to the V0 array
761
762 Double_t dcaV0Daughters = esdV0FromCascade->GetDcaV0Daughters();
5059e451 763 Double_t dcaV0ToPrimVertex = esdV0FromCascade->GetD(esd.GetPrimaryVertex()->GetX(),
c82bb898 764 esd.GetPrimaryVertex()->GetY(),
765 esd.GetPrimaryVertex()->GetZ() );
766 esdV0FromCascade->GetPPxPyPz( momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2] );
767 esdV0FromCascade->GetNPxPyPz( momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2] );
768
769 Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg
5059e451 770 dcaDaughterToPrimVertex[0] = TMath::Abs(esdCascadePos->GetD(esd.GetPrimaryVertex()->GetX(),
c82bb898 771 esd.GetPrimaryVertex()->GetY(),
772 esd.GetMagneticField()) );
5059e451 773 dcaDaughterToPrimVertex[1] = TMath::Abs(esdCascadeNeg->GetD(esd.GetPrimaryVertex()->GetX(),
c82bb898 774 esd.GetPrimaryVertex()->GetY(),
775 esd.GetMagneticField()) );
776
5059e451 777 aodV0 = new(V0s()[fNumberOfV0s++]) AliAODv0(vV0FromCascade,
c82bb898 778 dcaV0Daughters,
779 dcaV0ToPrimVertex,
780 momPosAtV0vtx,
781 momNegAtV0vtx,
782 dcaDaughterToPrimVertex);
783 // set the aod v0 on-the-fly status
784 aodV0->SetOnFlyStatus(esdV0FromCascade->GetOnFlyStatus());
785
786 // Add the aodV0 to the aodVORefs
787 fAODV0Refs->AddAt(aodV0,idxV0FromCascade);
788
789 fUsedV0[idxV0FromCascade] = kTRUE;
790
791 } else {
792 // 4.B - if V0 structure already used
793
794 // Note :
795 // one V0 can be used by several cascades (frequent in PbPb evts) :
796 // same V0 which used but attached to different bachelor tracks
797 // -> aodVORefs and fAODV0VtxRefs are needed.
798 // Goal : avoid a redundancy of the info in "Vertices" and "v0s" clones array.
799
5059e451 800 vV0FromCascade = static_cast<AliAODVertex*>(fAODV0VtxRefs->At(idxV0FromCascade));
801 aodV0 = static_cast<AliAODv0*> (fAODV0Refs ->At(idxV0FromCascade));
c82bb898 802
803 // - Treatment of the parent for such a "re-used" V0 :
804 // Insert the cascade that reuses the V0 vertex in the lineage chain
805 // Before : vV0 -> vCascade1 -> vPrimary
806 // - Hyp : cascade2 uses the same V0 as cascade1
807 // After : vV0 -> vCascade2 -> vCascade1 -> vPrimary
808
809 AliAODVertex *vCascadePreviousParent = static_cast<AliAODVertex*> (vV0FromCascade->GetParent());
5059e451 810 vV0FromCascade->SetParent(vCascade);
811 vCascade ->SetParent(vCascadePreviousParent);
c82bb898 812
813 }// end if V0 structure already used
814
c82bb898 815 // In any case (used V0 or not), add the V0 vertex to the cascade one.
816 vCascade->AddDaughter(vV0FromCascade);
c82bb898 817
818 // 5 - Add the primary track of the cascade (if any)
819
c82bb898 820 // 6 - Add the cascade to the AOD array of cascades
c82bb898 821 Double_t dcaBachToPrimVertexXY = TMath::Abs(esdCascadeBach->GetD(esd.GetPrimaryVertex()->GetX(),
822 esd.GetPrimaryVertex()->GetY(),
823 esd.GetMagneticField()) );
824
825 Double_t momBachAtCascadeVtx[3]={0.};
826
827 esdCascade->GetBPxPyPz(momBachAtCascadeVtx[0], momBachAtCascadeVtx[1], momBachAtCascadeVtx[2]);
828
5059e451 829 aodCascade = new(cascadesArray[fNumberOfCascades++]) AliAODcascade(vCascade,
830 esdCascade->Charge(),
831 esdCascade->GetDcaXiDaughters(),
832 -999.,
833 // DCAXiToPrimVtx -> needs to be calculated ----|
834 // doesn't exist at ESD level;
835 // See AODcascade::DcaXiToPrimVertex(Double, Double, Double)
836 dcaBachToPrimVertexXY,
837 momBachAtCascadeVtx,
838 *aodV0);
c82bb898 839 if (fDebug > 10) {
840 printf("---- Cascade / AOD cascade : \n\n");
841 aodCascade->PrintXi(fPrimaryVertex->GetX(), fPrimaryVertex->GetY(), fPrimaryVertex->GetZ());
842 }
843
844 } // end of the loop on cascades
845
846 Cascades().Expand(fNumberOfCascades);
847}
848
849//______________________________________________________________________________
850void AliAnalysisTaskESDfilter::ConvertV0s(const AliESDEvent& esd)
851{
852 // Access to the AOD container of V0s
853
854 AliCodeTimerAuto("",0);
855
856 //
857 // V0s
858 //
c82bb898 859 Double_t pos[3] = { 0. };
860 Double_t chi2(0.0);
861 Double_t covVtx[6] = { 0. };
862 Double_t momPos[3]={0.};
863 Double_t covTr[21]={0.};
76b98553 864 // Double_t pid[10]={0.};
c82bb898 865 AliAODTrack* aodTrack(0x0);
866 AliAODPid* detpid(0x0);
867 Double_t momNeg[3]={0.};
868 Double_t momPosAtV0vtx[3]={0.};
869 Double_t momNegAtV0vtx[3]={0.};
339288ed 870 Int_t tofLabel[3] = {0};
5059e451 871 for (Int_t nV0 = 0; nV0 < esd.GetNumberOfV0s(); ++nV0) {
c82bb898 872 if (fUsedV0[nV0]) continue; // skip if already added to the AOD
873
874 AliESDv0 *v0 = esd.GetV0(nV0);
875 Int_t posFromV0 = v0->GetPindex();
876 Int_t negFromV0 = v0->GetNindex();
877
878 // V0 selection
879 //
880 AliESDVertex *esdVtx = new AliESDVertex(*(esd.GetPrimaryVertex()));
881 AliESDtrack *esdV0Pos = esd.GetTrack(posFromV0);
882 AliESDtrack *esdV0Neg = esd.GetTrack(negFromV0);
883 TList v0objects;
884 v0objects.AddAt(v0, 0);
885 v0objects.AddAt(esdV0Pos, 1);
886 v0objects.AddAt(esdV0Neg, 2);
887 v0objects.AddAt(esdVtx, 3);
888 UInt_t selectV0 = 0;
889 if (fV0Filter) {
890 selectV0 = fV0Filter->IsSelected(&v0objects);
891 // this is a little awkward but otherwise the
892 // list wants to access the pointer (delete it)
893 // again when going out of scope
894 delete v0objects.RemoveAt(3); // esdVtx created via copy construct
895 esdVtx = 0;
896 if (!selectV0)
897 continue;
5059e451 898 } else {
c82bb898 899 delete v0objects.RemoveAt(3); // esdVtx created via copy construct
900 esdVtx = 0;
901 }
902
903 v0->GetXYZ(pos[0], pos[1], pos[2]);
904
905 if (!fOldESDformat) {
906 chi2 = v0->GetChi2V0(); // = chi2/NDF since NDF = 2*2-3
907 v0->GetPosCov(covVtx);
908 } else {
909 chi2 = -999.;
910 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
911 }
912
913
914 AliAODVertex * vV0 =
915 new(Vertices()[fNumberOfVertices++]) AliAODVertex(pos,
5059e451 916 covVtx,
917 chi2,
918 fPrimaryVertex,
919 nV0,
920 AliAODVertex::kV0);
c82bb898 921 fPrimaryVertex->AddDaughter(vV0);
922
923
924 // Add the positive tracks from the V0
c82bb898 925
926 esdV0Pos->GetPxPyPz(momPos);
927 esdV0Pos->GetXYZ(pos);
928 esdV0Pos->GetCovarianceXYZPxPyPz(covTr);
76b98553 929 // esdV0Pos->GetESDpid(pid);
339288ed 930 esdV0Pos->GetTOFLabel(tofLabel);
c82bb898 931
932 const AliESDVertex *vtx = esd.GetPrimaryVertex();
933
934 if (!fUsedTrack[posFromV0]) {
935 fUsedTrack[posFromV0] = kTRUE;
936 UInt_t selectInfo = 0;
937 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Pos);
938 if(fMChandler)fMChandler->SelectParticle(esdV0Pos->GetLabel());
939 aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdV0Pos->GetID(),
5059e451 940 esdV0Pos->GetLabel(),
941 momPos,
942 kTRUE,
943 pos,
944 kFALSE,
945 covTr,
946 (Short_t)esdV0Pos->GetSign(),
947 esdV0Pos->GetITSClusterMap(),
76b98553 948 // pid,
5059e451 949 vV0,
950 kTRUE, // check if this is right
951 vtx->UsesTrack(esdV0Pos->GetID()),
952 AliAODTrack::kSecondary,
953 selectInfo);
76b98553 954 aodTrack->SetPIDForTracking(esdV0Pos->GetPIDForTracking());
c82bb898 955 aodTrack->SetTPCFitMap(esdV0Pos->GetTPCFitMap());
956 aodTrack->SetTPCClusterMap(esdV0Pos->GetTPCClusterMap());
957 aodTrack->SetTPCSharedMap (esdV0Pos->GetTPCSharedMap());
958 aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Pos));
959 aodTrack->SetTPCPointsF(esdV0Pos->GetTPCNclsF());
820214a7 960 aodTrack->SetTPCNCrossedRows(UShort_t(esdV0Pos->GetTPCCrossedRows()));
9b5c8b95 961 aodTrack->SetIntegratedLength(esdV0Pos->GetIntegratedLength());
339288ed 962 aodTrack->SetTOFLabel(tofLabel);
63825dc4 963 CopyCaloProps(esdV0Pos,aodTrack);
c82bb898 964 fAODTrackRefs->AddAt(aodTrack,posFromV0);
c82bb898 965 if (esdV0Pos->GetSign() > 0) ++fNumberOfPositiveTracks;
966 aodTrack->ConvertAliPIDtoAODPID();
967 aodTrack->SetFlags(esdV0Pos->GetStatus());
339288ed 968 SetAODPID(esdV0Pos,aodTrack,detpid);
5059e451 969 } else {
970 aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(posFromV0));
c82bb898 971 }
972 vV0->AddDaughter(aodTrack);
973
974 // Add the negative tracks from the V0
c82bb898 975 esdV0Neg->GetPxPyPz(momNeg);
976 esdV0Neg->GetXYZ(pos);
977 esdV0Neg->GetCovarianceXYZPxPyPz(covTr);
76b98553 978 // esdV0Neg->GetESDpid(pid);
339288ed 979 esdV0Neg->GetTOFLabel(tofLabel);
c82bb898 980
981 if (!fUsedTrack[negFromV0]) {
5059e451 982 fUsedTrack[negFromV0] = kTRUE;
983 UInt_t selectInfo = 0;
984 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Neg);
985 if(fMChandler)fMChandler->SelectParticle(esdV0Neg->GetLabel());
986 aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdV0Neg->GetID(),
987 esdV0Neg->GetLabel(),
988 momNeg,
989 kTRUE,
990 pos,
991 kFALSE,
992 covTr,
993 (Short_t)esdV0Neg->GetSign(),
994 esdV0Neg->GetITSClusterMap(),
76b98553 995 // pid,
5059e451 996 vV0,
997 kTRUE, // check if this is right
998 vtx->UsesTrack(esdV0Neg->GetID()),
999 AliAODTrack::kSecondary,
1000 selectInfo);
76b98553 1001 aodTrack->SetPIDForTracking(esdV0Neg->GetPIDForTracking());
5059e451 1002 aodTrack->SetTPCFitMap(esdV0Neg->GetTPCFitMap());
1003 aodTrack->SetTPCClusterMap(esdV0Neg->GetTPCClusterMap());
1004 aodTrack->SetTPCSharedMap (esdV0Neg->GetTPCSharedMap());
1005 aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Neg));
1006 aodTrack->SetTPCPointsF(esdV0Neg->GetTPCNclsF());
1007 aodTrack->SetTPCNCrossedRows(UShort_t(esdV0Neg->GetTPCCrossedRows()));
1008 aodTrack->SetIntegratedLength(esdV0Neg->GetIntegratedLength());
1009 aodTrack->SetTOFLabel(tofLabel);
1010 CopyCaloProps(esdV0Neg,aodTrack);
1011 fAODTrackRefs->AddAt(aodTrack,negFromV0);
1012 if (esdV0Neg->GetSign() > 0) ++fNumberOfPositiveTracks;
1013 aodTrack->ConvertAliPIDtoAODPID();
1014 aodTrack->SetFlags(esdV0Neg->GetStatus());
1015 SetAODPID(esdV0Neg,aodTrack,detpid);
1016 } else {
1017 aodTrack = static_cast<AliAODTrack*>(fAODTrackRefs->At(negFromV0));
c82bb898 1018 }
1019 vV0->AddDaughter(aodTrack);
1020
c82bb898 1021 // Add the V0 the V0 array as well
c82bb898 1022 Double_t dcaV0Daughters = v0->GetDcaV0Daughters();
1023 Double_t dcaV0ToPrimVertex = v0->GetD(esd.GetPrimaryVertex()->GetX(),
1024 esd.GetPrimaryVertex()->GetY(),
1025 esd.GetPrimaryVertex()->GetZ());
1026
1027 v0->GetPPxPyPz(momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2]);
1028 v0->GetNPxPyPz(momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2]);
1029
1030 Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg
1031 dcaDaughterToPrimVertex[0] = TMath::Abs(esdV0Pos->GetD( esd.GetPrimaryVertex()->GetX(),
1032 esd.GetPrimaryVertex()->GetY(),
1033 esd.GetMagneticField()) );
1034 dcaDaughterToPrimVertex[1] = TMath::Abs(esdV0Neg->GetD( esd.GetPrimaryVertex()->GetX(),
1035 esd.GetPrimaryVertex()->GetY(),
1036 esd.GetMagneticField()) );
1037
1038 AliAODv0* aodV0 = new(V0s()[fNumberOfV0s++]) AliAODv0(vV0,
1039 dcaV0Daughters,
1040 dcaV0ToPrimVertex,
1041 momPosAtV0vtx,
1042 momNegAtV0vtx,
1043 dcaDaughterToPrimVertex);
1044
1045 // set the aod v0 on-the-fly status
1046 aodV0->SetOnFlyStatus(v0->GetOnFlyStatus());
1047 }//End of loop on V0s
1048
1049 V0s().Expand(fNumberOfV0s);
1050}
1051
1052//______________________________________________________________________________
1053void AliAnalysisTaskESDfilter::ConvertTPCOnlyTracks(const AliESDEvent& esd)
1054{
1055 // Convert TPC only tracks
1056 // Here we have wo hybrid appraoch to remove fakes
1057 // ******* ITSTPC ********
1058 // Uses a cut on the ITS properties to select global tracks
1059 // which are than marked as HybdridITSTPC for the remainder
1060 // the TPC only tracks are flagged as HybridITSTPConly.
1061 // Note, in order not to get fakes back in the TPC cuts, one needs
1062 // two "ITS" cuts one tight (1) (to throw out fakes) and one lose (2) (to NOT flag the trakcs in the TPC only)
1063 // using cut number (3)
1064 // so fHybridFilterMask == (1)|(2) fTPCFilterMask = (3), Usercode needs to slect with mask = (1)|(3) and track->IsHybridITSTPC()
1065 // ******* TPC ********
1066 // Here, only TPC tracks are flagged that pass the tight ITS cuts and tracks that pass the TPC cuts and NOT the loose ITS cuts
1067 // the ITS cuts neeed to be added to the filter as extra cuts, since here the selections info is reset in the global and put to the TPC only track
1068
1069 AliCodeTimerAuto("",0);
1070
1071 // Loop over the tracks and extract and mask out all aod tracks that pass the selections for AODt racks
1072 for(int it = 0;it < fNumberOfTracks;++it)
1073 {
1074 AliAODTrack *tr = (AliAODTrack*)(Tracks().At(it));
1075 if(!tr)continue;
1076 UInt_t map = tr->GetFilterMap();
1077 if(map&fTPCConstrainedFilterMask){
1078 // we only reset the track select ionfo, no deletion...
1079 tr->SetFilterMap(map&~fTPCConstrainedFilterMask);
1080 }
1081 if(map&fHybridFilterMaskTPCCG){
1082 // this is one part of the hybrid tracks
1083 // the others not passing the selection will be TPC only selected below
1084 tr->SetIsHybridTPCConstrainedGlobal(kTRUE);
1085 }
1086 }
5059e451 1087
c82bb898 1088 // Loop over the ESD trcks and pick out the tracks passing TPC only cuts
c82bb898 1089 const AliESDVertex *vtxSPD = esd.GetPrimaryVertexSPD();
1090 const AliESDVertex *vtx = esd.GetPrimaryVertex();
1091
1092 Double_t pos[3] = { 0. };
1093 Double_t covTr[21]={0.};
76b98553 1094 // Double_t pid[10]={0.};
c82bb898 1095 Double_t p[3] = { 0. };
c82bb898 1096 Double_t pDCA[3] = { 0. }; // momentum at DCA
1097 Double_t rDCA[3] = { 0. }; // position at DCA
1098 Float_t dDCA[2] = {0.}; // DCA to the vertex d and z
1099 Float_t cDCA[3] = {0.}; // covariance of impact parameters
339288ed 1100 Int_t tofLabel[3] = {0};
c82bb898 1101
1102 AliAODTrack* aodTrack(0x0);
c82bb898 1103
1104 // account for change in pT after the constraint
1105 Float_t ptMax = 1E10;
1106 Float_t ptMin = 0;
1107 for(int i = 0;i<32;i++){
1108 if(fTPCConstrainedFilterMask&(1<<i)){
1109 AliESDtrackCuts*cuts = (AliESDtrackCuts*)fTrackFilter->GetCuts()->At(i);
1110 Float_t tmp1= 0,tmp2 = 0;
1111 cuts->GetPtRange(tmp1,tmp2);
1112 if(tmp1>ptMin)ptMin=tmp1;
1113 if(tmp2<ptMax)ptMax=tmp2;
1114 }
1115 }
1116
1117 for (Int_t nTrack = 0; nTrack < esd.GetNumberOfTracks(); ++nTrack)
1118 {
1119 AliESDtrack* esdTrack = esd.GetTrack(nTrack); //carefull do not modify it othwise need to work with a copy
1120
1121 UInt_t selectInfo = 0;
1122 Bool_t isHybridITSTPC = false;
1123 //
1124 // Track selection
1125 if (fTrackFilter) {
1126 selectInfo = fTrackFilter->IsSelected(esdTrack);
1127 }
1128
1129 if(!(selectInfo&fHybridFilterMaskTPCCG)){
1130 // not already selected tracks, use second part of hybrid tracks
1131 isHybridITSTPC = true;
1132 // too save space one could only store these...
1133 }
1134
1135 selectInfo &= fTPCConstrainedFilterMask;
5059e451 1136 if (!selectInfo) continue;
1137 if (fWriteHybridTPCCOnly&&!isHybridITSTPC) continue; // write only complementary tracks
c82bb898 1138 // create a tpc only tracl
1139 AliESDtrack *track = AliESDtrackCuts::GetTPCOnlyTrack(const_cast<AliESDEvent*>(&esd),esdTrack->GetID());
5059e451 1140 if (!track) continue;
c82bb898 1141
5059e451 1142 if (track->Pt()>0.) {
c82bb898 1143 // only constrain tracks above threshold
1144 AliExternalTrackParam exParam;
1145 // take the B-field from the ESD, no 3D fieldMap available at this point
1146 Bool_t relate = false;
1147 relate = track->RelateToVertexTPC(vtxSPD,esd.GetMagneticField(),kVeryBig,&exParam);
1148 if(!relate){
1149 delete track;
1150 continue;
1151 }
1152 // fetch the track parameters at the DCA (unconstraint)
1153 if(track->GetTPCInnerParam()){
1154 track->GetTPCInnerParam()->GetPxPyPz(pDCA);
1155 track->GetTPCInnerParam()->GetXYZ(rDCA);
1156 }
1157 // get the DCA to the vertex:
1158 track->GetImpactParametersTPC(dDCA,cDCA);
1159 // set the constrained parameters to the track
1160 track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());
1161 }
1162
1163 track->GetPxPyPz(p);
1164
1165 Float_t pT = track->Pt();
1166 if(pT<ptMin||pT>ptMax){
1167 delete track;
1168 continue;
1169 }
1170
c82bb898 1171 track->GetXYZ(pos);
1172 track->GetCovarianceXYZPxPyPz(covTr);
76b98553 1173 // esdTrack->GetESDpid(pid);// original PID
339288ed 1174 esdTrack->GetTOFLabel(tofLabel);
c82bb898 1175 if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());
b2b65de9 1176 fUsedTrackCopy[nTrack] |= selectInfo;
c82bb898 1177 aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack((track->GetID()+1)*-1,
5059e451 1178 track->GetLabel(),
1179 p,
1180 kTRUE,
1181 pos,
1182 kFALSE,
1183 covTr,
1184 (Short_t)track->GetSign(),
1185 track->GetITSClusterMap(),
76b98553 1186 // pid,
5059e451 1187 fPrimaryVertex,
1188 kTRUE, // check if this is right
1189 vtx->UsesTrack(track->GetID()),
1190 AliAODTrack::kPrimary,
1191 selectInfo);
76b98553 1192 aodTrack->SetPIDForTracking(track->GetPIDForTracking());
c82bb898 1193 aodTrack->SetIsHybridTPCConstrainedGlobal(isHybridITSTPC);
1194 aodTrack->SetTPCFitMap(track->GetTPCFitMap());
1195 aodTrack->SetTPCClusterMap(track->GetTPCClusterMap());
1196 aodTrack->SetTPCSharedMap (track->GetTPCSharedMap());
1197 aodTrack->SetIsTPCConstrained(kTRUE);
1198 aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack)); // original track
1199 // set the DCA values to the AOD track
1200 aodTrack->SetPxPyPzAtDCA(pDCA[0],pDCA[1],pDCA[2]);
1201 aodTrack->SetXYAtDCA(rDCA[0],rDCA[1]);
1202 aodTrack->SetDCA(dDCA[0],dDCA[1]);
c82bb898 1203 aodTrack->SetFlags(track->GetStatus());
1204 aodTrack->SetTPCPointsF(track->GetTPCNclsF());
820214a7 1205 aodTrack->SetTPCNCrossedRows(UShort_t(track->GetTPCCrossedRows()));
9b5c8b95 1206 aodTrack->SetIntegratedLength(track->GetIntegratedLength());
339288ed 1207 aodTrack->SetTOFLabel(tofLabel);
63825dc4 1208 CopyCaloProps(track,aodTrack);
c82bb898 1209 // do not duplicate PID information
1210 // aodTrack->ConvertAliPIDtoAODPID();
1211 // SetAODPID(esdTrack,aodTrack,detpid);
c82bb898 1212 delete track;
1213 } // end of loop on tracks
c82bb898 1214}
1215
37b92631 1216//______________________________________________________________________________
c82bb898 1217void AliAnalysisTaskESDfilter::ConvertGlobalConstrainedTracks(const AliESDEvent& esd)
1218{
c82bb898 1219 // Here we have the option to store the complement from global constraint information
1220 // to tracks passing tight cuts (1) in order not to get fakes back in, one needs
1221 // two sets of cuts one tight (1) (to throw out fakes) and one lose (2) (fakes/bad tracks would pass (2) but not (1))
1222 // using cut number (3) selects the tracks that complement (1) e.g. tracks witout ITS refit or cluster requirement
1223
c82bb898 1224 AliCodeTimerAuto("",0);
1225
1226 // Loop over the tracks and extract and mask out all aod tracks that pass the selections for AODt racks
1227 for(int it = 0;it < fNumberOfTracks;++it)
1228 {
1229 AliAODTrack *tr = (AliAODTrack*)(Tracks().At(it));
1230 if(!tr)continue;
1231 UInt_t map = tr->GetFilterMap();
1232 if(map&fGlobalConstrainedFilterMask){
1233 // we only reset the track select info, no deletion...
1234 // mask reset mask in case track is already taken
1235 tr->SetFilterMap(map&~fGlobalConstrainedFilterMask);
1236 }
1237 if(map&fHybridFilterMaskGCG){
1238 // this is one part of the hybrid tracks
1239 // the others not passing the selection will be the ones selected below
1240 tr->SetIsHybridGlobalConstrainedGlobal(kTRUE);
1241 }
1242 }
1243 // Loop over the ESD trcks and pick out the tracks passing the GlobalConstraint cuts
1244
c82bb898 1245 Double_t pos[3] = { 0. };
1246 Double_t covTr[21]={0.};
76b98553 1247 // Double_t pid[10]={0.};
c82bb898 1248 Double_t p[3] = { 0. };
1249
1250 Double_t pDCA[3] = { 0. }; // momentum at DCA
1251 Double_t rDCA[3] = { 0. }; // position at DCA
1252 Float_t dDCA[2] = {0.}; // DCA to the vertex d and z
1253 Float_t cDCA[3] = {0.}; // covariance of impact parameters
339288ed 1254 Int_t tofLabel[3] = {0};
c82bb898 1255
c82bb898 1256 AliAODTrack* aodTrack(0x0);
1257 AliAODPid* detpid(0x0);
1258 const AliESDVertex *vtx = esd.GetPrimaryVertex();
1259
1260 // account for change in pT after the constraint
1261 Float_t ptMax = 1E10;
1262 Float_t ptMin = 0;
1263 for(int i = 0;i<32;i++){
1264 if(fGlobalConstrainedFilterMask&(1<<i)){
1265 AliESDtrackCuts*cuts = (AliESDtrackCuts*)fTrackFilter->GetCuts()->At(i);
1266 Float_t tmp1= 0,tmp2 = 0;
1267 cuts->GetPtRange(tmp1,tmp2);
1268 if(tmp1>ptMin)ptMin=tmp1;
1269 if(tmp2<ptMax)ptMax=tmp2;
1270 }
1271 }
1272
c82bb898 1273 for (Int_t nTrack = 0; nTrack < esd.GetNumberOfTracks(); ++nTrack)
1274 {
1275 AliESDtrack* esdTrack = esd.GetTrack(nTrack); //carefull do not modify it othwise need to work with a copy
1276 const AliExternalTrackParam * exParamGC = esdTrack->GetConstrainedParam();
1277 if(!exParamGC)continue;
1278
1279 UInt_t selectInfo = 0;
1280 Bool_t isHybridGC = false;
1281
1282 //
1283 // Track selection
1284 if (fTrackFilter) {
1285 selectInfo = fTrackFilter->IsSelected(esdTrack);
1286 }
1287
5059e451 1288 if (!(selectInfo&fHybridFilterMaskGCG)) isHybridGC = true;
1289 if (fWriteHybridGCOnly&&!isHybridGC) continue; // write only complementary tracks
c82bb898 1290
1291 selectInfo &= fGlobalConstrainedFilterMask;
5059e451 1292 if (!selectInfo) continue;
c82bb898 1293 // fetch the track parameters at the DCA (unconstrained)
1294 esdTrack->GetPxPyPz(pDCA);
1295 esdTrack->GetXYZ(rDCA);
1296 // get the DCA to the vertex:
1297 esdTrack->GetImpactParameters(dDCA,cDCA);
c82bb898 1298 if (!esdTrack->GetConstrainedPxPyPz(p)) continue;
1299
c82bb898 1300 Float_t pT = exParamGC->Pt();
1301 if(pT<ptMin||pT>ptMax){
1302 continue;
1303 }
1304
c82bb898 1305 esdTrack->GetConstrainedXYZ(pos);
1306 exParamGC->GetCovarianceXYZPxPyPz(covTr);
76b98553 1307 // esdTrack->GetESDpid(pid);
339288ed 1308 esdTrack->GetTOFLabel(tofLabel);
c82bb898 1309 if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());
b2b65de9 1310 fUsedTrackCopy[nTrack] |= selectInfo;
c82bb898 1311 aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack((esdTrack->GetID()+1)*-1,
1312 esdTrack->GetLabel(),
1313 p,
1314 kTRUE,
1315 pos,
1316 kFALSE,
1317 covTr,
1318 (Short_t)esdTrack->GetSign(),
1319 esdTrack->GetITSClusterMap(),
76b98553 1320 // pid,
c82bb898 1321 fPrimaryVertex,
1322 kTRUE, // check if this is right
1323 vtx->UsesTrack(esdTrack->GetID()),
1324 AliAODTrack::kPrimary,
1325 selectInfo);
76b98553 1326 aodTrack->SetPIDForTracking(esdTrack->GetPIDForTracking());
c82bb898 1327 aodTrack->SetIsHybridGlobalConstrainedGlobal(isHybridGC);
1328 aodTrack->SetIsGlobalConstrained(kTRUE);
1329 aodTrack->SetTPCFitMap(esdTrack->GetTPCFitMap());
1330 aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());
1331 aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());
1332 aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));
c82bb898 1333
1334 // set the DCA values to the AOD track
1335 aodTrack->SetPxPyPzAtDCA(pDCA[0],pDCA[1],pDCA[2]);
1336 aodTrack->SetXYAtDCA(rDCA[0],rDCA[1]);
1337 aodTrack->SetDCA(dDCA[0],dDCA[1]);
c82bb898 1338 aodTrack->SetFlags(esdTrack->GetStatus());
1339 aodTrack->SetTPCPointsF(esdTrack->GetTPCNclsF());
820214a7 1340 aodTrack->SetTPCNCrossedRows(UShort_t(esdTrack->GetTPCCrossedRows()));
9b5c8b95 1341 aodTrack->SetIntegratedLength(esdTrack->GetIntegratedLength());
339288ed 1342 aodTrack->SetTOFLabel(tofLabel);
63825dc4 1343 CopyCaloProps(esdTrack,aodTrack);
c82bb898 1344 if(isHybridGC){
1345 // only copy AOD information for hybrid, no duplicate information
1346 aodTrack->ConvertAliPIDtoAODPID();
1347 SetAODPID(esdTrack,aodTrack,detpid);
1348 }
1349 } // end of loop on tracks
c82bb898 1350}
1351
c82bb898 1352//______________________________________________________________________________
1353void AliAnalysisTaskESDfilter::ConvertTracks(const AliESDEvent& esd)
1354{
1355 // Tracks (primary and orphan)
1356
1357 AliCodeTimerAuto("",0);
1358
1359 AliDebug(1,Form("NUMBER OF ESD TRACKS %5d\n", esd.GetNumberOfTracks()));
1360
1361 const AliESDVertex *vtx = esd.GetPrimaryVertex();
1362 Double_t p[3] = { 0. };
1363 Double_t pos[3] = { 0. };
c82bb898 1364 Double_t covTr[21] = { 0. };
76b98553 1365 // Double_t pid[10] = { 0. };
339288ed 1366 Int_t tofLabel[3] = {0};
c82bb898 1367 AliAODTrack* aodTrack(0x0);
1368 AliAODPid* detpid(0x0);
1369
1370 for (Int_t nTrack = 0; nTrack < esd.GetNumberOfTracks(); ++nTrack)
1371 {
1372 if (fUsedTrack[nTrack]) continue;
1373
1374 AliESDtrack *esdTrack = esd.GetTrack(nTrack);
1375 UInt_t selectInfo = 0;
1376 //
1377 // Track selection
1378 if (fTrackFilter) {
5059e451 1379 selectInfo = fTrackFilter->IsSelected(esdTrack);
1380 if (!selectInfo && !vtx->UsesTrack(esdTrack->GetID())) continue;
c82bb898 1381 }
1382
c82bb898 1383 esdTrack->GetPxPyPz(p);
1384 esdTrack->GetXYZ(pos);
1385 esdTrack->GetCovarianceXYZPxPyPz(covTr);
76b98553 1386 // esdTrack->GetESDpid(pid);
339288ed 1387 esdTrack->GetTOFLabel(tofLabel);
c82bb898 1388 if(fMChandler)fMChandler->SelectParticle(esdTrack->GetLabel());
7e32c94c 1389 fUsedTrack[nTrack] = kTRUE;
5059e451 1390 aodTrack = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrack->GetID(),
c82bb898 1391 esdTrack->GetLabel(),
1392 p,
1393 kTRUE,
1394 pos,
1395 kFALSE,
1396 covTr,
1397 (Short_t)esdTrack->GetSign(),
1398 esdTrack->GetITSClusterMap(),
76b98553 1399 // pid,
c82bb898 1400 fPrimaryVertex,
1401 kTRUE, // check if this is right
1402 vtx->UsesTrack(esdTrack->GetID()),
1403 AliAODTrack::kPrimary,
5059e451 1404 selectInfo);
1405 fPrimaryVertex->AddDaughter(aodTrack);
76b98553 1406 aodTrack->SetPIDForTracking(esdTrack->GetPIDForTracking());
c82bb898 1407 aodTrack->SetTPCFitMap(esdTrack->GetTPCFitMap());
1408 aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());
1409 aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());
1410 aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));
1411 aodTrack->SetTPCPointsF(esdTrack->GetTPCNclsF());
820214a7 1412 aodTrack->SetTPCNCrossedRows(UShort_t(esdTrack->GetTPCCrossedRows()));
9b5c8b95 1413 aodTrack->SetIntegratedLength(esdTrack->GetIntegratedLength());
339288ed 1414 aodTrack->SetTOFLabel(tofLabel);
63825dc4 1415 CopyCaloProps(esdTrack,aodTrack);
c82bb898 1416 fAODTrackRefs->AddAt(aodTrack, nTrack);
c82bb898 1417 if (esdTrack->GetSign() > 0) ++fNumberOfPositiveTracks;
1418 aodTrack->SetFlags(esdTrack->GetStatus());
1419 aodTrack->ConvertAliPIDtoAODPID();
1420 SetAODPID(esdTrack,aodTrack,detpid);
1421 } // end of loop on tracks
1422}
1423
1424//______________________________________________________________________________
1425void AliAnalysisTaskESDfilter::ConvertPmdClusters(const AliESDEvent& esd)
1426{
5059e451 1427 // Convert PMD Clusters
c82bb898 1428 AliCodeTimerAuto("",0);
1429 Int_t jPmdClusters=0;
1430 // Access to the AOD container of PMD clusters
1431 TClonesArray &pmdClusters = *(AODEvent()->GetPmdClusters());
1432 for (Int_t iPmd = 0; iPmd < esd.GetNumberOfPmdTracks(); ++iPmd) {
1433 // file pmd clusters, to be revised!
1434 AliESDPmdTrack *pmdTrack = esd.GetPmdTrack(iPmd);
1435 Int_t nLabel = 0;
1436 Int_t *label = 0x0;
1437 Double_t posPmd[3] = { pmdTrack->GetClusterX(), pmdTrack->GetClusterY(), pmdTrack->GetClusterZ()};
1438 Double_t pidPmd[13] = { 0.}; // to be revised!
1439 // type not set!
1440 // assoc cluster not set
1441 new(pmdClusters[jPmdClusters++]) AliAODPmdCluster(iPmd, nLabel, label, pmdTrack->GetClusterADC(), posPmd, pidPmd);
1442 }
1443}
1444
c82bb898 1445//______________________________________________________________________________
1446void AliAnalysisTaskESDfilter::ConvertCaloClusters(const AliESDEvent& esd)
1447{
5059e451 1448 // Convert Calorimeter Clusters
c82bb898 1449 AliCodeTimerAuto("",0);
1450
1451 // Access to the AOD container of clusters
1452 TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());
1453 Int_t jClusters(0);
1454
1455 for (Int_t iClust=0; iClust<esd.GetNumberOfCaloClusters(); ++iClust) {
c82bb898 1456 AliESDCaloCluster * cluster = esd.GetCaloCluster(iClust);
1457
1458 Int_t id = cluster->GetID();
1459 Int_t nLabel = cluster->GetNLabels();
1460 Int_t *labels = cluster->GetLabels();
1461 if(labels){
5059e451 1462 for(int i = 0;i < nLabel;++i) {
1463 if(fMChandler)fMChandler->SelectParticle(labels[i]);
1464 }
1465 }
c82bb898 1466
1467 Float_t energy = cluster->E();
1468 Float_t posF[3] = { 0.};
1469 cluster->GetPosition(posF);
1470
1471 AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) AliAODCaloCluster(id,
1472 nLabel,
1473 labels,
1474 energy,
1475 posF,
1476 NULL,
1477 cluster->GetType(),0);
1478
1479 caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),
1480 cluster->GetDispersion(),
1481 cluster->GetM20(), cluster->GetM02(),
1482 cluster->GetEmcCpvDistance(),
5059e451 1483 cluster->GetNExMax(),cluster->GetTOF()) ;
c82bb898 1484 caloCluster->SetPIDFromESD(cluster->GetPID());
1485 caloCluster->SetNCells(cluster->GetNCells());
1486 caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());
1487 caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());
c82bb898 1488 caloCluster->SetTrackDistance(cluster->GetTrackDx(), cluster->GetTrackDz());
1489
1490 Int_t nMatchCount = 0;
5059e451 1491 TArrayI* matchedT = cluster->GetTracksMatched();
c82bb898 1492 if (fNumberOfTracks>0 && matchedT && cluster->GetTrackMatchedIndex() >= 0) {
1493 for (Int_t im = 0; im < matchedT->GetSize(); im++) {
1494 Int_t iESDtrack = matchedT->At(im);;
1495 if (fAODTrackRefs->At(iESDtrack) != 0) {
1496 caloCluster->AddTrackMatched((AliAODTrack*)fAODTrackRefs->At(iESDtrack));
1497 nMatchCount++;
1498 }
1499 }
1500 }
1501 if(nMatchCount==0)
1502 caloCluster->SetTrackDistance(-999,-999);
1503
1504 }
1505 caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters
1506}
1507
1508//______________________________________________________________________________
1509void AliAnalysisTaskESDfilter::ConvertCaloTrigger(TString calo, const AliESDEvent& esd)
1510{
5059e451 1511 AliCodeTimerAuto("",0);
c82bb898 1512
5059e451 1513 if (calo == "PHOS") {
1514 AliAODCaloTrigger &aodTrigger = *(AODEvent()->GetCaloTrigger(calo));
1515 AliESDCaloTrigger &esdTrigger = *(esd.GetCaloTrigger(calo));
1516
1517 aodTrigger.Allocate(esdTrigger.GetEntries());
1518 esdTrigger.Reset();
1519
1520 Float_t a;
1521 Int_t tmod,tabsId;
1522 while (esdTrigger.Next()) {
1523 esdTrigger.GetPosition(tmod,tabsId);
1524 esdTrigger.GetAmplitude(a);
1525 aodTrigger.Add(tmod,tabsId,a,0.,(Int_t*)NULL,0,0,0);
1526 }
1527 return;
1528 }
1529
1530 AliAODHandler *aodHandler = dynamic_cast<AliAODHandler*>(AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler());
1531 if (aodHandler) {
1532 TTree *aodTree = aodHandler->GetTree();
1533 if (aodTree) {
1534 Int_t *type = esd.GetCaloTriggerType();
1535 for (Int_t i = 0; i < 15; i++) {
1536 aodTree->GetUserInfo()->Add(new TParameter<int>(Form("EMCALCaloTrigger%d",i), type[i]));
1537 }
1538 }
1539 }
c82bb898 1540
5059e451 1541 AliAODCaloTrigger &aodTrigger = *(AODEvent()->GetCaloTrigger(calo));
1542 AliESDCaloTrigger &esdTrigger = *(esd.GetCaloTrigger(calo));
1543 aodTrigger.Allocate(esdTrigger.GetEntries());
c82bb898 1544
5059e451 1545 esdTrigger.Reset();
1546 while (esdTrigger.Next()) {
1547 Int_t px, py, ts, nTimes, times[10], b;
1548 Float_t a, t;
1549 esdTrigger.GetPosition(px, py);
1550 esdTrigger.GetAmplitude(a);
1551 esdTrigger.GetTime(t);
1552 esdTrigger.GetL0Times(times);
1553 esdTrigger.GetNL0Times(nTimes);
1554 esdTrigger.GetL1TimeSum(ts);
1555 esdTrigger.GetTriggerBits(b);
1556 aodTrigger.Add(px, py, a, t, times, nTimes, ts, b);
1557 }
1558
1559 for (int i = 0; i < 4; i++) aodTrigger.SetL1Threshold(i, esdTrigger.GetL1Threshold(i));
1560 Int_t v0[2] = {
1561 esdTrigger.GetL1V0(0),
1562 esdTrigger.GetL1V0(1)
1563 };
1564 aodTrigger.SetL1V0(v0);
1565 aodTrigger.SetL1FrameMask(esdTrigger.GetL1FrameMask());
c82bb898 1566}
1567
1568//______________________________________________________________________________
1569void AliAnalysisTaskESDfilter::ConvertEMCALCells(const AliESDEvent& esd)
1570{
5059e451 1571 // Convert EMCAL Cells
c82bb898 1572 AliCodeTimerAuto("",0);
5059e451 1573
c82bb898 1574 // fill EMCAL cell info
1575 if (esd.GetEMCALCells()) { // protection against missing ESD information
1576 AliESDCaloCells &esdEMcells = *(esd.GetEMCALCells());
1577 Int_t nEMcell = esdEMcells.GetNumberOfCells() ;
c82bb898 1578 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
1579 aodEMcells.CreateContainer(nEMcell);
1580 aodEMcells.SetType(AliAODCaloCells::kEMCALCell);
1581 for (Int_t iCell = 0; iCell < nEMcell; iCell++) {
77e93dc2 1582 aodEMcells.SetCell(iCell,esdEMcells.GetCellNumber(iCell),esdEMcells.GetAmplitude(iCell),
c82bb898 1583 esdEMcells.GetTime(iCell), esdEMcells.GetMCLabel(iCell), esdEMcells.GetEFraction(iCell));
1584 }
1585 aodEMcells.Sort();
1586 }
1587}
1588
1589//______________________________________________________________________________
1590void AliAnalysisTaskESDfilter::ConvertPHOSCells(const AliESDEvent& esd)
1591{
5059e451 1592 // Convert PHOS Cells
c82bb898 1593 AliCodeTimerAuto("",0);
5059e451 1594
c82bb898 1595 // fill PHOS cell info
1596 if (esd.GetPHOSCells()) { // protection against missing ESD information
1597 AliESDCaloCells &esdPHcells = *(esd.GetPHOSCells());
1598 Int_t nPHcell = esdPHcells.GetNumberOfCells() ;
1599
1600 AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());
1601 aodPHcells.CreateContainer(nPHcell);
1602 aodPHcells.SetType(AliAODCaloCells::kPHOSCell);
1603 for (Int_t iCell = 0; iCell < nPHcell; iCell++) {
77e93dc2 1604 aodPHcells.SetCell(iCell,esdPHcells.GetCellNumber(iCell),esdPHcells.GetAmplitude(iCell),
c82bb898 1605 esdPHcells.GetTime(iCell), esdPHcells.GetMCLabel(iCell), esdPHcells.GetEFraction(iCell));
1606 }
1607 aodPHcells.Sort();
1608 }
1609}
1610
1611//______________________________________________________________________________
1612void AliAnalysisTaskESDfilter::ConvertTracklets(const AliESDEvent& esd)
1613{
1614 // tracklets
1615 AliCodeTimerAuto("",0);
1616
1617 AliAODTracklets &SPDTracklets = *(AODEvent()->GetTracklets());
1618 const AliMultiplicity *mult = esd.GetMultiplicity();
1619 if (mult) {
9a003bdc 1620 if (mult->GetNumberOfTracklets()>0) {
c82bb898 1621 SPDTracklets.CreateContainer(mult->GetNumberOfTracklets());
9a003bdc 1622 SPDTracklets.SetScaleDThetaBySin2T(mult->GetScaleDThetaBySin2T());
c82bb898 1623 for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {
1624 if(fMChandler){
1625 fMChandler->SelectParticle(mult->GetLabel(n, 0));
1626 fMChandler->SelectParticle(mult->GetLabel(n, 1));
1627 }
1628 SPDTracklets.SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n, 0),mult->GetLabel(n, 1));
1629 }
1630 }
1631 } else {
1632 //Printf("ERROR: AliMultiplicity could not be retrieved from ESD");
1633 }
1634}
1635
1636//______________________________________________________________________________
1637void AliAnalysisTaskESDfilter::ConvertKinks(const AliESDEvent& esd)
1638{
1639 AliCodeTimerAuto("",0);
1640
1641 // Kinks: it is a big mess the access to the information in the kinks
1642 // The loop is on the tracks in order to find the mother and daugther of each kink
1643
1644 Double_t covTr[21]={0.};
76b98553 1645 // Double_t pid[10]={0.};
c82bb898 1646 AliAODPid* detpid(0x0);
339288ed 1647 Int_t tofLabel[3] = {0};
c82bb898 1648
1649 fNumberOfKinks = esd.GetNumberOfKinks();
1650
1651 const AliESDVertex* vtx = esd.GetPrimaryVertex();
1652
1653 for (Int_t iTrack=0; iTrack<esd.GetNumberOfTracks(); ++iTrack)
1654 {
1655 AliESDtrack * esdTrack = esd.GetTrack(iTrack);
1656
1657 Int_t ikink = esdTrack->GetKinkIndex(0);
1658
1659 if (ikink && fNumberOfKinks) {
5059e451 1660 // Negative kink index: mother, positive: daughter
1661 // Search for the second track of the kink
c82bb898 1662
5059e451 1663 for (Int_t jTrack = iTrack+1; jTrack<esd.GetNumberOfTracks(); ++jTrack) {
c82bb898 1664 AliESDtrack * esdTrack1 = esd.GetTrack(jTrack);
c82bb898 1665 Int_t jkink = esdTrack1->GetKinkIndex(0);
1666
1667 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
c82bb898 1668 // The two tracks are from the same kink
c82bb898 1669 if (fUsedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
1670
1671 Int_t imother = -1;
1672 Int_t idaughter = -1;
1673
1674 if (ikink<0 && jkink>0) {
c82bb898 1675 imother = iTrack;
1676 idaughter = jTrack;
5059e451 1677 } else if (ikink>0 && jkink<0) {
1678 imother = jTrack;
c82bb898 1679 idaughter = iTrack;
5059e451 1680 } else {
1681 //cerr << "Error: Wrong combination of kink indexes: "
1682 // << ikink << " " << jkink << endl;
c82bb898 1683 continue;
1684 }
1685
1686 // Add the mother track if it passed primary track selection cuts
c82bb898 1687 AliAODTrack * mother = NULL;
1688
1689 UInt_t selectInfo = 0;
1690 if (fTrackFilter) {
1691 selectInfo = fTrackFilter->IsSelected(esd.GetTrack(imother));
1692 if (!selectInfo) continue;
1693 }
1694
1695 if (!fUsedTrack[imother]) {
c82bb898 1696 fUsedTrack[imother] = kTRUE;
c82bb898 1697 AliESDtrack *esdTrackM = esd.GetTrack(imother);
1698 Double_t p[3] = { 0. };
1699 Double_t pos[3] = { 0. };
1700 esdTrackM->GetPxPyPz(p);
1701 esdTrackM->GetXYZ(pos);
1702 esdTrackM->GetCovarianceXYZPxPyPz(covTr);
76b98553 1703 // esdTrackM->GetESDpid(pid);
339288ed 1704 esdTrackM->GetTOFLabel(tofLabel);
c82bb898 1705 if(fMChandler)fMChandler->SelectParticle(esdTrackM->GetLabel());
5059e451 1706 mother = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrackM->GetID(),
1707 esdTrackM->GetLabel(),
1708 p,
1709 kTRUE,
1710 pos,
1711 kFALSE,
1712 covTr,
1713 (Short_t)esdTrackM->GetSign(),
1714 esdTrackM->GetITSClusterMap(),
76b98553 1715 // pid,
5059e451 1716 fPrimaryVertex,
1717 kTRUE, // check if this is right
1718 vtx->UsesTrack(esdTrack->GetID()),
1719 AliAODTrack::kPrimary,
1720 selectInfo);
76b98553 1721 mother->SetPIDForTracking(esdTrackM->GetPIDForTracking());
c82bb898 1722 mother->SetTPCFitMap(esdTrackM->GetTPCFitMap());
1723 mother->SetTPCClusterMap(esdTrackM->GetTPCClusterMap());
1724 mother->SetTPCSharedMap (esdTrackM->GetTPCSharedMap());
1725 mother->SetChi2perNDF(Chi2perNDF(esdTrackM));
1726 mother->SetTPCPointsF(esdTrackM->GetTPCNclsF());
820214a7 1727 mother->SetTPCNCrossedRows(UShort_t(esdTrackM->GetTPCCrossedRows()));
9b5c8b95 1728 mother->SetIntegratedLength(esdTrackM->GetIntegratedLength());
339288ed 1729 mother->SetTOFLabel(tofLabel);
63825dc4 1730 CopyCaloProps(esdTrackM,mother);
c82bb898 1731 fAODTrackRefs->AddAt(mother, imother);
c82bb898 1732 if (esdTrackM->GetSign() > 0) ++fNumberOfPositiveTracks;
1733 mother->SetFlags(esdTrackM->GetStatus());
1734 mother->ConvertAliPIDtoAODPID();
1735 fPrimaryVertex->AddDaughter(mother);
1736 mother->ConvertAliPIDtoAODPID();
1737 SetAODPID(esdTrackM,mother,detpid);
1738 }
1739 else {
5059e451 1740 //cerr << "Error: event " << esd.GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1
1741 // << " track " << imother << " has already been used!" << endl;
c82bb898 1742 }
1743
1744 // Add the kink vertex
1745 AliESDkink * kink = esd.GetKink(TMath::Abs(ikink)-1);
1746
5059e451 1747 AliAODVertex * vkink = new(Vertices()[fNumberOfVertices++]) AliAODVertex(kink->GetPosition(),
1748 NULL,
1749 0.,
1750 mother,
1751 esdTrack->GetID(), // ID of mother's track!
1752 AliAODVertex::kKink);
c82bb898 1753 // Add the daughter track
c82bb898 1754 AliAODTrack * daughter = NULL;
c82bb898 1755 if (!fUsedTrack[idaughter]) {
c82bb898 1756 fUsedTrack[idaughter] = kTRUE;
c82bb898 1757 AliESDtrack *esdTrackD = esd.GetTrack(idaughter);
1758 Double_t p[3] = { 0. };
1759 Double_t pos[3] = { 0. };
c82bb898 1760 esdTrackD->GetPxPyPz(p);
1761 esdTrackD->GetXYZ(pos);
1762 esdTrackD->GetCovarianceXYZPxPyPz(covTr);
76b98553 1763 // esdTrackD->GetESDpid(pid);
339288ed 1764 esdTrackD->GetTOFLabel(tofLabel);
c82bb898 1765 selectInfo = 0;
1766 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdTrackD);
1767 if(fMChandler)fMChandler->SelectParticle(esdTrackD->GetLabel());
5059e451 1768 daughter = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrackD->GetID(),
1769 esdTrackD->GetLabel(),
1770 p,
1771 kTRUE,
1772 pos,
1773 kFALSE,
1774 covTr,
1775 (Short_t)esdTrackD->GetSign(),
1776 esdTrackD->GetITSClusterMap(),
76b98553 1777 // pid,
5059e451 1778 vkink,
1779 kTRUE, // check if this is right
1780 vtx->UsesTrack(esdTrack->GetID()),
1781 AliAODTrack::kSecondary,
1782 selectInfo);
76b98553 1783 daughter->SetPIDForTracking(esdTrackD->GetPIDForTracking());
c82bb898 1784 daughter->SetTPCFitMap(esdTrackD->GetTPCFitMap());
1785 daughter->SetTPCClusterMap(esdTrackD->GetTPCClusterMap());
1786 daughter->SetTPCSharedMap (esdTrackD->GetTPCSharedMap());
1787 daughter->SetTPCPointsF(esdTrackD->GetTPCNclsF());
820214a7 1788 daughter->SetTPCNCrossedRows(UShort_t(esdTrackD->GetTPCCrossedRows()));
9b5c8b95 1789 daughter->SetIntegratedLength(esdTrackD->GetIntegratedLength());
339288ed 1790 daughter->SetTOFLabel(tofLabel);
63825dc4 1791 CopyCaloProps(esdTrackD,daughter);
c82bb898 1792 fAODTrackRefs->AddAt(daughter, idaughter);
c82bb898 1793 if (esdTrackD->GetSign() > 0) ++fNumberOfPositiveTracks;
1794 daughter->SetFlags(esdTrackD->GetStatus());
1795 daughter->ConvertAliPIDtoAODPID();
1796 vkink->AddDaughter(daughter);
1797 daughter->ConvertAliPIDtoAODPID();
1798 SetAODPID(esdTrackD,daughter,detpid);
5059e451 1799 } else {
1800 //cerr << "Error: event " << esd.GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1
1801 // << " track " << idaughter << " has already been used!" << endl;
c82bb898 1802 }
1803 }
5059e451 1804 }
c82bb898 1805 }
1806 }
1807}
1808
1809//______________________________________________________________________________
1810void AliAnalysisTaskESDfilter::ConvertPrimaryVertices(const AliESDEvent& esd)
1811{
1812 AliCodeTimerAuto("",0);
1813
1814 // Access to the AOD container of vertices
1815 fNumberOfVertices = 0;
1816
1817 Double_t pos[3] = { 0. };
1818 Double_t covVtx[6] = { 0. };
1819
1820 // Add primary vertex. The primary tracks will be defined
1821 // after the loops on the composite objects (V0, cascades, kinks)
1822 const AliESDVertex *vtx = esd.GetPrimaryVertex();
1823
1824 vtx->GetXYZ(pos); // position
1825 vtx->GetCovMatrix(covVtx); //covariance matrix
1826
1827 fPrimaryVertex = new(Vertices()[fNumberOfVertices++])
1828 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);
1829 fPrimaryVertex->SetName(vtx->GetName());
1830 fPrimaryVertex->SetTitle(vtx->GetTitle());
c6ee88f3 1831 fPrimaryVertex->SetBC(vtx->GetBC());
c82bb898 1832
1833 TString vtitle = vtx->GetTitle();
1834 if (!vtitle.Contains("VertexerTracks"))
1835 fPrimaryVertex->SetNContributors(vtx->GetNContributors());
1836
1837 if (fDebug > 0) fPrimaryVertex->Print();
1838
1839 // Add SPD "main" vertex
1840 const AliESDVertex *vtxS = esd.GetPrimaryVertexSPD();
1841 vtxS->GetXYZ(pos); // position
1842 vtxS->GetCovMatrix(covVtx); //covariance matrix
1843 AliAODVertex * mVSPD = new(Vertices()[fNumberOfVertices++])
1844 AliAODVertex(pos, covVtx, vtxS->GetChi2toNDF(), NULL, -1, AliAODVertex::kMainSPD);
1845 mVSPD->SetName(vtxS->GetName());
1846 mVSPD->SetTitle(vtxS->GetTitle());
1847 mVSPD->SetNContributors(vtxS->GetNContributors());
1848
1849 // Add SPD pileup vertices
5059e451 1850 for(Int_t iV=0; iV<esd.GetNumberOfPileupVerticesSPD(); ++iV) {
c82bb898 1851 const AliESDVertex *vtxP = esd.GetPileupVertexSPD(iV);
1852 vtxP->GetXYZ(pos); // position
1853 vtxP->GetCovMatrix(covVtx); //covariance matrix
1854 AliAODVertex * pVSPD = new(Vertices()[fNumberOfVertices++])
1855 AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupSPD);
1856 pVSPD->SetName(vtxP->GetName());
1857 pVSPD->SetTitle(vtxP->GetTitle());
1858 pVSPD->SetNContributors(vtxP->GetNContributors());
1859 pVSPD->SetBC(vtxP->GetBC());
1860 }
1861
1862 // Add TRK pileup vertices
5059e451 1863 for(Int_t iV=0; iV<esd.GetNumberOfPileupVerticesTracks(); ++iV) {
c82bb898 1864 const AliESDVertex *vtxP = esd.GetPileupVertexTracks(iV);
1865 vtxP->GetXYZ(pos); // position
1866 vtxP->GetCovMatrix(covVtx); //covariance matrix
1867 AliAODVertex * pVTRK = new(Vertices()[fNumberOfVertices++])
1868 AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupTracks);
1869 pVTRK->SetName(vtxP->GetName());
1870 pVTRK->SetTitle(vtxP->GetTitle());
1871 pVTRK->SetNContributors(vtxP->GetNContributors());
1872 pVTRK->SetBC(vtxP->GetBC());
1873 }
a0d458de 1874
1875 // Add TPC "main" vertex
1876 const AliESDVertex *vtxT = esd.GetPrimaryVertexTPC();
1877 vtxT->GetXYZ(pos); // position
1878 vtxT->GetCovMatrix(covVtx); //covariance matrix
1879 AliAODVertex * mVTPC = new(Vertices()[fNumberOfVertices++])
1880 AliAODVertex(pos, covVtx, vtxT->GetChi2toNDF(), NULL, -1, AliAODVertex::kMainTPC);
1881 mVTPC->SetName(vtxT->GetName());
1882 mVTPC->SetTitle(vtxT->GetTitle());
1883 mVTPC->SetNContributors(vtxT->GetNContributors());
c82bb898 1884}
1885
1886//______________________________________________________________________________
1887void AliAnalysisTaskESDfilter::ConvertVZERO(const AliESDEvent& esd)
1888{
1889 // Convert VZERO data
1890 AliAODVZERO* vzeroData = AODEvent()->GetVZEROData();
1891 *vzeroData = *(esd.GetVZEROData());
1892}
1893
1894//______________________________________________________________________________
1895void AliAnalysisTaskESDfilter::ConvertTZERO(const AliESDEvent& esd)
1896{
1897 // Convert TZERO data
1898 const AliESDTZERO* esdTzero = esd.GetESDTZERO();
1899 AliAODTZERO* aodTzero = AODEvent()->GetTZEROData();
1900
1901 for (Int_t icase=0; icase<3; icase++){
1902 aodTzero->SetT0TOF( icase, esdTzero->GetT0TOF(icase));
1903 aodTzero->SetT0TOFbest(icase, esdTzero->GetT0TOFbest(icase));
1904 }
1905 aodTzero->SetBackgroundFlag(esdTzero->GetBackgroundFlag());
1906 aodTzero->SetPileupFlag(esdTzero->GetPileupFlag());
1907 aodTzero->SetSatelliteFlag(esdTzero->GetSatellite());
1908
1909 Float_t rawTime[24];
1910 for(Int_t ipmt=0; ipmt<24; ipmt++)
1911 rawTime[ipmt] = esdTzero->GetTimeFull(ipmt,0);
1912
1913 Int_t idxOfFirstPmtA = -1, idxOfFirstPmtC = -1;
1914 Float_t timeOfFirstPmtA = 9999, timeOfFirstPmtC = 9999;
1915 for(int ipmt=0; ipmt<12; ipmt++){
1916 if( rawTime[ipmt] > -200 && rawTime[ipmt] < timeOfFirstPmtC && rawTime[ipmt]!=0){
1917 timeOfFirstPmtC = rawTime[ipmt];
1918 idxOfFirstPmtC = ipmt;
1919 }
1920 }
1921 for(int ipmt=12; ipmt<24; ipmt++){
1922 if( rawTime[ipmt] > -200 && rawTime[ipmt] < timeOfFirstPmtA && rawTime[ipmt]!=0 ){
1923 timeOfFirstPmtA = rawTime[ipmt];
1924 idxOfFirstPmtA = ipmt;
1925 }
1926 }
1927
1928 if(idxOfFirstPmtA != -1 && idxOfFirstPmtC != -1){
1929 //speed of light in cm/ns TMath::C()*1e-7
1930 Float_t vertexraw = TMath::C()*1e-7 * (rawTime[idxOfFirstPmtA] - rawTime[idxOfFirstPmtC])/2;
1931 aodTzero->SetT0VertexRaw( vertexraw );
1932 }else{
1933 aodTzero->SetT0VertexRaw(99999);
1934 }
1935
5bb5611e 1936 aodTzero->SetT0zVertex(esdTzero->GetT0zVertex());
dd3e4637 1937 //amplitude
1938
1939 const Double32_t *amp=esdTzero->GetT0amplitude();
1940 for(int ipmt=0; ipmt<24; ipmt++)
1941 aodTzero->SetAmp(ipmt, amp[ipmt]);
1942 aodTzero->SetAmp(24,esdTzero->GetMultC() );
1943 aodTzero->SetAmp(25,esdTzero->GetMultA() );
c82bb898 1944}
1945
c82bb898 1946//______________________________________________________________________________
1947void AliAnalysisTaskESDfilter::ConvertZDC(const AliESDEvent& esd)
1948{
1949 // Convert ZDC data
1950 AliESDZDC* esdZDC = esd.GetZDCData();
1951
1952 const Double_t zem1Energy = esdZDC->GetZEM1Energy();
1953 const Double_t zem2Energy = esdZDC->GetZEM2Energy();
1954
1955 const Double_t *towZNC = esdZDC->GetZNCTowerEnergy();
1956 const Double_t *towZPC = esdZDC->GetZPCTowerEnergy();
1957 const Double_t *towZNA = esdZDC->GetZNATowerEnergy();
1958 const Double_t *towZPA = esdZDC->GetZPATowerEnergy();
1959 const Double_t *towZNCLG = esdZDC->GetZNCTowerEnergyLR();
1960 const Double_t *towZNALG = esdZDC->GetZNATowerEnergyLR();
1961
1962 AliAODZDC* zdcAOD = AODEvent()->GetZDCData();
1963
1964 zdcAOD->SetZEM1Energy(zem1Energy);
1965 zdcAOD->SetZEM2Energy(zem2Energy);
1966 zdcAOD->SetZNCTowers(towZNC, towZNCLG);
1967 zdcAOD->SetZNATowers(towZNA, towZNALG);
1968 zdcAOD->SetZPCTowers(towZPC);
1969 zdcAOD->SetZPATowers(towZPA);
1970
1971 zdcAOD->SetZDCParticipants(esdZDC->GetZDCParticipants(), esdZDC->GetZDCPartSideA(), esdZDC->GetZDCPartSideC());
5059e451 1972 zdcAOD->SetZDCImpactParameter(esdZDC->GetImpactParameter(), esdZDC->GetImpactParamSideA(), esdZDC->GetImpactParamSideC());
c82bb898 1973 zdcAOD->SetZDCTDCSum(esdZDC->GetZNTDCSum(0));
1974 zdcAOD->SetZDCTDCDiff(esdZDC->GetZNTDCDiff(0));
26428fe7 1975 if(esdZDC->IsZNChit()) zdcAOD->SetZNCTDC(esdZDC->GetZDCTDCCorrected(10,0));
1976 if(esdZDC->IsZNAhit()) zdcAOD->SetZNATDC(esdZDC->GetZDCTDCCorrected(12,0));
c82bb898 1977}
1978
5059e451 1979//_____________________________________________________________________________
08b38f3f 1980Int_t AliAnalysisTaskESDfilter::ConvertHMPID(const AliESDEvent& esd) // clm
1981{
1982 //
1983 // Convtert ESD HMPID info to AOD and return the number of good tracks with HMPID signal.
1984 // We need to return an int since there is no signal counter in the ESD.
1985 //
1986
1987 AliCodeTimerAuto("",0);
1988
1989 Int_t cntHmpidGoodTracks = 0;
1990
1991 Float_t xMip = 0;
1992 Float_t yMip = 0;
1993 Int_t qMip = 0;
1994 Int_t nphMip = 0;
1995
1996 Float_t xTrk = 0;
1997 Float_t yTrk = 0;
1998 Float_t thetaTrk = 0;
1999 Float_t phiTrk = 0;
2000
2001 Double_t hmpPid[5]={0};
2002 Double_t hmpMom[3]={0};
2003
2004 TClonesArray &hmpidRings = *(AODEvent()->GetHMPIDrings());
2005
5059e451 2006 for (Int_t iTrack=0; iTrack<esd.GetNumberOfTracks(); ++iTrack) {
08b38f3f 2007 if(! esd.GetTrack(iTrack) ) continue;
2008
2009 if(esd.GetTrack(iTrack)->GetHMPIDsignal() > -20 ) { //
08b38f3f 2010 (esd.GetTrack(iTrack))->GetHMPIDmip(xMip, yMip, qMip, nphMip); // Get MIP properties
2011 (esd.GetTrack(iTrack))->GetHMPIDtrk(xTrk,yTrk,thetaTrk,phiTrk);
2012 (esd.GetTrack(iTrack))->GetHMPIDpid(hmpPid);
2013 if((esd.GetTrack(iTrack))->GetOuterHmpParam()) (esd.GetTrack(iTrack))->GetOuterHmpPxPyPz(hmpMom);
2014
5059e451 2015 if(esd.GetTrack(iTrack)->GetHMPIDsignal() == 0 && thetaTrk == 0 && qMip == 0 && nphMip ==0 ) continue; //
08b38f3f 2016
5059e451 2017 new(hmpidRings[cntHmpidGoodTracks++]) AliAODHMPIDrings((esd.GetTrack(iTrack))->GetID(), // Unique track id to attach the ring to
2018 1000000*nphMip+qMip, // MIP charge and number of photons
2019 (esd.GetTrack(iTrack))->GetHMPIDcluIdx(), // 1000000*chamber id + cluster idx of assigned MIP cluster
2020 thetaTrk, // track inclination angle theta
2021 phiTrk, // track inclination angle phi
2022 (esd.GetTrack(iTrack))->GetHMPIDsignal(), // Cherenkov angle
2023 (esd.GetTrack(iTrack))->GetHMPIDoccupancy(), // Occupancy claculated for the given chamber
2024 (esd.GetTrack(iTrack))->GetHMPIDchi2(), // Ring resolution squared
2025 xTrk, // Track x coordinate (LORS)
2026 yTrk, // Track y coordinate (LORS)
2027 xMip, // MIP x coordinate (LORS)
2028 yMip, // MIP y coordinate (LORS)
2029 hmpPid, // PID probablities from ESD, remove once it is CombinedPid
2030 hmpMom // Track momentum in HMPID at ring reconstruction
2031 );
2032 }
2033 }
08b38f3f 2034
2035 return cntHmpidGoodTracks;
2036}
2037
b2b65de9 2038void AliAnalysisTaskESDfilter::ConvertTRD(const AliESDEvent& esd)
2039{
2040 // fill TRD on-line tracks with assiocated tracklets
2041 // as used for the TRD level-1 triggers
2042
2043 const Int_t nTrdTracks = esd.GetNumberOfTrdTracks();
2044 const Int_t nLayers = 6;
2045
2046 for (Int_t iTrdTrack = 0; iTrdTrack < nTrdTracks; ++iTrdTrack) {
2047 // copy information from ESD track to AOD track
2048 const AliESDTrdTrack *esdTrdTrk = esd.GetTrdTrack(iTrdTrack);
2049 AliAODTrdTrack &aodTrdTrk = AODEvent()->AddTrdTrack(esdTrdTrk);
2050
2051 // copy the contributing tracklets
2052 for (Int_t iTracklet = 0; iTracklet < nLayers; ++iTracklet) {
2053 if (const AliESDTrdTracklet *esdTrdTrkl = esdTrdTrk->GetTracklet(iTracklet))
2054 aodTrdTrk.AddTracklet(*esdTrdTrkl, iTracklet);
2055 }
2056
2057 // add the reference to the matched global track
2058 AliAODTrack *aodTrkMatch = 0x0;
2059 AliESDtrack *esdTrkMatch = (AliESDtrack*) esdTrdTrk->GetTrackMatch();
2060 if (esdTrkMatch) {
2061 Int_t idx = esdTrkMatch->GetID();
2062
2063 if (idx < 0)
2064 AliError("track has a matched track that was not found");
2065 else if (esdTrkMatch != esd.GetTrack(idx))
2066 AliError("wrong track found for ESD track index");
2067 else {
2068 UInt_t selectInfo = fTrackFilter ? fTrackFilter->IsSelected(esdTrkMatch) : 0;
2069
2070 if (fUsedTrack[idx]) {
2071 aodTrkMatch = (AliAODTrack*) (*fAODTrackRefs)[idx];
2072 AliDebug(2, Form("event %lld: existing track (idx %i, pt = %f) matched to TRD track (idx %i, pt = %f), cut flags: 0x%08x",
2073 Entry(), idx, esdTrkMatch->Pt(), iTrdTrack, esdTrdTrk->Pt(),
2074 selectInfo));
5059e451 2075 } else {
b2b65de9 2076 if (selectInfo & fUsedTrackCopy[idx]) {
2077 // mask filter bits already used in track copies
2078 selectInfo &= ~fUsedTrackCopy[idx];
2079 AliWarning(Form("event %lld: copied track (idx %i, pt = %f) matched to TRD track (idx %i, pt = %f), cut flags: 0x%08x -> 0x%08x",
2080 Entry(), idx, esdTrkMatch->Pt(), iTrdTrack, esdTrdTrk->Pt(),
2081 fTrackFilter->IsSelected(esdTrkMatch), selectInfo));
2082 }
2083 AliDebug(2, Form("event %lld: unused track (idx %i, pt = %f) matched to TRD track (idx %i, pt = %f), cut flags: 0x%08x -> 0x%08x",
2084 Entry(), idx, esdTrkMatch->Pt(), iTrdTrack, esdTrdTrk->Pt(),
2085 fTrackFilter->IsSelected(esdTrkMatch), selectInfo));
2086
2087 Double_t mom[3]={0.};
2088 Double_t pos[3]={0.};
2089 Double_t covTr[21]={0.};
76b98553 2090 // Double_t pid[10]={0.};
b2b65de9 2091
2092 esdTrkMatch->GetPxPyPz(mom);
2093 esdTrkMatch->GetXYZ(pos);
2094 esdTrkMatch->GetCovarianceXYZPxPyPz(covTr);
76b98553 2095 // esdTrkMatch->GetESDpid(pid);
b2b65de9 2096 const AliESDVertex* vtx = esd.GetPrimaryVertex();
2097
2098 fUsedTrack[idx] = kTRUE;
2099 if(fMChandler) fMChandler->SelectParticle(esdTrkMatch->GetLabel());
2100
5059e451 2101 aodTrkMatch = new(Tracks()[fNumberOfTracks++]) AliAODTrack(esdTrkMatch->GetID(),
2102 esdTrkMatch->GetLabel(),
2103 mom,
2104 kTRUE,
2105 pos,
2106 kFALSE,
2107 covTr,
2108 (Short_t)esdTrkMatch->GetSign(),
2109 esdTrkMatch->GetITSClusterMap(),
76b98553 2110 // pid,
5059e451 2111 fPrimaryVertex,
2112 kTRUE,
2113 vtx->UsesTrack(esdTrkMatch->GetID()),
2114 AliAODTrack::kUndef,
2115 selectInfo);
76b98553 2116 aodTrkMatch->SetPIDForTracking(esdTrkMatch->GetPIDForTracking());
b2b65de9 2117 aodTrkMatch->SetTPCFitMap(esdTrkMatch->GetTPCFitMap());
2118 aodTrkMatch->SetTPCClusterMap(esdTrkMatch->GetTPCClusterMap());
2119 aodTrkMatch->SetTPCSharedMap (esdTrkMatch->GetTPCSharedMap());
2120 aodTrkMatch->SetChi2perNDF(Chi2perNDF(esdTrkMatch));
2121 aodTrkMatch->SetTPCPointsF(esdTrkMatch->GetTPCNclsF());
2122 aodTrkMatch->SetTPCNCrossedRows(UShort_t(esdTrkMatch->GetTPCCrossedRows()));
2123 aodTrkMatch->SetIntegratedLength(esdTrkMatch->GetIntegratedLength());
63825dc4 2124 CopyCaloProps(esdTrkMatch,aodTrkMatch);
2125 fAODTrackRefs->AddAt(aodTrkMatch,idx);
b2b65de9 2126 if (esdTrkMatch->GetSign() > 0) ++fNumberOfPositiveTracks;
2127 aodTrkMatch->ConvertAliPIDtoAODPID();
2128 aodTrkMatch->SetFlags(esdTrkMatch->GetStatus());
2129 }
2130 }
2131 }
2132 aodTrdTrk.SetTrackMatchReference(aodTrkMatch);
2133 }
2134}
2135
c82bb898 2136//______________________________________________________________________________
2137void AliAnalysisTaskESDfilter::ConvertESDtoAOD()
2138{
2139 // ESD Filter analysis task executed for each event
2140
2141 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
2142
2143 if(!esd)return;
2144
2145 AliCodeTimerAuto("",0);
db47bd9e 2146
546afe0c 2147 if (fRefitVertexTracks>=0) AliESDUtils::RefitESDVertexTracks(esd,fRefitVertexTracks,
2148 fRefitVertexTracksNCuts ? fRefitVertexTracksCuts:0);
c82bb898 2149
2150 fOldESDformat = ( esd->GetAliESDOld() != 0x0 );
2151
2152 // Reconstruct cascades and V0 here
2153 if (fIsV0CascadeRecoEnabled) {
2154 esd->ResetCascades();
2155 esd->ResetV0s();
2156
2157 AliV0vertexer lV0vtxer;
2158 AliCascadeVertexer lCascVtxer;
2159
2160 lV0vtxer.SetCuts(fV0Cuts);
2161 lCascVtxer.SetCuts(fCascadeCuts);
2162
2163
2164 lV0vtxer.Tracks2V0vertices(esd);
2165 lCascVtxer.V0sTracks2CascadeVertices(esd);
2166 }
2167
63825dc4 2168 // Perform progagation of tracks if needed
2169 if (fDoPropagateTrackToEMCal) {
2170 const Int_t ntrack = esd->GetNumberOfTracks();
2171 for (Int_t i=0;i<ntrack;++i) {
2172 AliESDtrack *t = esd->GetTrack(i);
2173 AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(t,fEMCalSurfaceDistance);
2174 }
2175 }
c82bb898 2176
2177 fNumberOfTracks = 0;
2178 fNumberOfPositiveTracks = 0;
2179 fNumberOfV0s = 0;
2180 fNumberOfVertices = 0;
2181 fNumberOfCascades = 0;
2182 fNumberOfKinks = 0;
2183
2184 AliAODHeader* header = ConvertHeader(*esd);
2185
2186 if ( fIsVZEROEnabled ) ConvertVZERO(*esd);
2187 if ( fIsTZEROEnabled ) ConvertTZERO(*esd);
2188
2189 // Fetch Stack for debuggging if available
2190 fMChandler=0x0;
5059e451 2191 if(MCEvent()) {
c82bb898 2192 fMChandler = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
2193 }
2194
2195 // loop over events and fill them
2196 // Multiplicity information needed by the header (to be revised!)
2197 Int_t nTracks = esd->GetNumberOfTracks();
d38034b8 2198
2199// The line below should not be needed anymore (tracks already connected)
2200// for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) esd->GetTrack(iTrack)->SetESDEvent(esd);
c82bb898 2201
2202 // Update the header
c82bb898 2203 Int_t nV0s = esd->GetNumberOfV0s();
2204 Int_t nCascades = esd->GetNumberOfCascades();
2205 Int_t nKinks = esd->GetNumberOfKinks();
2206 Int_t nVertices = nV0s + nCascades /*V0 wihtin cascade already counted*/+ nKinks + 1 /* = prim. vtx*/;
2207 Int_t nPileSPDVertices=1+esd->GetNumberOfPileupVerticesSPD(); // also SPD main vertex
2208 Int_t nPileTrkVertices=esd->GetNumberOfPileupVerticesTracks();
2209 nVertices+=nPileSPDVertices;
2210 nVertices+=nPileTrkVertices;
2211 Int_t nJets = 0;
2212 Int_t nCaloClus = esd->GetNumberOfCaloClusters();
2213 Int_t nFmdClus = 0;
2214 Int_t nPmdClus = esd->GetNumberOfPmdTracks();
08b38f3f 2215 Int_t nHmpidRings = 0;
c82bb898 2216
2217 AliDebug(1,Form(" NV0=%d NCASCADES=%d NKINKS=%d", nV0s, nCascades, nKinks));
2218
5059e451 2219 AODEvent()->ResetStd(nTracks, nVertices, nV0s, nCascades, nJets, nCaloClus, nFmdClus, nPmdClus, nHmpidRings);
c82bb898 2220
5059e451 2221 if (nV0s > 0) {
c82bb898 2222 // RefArray to store a mapping between esd V0 number and newly created AOD-Vertex V0
2223 fAODV0VtxRefs = new TRefArray(nV0s);
2224 // RefArray to store the mapping between esd V0 number and newly created AOD-V0
2225 fAODV0Refs = new TRefArray(nV0s);
2226 // Array to take into account the V0s already added to the AOD (V0 within cascades)
2227 fUsedV0 = new Bool_t[nV0s];
2228 for (Int_t iV0=0; iV0<nV0s; ++iV0) fUsedV0[iV0]=kFALSE;
2229 }
2230
5059e451 2231 if (nTracks>0) {
c82bb898 2232 // RefArray to store the mapping between esd track number and newly created AOD-Track
2233
2234 fAODTrackRefs = new TRefArray(nTracks);
2235
2236 // Array to take into account the tracks already added to the AOD
2237 fUsedTrack = new Bool_t[nTracks];
b2b65de9 2238 fUsedTrackCopy = new UInt_t[nTracks];
2239 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2240 fUsedTrack[iTrack]=kFALSE;
2241 fUsedTrackCopy[iTrack] = 0;
2242 }
c82bb898 2243 }
2244
2245 // Array to take into account the kinks already added to the AOD
5059e451 2246 if (nKinks>0) {
c82bb898 2247 fUsedKink = new Bool_t[nKinks];
2248 for (Int_t iKink=0; iKink<nKinks; ++iKink) fUsedKink[iKink]=kFALSE;
2249 }
2250
2251 ConvertPrimaryVertices(*esd);
2252
2253 //setting best TOF PID
2254 AliESDInputHandler* esdH = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
2255 if (esdH)
5059e451 2256 fESDpid = esdH->GetESDpid();
c82bb898 2257
5059e451 2258 if (fIsPidOwner && fESDpid) {
c82bb898 2259 delete fESDpid;
2260 fESDpid = 0;
2261 }
5059e451 2262 if (!fESDpid) { //in case of no Tender attached
c82bb898 2263 fESDpid = new AliESDpid;
2264 fIsPidOwner = kTRUE;
2265 }
2266
5059e451 2267 if (!esd->GetTOFHeader()) { //protection in case the pass2 LHC10b,c,d have been processed without tender.
c82bb898 2268 Float_t t0spread[10];
2269 Float_t intrinsicTOFres=100; //ps ok for LHC10b,c,d pass2!!
2270 for (Int_t i=0; i<10; i++) t0spread[i] = (TMath::Sqrt(esd->GetSigma2DiamondZ()))/0.03; //0.03 to convert from cm to ps
2271 fESDpid->GetTOFResponse().SetT0resolution(t0spread);
2272 fESDpid->GetTOFResponse().SetTimeResolution(intrinsicTOFres);
5059e451 2273 // fESDpid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType);
c82bb898 2274 AliTOFHeader tmpTOFHeader(0,t0spread[0],0,NULL,NULL,NULL,intrinsicTOFres,t0spread[0]);
2275 AODEvent()->SetTOFHeader(&tmpTOFHeader); // write dummy TOF header in AOD
2276 } else {
2277 AODEvent()->SetTOFHeader(esd->GetTOFHeader()); // write TOF header in AOD
2278 }
2279
5059e451 2280 // In case of AOD production strating form LHC10e without Tender.
2281 //if(esd->GetTOFHeader() && fIsPidOwner) fESDpid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType);
c82bb898 2282
5059e451 2283 if (fAreCascadesEnabled) ConvertCascades(*esd);
2284 if (fAreV0sEnabled) ConvertV0s(*esd);
2285 if (fAreKinksEnabled) ConvertKinks(*esd);
2286 if (fAreTracksEnabled) ConvertTracks(*esd);
c82bb898 2287
2288 // Update number of AOD tracks in header at the end of track loop (M.G.)
2289 header->SetRefMultiplicity(fNumberOfTracks);
2290 header->SetRefMultiplicityPos(fNumberOfPositiveTracks);
2291 header->SetRefMultiplicityNeg(fNumberOfTracks - fNumberOfPositiveTracks);
2292
5059e451 2293 if (fTPCConstrainedFilterMask) ConvertTPCOnlyTracks(*esd);
2294 if (fGlobalConstrainedFilterMask) ConvertGlobalConstrainedTracks(*esd);
2295 if (fArePmdClustersEnabled) ConvertPmdClusters(*esd);
2296 if (fAreCaloClustersEnabled) ConvertCaloClusters(*esd);
2297 if (fAreEMCALCellsEnabled) ConvertEMCALCells(*esd);
2298 if (fArePHOSCellsEnabled) ConvertPHOSCells(*esd);
2299 if (fAreEMCALTriggerEnabled) ConvertCaloTrigger(TString("EMCAL"), *esd);
2300 if (fArePHOSTriggerEnabled) ConvertCaloTrigger(TString("PHOS"), *esd);
2301 if (fAreTrackletsEnabled) ConvertTracklets(*esd);
2302 if (fIsZDCEnabled) ConvertZDC(*esd);
2303 if (fIsHMPIDEnabled) nHmpidRings = ConvertHMPID(*esd);
b2b65de9 2304 if (fIsTRDEnabled) ConvertTRD(*esd);
2305
c82bb898 2306 delete fAODTrackRefs; fAODTrackRefs=0x0;
2307 delete fAODV0VtxRefs; fAODV0VtxRefs=0x0;
2308 delete fAODV0Refs; fAODV0Refs=0x0;
c82bb898 2309 delete[] fUsedTrack; fUsedTrack=0x0;
b2b65de9 2310 delete[] fUsedTrackCopy; fUsedTrackCopy=0x0;
c82bb898 2311 delete[] fUsedV0; fUsedV0=0x0;
2312 delete[] fUsedKink; fUsedKink=0x0;
2313
5059e451 2314 if (fIsPidOwner) {
c82bb898 2315 delete fESDpid;
2316 fESDpid = 0x0;
2317 }
6b7a3c38 2318 AODEvent()->ConnectTracks();
c82bb898 2319}
2320
c82bb898 2321//______________________________________________________________________________
2322void AliAnalysisTaskESDfilter::SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aodtrack, AliAODPid *detpid)
2323{
2324 //
2325 // Setter for the raw PID detector signals
2326 //
2327
2328 // Save PID object for candidate electrons
5059e451 2329 Bool_t pidSave = kFALSE;
2330 if (fTrackFilter) {
2331 Bool_t selectInfo = fTrackFilter->IsSelected((char*) "Electrons");
2332 if (selectInfo) pidSave = kTRUE;
2333 }
c82bb898 2334
5059e451 2335 // Tracks passing pt cut
2336 if(esdtrack->Pt()>fHighPthreshold) {
2337 pidSave = kTRUE;
2338 } else {
2339 if(fPtshape){
2340 if(esdtrack->Pt()> fPtshape->GetXmin()){
2341 Double_t y = fPtshape->Eval(esdtrack->Pt())/fPtshape->Eval(fHighPthreshold);
2342 if(gRandom->Rndm(0)<1./y){
2343 pidSave = kTRUE;
2344 }//end rndm
2345 }//end if p < pmin
2346 }//end if p function
2347 }// end else
2348
2349 if (pidSave) {
2350 if(!aodtrack->GetDetPid()){// prevent memory leak when calling SetAODPID twice for the same track
2351 detpid = new AliAODPid();
2352 SetDetectorRawSignals(detpid,esdtrack);
2353 aodtrack->SetDetPID(detpid);
c82bb898 2354 }
5059e451 2355 }
c82bb898 2356}
2357
2358//______________________________________________________________________________
2359void AliAnalysisTaskESDfilter::SetDetectorRawSignals(AliAODPid *aodpid, AliESDtrack *track)
2360{
5059e451 2361 // Assignment of the detector signals (AliXXXesdPID inspired)
2362
2363 if(!track) {
2364 AliInfo("no ESD track found. .....exiting");
2365 return;
2366 }
2367
2368 // TPC momentum
2369 aodpid->SetTPCmomentum(track->GetTPCmomentum());
2370 aodpid->SetTPCTgl(track->GetTPCTgl());
2371 aodpid->SetITSsignal(track->GetITSsignal());
2372 Double_t itsdedx[4]; // dE/dx samples for individual ITS layers
2373 track->GetITSdEdxSamples(itsdedx);
2374 aodpid->SetITSdEdxSamples(itsdedx);
2375
2376 aodpid->SetTPCsignal(track->GetTPCsignal());
2377 aodpid->SetTPCsignalN(track->GetTPCsignalN());
2378 if (track->GetTPCdEdxInfo()) aodpid->SetTPCdEdxInfo(track->GetTPCdEdxInfo());
2379
2380 //n TRD planes = 6
2381 Int_t nslices = track->GetNumberOfTRDslices()*6;
2382 TArrayD trdslices(nslices);
2383 for(Int_t iSl =0; iSl < track->GetNumberOfTRDslices(); iSl++) {
2384 for(Int_t iPl =0; iPl<6; iPl++) trdslices[iPl*track->GetNumberOfTRDslices()+iSl] = track->GetTRDslice(iPl,iSl);
2385 }
c82bb898 2386
5059e451 2387 //TRD momentum
2388 for(Int_t iPl=0;iPl<6;iPl++){
2389 Double_t trdmom=track->GetTRDmomentum(iPl);
2390 aodpid->SetTRDmomentum(iPl,trdmom);
2391 }
2392
2393 aodpid->SetTRDslices(track->GetNumberOfTRDslices()*6,trdslices.GetArray());
2394 aodpid->SetTRDsignal(track->GetTRDsignal());
2395
2396 //TRD clusters and tracklets
2397 aodpid->SetTRDncls(track->GetTRDncls());
2398 aodpid->SetTRDntrackletsPID(track->GetTRDntrackletsPID());
2399
2400 aodpid->SetTRDChi2(track->GetTRDchi2());
820214a7 2401
5059e451 2402 //TOF PID
fc9b31a7 2403 Double_t times[AliPID::kSPECIESC]; track->GetIntegratedTimes(times,AliPID::kSPECIESC);
5059e451 2404 aodpid->SetIntegratedTimes(times);
c82bb898 2405
5059e451 2406 // Float_t tzeroTrack = fESDpid->GetTOFResponse().GetStartTime(track->P());
2407 // aodpid->SetTOFsignal(track->GetTOFsignal()-tzeroTrack);
2408 aodpid->SetTOFsignal(track->GetTOFsignal());
c82bb898 2409
2410 Double_t tofRes[5];
2411 for (Int_t iMass=0; iMass<5; iMass++){
2412 // tofRes[iMass]=(Double_t)fESDpid->GetTOFResponse().GetExpectedSigma(track->P(), times[iMass], AliPID::ParticleMass(iMass));
498165cf 2413 tofRes[iMass]=0; //backward compatibility
c82bb898 2414 }
2415 aodpid->SetTOFpidResolution(tofRes);
5059e451 2416 //aodpid->SetHMPIDsignal(0); // set to zero for compression but it will be removed later
c82bb898 2417}
2418
5059e451 2419Double_t AliAnalysisTaskESDfilter::Chi2perNDF(AliESDtrack* track)
c82bb898 2420{
5059e451 2421 // Calculate chi2 per ndf for track
c82bb898 2422
5059e451 2423 Int_t nClustersTPC = track->GetTPCNcls();
2424 if ( nClustersTPC > 5) {
2425 return (track->GetTPCchi2()/Float_t(nClustersTPC - 5));
2426 } else {
2427 return (-1.);
2428 }
2429}
c82bb898 2430
2431//______________________________________________________________________________
2432void AliAnalysisTaskESDfilter::Terminate(Option_t */*option*/)
2433{
5059e451 2434 // Terminate analysis
2435
2436 if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");
c82bb898 2437}
2438
2439//______________________________________________________________________________
5059e451 2440void AliAnalysisTaskESDfilter::PrintMCInfo(AliStack *pStack,Int_t label)
2441{
2442 // Print MC info
2443 if (!pStack) return;
c82bb898 2444 label = TMath::Abs(label);
2445 TParticle *part = pStack->Particle(label);
2446 Printf("########################");
2447 Printf("%s:%d %d UniqueID %d PDG %d P %3.3f",(char*)__FILE__,__LINE__,label,part->GetUniqueID(),part->GetPdgCode(),part->P());
2448 part->Print();
2449 TParticle* mother = part;
2450 Int_t imo = part->GetFirstMother();
2451 Int_t nprim = pStack->GetNprimary();
2452 // while((imo >= nprim) && (mother->GetUniqueID() == 4)) {
2453 while((imo >= nprim)) {
2454 mother = pStack->Particle(imo);
2455 Printf("Mother %s:%d Label %d UniqueID %d PDG %d P %3.3f",(char*)__FILE__,__LINE__,imo,mother->GetUniqueID(),mother->GetPdgCode(),mother->P());
2456 mother->Print();
2457 imo = mother->GetFirstMother();
2458 }
2459 Printf("########################");
2460}
2461
63825dc4 2462//______________________________________________________________________________
5059e451 2463void AliAnalysisTaskESDfilter::CopyCaloProps(AliESDtrack *tre, AliAODTrack *tra)
2464{
2465 // Copy calo properties from ESD track to AOD track
63825dc4 2466 tra->SetTrackPhiEtaPtOnEMCal(tre->GetTrackPhiOnEMCal(),tre->GetTrackEtaOnEMCal(),tre->GetTrackPtOnEMCal());
5059e451 2467 if (tre->IsEMCAL()) tra->SetEMCALcluster(tre->GetEMCALcluster());
2468 if (tre->IsPHOS()) tra->SetPHOScluster(tre->GetPHOScluster());
63825dc4 2469}
2470
2471//______________________________________________________________________________
db47bd9e 2472void AliAnalysisTaskESDfilter::SetRefitVertexTracks(Int_t algo, Double_t* cuts)
2473{
2474 // request vertexTrack reprocessing from ESDtracks
2475 // if algo>=0 and cuts==0 then algo is interpreted as the algorithm ID to be run with default cuts
2476 // otherwise it is number of cuts to digest
2477 fRefitVertexTracks = algo;
db47bd9e 2478 if (algo>0 && cuts) {
2479 fRefitVertexTracksCuts = new Double_t[fRefitVertexTracks];
2480 for (int i=fRefitVertexTracks;i--;) fRefitVertexTracksCuts[i] = cuts[i];
ca77219c 2481 fRefitVertexTracksNCuts = fRefitVertexTracks;
db47bd9e 2482 }
2483}