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