Adding AliAODTracklets (SPD tracklets) to the standard AOD.
[u/mrichter/AliRoot.git] / STEER / CreateAODfromESD.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2
3 #include <Riostream.h>
4 #include <TFile.h>
5 #include <TTree.h>
6 #include <TMath.h>
7
8 #include "AliAODEvent.h"
9 #include "AliAODHeader.h"
10 #include "AliAODVertex.h"
11 #include "AliAODTrack.h"
12 #include "AliAODCluster.h"
13 #include "AliAODTracklets.h"
14
15 #include "AliESDEvent.h"
16 #include "AliESDtrack.h"
17 #include "AliESDMuonTrack.h"
18 #include "AliESDVertex.h"
19 #include "AliESDv0.h"
20 #include "AliESDcascade.h"
21 #include "AliESDCaloCluster.h"
22
23 #endif
24
25 void CreateAODfromESD(const char *inFileName = "AliESDs.root",
26                       const char *outFileName = "AliAOD.root") {
27
28   // create an AliAOD object 
29   AliAODEvent *aod = new AliAODEvent();
30   aod->CreateStdContent();
31
32   // open the file
33   TFile *outFile = TFile::Open(outFileName, "RECREATE");
34
35   // create the tree
36   TTree *aodTree = new TTree("AOD", "AliAOD tree");
37   aodTree->Branch(aod->GetList());
38
39   // connect to ESD
40   TFile *inFile = TFile::Open(inFileName, "READ");
41   TTree *t = (TTree*) inFile->Get("esdTree");
42   AliESDEvent *esd = new AliESDEvent();
43   esd->ReadFromTree(t);
44
45   Int_t nEvents = t->GetEntries();
46
47   // set arrays and pointers
48   Float_t posF[3];
49   Double_t pos[3];
50   Double_t p[3];
51   Double_t covVtx[6];
52   Double_t covTr[21];
53   Double_t pid[10];
54
55   // loop over events and fill them
56   for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
57     t->GetEntry(iEvent);
58
59     // Multiplicity information needed by the header (to be revised!)
60     Int_t nTracks   = esd->GetNumberOfTracks();
61     Int_t nPosTracks = 0;
62     for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) 
63       if (esd->GetTrack(iTrack)->GetSign()> 0) nPosTracks++;
64     
65     // Access to the header
66     AliAODHeader *header = aod->GetHeader();
67
68     // fill the header
69     *header = AliAODHeader(esd->GetRunNumber(),
70                            esd->GetBunchCrossNumber(),
71                            esd->GetOrbitNumber(),
72                            esd->GetPeriodNumber(),
73                            nTracks,
74                            nPosTracks,
75                            nTracks-nPosTracks,
76                            esd->GetMagneticField(),
77                            -999., // fill muon magnetic field
78                            -999., // centrality; to be filled, still
79                            esd->GetZDCN1Energy(),
80                            esd->GetZDCP1Energy(),
81                            esd->GetZDCN2Energy(),
82                            esd->GetZDCP2Energy(),
83                            esd->GetZDCEMEnergy(),
84                            esd->GetTriggerMask(),
85                            esd->GetTriggerCluster(),
86                            esd->GetEventType());
87   
88     Int_t nV0s      = esd->GetNumberOfV0s();
89     Int_t nCascades = esd->GetNumberOfCascades();
90     Int_t nKinks    = esd->GetNumberOfKinks();
91     Int_t nVertices = nV0s + nCascades + nKinks;
92     
93     aod->ResetStd(nTracks, nVertices);
94     AliAODTrack *aodTrack;
95     
96     // Array to take into account the tracks already added to the AOD
97     Bool_t * usedTrack = NULL;
98     if (nTracks>0) {
99       usedTrack = new Bool_t[nTracks];
100       for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
101     }
102     // Array to take into account the V0s already added to the AOD
103     Bool_t * usedV0 = NULL;
104     if (nV0s>0) {
105       usedV0 = new Bool_t[nV0s];
106       for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
107     }
108     // Array to take into account the kinks already added to the AOD
109     Bool_t * usedKink = NULL;
110     if (nKinks>0) {
111       usedKink = new Bool_t[nKinks];
112       for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
113     }
114
115     // Access to the AOD container of vertices
116     TClonesArray &vertices = *(aod->GetVertices());
117     Int_t jVertices=0;
118
119     // Access to the AOD container of tracks
120     TClonesArray &tracks = *(aod->GetTracks());
121     Int_t jTracks=0; 
122   
123     // Add primary vertex. The primary tracks will be defined
124     // after the loops on the composite objects (V0, cascades, kinks)
125     const AliESDVertex *vtx = esd->GetPrimaryVertex();
126       
127     vtx->GetXYZ(pos); // position
128     vtx->GetCovMatrix(covVtx); //covariance matrix
129
130     AliAODVertex * primary = new(vertices[jVertices++])
131       AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, AliAODVertex::kPrimary);
132          
133     // Create vertices starting from the most complex objects
134       
135     // Cascades
136     for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
137       AliESDcascade *cascade = esd->GetCascade(nCascade);
138       
139       cascade->GetXYZ(pos[0], pos[1], pos[2]);
140       cascade->GetPosCovXi(covVtx);
141      
142       // Add the cascade vertex
143       AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
144                                                                         covVtx,
145                                                                         cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
146                                                                         primary,
147                                                                         AliAODVertex::kCascade);
148
149       primary->AddDaughter(vcascade);
150
151       // Add the V0 from the cascade. The ESD class have to be optimized...
152       // Now we have to search for the corresponding Vo in the list of V0s
153       // using the indeces of the positive and negative tracks
154
155       Int_t posFromV0 = cascade->GetPindex();
156       Int_t negFromV0 = cascade->GetNindex();
157
158
159       AliESDv0 * v0 = 0x0;
160       Int_t indV0 = -1;
161
162       for (Int_t iV0=0; iV0<nV0s; ++iV0) {
163
164         v0 = esd->GetV0(iV0);
165         Int_t posV0 = v0->GetPindex();
166         Int_t negV0 = v0->GetNindex();
167
168         if (posV0==posFromV0 && negV0==negFromV0) {
169           indV0 = iV0;
170           break;
171         }
172       }
173
174       AliAODVertex * vV0FromCascade = 0x0;
175
176       if (indV0>-1 && !usedV0[indV0] ) {
177         
178         // the V0 exists in the array of V0s and is not used
179
180         usedV0[indV0] = kTRUE;
181         
182         v0->GetXYZ(pos[0], pos[1], pos[2]);
183         v0->GetPosCov(covVtx);
184         
185         vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
186                                                                  covVtx,
187                                                                  v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
188                                                                  vcascade,
189                                                                  AliAODVertex::kV0);
190       } else {
191
192         // the V0 doesn't exist in the array of V0s or was used
193         cerr << "Error: event " << iEvent << " cascade " << nCascade
194              << " The V0 " << indV0 
195              << " doesn't exist in the array of V0s or was used!" << endl;
196
197         cascade->GetXYZ(pos[0], pos[1], pos[2]);
198         cascade->GetPosCov(covVtx);
199       
200         vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
201                                                                  covVtx,
202                                                                  v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
203                                                                  vcascade,
204                                                                  AliAODVertex::kV0);
205         vcascade->AddDaughter(vV0FromCascade);
206       }
207
208       // Add the positive tracks from the V0
209
210       if (! usedTrack[posFromV0]) {
211
212         usedTrack[posFromV0] = kTRUE;
213
214         AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
215         esdTrack->GetPxPyPz(p);
216         esdTrack->GetXYZ(pos);
217         esdTrack->GetCovarianceXYZPxPyPz(covTr);
218         esdTrack->GetESDpid(pid);
219         
220         vV0FromCascade->AddDaughter(aodTrack =
221                                     new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
222                                            esdTrack->GetLabel(), 
223                                            p, 
224                                            kTRUE,
225                                            pos,
226                                            kFALSE,
227                                            covTr, 
228                                            (Short_t)esdTrack->GetSign(),
229                                            esdTrack->GetITSClusterMap(), 
230                                            pid,
231                                            vV0FromCascade,
232                                            kTRUE,  // check if this is right
233                                            kFALSE, // check if this is right
234                                            AliAODTrack::kSecondary)
235                 );
236         aodTrack->ConvertAliPIDtoAODPID();
237       }
238       else {
239         cerr << "Error: event " << iEvent << " cascade " << nCascade
240              << " track " << posFromV0 << " has already been used!" << endl;
241       }
242
243       // Add the negative tracks from the V0
244
245       if (!usedTrack[negFromV0]) {
246         
247         usedTrack[negFromV0] = kTRUE;
248         
249         AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
250         esdTrack->GetPxPyPz(p);
251         esdTrack->GetXYZ(pos);
252         esdTrack->GetCovarianceXYZPxPyPz(covTr);
253         esdTrack->GetESDpid(pid);
254         
255         vV0FromCascade->AddDaughter(aodTrack =
256                 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
257                                            esdTrack->GetLabel(),
258                                            p,
259                                            kTRUE,
260                                            pos,
261                                            kFALSE,
262                                            covTr, 
263                                            (Short_t)esdTrack->GetSign(),
264                                            esdTrack->GetITSClusterMap(), 
265                                            pid,
266                                            vV0FromCascade,
267                                            kTRUE,  // check if this is right
268                                            kFALSE, // check if this is right
269                                            AliAODTrack::kSecondary)
270                 );
271         aodTrack->ConvertAliPIDtoAODPID();
272       }
273       else {
274         cerr << "Error: event " << iEvent << " cascade " << nCascade
275              << " track " << negFromV0 << " has already been used!" << endl;
276       }
277
278       // Add the bachelor track from the cascade
279
280       Int_t bachelor = cascade->GetBindex();
281       
282       if(!usedTrack[bachelor]) {
283       
284         usedTrack[bachelor] = kTRUE;
285         
286         AliESDtrack *esdTrack = esd->GetTrack(bachelor);
287         esdTrack->GetPxPyPz(p);
288         esdTrack->GetXYZ(pos);
289         esdTrack->GetCovarianceXYZPxPyPz(covTr);
290         esdTrack->GetESDpid(pid);
291
292         vcascade->AddDaughter(aodTrack =
293                 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
294                                            esdTrack->GetLabel(),
295                                            p,
296                                            kTRUE,
297                                            pos,
298                                            kFALSE,
299                                            covTr, 
300                                            (Short_t)esdTrack->GetSign(),
301                                            esdTrack->GetITSClusterMap(), 
302                                            pid,
303                                            vcascade,
304                                            kTRUE,  // check if this is right
305                                            kFALSE, // check if this is right
306                                            AliAODTrack::kSecondary)
307                 );
308         aodTrack->ConvertAliPIDtoAODPID();
309      }
310       else {
311         cerr << "Error: event " << iEvent << " cascade " << nCascade
312              << " track " << bachelor << " has already been used!" << endl;
313       }
314
315       // Add the primary track of the cascade (if any)
316
317     } // end of the loop on cascades
318     
319     // V0s
320         
321     for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
322
323       if (usedV0[nV0]) continue; // skip if aready added to the AOD
324
325       AliESDv0 *v0 = esd->GetV0(nV0);
326       
327       v0->GetXYZ(pos[0], pos[1], pos[2]);
328       v0->GetPosCov(covVtx);
329
330       AliAODVertex * vV0 = 
331         new(vertices[jVertices++]) AliAODVertex(pos,
332                                                 covVtx,
333                                                 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
334                                                 primary,
335                                                 AliAODVertex::kV0);
336       primary->AddDaughter(vV0);
337
338       Int_t posFromV0 = v0->GetPindex();
339       Int_t negFromV0 = v0->GetNindex();
340       
341       // Add the positive tracks from the V0
342
343       if (!usedTrack[posFromV0]) {
344         
345         usedTrack[posFromV0] = kTRUE;
346
347         AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
348         esdTrack->GetPxPyPz(p);
349         esdTrack->GetXYZ(pos);
350         esdTrack->GetCovarianceXYZPxPyPz(covTr);
351         esdTrack->GetESDpid(pid);
352         
353         vV0->AddDaughter(aodTrack =
354                 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
355                                            esdTrack->GetLabel(), 
356                                            p, 
357                                            kTRUE,
358                                            pos,
359                                            kFALSE,
360                                            covTr, 
361                                            (Short_t)esdTrack->GetSign(),
362                                            esdTrack->GetITSClusterMap(), 
363                                            pid,
364                                            vV0,
365                                            kTRUE,  // check if this is right
366                                            kFALSE, // check if this is right
367                                            AliAODTrack::kSecondary)
368                 );
369         aodTrack->ConvertAliPIDtoAODPID();
370       }
371       else {
372         cerr << "Error: event " << iEvent << " V0 " << nV0
373              << " track " << posFromV0 << " has already been used!" << endl;
374       }
375
376       // Add the negative tracks from the V0
377
378       if (!usedTrack[negFromV0]) {
379
380         usedTrack[negFromV0] = kTRUE;
381
382         AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
383         esdTrack->GetPxPyPz(p);
384         esdTrack->GetXYZ(pos);
385         esdTrack->GetCovarianceXYZPxPyPz(covTr);
386         esdTrack->GetESDpid(pid);
387
388         vV0->AddDaughter(aodTrack =
389                 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
390                                            esdTrack->GetLabel(),
391                                            p,
392                                            kTRUE,
393                                            pos,
394                                            kFALSE,
395                                            covTr, 
396                                            (Short_t)esdTrack->GetSign(),
397                                            esdTrack->GetITSClusterMap(), 
398                                            pid,
399                                            vV0,
400                                            kTRUE,  // check if this is right
401                                            kFALSE, // check if this is right
402                                            AliAODTrack::kSecondary)
403                 );
404         aodTrack->ConvertAliPIDtoAODPID();
405       }
406       else {
407         cerr << "Error: event " << iEvent << " V0 " << nV0
408              << " track " << negFromV0 << " has already been used!" << endl;
409       }
410
411     } // end of the loop on V0s
412     
413     // Kinks: it is a big mess the access to the information in the kinks
414     // The loop is on the tracks in order to find the mother and daugther of each kink
415
416
417     for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
418
419
420       AliESDtrack * esdTrack = esd->GetTrack(iTrack);
421
422       Int_t ikink = esdTrack->GetKinkIndex(0);
423
424       if (ikink) {
425         // Negative kink index: mother, positive: daughter
426
427         // Search for the second track of the kink
428
429         for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
430
431           AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
432
433           Int_t jkink = esdTrack1->GetKinkIndex(0);
434
435           if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
436
437             // The two tracks are from the same kink
438           
439             if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
440
441             Int_t imother = -1;
442             Int_t idaughter = -1;
443
444             if (ikink<0 && jkink>0) {
445
446               imother = iTrack;
447               idaughter = jTrack;
448             }
449             else if (ikink>0 && jkink<0) {
450
451               imother = jTrack;
452               idaughter = iTrack;
453             }
454             else {
455               cerr << "Error: Wrong combination of kink indexes: "
456               << ikink << " " << jkink << endl;
457               continue;
458             }
459
460             // Add the mother track
461
462             AliAODTrack * mother = NULL;
463
464             if (!usedTrack[imother]) {
465         
466               usedTrack[imother] = kTRUE;
467         
468               AliESDtrack *esdTrack = esd->GetTrack(imother);
469               esdTrack->GetPxPyPz(p);
470               esdTrack->GetXYZ(pos);
471               esdTrack->GetCovarianceXYZPxPyPz(covTr);
472               esdTrack->GetESDpid(pid);
473
474               mother = 
475                 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
476                                            esdTrack->GetLabel(),
477                                            p,
478                                            kTRUE,
479                                            pos,
480                                            kFALSE,
481                                            covTr, 
482                                            (Short_t)esdTrack->GetSign(),
483                                            esdTrack->GetITSClusterMap(), 
484                                            pid,
485                                            primary,
486                                            kTRUE, // check if this is right
487                                            kTRUE, // check if this is right
488                                            AliAODTrack::kPrimary);
489               primary->AddDaughter(mother);
490               mother->ConvertAliPIDtoAODPID();
491             }
492             else {
493               cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
494               << " track " << imother << " has already been used!" << endl;
495             }
496
497             // Add the kink vertex
498             AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
499
500             AliAODVertex * vkink = 
501             new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
502                                                     NULL,
503                                                     0.,
504                                                     mother,
505                                                     AliAODVertex::kKink);
506             // Add the daughter track
507
508             AliAODTrack * daughter = NULL;
509
510             if (!usedTrack[idaughter]) {
511         
512               usedTrack[idaughter] = kTRUE;
513         
514               AliESDtrack *esdTrack = esd->GetTrack(idaughter);
515               esdTrack->GetPxPyPz(p);
516               esdTrack->GetXYZ(pos);
517               esdTrack->GetCovarianceXYZPxPyPz(covTr);
518               esdTrack->GetESDpid(pid);
519
520               daughter = 
521                 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
522                                            esdTrack->GetLabel(),
523                                            p,
524                                            kTRUE,
525                                            pos,
526                                            kFALSE,
527                                            covTr, 
528                                            (Short_t)esdTrack->GetSign(),
529                                            esdTrack->GetITSClusterMap(), 
530                                            pid,
531                                            vkink,
532                                            kTRUE, // check if this is right
533                                            kTRUE, // check if this is right
534                                            AliAODTrack::kPrimary);
535               vkink->AddDaughter(daughter);
536               daughter->ConvertAliPIDtoAODPID();
537             }
538             else {
539               cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
540               << " track " << idaughter << " has already been used!" << endl;
541             }
542
543
544           }
545         }
546
547       }      
548
549     }
550
551     
552     // Tracks (primary and orphan)
553       
554     for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
555         
556
557       if (usedTrack[nTrack]) continue;
558
559       AliESDtrack *esdTrack = esd->GetTrack(nTrack);
560       esdTrack->GetPxPyPz(p);
561       esdTrack->GetXYZ(pos);
562       esdTrack->GetCovarianceXYZPxPyPz(covTr);
563       esdTrack->GetESDpid(pid);
564
565       Float_t impactXY, impactZ;
566
567       esdTrack->GetImpactParameters(impactXY,impactZ);
568
569       if (impactXY<3) {
570         // track inside the beam pipe
571       
572         primary->AddDaughter(aodTrack =
573             new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
574                                          esdTrack->GetLabel(),
575                                          p,
576                                          kTRUE,
577                                          pos,
578                                          kFALSE,
579                                          covTr, 
580                                          (Short_t)esdTrack->GetSign(),
581                                          esdTrack->GetITSClusterMap(), 
582                                          pid,
583                                          primary,
584                                          kTRUE, // check if this is right
585                                          kTRUE, // check if this is right
586                                          AliAODTrack::kPrimary)
587             );
588         aodTrack->ConvertAliPIDtoAODPID();
589       }
590       else {
591         // outside the beam pipe: orphan track
592             aodTrack =
593             new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
594                                          esdTrack->GetLabel(),
595                                          p,
596                                          kTRUE,
597                                          pos,
598                                          kFALSE,
599                                          covTr, 
600                                          (Short_t)esdTrack->GetSign(),
601                                          esdTrack->GetITSClusterMap(), 
602                                          pid,
603                                          NULL,
604                                          kFALSE, // check if this is right
605                                          kFALSE, // check if this is right
606                                          AliAODTrack::kOrphan);
607             aodTrack->ConvertAliPIDtoAODPID();
608       } 
609     } // end of loop on tracks
610
611     // muon tracks
612     Int_t nMuTracks = esd->GetNumberOfMuonTracks();
613     for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
614       
615       AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);     
616       p[0] = esdMuTrack->Px(); 
617       p[1] = esdMuTrack->Py(); 
618       p[2] = esdMuTrack->Pz();
619       pos[0] = primary->GetX(); 
620       pos[1] = primary->GetY(); 
621       pos[2] = primary->GetZ();
622       
623       // has to be changed once the muon pid is provided by the ESD
624       for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
625       
626       primary->AddDaughter( aodTrack =
627           new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
628                                              0, // no label provided
629                                              p,
630                                              kTRUE,
631                                              pos,
632                                              kFALSE,
633                                              NULL, // no covariance matrix provided
634                                              (Short_t)-99, // no charge provided
635                                              0, // no ITSClusterMap
636                                              pid,
637                                              primary,
638                                              kFALSE,  // muon tracks are not used to fit the primary vtx
639                                              kFALSE,  // not used for vertex fit
640                                              AliAODTrack::kPrimary)
641           );
642         aodTrack->SetHitsPatternInTrigCh(esdMuTrack->GetHitsPatternInTrigCh());
643         Int_t track2Trigger = esdMuTrack->GetMatchTrigger();
644         aodTrack->SetMatchTrigger(track2Trigger);
645         if (track2Trigger) 
646           aodTrack->SetChi2MatchTrigger(esdMuTrack->GetChi2MatchTrigger());
647         else 
648           aodTrack->SetChi2MatchTrigger(0.);
649     }
650     
651     // Access to the AOD container of clusters
652     TClonesArray &clusters = *(aod->GetClusters());
653     Int_t jClusters=0;
654
655     // Calo Clusters
656     Int_t nClusters    = esd->GetNumberOfCaloClusters();
657
658     for (Int_t iClust=0; iClust<nClusters; ++iClust) {
659
660       AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
661
662       Int_t id = cluster->GetID();
663       Int_t label = -1;
664       Float_t energy = cluster->E();
665       cluster->GetPosition(posF);
666       AliAODVertex *prodVertex = primary;
667       AliAODTrack *primTrack = NULL;
668       Char_t ttype=AliAODCluster::kUndef;
669
670       if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral;
671       else if (cluster->IsEMCAL()) {
672
673         if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster)
674           ttype = AliAODCluster::kEMCALPseudoCluster;
675         else
676           ttype = AliAODCluster::kEMCALClusterv1;
677
678       }
679       
680       new(clusters[jClusters++]) AliAODCluster(id,
681                                                label,
682                                                energy,
683                                                pos,
684                                                NULL, // no covariance matrix provided
685                                                NULL, // no pid for clusters provided
686                                                prodVertex,
687                                                primTrack,
688                                                ttype);
689
690     } // end of loop on calo clusters
691
692     // tracklets
693     const AliMultiplicity *mult = esd->GetMultiplicity();
694     if (mult) {
695       if (mult->GetNumberOfTracklets()>0) {
696         aod->GetTracklets()->CreateContainer(mult->GetNumberOfTracklets());
697
698         for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {
699           aod->GetTracklets()->SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n));
700         }
701       }
702     } else {
703       Printf("ERROR: AliMultiplicity could not be retrieved from ESD");
704     }
705
706     delete [] usedTrack;
707     delete [] usedV0;
708     delete [] usedKink;
709
710     // fill the tree for this event
711     aodTree->Fill();
712   } // end of event loop
713   
714   aodTree->GetUserInfo()->Add(aod);
715
716   // close ESD file
717   inFile->Close();
718   
719   // write the tree to the specified file
720   outFile = aodTree->GetCurrentFile();
721   outFile->cd();
722   aodTree->Write();
723   outFile->Close();
724
725 }