removing the setting of AOD track references for TPC only tracks
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTaskESDfilter.cxx
CommitLineData
f7ed7e88 1/**************************************************************************\r
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *\r
3 * *\r
4 * Author: The ALICE Off-line Project. *\r
5 * Contributors are mentioned in the code where appropriate. *\r
6 * *\r
7 * Permission to use, copy, modify and distribute this software and its *\r
8 * documentation strictly for non-commercial purposes is hereby granted *\r
9 * without fee, provided that the above copyright notice appears in all *\r
10 * copies and that both the copyright notice and this permission notice *\r
11 * appear in the supporting documentation. The authors make no claims *\r
12 * about the suitability of this software for any purpose. It is *\r
13 * provided "as is" without express or implied warranty. *\r
14 **************************************************************************/\r
15\r
16/* $Id: AliAnalysisTaskESDfilter.cxx 24535 2008-03-16 22:43:30Z fca $ */\r
17 \r
18#include <TChain.h>\r
19#include <TTree.h>\r
20#include <TList.h>\r
21#include <TArrayI.h>\r
22#include <TRandom.h>\r
23#include <TParticle.h>\r
a5f7aba4 24#include <TFile.h>\r
f7ed7e88 25\r
26#include "AliAnalysisTaskESDfilter.h"\r
27#include "AliAnalysisManager.h"\r
28#include "AliESDEvent.h"\r
f2f21b24 29#include "AliESDRun.h"\r
f7ed7e88 30#include "AliStack.h"\r
31#include "AliAODEvent.h"\r
32#include "AliMCEvent.h"\r
33#include "AliMCEventHandler.h"\r
34#include "AliESDInputHandler.h"\r
35#include "AliAODHandler.h"\r
36#include "AliAODMCParticle.h"\r
37#include "AliAnalysisFilter.h"\r
38#include "AliESDMuonTrack.h"\r
39#include "AliESDVertex.h"\r
fba4b2e2 40#include "AliCentrality.h"\r
f7ed7e88 41#include "AliESDv0.h"\r
42#include "AliESDkink.h"\r
43#include "AliESDcascade.h"\r
44#include "AliESDPmdTrack.h"\r
45#include "AliESDCaloCluster.h"\r
46#include "AliESDCaloCells.h"\r
47#include "AliMultiplicity.h"\r
48#include "AliLog.h"\r
a7b1466d 49#include "AliTrackerBase.h"\r
50#include "AliESDtrackCuts.h"\r
b13bcc35 51#include "AliPID.h"\r
52 \r
f7ed7e88 53ClassImp(AliAnalysisTaskESDfilter)\r
54\r
55////////////////////////////////////////////////////////////////////////\r
56\r
57AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter():\r
58 AliAnalysisTaskSE(),\r
59 fTrackFilter(0x0),\r
60 fKinkFilter(0x0),\r
61 fV0Filter(0x0),\r
62 fCascadeFilter(0x0),\r
a7b1466d 63 fTPCOnlyFilterMask(0),\r
f7ed7e88 64 fHighPthreshold(0),\r
12588061 65 fPtshape(0x0),\r
26917b0b 66 fEnableFillAOD(kTRUE),\r
67 fTimeZeroType(AliESDpid::kTOF_T0)\r
f7ed7e88 68{\r
69 // Default constructor\r
70}\r
71\r
72AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter(const char* name):\r
73 AliAnalysisTaskSE(name),\r
74 fTrackFilter(0x0),\r
75 fKinkFilter(0x0),\r
76 fV0Filter(0x0),\r
77 fCascadeFilter(0x0),\r
a7b1466d 78 fTPCOnlyFilterMask(0),\r
f7ed7e88 79 fHighPthreshold(0),\r
12588061 80 fPtshape(0x0),\r
26917b0b 81 fEnableFillAOD(kTRUE),\r
82 fTimeZeroType(AliESDpid::kTOF_T0)\r
f7ed7e88 83{\r
84 // Constructor\r
85}\r
86\r
87void AliAnalysisTaskESDfilter::UserCreateOutputObjects()\r
88{\r
cd5eefa7 89 //\r
90 // Create Output Objects conenct filter to outputtree\r
91 // \r
d3815ca9 92 if(OutputTree()){\r
f7ed7e88 93 OutputTree()->GetUserInfo()->Add(fTrackFilter);\r
d3815ca9 94 }\r
95 else{\r
96 AliError("No OutputTree() for adding the track filter");\r
97 }\r
f7ed7e88 98}\r
99\r
100void AliAnalysisTaskESDfilter::Init()\r
101{\r
102 // Initialization\r
103 if (fDebug > 1) AliInfo("Init() \n");\r
104 // Call configuration file\r
105}\r
106\r
107\r
108void AliAnalysisTaskESDfilter::UserExec(Option_t */*option*/)\r
109{\r
110// Execute analysis for current event\r
111//\r
112 \r
113 Long64_t ientry = Entry();\r
f2f21b24 114 \r
e26c0b71 115 if (fDebug > 0) {\r
f2f21b24 116 printf("Filter: Analysing event # %5d\n", (Int_t) ientry);\r
117 if (fHighPthreshold == 0) AliInfo("detector PID signals are stored in each track");\r
118 if (!fPtshape) AliInfo("detector PID signals are not stored below the pt threshold");\r
e26c0b71 119 }\r
5b173801 120 // Filters must explicitely enable AOD filling in their UserExec (AG)\r
121 if (!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) AliFatal("Cannot run ESD filter without an output event handler");\r
12588061 122 if(fEnableFillAOD) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);\r
5b173801 123\r
f7ed7e88 124 ConvertESDtoAOD();\r
125}\r
126\r
127void AliAnalysisTaskESDfilter::ConvertESDtoAOD() {\r
128 // ESD Filter analysis task executed for each event\r
129\r
130 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());\r
dcbfafb9 131 if(!esd)return;\r
f7ed7e88 132 AliESD* old = esd->GetAliESDOld();\r
133\r
134 // Fetch Stack for debuggging if available \r
f7ed7e88 135 AliMCEventHandler *mcH = 0;\r
136 if(MCEvent()){\r
f7ed7e88 137 mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); \r
138 }\r
139 // set arrays and pointers\r
140 Float_t posF[3];\r
141 Double_t pos[3];\r
142 Double_t p[3];\r
143 Double_t momPos[3]; \r
144 Double_t momNeg[3];\r
145 Double_t momBach[3];\r
146 Double_t momPosAtV0vtx[3];\r
147 Double_t momNegAtV0vtx[3];\r
148 Double_t momBachAtCascadeVtx[3];\r
149 Double_t covVtx[6];\r
150 Double_t covTr[21];\r
151 Double_t pid[10];\r
152\r
153 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;\r
154 for (Int_t i = 0; i < 21; i++) covTr [i] = 0.;\r
155\r
156 \r
157 // loop over events and fill them\r
f7ed7e88 158 // Multiplicity information needed by the header (to be revised!)\r
159 Int_t nTracks = esd->GetNumberOfTracks();\r
95621324 160 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) esd->GetTrack(iTrack)->SetESDEvent(esd);\r
161\r
f7ed7e88 162 // if (fDebug > 0) printf("-------------------Bo: Number of ESD tracks %d \n",nTracks);\r
163\r
164 Int_t nPosTracks = 0;\r
f7ed7e88 165 \r
166 // Update the header\r
167\r
168 AliAODHeader* header = AODEvent()->GetHeader();\r
f2f21b24 169 \r
f7ed7e88 170 header->SetRunNumber(esd->GetRunNumber());\r
0c6c629b 171 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection\r
a5f7aba4 172 TTree* tree = fInputHandler->GetTree();\r
173 if (tree) {\r
174 TFile* file = tree->GetCurrentFile();\r
175 if (file) header->SetESDFileName(file->GetName());\r
176 }\r
177 \r
f7ed7e88 178 if (old) {\r
179 header->SetBunchCrossNumber(0);\r
180 header->SetOrbitNumber(0);\r
181 header->SetPeriodNumber(0);\r
182 header->SetEventType(0);\r
f2f21b24 183 header->SetMuonMagFieldScale(-999.);\r
fba4b2e2 184 header->SetCentrality(0); \r
f7ed7e88 185 } else {\r
186 header->SetBunchCrossNumber(esd->GetBunchCrossNumber());\r
187 header->SetOrbitNumber(esd->GetOrbitNumber());\r
188 header->SetPeriodNumber(esd->GetPeriodNumber());\r
189 header->SetEventType(esd->GetEventType());\r
0a1f09ad 190\r
a5f7aba4 191 header->SetEventNumberESDFile(esd->GetHeader()->GetEventNumberInFile());\r
0a1f09ad 192 if(esd->GetCentrality()){\r
fba4b2e2 193 header->SetCentrality(new AliCentrality(*(esd->GetCentrality())));\r
0a1f09ad 194 }\r
195 else{\r
fba4b2e2 196 header->SetCentrality(0);\r
0a1f09ad 197 }\r
f7ed7e88 198 }\r
0a1f09ad 199 \r
f2f21b24 200 // Trigger\r
efa1edeb 201 header->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());\r
f7ed7e88 202 header->SetTriggerMask(esd->GetTriggerMask()); \r
203 header->SetTriggerCluster(esd->GetTriggerCluster());\r
a5f7aba4 204 header->SetL0TriggerInputs(esd->GetHeader()->GetL0TriggerInputs()); \r
205 header->SetL1TriggerInputs(esd->GetHeader()->GetL1TriggerInputs()); \r
206 header->SetL2TriggerInputs(esd->GetHeader()->GetL2TriggerInputs()); \r
f2f21b24 207\r
f7ed7e88 208 header->SetMagneticField(esd->GetMagneticField());\r
db7ce896 209 header->SetMuonMagFieldScale(esd->GetCurrentDip()/6000.);\r
f7ed7e88 210 header->SetZDCN1Energy(esd->GetZDCN1Energy());\r
211 header->SetZDCP1Energy(esd->GetZDCP1Energy());\r
212 header->SetZDCN2Energy(esd->GetZDCN2Energy());\r
213 header->SetZDCP2Energy(esd->GetZDCP2Energy());\r
214 header->SetZDCEMEnergy(esd->GetZDCEMEnergy(0),esd->GetZDCEMEnergy(1));\r
f2f21b24 215\r
216 \r
f7ed7e88 217 Float_t diamxy[2]={esd->GetDiamondX(),esd->GetDiamondY()};\r
218 Float_t diamcov[3]; esd->GetDiamondCovXY(diamcov);\r
219 header->SetDiamond(diamxy,diamcov);\r
a98c78e5 220 header->SetDiamondZ(esd->GetDiamondZ(),esd->GetSigma2DiamondZ());\r
f7ed7e88 221//\r
222//\r
223 Int_t nV0s = esd->GetNumberOfV0s();\r
d5880989 224 Int_t nCascades = 0; // esd->GetNumberOfCascades();\r
225 Int_t nKinks = 0; // esd->GetNumberOfKinks();\r
f7ed7e88 226 Int_t nVertices = nV0s + nCascades /*V0 wihtin cascade already counted*/+ nKinks + 1 /* = prim. vtx*/;\r
a98c78e5 227 Int_t nPileSPDVertices=1+esd->GetNumberOfPileupVerticesSPD(); // also SPD main vertex\r
228 Int_t nPileTrkVertices=esd->GetNumberOfPileupVerticesTracks();\r
229 nVertices+=nPileSPDVertices;\r
230 nVertices+=nPileTrkVertices;\r
f7ed7e88 231 Int_t nJets = 0;\r
232 Int_t nCaloClus = esd->GetNumberOfCaloClusters();\r
233 Int_t nFmdClus = 0;\r
234 Int_t nPmdClus = esd->GetNumberOfPmdTracks();\r
235 \r
236 if (fDebug > 0) \r
237 printf(" NV0=%d NCASCADES=%d NKINKS=%d\n", nV0s, nCascades, nKinks);\r
238 \r
239 AODEvent()->ResetStd(nTracks, nVertices, nV0s, nCascades, nJets, nCaloClus, nFmdClus, nPmdClus);\r
240\r
241\r
242 AliAODTrack *aodTrack = 0x0;\r
243 AliAODPid *detpid = 0x0;\r
b13bcc35 244 // Double_t timezero = 0; //not needed anymore \r
f7ed7e88 245 AliAODVertex *vV0FromCascade = 0x0;\r
246 AliAODv0 *aodV0 = 0x0;\r
247 AliAODcascade *aodCascade = 0x0;\r
248 \r
249 // RefArray to store the mapping between esd track number and newly created AOD-Track\r
250 TRefArray *aodTrackRefs = NULL;\r
251 if (nTracks > 0) aodTrackRefs = new TRefArray(nTracks);\r
252\r
253 // RefArray to store a mapping between esd V0 number and newly created AOD-Vertex V0\r
254 TRefArray *aodV0VtxRefs = NULL;\r
255 if (nV0s > 0) aodV0VtxRefs = new TRefArray(nV0s);\r
256\r
257 // RefArray to store the mapping between esd V0 number and newly created AOD-V0\r
258 TRefArray *aodV0Refs = NULL;\r
259 if (nV0s > 0) aodV0Refs = new TRefArray(nV0s);\r
260\r
f7ed7e88 261 // Array to take into account the tracks already added to the AOD\r
262 Bool_t * usedTrack = NULL;\r
263 if (nTracks>0) {\r
264 usedTrack = new Bool_t[nTracks];\r
265 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;\r
266 }\r
267 // Array to take into account the V0s already added to the AOD (V0 within cascades)\r
268 Bool_t * usedV0 = NULL;\r
269 if (nV0s>0) {\r
270 usedV0 = new Bool_t[nV0s];\r
271 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;\r
272 }\r
273 // Array to take into account the kinks already added to the AOD\r
274 Bool_t * usedKink = NULL;\r
275 if (nKinks>0) {\r
276 usedKink = new Bool_t[nKinks];\r
277 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;\r
278 }\r
279 \r
280 // Access to the AOD container of vertices\r
281 TClonesArray &vertices = *(AODEvent()->GetVertices());\r
282 Int_t jVertices=0;\r
283 \r
284 // Access to the AOD container of tracks\r
285 TClonesArray &tracks = *(AODEvent()->GetTracks());\r
286 Int_t jTracks=0; \r
287 \r
288 // Access to the AOD container of Cascades\r
289 TClonesArray &cascades = *(AODEvent()->GetCascades());\r
290 Int_t jCascades=0;\r
291\r
292 // Access to the AOD container of V0s\r
293 TClonesArray &v0s = *(AODEvent()->GetV0s());\r
294 Int_t jV0s=0;\r
295 \r
296 // Add primary vertex. The primary tracks will be defined\r
297 // after the loops on the composite objects (V0, cascades, kinks)\r
298 const AliESDVertex *vtx = esd->GetPrimaryVertex();\r
299 \r
300 vtx->GetXYZ(pos); // position\r
301 vtx->GetCovMatrix(covVtx); //covariance matrix\r
302 \r
303 AliAODVertex * primary = new(vertices[jVertices++])\r
304 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);\r
305 primary->SetName(vtx->GetName());\r
306 primary->SetTitle(vtx->GetTitle());\r
1c1c7167 307\r
308 TString vtitle = vtx->GetTitle();\r
309 if (!vtitle.Contains("VertexerTracks")) \r
310 primary->SetNContributors(vtx->GetNContributors());\r
f7ed7e88 311\r
312 if (fDebug > 0) primary->Print();\r
313\r
a98c78e5 314\r
315 // Add SPD "main" vertex \r
316 const AliESDVertex *vtxS = esd->GetPrimaryVertexSPD();\r
317 vtxS->GetXYZ(pos); // position\r
318 vtxS->GetCovMatrix(covVtx); //covariance matrix\r
319 AliAODVertex * mVSPD = new(vertices[jVertices++])\r
320 AliAODVertex(pos, covVtx, vtxS->GetChi2toNDF(), NULL, -1, AliAODVertex::kMainSPD);\r
321 mVSPD->SetName(vtxS->GetName());\r
322 mVSPD->SetTitle(vtxS->GetTitle());\r
323 mVSPD->SetNContributors(vtxS->GetNContributors()); \r
324\r
325 // Add SPD pileup vertices\r
326 for(Int_t iV=0; iV<nPileSPDVertices-1; iV++){\r
327 const AliESDVertex *vtxP = esd->GetPileupVertexSPD(iV);\r
328 vtxP->GetXYZ(pos); // position\r
329 vtxP->GetCovMatrix(covVtx); //covariance matrix\r
330 AliAODVertex * pVSPD = new(vertices[jVertices++])\r
331 AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupSPD);\r
332 pVSPD->SetName(vtxP->GetName());\r
333 pVSPD->SetTitle(vtxP->GetTitle());\r
334 pVSPD->SetNContributors(vtxP->GetNContributors()); \r
335 }\r
336\r
337 // Add TRK pileup vertices\r
338 for(Int_t iV=0; iV<nPileTrkVertices; iV++){\r
339 const AliESDVertex *vtxP = esd->GetPileupVertexTracks(iV);\r
340 vtxP->GetXYZ(pos); // position\r
341 vtxP->GetCovMatrix(covVtx); //covariance matrix\r
342 AliAODVertex * pVTRK = new(vertices[jVertices++])\r
343 AliAODVertex(pos, covVtx, vtxP->GetChi2toNDF(), NULL, -1, AliAODVertex::kPileupTracks);\r
344 pVTRK->SetName(vtxP->GetName());\r
345 pVTRK->SetTitle(vtxP->GetTitle());\r
346 pVTRK->SetNContributors(vtxP->GetNContributors());\r
347 }\r
348\r
f7ed7e88 349 // Create vertices starting from the most complex objects\r
350 Double_t chi2 = 0.;\r
b13bcc35 351\r
352\r
353 //setting best TOF PID\r
6878d51e 354 AliESDInputHandler* handler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());\r
355 \r
356 AliESDpid *esdPid = 0;\r
357 if (handler) esdPid = handler->GetESDpid();\r
253cab77 358\r
359 Bool_t isPidOwner = kFALSE;\r
360 if(!esdPid){ //in case of no Tender attached \r
361 esdPid = new AliESDpid;\r
362 isPidOwner = kTRUE;\r
363 }\r
b13bcc35 364 \r
253cab77 365 if(!esd->GetTOFHeader()){ //protection in case the pass2 LHC10b,c,d have been processed without tender. \r
b13bcc35 366 Float_t *t0spread= new Float_t[10];\r
367 Float_t intrinsicTOFres=100; //ps ok for LHC10b,c,d pass2!! \r
368 for (Int_t i=0; i<10; i++) t0spread[i] = (TMath::Sqrt(esd->GetSigma2DiamondZ()))/0.03; //0.03 to convert from cm to ps\r
b13bcc35 369 esdPid->GetTOFResponse().SetT0resolution(t0spread);\r
370 esdPid->GetTOFResponse().SetTimeResolution(intrinsicTOFres);\r
253cab77 371 \r
26917b0b 372 esdPid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType);\r
253cab77 373 \r
b13bcc35 374 delete[] t0spread;\r
375 t0spread=0x0;\r
376 }\r
f7ed7e88 377 \r
26917b0b 378 if(esd->GetTOFHeader() && isPidOwner) esdPid->SetTOFResponse(esd, (AliESDpid::EStartTimeType_t)fTimeZeroType); //in case of AOD production strating form LHC10e without Tender. \r
253cab77 379\r
380\r
f7ed7e88 381 // Cascades (Modified by A.Maire - February 2009)\r
382 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {\r
383\r
384 if (fDebug > 1) \r
385 printf("\n ******** Cascade number : %d/%d *********\n", nCascade, nCascades);\r
386\r
387 // 0- Preparation\r
388 //\r
389 AliESDcascade *esdCascade = esd->GetCascade(nCascade);\r
390 Int_t idxPosFromV0Dghter = esdCascade->GetPindex();\r
391 Int_t idxNegFromV0Dghter = esdCascade->GetNindex();\r
392 Int_t idxBachFromCascade = esdCascade->GetBindex();\r
393 \r
394 AliESDtrack *esdCascadePos = esd->GetTrack( idxPosFromV0Dghter);\r
395 AliESDtrack *esdCascadeNeg = esd->GetTrack( idxNegFromV0Dghter);\r
396 AliESDtrack *esdCascadeBach = esd->GetTrack( idxBachFromCascade);\r
397\r
398 // Identification of the V0 within the esdCascade (via both daughter track indices)\r
399 AliESDv0 * currentV0 = 0x0;\r
400 Int_t idxV0FromCascade = -1;\r
401 \r
402 for (Int_t iV0=0; iV0<nV0s; ++iV0) {\r
403 \r
404 currentV0 = esd->GetV0(iV0);\r
405 Int_t posCurrentV0 = currentV0->GetPindex();\r
406 Int_t negCurrentV0 = currentV0->GetNindex();\r
407 \r
408 if (posCurrentV0==idxPosFromV0Dghter && negCurrentV0==idxNegFromV0Dghter) {\r
409 idxV0FromCascade = iV0;\r
410 break;\r
411 }\r
412 }\r
413\r
414 if(idxV0FromCascade < 0){\r
415 printf("Cascade - no matching for the V0 (index V0 = -1) ! Skip ... \n");\r
416 continue;\r
417 }// a priori, useless check, but safer ... in case of pb with tracks "out of bounds"\r
418\r
419 if (fDebug > 1) \r
420 printf("Cascade %d - V0fromCascade ind : %d/%d\n", nCascade, idxV0FromCascade, nV0s);\r
421\r
422 AliESDv0 *esdV0FromCascade = esd->GetV0(idxV0FromCascade);\r
423 \r
424\r
425 // 1 - Cascade selection \r
426 \r
427 // AliESDVertex *esdPrimVtx = new AliESDVertex(*(esd->GetPrimaryVertex()));\r
428 // TList cascadeObjects;\r
429 // cascadeObjects.AddAt(esdV0FromCascade, 0);\r
430 // cascadeObjects.AddAt(esdCascadePos, 1);\r
431 // cascadeObjects.AddAt(esdCascadeNeg, 2);\r
432 // cascadeObjects.AddAt(esdCascade, 3);\r
433 // cascadeObjects.AddAt(esdCascadeBach, 4);\r
434 // cascadeObjects.AddAt(esdPrimVtx, 5);\r
435 // \r
436 // UInt_t selectCascade = 0;\r
437 // if (fCascadeFilter) {\r
438 // // selectCascade = fCascadeFilter->IsSelected(&cascadeObjects); \r
439 // // FIXME AliESDCascadeCuts to be implemented ...\r
440 // \r
441 // // Here we may encounter a moot point at the V0 level \r
442 // // between the cascade selections and the V0 ones :\r
443 // // the V0 selected along with the cascade (secondary V0) may \r
444 // // usually be removed from the dedicated V0 selections (prim V0) ...\r
445 // // -> To be discussed !\r
446 // \r
447 // // this is a little awkward but otherwise the \r
448 // // list wants to access the pointer (delete it) \r
449 // // again when going out of scope\r
450 // delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct\r
451 // esdPrimVtx = 0;\r
452 // if (!selectCascade) \r
453 // continue;\r
454 // }\r
455 // else{\r
456 // delete cascadeObjects.RemoveAt(5); // esdPrimVtx created via copy construct\r
457 // esdPrimVtx = 0;\r
458 // }\r
459\r
460 // 2 - Add the cascade vertex\r
461 \r
462 esdCascade->GetXYZcascade(pos[0], pos[1], pos[2]);\r
463 esdCascade->GetPosCovXi(covVtx);\r
464 chi2 = esdCascade->GetChi2Xi(); \r
465 \r
466 AliAODVertex *vCascade = new(vertices[jVertices++]) AliAODVertex( pos,\r
467 covVtx,\r
468 chi2, // FIXME = Chi2/NDF will be needed\r
469 primary,\r
470 nCascade, // id\r
471 AliAODVertex::kCascade);\r
472 primary->AddDaughter(vCascade);\r
473\r
474 if (fDebug > 2) {\r
475 printf("---- Cascade / Cascade Vertex (AOD) : \n");\r
476 vCascade->Print();\r
477 }\r
478\r
479\r
480 // 3 - Add the bachelor track from the cascade\r
481 \r
482 if (!usedTrack[idxBachFromCascade]) {\r
483\r
484 esdCascadeBach->GetPxPyPz(momBach);\r
485 esdCascadeBach->GetXYZ(pos);\r
486 esdCascadeBach->GetCovarianceXYZPxPyPz(covTr);\r
487 esdCascadeBach->GetESDpid(pid);\r
488\r
489 usedTrack[idxBachFromCascade] = kTRUE;\r
490 UInt_t selectInfo = 0;\r
9eeae5d5 491 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeBach);\r
f7ed7e88 492 if(mcH)mcH->SelectParticle(esdCascadeBach->GetLabel());\r
493 aodTrack = new(tracks[jTracks++]) AliAODTrack(esdCascadeBach->GetID(),\r
494 esdCascadeBach->GetLabel(), \r
495 momBach, \r
496 kTRUE,\r
497 pos,\r
498 kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
499 covTr, \r
500 (Short_t)esdCascadeBach->GetSign(),\r
501 esdCascadeBach->GetITSClusterMap(), \r
502 pid,\r
503 vCascade,\r
504 kTRUE, // usedForVtxFit = kFALSE ? FIXME\r
505 vtx->UsesTrack(esdCascadeBach->GetID()),\r
506 AliAODTrack::kSecondary,\r
507 selectInfo);\r
f2f21b24 508 aodTrack->SetTPCClusterMap(esdCascadeBach->GetTPCClusterMap());\r
509 aodTrack->SetTPCSharedMap (esdCascadeBach->GetTPCSharedMap());\r
40a060e5 510 aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeBach));\r
f7ed7e88 511 aodTrackRefs->AddAt(aodTrack,idxBachFromCascade);\r
f2f21b24 512 \r
f7ed7e88 513 if (esdCascadeBach->GetSign() > 0) nPosTracks++;\r
514 aodTrack->ConvertAliPIDtoAODPID();\r
515 aodTrack->SetFlags(esdCascadeBach->GetStatus());\r
b13bcc35 516 SetAODPID(esdCascadeBach,aodTrack,detpid,esd->GetMagneticField(), esdPid);\r
f7ed7e88 517 }\r
518 else {\r
519 aodTrack = dynamic_cast<AliAODTrack*>( aodTrackRefs->At(idxBachFromCascade) );\r
520 }\r
521\r
522 vCascade->AddDaughter(aodTrack);\r
523\r
524 if (fDebug > 4) {\r
525 printf("---- Cascade / bach dghter : \n");\r
526 aodTrack->Print();\r
527 }\r
528 \r
529\r
530 // 4 - Add the V0 from the cascade. \r
531 // = V0vtx + both pos and neg daughter tracks + the aodV0 itself\r
532 //\r
533\r
534 if ( !usedV0[idxV0FromCascade] ) {\r
535 // 4.A - if VO structure hasn't been created yet\r
536 \r
537 // 4.A.1 - Create the V0 vertex of the cascade\r
538 \r
539 esdV0FromCascade->GetXYZ(pos[0], pos[1], pos[2]);\r
540 esdV0FromCascade->GetPosCov(covVtx);\r
541 chi2 = esdV0FromCascade->GetChi2V0(); // = chi2/NDF since NDF = 2*2-3 ?\r
542 \r
543 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,\r
544 covVtx,\r
545 chi2,\r
546 vCascade,\r
547 idxV0FromCascade, //id of ESDv0\r
548 AliAODVertex::kV0);\r
549 // Note:\r
550 // one V0 can be used by several cascades.\r
551 // So, one AOD V0 vtx can have several parent vtx.\r
552 // This is not directly allowed by AliAODvertex.\r
553 // Setting the parent vtx (here = param "vCascade") doesn't lead to a crash\r
554 // but to a problem of consistency within AODEvent.\r
555 // -> See below paragraph 4.B, for the proposed treatment of such a case.\r
556\r
557 // Add the vV0FromCascade to the aodVOVtxRefs\r
558 aodV0VtxRefs->AddAt(vV0FromCascade,idxV0FromCascade);\r
559 \r
560 \r
561 // 4.A.2 - Add the positive tracks from the V0\r
562 \r
563 esdCascadePos->GetPxPyPz(momPos);\r
564 esdCascadePos->GetXYZ(pos);\r
565 esdCascadePos->GetCovarianceXYZPxPyPz(covTr);\r
566 esdCascadePos->GetESDpid(pid);\r
567 \r
568 \r
569 if (!usedTrack[idxPosFromV0Dghter]) {\r
570 usedTrack[idxPosFromV0Dghter] = kTRUE;\r
571 \r
572 UInt_t selectInfo = 0;\r
9eeae5d5 573 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadePos);\r
f7ed7e88 574 if(mcH) mcH->SelectParticle(esdCascadePos->GetLabel());\r
575 aodTrack = new(tracks[jTracks++]) AliAODTrack( esdCascadePos->GetID(),\r
576 esdCascadePos->GetLabel(), \r
577 momPos, \r
578 kTRUE,\r
579 pos,\r
580 kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
581 covTr, \r
582 (Short_t)esdCascadePos->GetSign(),\r
583 esdCascadePos->GetITSClusterMap(), \r
584 pid,\r
585 vV0FromCascade,\r
586 kTRUE, // usedForVtxFit = kFALSE ? FIXME\r
587 vtx->UsesTrack(esdCascadePos->GetID()),\r
588 AliAODTrack::kSecondary,\r
589 selectInfo);\r
f2f21b24 590 aodTrack->SetTPCClusterMap(esdCascadePos->GetTPCClusterMap());\r
591 aodTrack->SetTPCSharedMap (esdCascadePos->GetTPCSharedMap());\r
40a060e5 592 aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadePos));\r
f7ed7e88 593 aodTrackRefs->AddAt(aodTrack,idxPosFromV0Dghter);\r
40a060e5 594\r
f7ed7e88 595 if (esdCascadePos->GetSign() > 0) nPosTracks++;\r
596 aodTrack->ConvertAliPIDtoAODPID();\r
597 aodTrack->SetFlags(esdCascadePos->GetStatus());\r
b13bcc35 598 SetAODPID(esdCascadePos,aodTrack,detpid,esd->GetMagneticField(), esdPid);\r
f7ed7e88 599 }\r
600 else {\r
601 aodTrack = dynamic_cast<AliAODTrack*>(aodTrackRefs->At(idxPosFromV0Dghter));\r
602 }\r
603 vV0FromCascade->AddDaughter(aodTrack);\r
604 \r
605 \r
606 // 4.A.3 - Add the negative tracks from the V0\r
607 \r
608 esdCascadeNeg->GetPxPyPz(momNeg);\r
609 esdCascadeNeg->GetXYZ(pos);\r
610 esdCascadeNeg->GetCovarianceXYZPxPyPz(covTr);\r
611 esdCascadeNeg->GetESDpid(pid);\r
612 \r
613 \r
614 if (!usedTrack[idxNegFromV0Dghter]) {\r
615 usedTrack[idxNegFromV0Dghter] = kTRUE;\r
616 \r
617 UInt_t selectInfo = 0;\r
9eeae5d5 618 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdCascadeNeg);\r
f7ed7e88 619 if(mcH)mcH->SelectParticle(esdCascadeNeg->GetLabel());\r
620 aodTrack = new(tracks[jTracks++]) AliAODTrack( esdCascadeNeg->GetID(),\r
621 esdCascadeNeg->GetLabel(),\r
622 momNeg,\r
623 kTRUE,\r
624 pos,\r
625 kFALSE, // Why kFALSE for "isDCA" ? FIXME\r
626 covTr, \r
627 (Short_t)esdCascadeNeg->GetSign(),\r
628 esdCascadeNeg->GetITSClusterMap(), \r
629 pid,\r
630 vV0FromCascade,\r
631 kTRUE, // usedForVtxFit = kFALSE ? FIXME\r
632 vtx->UsesTrack(esdCascadeNeg->GetID()),\r
633 AliAODTrack::kSecondary,\r
634 selectInfo);\r
f2f21b24 635 aodTrack->SetTPCClusterMap(esdCascadeNeg->GetTPCClusterMap());\r
636 aodTrack->SetTPCSharedMap (esdCascadeNeg->GetTPCSharedMap());\r
40a060e5 637 aodTrack->SetChi2perNDF(Chi2perNDF(esdCascadeNeg));\r
f7ed7e88 638 aodTrackRefs->AddAt(aodTrack,idxNegFromV0Dghter);\r
639 \r
640 if (esdCascadeNeg->GetSign() > 0) nPosTracks++;\r
641 aodTrack->ConvertAliPIDtoAODPID();\r
642 aodTrack->SetFlags(esdCascadeNeg->GetStatus());\r
b13bcc35 643 SetAODPID(esdCascadeNeg,aodTrack,detpid,esd->GetMagneticField(),esdPid);\r
f7ed7e88 644 }\r
645 else {\r
646 aodTrack = dynamic_cast<AliAODTrack*>(aodTrackRefs->At(idxNegFromV0Dghter));\r
647 }\r
648 \r
649 vV0FromCascade->AddDaughter(aodTrack);\r
650 \r
651 \r
652 // 4.A.4 - Add the V0 from cascade to the V0 array\r
653\r
654 Double_t dcaV0Daughters = esdV0FromCascade->GetDcaV0Daughters();\r
655 Double_t dcaV0ToPrimVertex = esdV0FromCascade->GetD( esd->GetPrimaryVertex()->GetX(),\r
656 esd->GetPrimaryVertex()->GetY(),\r
657 esd->GetPrimaryVertex()->GetZ() );\r
658 esdV0FromCascade->GetPPxPyPz( momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2] ); \r
659 esdV0FromCascade->GetNPxPyPz( momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2] ); \r
660 \r
661 Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg\r
662 dcaDaughterToPrimVertex[0] = TMath::Abs(esdCascadePos->GetD( esd->GetPrimaryVertex()->GetX(),\r
663 esd->GetPrimaryVertex()->GetY(),\r
664 esd->GetMagneticField()) );\r
665 dcaDaughterToPrimVertex[1] = TMath::Abs(esdCascadeNeg->GetD( esd->GetPrimaryVertex()->GetX(),\r
666 esd->GetPrimaryVertex()->GetY(),\r
667 esd->GetMagneticField()) );\r
668 \r
669 aodV0 = new(v0s[jV0s++]) AliAODv0( vV0FromCascade, \r
670 dcaV0Daughters,\r
671 dcaV0ToPrimVertex, \r
672 momPosAtV0vtx, \r
673 momNegAtV0vtx, \r
674 dcaDaughterToPrimVertex); \r
675 // set the aod v0 on-the-fly status\r
676 aodV0->SetOnFlyStatus(esdV0FromCascade->GetOnFlyStatus());\r
677\r
678 // Add the aodV0 to the aodVORefs\r
679 aodV0Refs->AddAt(aodV0,idxV0FromCascade);\r
680 \r
681 usedV0[idxV0FromCascade] = kTRUE;\r
682\r
683 } else { \r
684 // 4.B - if V0 structure already used\r
685\r
686 // Note :\r
687 // one V0 can be used by several cascades (frequent in PbPb evts) : \r
688 // same V0 which used but attached to different bachelor tracks\r
689 // -> aodVORefs and aodV0VtxRefs are needed.\r
690 // Goal : avoid a redundancy of the info in "Vertices" and "v0s" clones array.\r
691 \r
692 vV0FromCascade = dynamic_cast<AliAODVertex*>( aodV0VtxRefs->At(idxV0FromCascade) );\r
693 aodV0 = dynamic_cast<AliAODv0*> ( aodV0Refs ->At(idxV0FromCascade) );\r
694 \r
695 // - Treatment of the parent for such a "re-used" V0 :\r
696 // Insert the cascade that reuses the V0 vertex in the lineage chain\r
697 // Before : vV0 -> vCascade1 -> vPrimary\r
698 // - Hyp : cascade2 uses the same V0 as cascade1\r
699 // After : vV0 -> vCascade2 -> vCascade1 -> vPrimary\r
700 \r
701 AliAODVertex *vCascadePreviousParent = dynamic_cast<AliAODVertex*> (vV0FromCascade->GetParent());\r
702 vV0FromCascade->SetParent(vCascade);\r
703 vCascade ->SetParent(vCascadePreviousParent);\r
704\r
705 if(fDebug > 2) \r
706 printf("---- Cascade / Lineage insertion\n"\r
707 "Parent of V0 vtx = Cascade vtx %p\n"\r
708 "Parent of the cascade vtx = Cascade vtx %p\n"\r
709 "Parent of the parent cascade vtx = Cascade vtx %p\n", \r
710 static_cast<void*> (vV0FromCascade->GetParent()),\r
711 static_cast<void*> (vCascade->GetParent()),\r
712 static_cast<void*> (vCascadePreviousParent->GetParent()) );\r
713 \r
714 }// end if V0 structure already used\r
715\r
716 if (fDebug > 2) {\r
717 printf("---- Cascade / V0 vertex: \n");\r
718 vV0FromCascade->Print();\r
719 }\r
720\r
721 if (fDebug > 4) {\r
722 printf("---- Cascade / pos dghter : \n");\r
723 aodTrack->Print();\r
724 printf("---- Cascade / neg dghter : \n");\r
725 aodTrack->Print();\r
726 printf("---- Cascade / aodV0 : \n");\r
727 aodV0->Print();\r
728 }\r
729\r
730 // In any case (used V0 or not), add the V0 vertex to the cascade one.\r
731 vCascade->AddDaughter(vV0FromCascade); \r
732 \r
733 \r
734 // 5 - Add the primary track of the cascade (if any)\r
735\r
736\r
737 // 6 - Add the cascade to the AOD array of cascades\r
738\r
739 Double_t dcaBachToPrimVertexXY = TMath::Abs(esdCascadeBach->GetD(esd->GetPrimaryVertex()->GetX(),\r
740 esd->GetPrimaryVertex()->GetY(),\r
741 esd->GetMagneticField()) );\r
742\r
743 esdCascade->GetBPxPyPz(momBachAtCascadeVtx[0], momBachAtCascadeVtx[1], momBachAtCascadeVtx[2]);\r
744\r
745 aodCascade = new(cascades[jCascades++]) AliAODcascade( vCascade,\r
746 esdCascade->Charge(),\r
747 esdCascade->GetDcaXiDaughters(),\r
748 -999.,\r
749 // DCAXiToPrimVtx -> needs to be calculated ----|\r
750 // doesn't exist at ESD level;\r
751 // See AODcascade::DcaXiToPrimVertex(Double, Double, Double)\r
752 dcaBachToPrimVertexXY,\r
753 momBachAtCascadeVtx,\r
754 *aodV0);\r
755 \r
756 if (fDebug > 3) {\r
757 printf("---- Cascade / AOD cascade : \n\n");\r
758 aodCascade->PrintXi(primary->GetX(), primary->GetY(), primary->GetZ());\r
759 }\r
760\r
761 } // end of the loop on cascades\r
762\r
763 cascades.Expand(jCascades);\r
764\r
765\r
766 //\r
767 // V0s\r
768 //\r
769 \r
770 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {\r
771 \r
772 if (usedV0[nV0]) continue; // skip if already added to the AOD\r
773 \r
774 AliESDv0 *v0 = esd->GetV0(nV0);\r
775 Int_t posFromV0 = v0->GetPindex();\r
776 Int_t negFromV0 = v0->GetNindex();\r
777 \r
778 // V0 selection \r
779 //\r
780 AliESDVertex *esdVtx = new AliESDVertex(*(esd->GetPrimaryVertex()));\r
781 AliESDtrack *esdV0Pos = esd->GetTrack(posFromV0);\r
782 AliESDtrack *esdV0Neg = esd->GetTrack(negFromV0);\r
783 TList v0objects;\r
784 v0objects.AddAt(v0, 0);\r
785 v0objects.AddAt(esdV0Pos, 1);\r
786 v0objects.AddAt(esdV0Neg, 2);\r
787 v0objects.AddAt(esdVtx, 3);\r
788 UInt_t selectV0 = 0;\r
789 if (fV0Filter) {\r
9eeae5d5 790 selectV0 = fV0Filter->IsSelected(&v0objects);\r
f7ed7e88 791 // this is a little awkward but otherwise the \r
792 // list wants to access the pointer (delete it) \r
793 // again when going out of scope\r
794 delete v0objects.RemoveAt(3); // esdVtx created via copy construct\r
795 esdVtx = 0;\r
796 if (!selectV0) \r
797 continue;\r
798 }\r
799 else{\r
800 delete v0objects.RemoveAt(3); // esdVtx created via copy construct\r
801 esdVtx = 0;\r
802 }\r
803 \r
804 v0->GetXYZ(pos[0], pos[1], pos[2]);\r
805\r
806 if (!old) {\r
807 chi2 = v0->GetChi2V0(); // = chi2/NDF since NDF = 2*2-3\r
808 v0->GetPosCov(covVtx);\r
809 } else {\r
810 chi2 = -999.;\r
811 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;\r
812 }\r
813\r
814\r
815 AliAODVertex * vV0 = \r
816 new(vertices[jVertices++]) AliAODVertex(pos,\r
817 covVtx,\r
818 chi2,\r
819 primary,\r
820 nV0,\r
821 AliAODVertex::kV0);\r
822 primary->AddDaughter(vV0);\r
823 \r
824\r
825 // Add the positive tracks from the V0\r
826 \r
827 esdV0Pos->GetPxPyPz(momPos);\r
828 esdV0Pos->GetXYZ(pos);\r
829 esdV0Pos->GetCovarianceXYZPxPyPz(covTr);\r
830 esdV0Pos->GetESDpid(pid);\r
831 \r
832 if (!usedTrack[posFromV0]) {\r
833 usedTrack[posFromV0] = kTRUE;\r
834 UInt_t selectInfo = 0;\r
9eeae5d5 835 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Pos);\r
f7ed7e88 836 if(mcH)mcH->SelectParticle(esdV0Pos->GetLabel());\r
837 aodTrack = new(tracks[jTracks++]) AliAODTrack(esdV0Pos->GetID(),\r
838 esdV0Pos->GetLabel(), \r
839 momPos, \r
840 kTRUE,\r
841 pos,\r
842 kFALSE,\r
843 covTr, \r
844 (Short_t)esdV0Pos->GetSign(),\r
845 esdV0Pos->GetITSClusterMap(), \r
846 pid,\r
847 vV0,\r
848 kTRUE, // check if this is right\r
849 vtx->UsesTrack(esdV0Pos->GetID()),\r
850 AliAODTrack::kSecondary,\r
851 selectInfo);\r
f2f21b24 852 aodTrack->SetTPCClusterMap(esdV0Pos->GetTPCClusterMap());\r
853 aodTrack->SetTPCSharedMap (esdV0Pos->GetTPCSharedMap());\r
40a060e5 854 aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Pos));\r
f7ed7e88 855 aodTrackRefs->AddAt(aodTrack,posFromV0);\r
856 // if (fDebug > 0) printf("-------------------Bo: pos track from original pt %.3f \n",aodTrack->Pt());\r
857 if (esdV0Pos->GetSign() > 0) nPosTracks++;\r
858 aodTrack->ConvertAliPIDtoAODPID();\r
859 aodTrack->SetFlags(esdV0Pos->GetStatus());\r
b13bcc35 860 SetAODPID(esdV0Pos,aodTrack,detpid,esd->GetMagneticField(),esdPid);\r
f7ed7e88 861 }\r
862 else {\r
863 aodTrack = dynamic_cast<AliAODTrack*>(aodTrackRefs->At(posFromV0));\r
864 // if (fDebug > 0) printf("-------------------Bo pos track from refArray pt %.3f \n",aodTrack->Pt());\r
865 }\r
866 vV0->AddDaughter(aodTrack);\r
867 \r
868 // Add the negative tracks from the V0\r
869 \r
870 esdV0Neg->GetPxPyPz(momNeg);\r
871 esdV0Neg->GetXYZ(pos);\r
872 esdV0Neg->GetCovarianceXYZPxPyPz(covTr);\r
873 esdV0Neg->GetESDpid(pid);\r
874 \r
875 if (!usedTrack[negFromV0]) {\r
876 usedTrack[negFromV0] = kTRUE;\r
877 UInt_t selectInfo = 0;\r
9eeae5d5 878 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdV0Neg);\r
f7ed7e88 879 if(mcH)mcH->SelectParticle(esdV0Neg->GetLabel());\r
880 aodTrack = new(tracks[jTracks++]) AliAODTrack(esdV0Neg->GetID(),\r
881 esdV0Neg->GetLabel(),\r
882 momNeg,\r
883 kTRUE,\r
884 pos,\r
885 kFALSE,\r
886 covTr, \r
887 (Short_t)esdV0Neg->GetSign(),\r
888 esdV0Neg->GetITSClusterMap(), \r
889 pid,\r
890 vV0,\r
891 kTRUE, // check if this is right\r
892 vtx->UsesTrack(esdV0Neg->GetID()),\r
893 AliAODTrack::kSecondary,\r
894 selectInfo);\r
f2f21b24 895 aodTrack->SetTPCClusterMap(esdV0Neg->GetTPCClusterMap());\r
896 aodTrack->SetTPCSharedMap (esdV0Neg->GetTPCSharedMap());\r
40a060e5 897 aodTrack->SetChi2perNDF(Chi2perNDF(esdV0Neg));\r
f7ed7e88 898 \r
899 aodTrackRefs->AddAt(aodTrack,negFromV0);\r
900 // if (fDebug > 0) printf("-------------------Bo: neg track from original pt %.3f \n",aodTrack->Pt());\r
901 if (esdV0Neg->GetSign() > 0) nPosTracks++;\r
902 aodTrack->ConvertAliPIDtoAODPID();\r
903 aodTrack->SetFlags(esdV0Neg->GetStatus());\r
b13bcc35 904 SetAODPID(esdV0Neg,aodTrack,detpid,esd->GetMagneticField(),esdPid);\r
f7ed7e88 905 }\r
906 else {\r
907 aodTrack = dynamic_cast<AliAODTrack*>(aodTrackRefs->At(negFromV0));\r
908 // if (fDebug > 0) printf("-------------------Bo neg track from refArray pt %.3f \n",aodTrack->Pt());\r
909 }\r
910 vV0->AddDaughter(aodTrack);\r
911\r
912\r
913 // Add the V0 the V0 array as well\r
914 \r
915 Double_t dcaV0Daughters = v0->GetDcaV0Daughters();\r
916 Double_t dcaV0ToPrimVertex = v0->GetD(esd->GetPrimaryVertex()->GetX(),\r
917 esd->GetPrimaryVertex()->GetY(),\r
918 esd->GetPrimaryVertex()->GetZ());\r
919 v0->GetPPxPyPz(momPosAtV0vtx[0],momPosAtV0vtx[1],momPosAtV0vtx[2]); \r
920 v0->GetNPxPyPz(momNegAtV0vtx[0],momNegAtV0vtx[1],momNegAtV0vtx[2]); \r
921 \r
922 Double_t dcaDaughterToPrimVertex[2] = { 999., 999.}; // ..[0] = DCA in (x,y) for Pos and ..[1] = Neg\r
923 dcaDaughterToPrimVertex[0] = TMath::Abs(esdV0Pos->GetD( esd->GetPrimaryVertex()->GetX(),\r
924 esd->GetPrimaryVertex()->GetY(),\r
925 esd->GetMagneticField()) );\r
926 dcaDaughterToPrimVertex[1] = TMath::Abs(esdV0Neg->GetD( esd->GetPrimaryVertex()->GetX(),\r
927 esd->GetPrimaryVertex()->GetY(),\r
928 esd->GetMagneticField()) );\r
929 \r
930 aodV0 = new(v0s[jV0s++]) AliAODv0(vV0, \r
931 dcaV0Daughters,\r
932 dcaV0ToPrimVertex,\r
933 momPosAtV0vtx,\r
934 momNegAtV0vtx,\r
935 dcaDaughterToPrimVertex);\r
936\r
937 // set the aod v0 on-the-fly status\r
938 aodV0->SetOnFlyStatus(v0->GetOnFlyStatus());\r
939 }//End of loop on V0s \r
940\r
941 v0s.Expand(jV0s); \r
942\r
943 if (fDebug > 0) printf(" NAODCascades=%d / NAODV0s=%d\n", jCascades, jV0s);\r
944 // end of V0 parts\r
945\r
946\r
947 // Kinks: it is a big mess the access to the information in the kinks\r
948 // The loop is on the tracks in order to find the mother and daugther of each kink\r
949 \r
950 \r
951 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {\r
952 \r
953 AliESDtrack * esdTrack = esd->GetTrack(iTrack);\r
954 \r
955 Int_t ikink = esdTrack->GetKinkIndex(0);\r
956 \r
957 if (ikink && nKinks) {\r
958 // Negative kink index: mother, positive: daughter\r
959 \r
960 // Search for the second track of the kink\r
961 \r
962 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {\r
963 \r
964 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);\r
965 \r
966 Int_t jkink = esdTrack1->GetKinkIndex(0);\r
967 \r
968 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {\r
969 \r
970 // The two tracks are from the same kink\r
971 \r
972 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks\r
973 \r
974 Int_t imother = -1;\r
975 Int_t idaughter = -1;\r
976 \r
977 if (ikink<0 && jkink>0) {\r
978 \r
979 imother = iTrack;\r
980 idaughter = jTrack;\r
981 }\r
982 else if (ikink>0 && jkink<0) {\r
983 \r
984 imother = jTrack;\r
985 idaughter = iTrack;\r
986 }\r
987 else {\r
988// cerr << "Error: Wrong combination of kink indexes: "\r
989// << ikink << " " << jkink << endl;\r
990 continue;\r
991 }\r
992 \r
993 // Add the mother track if it passed primary track selection cuts\r
994 \r
995 AliAODTrack * mother = NULL;\r
996 \r
997 UInt_t selectInfo = 0;\r
998 if (fTrackFilter) {\r
9eeae5d5 999 selectInfo = fTrackFilter->IsSelected(esd->GetTrack(imother));\r
f7ed7e88 1000 if (!selectInfo) continue;\r
1001 }\r
1002 \r
1003 if (!usedTrack[imother]) {\r
1004 \r
1005 usedTrack[imother] = kTRUE;\r
1006 \r
1007 AliESDtrack *esdTrackM = esd->GetTrack(imother);\r
1008 esdTrackM->GetPxPyPz(p);\r
1009 esdTrackM->GetXYZ(pos);\r
1010 esdTrackM->GetCovarianceXYZPxPyPz(covTr);\r
1011 esdTrackM->GetESDpid(pid);\r
1012 if(mcH)mcH->SelectParticle(esdTrackM->GetLabel());\r
1013 mother = \r
1014 new(tracks[jTracks++]) AliAODTrack(esdTrackM->GetID(),\r
1015 esdTrackM->GetLabel(),\r
1016 p,\r
1017 kTRUE,\r
1018 pos,\r
1019 kFALSE,\r
1020 covTr, \r
1021 (Short_t)esdTrackM->GetSign(),\r
1022 esdTrackM->GetITSClusterMap(), \r
1023 pid,\r
1024 primary,\r
1025 kTRUE, // check if this is right\r
1026 vtx->UsesTrack(esdTrack->GetID()),\r
1027 AliAODTrack::kPrimary,\r
1028 selectInfo);\r
f2f21b24 1029 mother->SetTPCClusterMap(esdTrackM->GetTPCClusterMap());\r
1030 mother->SetTPCSharedMap (esdTrackM->GetTPCSharedMap());\r
40a060e5 1031 mother->SetChi2perNDF(Chi2perNDF(esdTrackM));\r
1032\r
f7ed7e88 1033 aodTrackRefs->AddAt(mother, imother);\r
1034 \r
1035 if (esdTrackM->GetSign() > 0) nPosTracks++;\r
1036 mother->SetFlags(esdTrackM->GetStatus());\r
1037 mother->ConvertAliPIDtoAODPID();\r
1038 primary->AddDaughter(mother);\r
1039 mother->ConvertAliPIDtoAODPID();\r
b13bcc35 1040 SetAODPID(esdTrackM,mother,detpid,esd->GetMagneticField(),esdPid);\r
f7ed7e88 1041 }\r
1042 else {\r
1043// cerr << "Error: event " << esd->GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1\r
1044// << " track " << imother << " has already been used!" << endl;\r
1045 }\r
1046 \r
1047 // Add the kink vertex\r
1048 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);\r
1049 \r
1050 AliAODVertex * vkink = \r
1051 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),\r
1052 NULL,\r
1053 0.,\r
1054 mother,\r
1055 esdTrack->GetID(), // This is the track ID of the mother's track!\r
1056 AliAODVertex::kKink);\r
1057 // Add the daughter track\r
1058 \r
1059 AliAODTrack * daughter = NULL;\r
1060 \r
1061 if (!usedTrack[idaughter]) {\r
1062 \r
1063 usedTrack[idaughter] = kTRUE;\r
1064 \r
1065 AliESDtrack *esdTrackD = esd->GetTrack(idaughter);\r
1066 esdTrackD->GetPxPyPz(p);\r
1067 esdTrackD->GetXYZ(pos);\r
1068 esdTrackD->GetCovarianceXYZPxPyPz(covTr);\r
1069 esdTrackD->GetESDpid(pid);\r
1070 selectInfo = 0;\r
9eeae5d5 1071 if (fTrackFilter) selectInfo = fTrackFilter->IsSelected(esdTrackD);\r
f7ed7e88 1072 if(mcH)mcH->SelectParticle(esdTrackD->GetLabel());\r
1073 daughter = \r
1074 new(tracks[jTracks++]) AliAODTrack(esdTrackD->GetID(),\r
1075 esdTrackD->GetLabel(),\r
1076 p,\r
1077 kTRUE,\r
1078 pos,\r
1079 kFALSE,\r
1080 covTr, \r
1081 (Short_t)esdTrackD->GetSign(),\r
1082 esdTrackD->GetITSClusterMap(), \r
1083 pid,\r
1084 vkink,\r
1085 kTRUE, // check if this is right\r
1086 vtx->UsesTrack(esdTrack->GetID()),\r
1087 AliAODTrack::kSecondary,\r
1088 selectInfo);\r
f2f21b24 1089 daughter->SetTPCClusterMap(esdTrackD->GetTPCClusterMap());\r
1090 daughter->SetTPCSharedMap (esdTrackD->GetTPCSharedMap());\r
f7ed7e88 1091 aodTrackRefs->AddAt(daughter, idaughter);\r
1092 \r
1093 if (esdTrackD->GetSign() > 0) nPosTracks++;\r
1094 daughter->SetFlags(esdTrackD->GetStatus());\r
1095 daughter->ConvertAliPIDtoAODPID();\r
1096 vkink->AddDaughter(daughter);\r
1097 daughter->ConvertAliPIDtoAODPID();\r
b13bcc35 1098 SetAODPID(esdTrackD,daughter,detpid,esd->GetMagneticField(),esdPid);\r
f7ed7e88 1099 }\r
1100 else {\r
1101// cerr << "Error: event " << esd->GetEventNumberInFile() << " kink " << TMath::Abs(ikink)-1\r
1102// << " track " << idaughter << " has already been used!" << endl;\r
1103 }\r
1104 }\r
1105 }\r
1106 } \r
1107 }\r
1108 \r
1109 \r
1110 // Tracks (primary and orphan)\r
1111\r
1112 if (fDebug > 0) printf("NUMBER OF ESD TRACKS %5d\n", nTracks);\r
1113 \r
1114 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {\r
1115 \r
1116 \r
a7b1466d 1117 if (usedTrack[nTrack]){\r
1118 continue;\r
1119 }\r
f7ed7e88 1120 AliESDtrack *esdTrack = esd->GetTrack(nTrack);\r
1121 UInt_t selectInfo = 0;\r
1122 //\r
1123 // Track selection\r
1124 if (fTrackFilter) {\r
9eeae5d5 1125 selectInfo = fTrackFilter->IsSelected(esdTrack);\r
f7ed7e88 1126 if (!selectInfo && !vtx->UsesTrack(esdTrack->GetID())) continue;\r
1127 }\r
1128 \r
1129 //\r
1130 esdTrack->GetPxPyPz(p);\r
1131 esdTrack->GetXYZ(pos);\r
1132 esdTrack->GetCovarianceXYZPxPyPz(covTr);\r
1133 esdTrack->GetESDpid(pid);\r
1134 if(mcH)mcH->SelectParticle(esdTrack->GetLabel());\r
1135 primary->AddDaughter(aodTrack =\r
1136 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),\r
1137 esdTrack->GetLabel(),\r
1138 p,\r
1139 kTRUE,\r
1140 pos,\r
1141 kFALSE,\r
1142 covTr, \r
1143 (Short_t)esdTrack->GetSign(),\r
1144 esdTrack->GetITSClusterMap(), \r
1145 pid,\r
1146 primary,\r
1147 kTRUE, // check if this is right\r
1148 vtx->UsesTrack(esdTrack->GetID()),\r
1149 AliAODTrack::kPrimary, \r
1150 selectInfo)\r
1151 );\r
f2f21b24 1152 aodTrack->SetTPCClusterMap(esdTrack->GetTPCClusterMap());\r
1153 aodTrack->SetTPCSharedMap (esdTrack->GetTPCSharedMap());\r
40a060e5 1154 aodTrack->SetChi2perNDF(Chi2perNDF(esdTrack));\r
1155\r
f7ed7e88 1156 aodTrackRefs->AddAt(aodTrack, nTrack);\r
f2f21b24 1157\r
f7ed7e88 1158 \r
1159 if (esdTrack->GetSign() > 0) nPosTracks++;\r
1160 aodTrack->SetFlags(esdTrack->GetStatus());\r
1161 aodTrack->ConvertAliPIDtoAODPID();\r
b13bcc35 1162 SetAODPID(esdTrack,aodTrack,detpid,esd->GetMagneticField(),esdPid);\r
f7ed7e88 1163 } // end of loop on tracks\r
1164 \r
1165 // Update number of AOD tracks in header at the end of track loop (M.G.)\r
1166 header->SetRefMultiplicity(jTracks);\r
1167 header->SetRefMultiplicityPos(nPosTracks);\r
1168 header->SetRefMultiplicityNeg(jTracks - nPosTracks);\r
1169 if (fDebug > 0) \r
1170 printf(" NAODTRACKS=%d NPOS=%d NNEG=%d\n", jTracks, nPosTracks, jTracks - nPosTracks);\r
a7b1466d 1171\r
1172\r
f7ed7e88 1173 // Do not shrink the array of tracks - other filters may add to it (M.G)\r
1174 // tracks.Expand(jTracks); // remove 'empty slots' due to unwritten tracks\r
a7b1466d 1175 \r
1176 if(fTPCOnlyFilterMask){\r
1177 // Loop over the tracks and extract and mask out all aod tracks that pass the selections for AODt racks\r
1178 for(int it = 0;it < jTracks;++it){\r
1179 AliAODTrack *tr = (AliAODTrack*)tracks.At(it);\r
1180 if(!tr)continue;\r
1181 UInt_t map = tr->GetFilterMap();\r
1182 if(map&fTPCOnlyFilterMask){\r
1183 // we only reset the track select ionfo, no deletion...\r
1184 tr->SetFilterMap(map&~fTPCOnlyFilterMask);\r
1185 }\r
1186 }\r
1187 // Loop over the ESD trcks and pick out the tracks passing TPC only cuts\r
1188 \r
1189 \r
1190 const AliESDVertex *vtxSPD = esd->GetPrimaryVertexSPD();\r
1191 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {\r
1192 AliESDtrack* esdTrack = esd->GetTrack(nTrack); //carefull do not modify it othwise need to work with a copy \r
1193 \r
1194 UInt_t selectInfo = 0;\r
1195 //\r
1196 // Track selection\r
1197 if (fTrackFilter) {\r
1198 selectInfo = fTrackFilter->IsSelected(esdTrack);\r
1199 }\r
1200 selectInfo &= fTPCOnlyFilterMask;\r
1201 if (!selectInfo)continue;\r
1202\r
1203 // create a tpc only tracl\r
1204 AliESDtrack *track = AliESDtrackCuts::GetTPCOnlyTrack(esd,esdTrack->GetID());\r
1205 if(!track) continue;\r
1206\r
a7b1466d 1207\r
1208\r
1a64aeb8 1209 if(track->Pt()>0.){\r
1210 // only constrain tracks above threshold\r
1211 AliExternalTrackParam exParam;\r
1212 // take the B-feild from the ESD, no 3D fieldMap available at this point\r
1213 Bool_t relate = false;\r
1214 relate = track->RelateToVertex(vtxSPD,esd->GetMagneticField(),kVeryBig,&exParam);\r
1215 if(!relate){\r
1216 delete track;\r
1217 continue;\r
1218 }\r
1219 track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());\r
1220 }\r
1221\r
a7b1466d 1222 track->GetPxPyPz(p);\r
1223 track->GetXYZ(pos);\r
1224 track->GetCovarianceXYZPxPyPz(covTr);\r
1225 track->GetESDpid(pid);\r
1226 if(mcH)mcH->SelectParticle(esdTrack->GetLabel());\r
1227 aodTrack = new(tracks[jTracks++]) AliAODTrack(track->GetID(),\r
1228 track->GetLabel(),\r
1229 p,\r
1230 kTRUE,\r
1231 pos,\r
1232 kFALSE,\r
1233 covTr, \r
1234 (Short_t)track->GetSign(),\r
1235 track->GetITSClusterMap(), \r
1236 pid,\r
1237 primary,\r
1238 kTRUE, // check if this is right\r
1239 vtx->UsesTrack(track->GetID()),\r
1240 AliAODTrack::kPrimary, \r
1241 selectInfo);\r
1242 aodTrack->SetTPCClusterMap(track->GetTPCClusterMap());\r
1243 aodTrack->SetTPCSharedMap (track->GetTPCSharedMap());\r
1244 aodTrack->SetChi2perNDF(Chi2perNDF(track));\r
1ac298e6 1245 aodTrack->SetFlags(track->GetStatus());\r
a7b1466d 1246 delete track;\r
1247 } // end of loop on tracks\r
1248 \r
1249 }//end if(fTPCOnlyFilterMask\r
1250 \r
f7ed7e88 1251 // Access to the AOD container of PMD clusters\r
1252 TClonesArray &pmdClusters = *(AODEvent()->GetPmdClusters());\r
1253 Int_t jPmdClusters=0;\r
1254 \r
1255 for (Int_t iPmd = 0; iPmd < nPmdClus; ++iPmd) {\r
1256 // file pmd clusters, to be revised!\r
1257 AliESDPmdTrack *pmdTrack = esd->GetPmdTrack(iPmd);\r
1258 Int_t nLabel = 0;\r
1259 Int_t *label = 0x0;\r
1260 Double_t posPmd[3] = { pmdTrack->GetClusterX(), pmdTrack->GetClusterY(), pmdTrack->GetClusterZ()};\r
1261 Double_t pidPmd[13] = { 0.}; // to be revised!\r
1262 // type not set!\r
1263 // assoc cluster not set\r
1264 new(pmdClusters[jPmdClusters++]) AliAODPmdCluster(iPmd, nLabel, label, pmdTrack->GetClusterADC(), posPmd, pidPmd);\r
1265 }\r
1266\r
1267 // Access to the AOD container of clusters\r
1268 TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());\r
1269 Int_t jClusters=0;\r
1270 \r
1271 for (Int_t iClust=0; iClust<nCaloClus; ++iClust) {\r
1272\r
1273 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);\r
1274\r
c8fe2783 1275 Int_t id = cluster->GetID();\r
1276 Int_t nLabel = cluster->GetNLabels();\r
1277 Int_t *labels = cluster->GetLabels();\r
1278 if(labels){ \r
1279 for(int i = 0;i < nLabel;++i){\r
1280 if(mcH)mcH->SelectParticle(labels[i]);\r
1281 }\r
1282 } \r
f7ed7e88 1283\r
1284 Float_t energy = cluster->E();\r
1285 cluster->GetPosition(posF);\r
f7ed7e88 1286\r
f7ed7e88 1287 AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) AliAODCaloCluster(id,\r
1288 nLabel,\r
c8fe2783 1289 labels,\r
f7ed7e88 1290 energy,\r
1291 posF,\r
1292 NULL,\r
c8fe2783 1293 cluster->GetType(),0);\r
f7ed7e88 1294 \r
1295 caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),\r
c8fe2783 1296 cluster->GetDispersion(),\r
f7ed7e88 1297 cluster->GetM20(), cluster->GetM02(),\r
1298 cluster->GetEmcCpvDistance(), \r
1299 cluster->GetNExMax(),cluster->GetTOF()) ;\r
1300\r
c8fe2783 1301 caloCluster->SetPIDFromESD(cluster->GetPID());\r
f7ed7e88 1302 caloCluster->SetNCells(cluster->GetNCells());\r
1303 caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());\r
1304 caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());\r
1305\r
1306 TArrayI* matchedT = cluster->GetTracksMatched();\r
c8fe2783 1307 if (nTracks>0 && matchedT && cluster->GetTrackMatchedIndex() >= 0) { \r
f7ed7e88 1308 for (Int_t im = 0; im < matchedT->GetSize(); im++) {\r
1309 Int_t iESDtrack = matchedT->At(im);;\r
1310 if (aodTrackRefs->At(iESDtrack) != 0) {\r
1311 caloCluster->AddTrackMatched((AliAODTrack*)aodTrackRefs->At(iESDtrack));\r
1312 }\r
1313 }\r
1314 }\r
1315 \r
1316 } \r
1317 caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots for pseudo clusters \r
1318 // end of loop on calo clusters\r
1319\r
1320 // fill EMCAL cell info\r
1321 if (esd->GetEMCALCells()) { // protection against missing ESD information\r
1322 AliESDCaloCells &esdEMcells = *(esd->GetEMCALCells());\r
1323 Int_t nEMcell = esdEMcells.GetNumberOfCells() ;\r
1324 \r
1325 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());\r
1326 aodEMcells.CreateContainer(nEMcell);\r
c8fe2783 1327 aodEMcells.SetType(AliAODCaloCells::kEMCALCell);\r
f7ed7e88 1328 for (Int_t iCell = 0; iCell < nEMcell; iCell++) { \r
1329 aodEMcells.SetCell(iCell,esdEMcells.GetCellNumber(iCell),esdEMcells.GetAmplitude(iCell));\r
1330 }\r
1331 aodEMcells.Sort();\r
1332 }\r
1333\r
1334 // fill PHOS cell info\r
1335 if (esd->GetPHOSCells()) { // protection against missing ESD information\r
1336 AliESDCaloCells &esdPHcells = *(esd->GetPHOSCells());\r
1337 Int_t nPHcell = esdPHcells.GetNumberOfCells() ;\r
1338 \r
1339 AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());\r
1340 aodPHcells.CreateContainer(nPHcell);\r
c8fe2783 1341 aodPHcells.SetType(AliAODCaloCells::kPHOSCell);\r
f7ed7e88 1342 for (Int_t iCell = 0; iCell < nPHcell; iCell++) { \r
1343 aodPHcells.SetCell(iCell,esdPHcells.GetCellNumber(iCell),esdPHcells.GetAmplitude(iCell));\r
1344 }\r
1345 aodPHcells.Sort();\r
1346 }\r
1347\r
1348 // tracklets \r
1349 AliAODTracklets &SPDTracklets = *(AODEvent()->GetTracklets());\r
1350 const AliMultiplicity *mult = esd->GetMultiplicity();\r
1351 if (mult) {\r
1352 if (mult->GetNumberOfTracklets()>0) {\r
1353 SPDTracklets.CreateContainer(mult->GetNumberOfTracklets());\r
1354\r
1355 for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {\r
1356 if(mcH){\r
1357 mcH->SelectParticle(mult->GetLabel(n, 0));\r
1358 mcH->SelectParticle(mult->GetLabel(n, 1));\r
1359 }\r
1360 SPDTracklets.SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n, 0),mult->GetLabel(n, 1));\r
1361 }\r
1362 }\r
1363 } else {\r
1364 //Printf("ERROR: AliMultiplicity could not be retrieved from ESD");\r
1365 }\r
1366\r
1367 delete [] usedKink;\r
1368 delete [] usedV0;\r
1369 delete [] usedTrack; \r
1370 delete aodV0Refs;\r
1371 delete aodV0VtxRefs;\r
1372 delete aodTrackRefs;\r
253cab77 1373 if (isPidOwner) delete esdPid;\r
f7ed7e88 1374 return;\r
1375}\r
1376\r
1377\r
b13bcc35 1378void AliAnalysisTaskESDfilter::SetAODPID(AliESDtrack *esdtrack, AliAODTrack *aodtrack, AliAODPid *detpid, Double_t bfield, AliESDpid *esdpid)\r
f7ed7e88 1379{\r
1380 //\r
1381 // Setter for the raw PID detector signals\r
1382 //\r
1383\r
1384 // Save PID object for candidate electrons\r
1385 Bool_t pidSave = kFALSE;\r
1386 if (fTrackFilter) {\r
0c6c629b 1387 Bool_t selectInfo = fTrackFilter->IsSelected((char*) "Electrons");\r
f7ed7e88 1388 if (selectInfo) pidSave = kTRUE;\r
1389 }\r
1390\r
1391\r
1392 // Tracks passing pt cut \r
1393 if(esdtrack->Pt()>fHighPthreshold) {\r
1394 pidSave = kTRUE;\r
1395 } else {\r
1396 if(fPtshape){\r
1397 if(esdtrack->Pt()> fPtshape->GetXmin()){\r
1398 Double_t y = fPtshape->Eval(esdtrack->Pt())/fPtshape->Eval(fHighPthreshold);\r
1399 if(gRandom->Rndm(0)<1./y){\r
1400 pidSave = kTRUE;\r
1401 }//end rndm\r
1402 }//end if p < pmin\r
1403 }//end if p function\r
1404 }// end else\r
1405\r
1406 if (pidSave) {\r
6ece2430 1407 if(!aodtrack->GetDetPid()){// prevent memory leak when calling SetAODPID twice for the same track\r
f7ed7e88 1408 detpid = new AliAODPid();\r
b13bcc35 1409 SetDetectorRawSignals(detpid,esdtrack, bfield, esdpid);\r
f7ed7e88 1410 aodtrack->SetDetPID(detpid);\r
6ece2430 1411 }\r
f7ed7e88 1412 }\r
1413}\r
1414\r
b13bcc35 1415void AliAnalysisTaskESDfilter::SetDetectorRawSignals(AliAODPid *aodpid, AliESDtrack *track, Double_t bfield, AliESDpid *esdpid)\r
f7ed7e88 1416{\r
1417//\r
1418//assignment of the detector signals (AliXXXesdPID inspired)\r
1419//\r
1420 if(!track){\r
1421 AliInfo("no ESD track found. .....exiting");\r
1422 return;\r
1423 }\r
febefa51 1424 // TPC momentum\r
1425 const AliExternalTrackParam *in=track->GetInnerParam();\r
1426 if (in) {\r
1427 aodpid->SetTPCmomentum(in->GetP());\r
1428 }else{\r
1429 aodpid->SetTPCmomentum(-1.);\r
1430 }\r
1431\r
f7ed7e88 1432\r
1433 aodpid->SetITSsignal(track->GetITSsignal());\r
1434 aodpid->SetTPCsignal(track->GetTPCsignal());\r
597b16d8 1435 aodpid->SetTPCsignalN(track->GetTPCsignalN());\r
f7ed7e88 1436\r
febefa51 1437 //n TRD planes = 6\r
f7ed7e88 1438 Int_t nslices = track->GetNumberOfTRDslices()*6;\r
1439 Double_t *trdslices = new Double_t[nslices];\r
1440 for(Int_t iSl =0; iSl < track->GetNumberOfTRDslices(); iSl++) {\r
febefa51 1441 for(Int_t iPl =0; iPl<6; iPl++) trdslices[iPl*track->GetNumberOfTRDslices()+iSl] = track->GetTRDslice(iPl,iSl);\r
1442 }\r
1443 \r
1444//TRD momentum\r
1445 for(Int_t iPl=0;iPl<6;iPl++){\r
1446 Double_t trdmom=track->GetTRDmomentum(iPl);\r
1447 aodpid->SetTRDmomentum(iPl,trdmom);\r
1448 }\r
f7ed7e88 1449\r
1450 aodpid->SetTRDsignal(track->GetNumberOfTRDslices()*6,trdslices);\r
b13bcc35 1451\r
1452 //TOF PID \r
f7ed7e88 1453 Double_t times[AliAODPid::kSPECIES]; track->GetIntegratedTimes(times);\r
1454 aodpid->SetIntegratedTimes(times);\r
b13bcc35 1455 Float_t tzeroTrack = esdpid->GetTOFResponse().GetStartTime(track->P());\r
1456 aodpid->SetTOFsignal(track->GetTOFsignal()-tzeroTrack);\r
f7ed7e88 1457\r
b13bcc35 1458 Double_t tofRes[5];\r
1459 for (Int_t iMass=0; iMass<5; iMass++){\r
1460 tofRes[iMass]=(Double_t)esdpid->GetTOFResponse().GetExpectedSigma(track->P(), times[iMass], AliPID::ParticleMass(iMass));\r
1461 }\r
1462 aodpid->SetTOFpidResolution(tofRes);\r
1463 \r
f7ed7e88 1464 aodpid->SetHMPIDsignal(track->GetHMPIDsignal());\r
1465\r
1466 //Extrapolate track to EMCAL surface for AOD-level track-cluster matching\r
1467 Double_t emcpos[3] = {0.,0.,0.};\r
1468 Double_t emcmom[3] = {0.,0.,0.};\r
1469 aodpid->SetEMCALPosition(emcpos);\r
1470 aodpid->SetEMCALMomentum(emcmom);\r
1471\r
1472 AliExternalTrackParam *outerparam = (AliExternalTrackParam*)track->GetOuterParam();\r
1473 if(!outerparam) return;\r
1474\r
1475 //To be replaced by call to AliEMCALGeoUtils when the class becomes available\r
1476 Double_t radius = 441.0; //[cm] EMCAL radius +13cm\r
1477\r
1478 Bool_t okpos = outerparam->GetXYZAt(radius,bfield,emcpos);\r
1479 Bool_t okmom = outerparam->GetPxPyPzAt(radius,bfield,emcmom);\r
1480 if(!(okpos && okmom)) return;\r
1481\r
1482 aodpid->SetEMCALPosition(emcpos);\r
1483 aodpid->SetEMCALMomentum(emcmom);\r
1484\r
1485}\r
1486\r
40a060e5 1487Double_t AliAnalysisTaskESDfilter::Chi2perNDF(AliESDtrack* track)\r
1488{\r
1489 // Calculate chi2 per ndf for track\r
1490 Int_t nClustersTPC = track->GetTPCNcls();\r
1491\r
1492 if ( nClustersTPC > 5) {\r
1493 return (track->GetTPCchi2()/Float_t(nClustersTPC - 5));\r
1494 } else {\r
1495 return (-1.);\r
1496 }\r
1497 }\r
1498\r
1499\r
1500\r
f7ed7e88 1501void AliAnalysisTaskESDfilter::Terminate(Option_t */*option*/)\r
1502{\r
1503// Terminate analysis\r
1504//\r
1505 if (fDebug > 1) printf("AnalysisESDfilter: Terminate() \n");\r
1506}\r
1507\r
1508void AliAnalysisTaskESDfilter::PrintMCInfo(AliStack *pStack,Int_t label){\r
1509 if(!pStack)return;\r
1510 label = TMath::Abs(label);\r
1511 TParticle *part = pStack->Particle(label);\r
1512 Printf("########################");\r
1513 Printf("%s:%d %d UniqueID %d PDG %d P %3.3f",(char*)__FILE__,__LINE__,label,part->GetUniqueID(),part->GetPdgCode(),part->P());\r
1514 part->Print();\r
1515 TParticle* mother = part;\r
1516 Int_t imo = part->GetFirstMother();\r
1517 Int_t nprim = pStack->GetNprimary();\r
1518 // while((imo >= nprim) && (mother->GetUniqueID() == 4)) {\r
1519 while((imo >= nprim)) {\r
1520 mother = pStack->Particle(imo);\r
1521 Printf("Mother %s:%d Label %d UniqueID %d PDG %d P %3.3f",(char*)__FILE__,__LINE__,imo,mother->GetUniqueID(),mother->GetPdgCode(),mother->P());\r
1522 mother->Print();\r
1523 imo = mother->GetFirstMother();\r
1524 }\r
1525 Printf("########################");\r
1526}\r