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