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