1 #if !defined(__CINT__) || defined(__MAKECINT__)
9 #include "AliRunLoader.h"
10 #include "AliHeader.h"
12 #include "TParticle.h"
14 #include "AliAODEvent.h"
15 #include "AliAODHeader.h"
16 #include "AliAODVertex.h"
17 #include "AliAODTrack.h"
18 #include "AliAODCluster.h"
22 // function declarations
23 void SetVertexType(TParticle *part, AliAODVertex *vertex);
24 void SetChargeAndPID(Int_t pdgCode, AliAODTrack *track);
25 Int_t LoopOverSecondaries(TParticle *mother);
26 void CreateAODfromKineTree(const char *inFileName = "galice.root",
27 const char *outFileName = "AliAOD.root");
30 AliAODEvent *aod = NULL;
31 AliStack *stack = NULL;
48 Int_t nAntiProton = 0;
50 Int_t nAntiNeutron = 0;
58 void CreateAODfromKineTree(const char *inFileName,
59 const char *outFileName) {
60 printf("This macro works only correctly in comiled mode!\n");
61 /* This probem is due to CINT which gets confused if arrays are reused */
63 // create an AliAOD object
64 aod = new AliAODEvent();
65 aod->CreateStdContent();
68 TFile *outFile = TFile::Open(outFileName, "RECREATE");
71 TTree *aodTree = new TTree("AOD", "AliAOD tree");
72 aodTree->Branch(aod->GetList());
74 AliRunLoader *runLoader;
77 runLoader = AliRunLoader::Open(inFileName);
78 if (!runLoader) return;
80 runLoader->LoadHeader();
81 runLoader->LoadKinematics();
83 Int_t nEvents = runLoader->GetNumberOfEvents();
85 // loop over events and fill them
86 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
88 cout << "Event " << iEvent+1 << "/" << nEvents;
89 runLoader->GetEvent(iEvent);
91 AliHeader *aliHeader = runLoader->GetHeader();
92 stack = runLoader->Stack();
93 Int_t nTracks = stack->GetNtrack();
94 Int_t nPrims = stack->GetNprimary();
116 aod->AddHeader(new AliAODHeader(aliHeader->GetRun(),
123 -999., // muon mag. field
134 // Access to the header
135 AliAODHeader *header = aod->GetHeader();
137 // Access to the AOD container of vertices
138 TClonesArray &vertices = *(aod->GetVertices());
145 // Access to the AOD container of tracks
146 TClonesArray &tracks = *(aod->GetTracks());
149 aod->ResetStd(nTracks, 1);
153 Float_t *covTr = NULL;
155 AliAODVertex *primary = NULL;
156 AliAODTrack* currTrack = NULL;
158 for (Int_t iTrack = 0; iTrack < nPrims; ++iTrack) {
160 TParticle *part = stack->Particle(iTrack);
162 //if (part->IsPrimary()) { // this will exclude 'funny' primaries, too
163 if (kTRUE) { // this won't
164 p[0] = part->Px(); p[1] = part->Py(); p[2] = part->Pz();
165 x[0] = part->Vx(); x[1] = part->Vy(); x[2] = part->Vz();
168 // add primary vertex
169 primary = new(vertices[jVertices++])
170 AliAODVertex(x, NULL, -999., NULL, AliAODVertex::kPrimary);
173 // add primary tracks
174 primary->AddDaughter(new(tracks[jTracks++]) AliAODTrack(0, // ID,
182 0, // no ITSClusterMap
185 kFALSE, // no fit preformed
186 AliAODTrack::kPrimary));
187 currTrack = (AliAODTrack*)tracks.Last();
188 SetChargeAndPID(part->GetPdgCode(), currTrack);
189 if (currTrack->Charge() != -99) {
190 if (currTrack->Charge() > 0) {
192 } else if (currTrack->Charge() < 0) {
197 LoopOverSecondaries(part);
199 } // end of track loop
201 header->SetRefMultiplicityPos(nPos);
202 header->SetRefMultiplicityNeg(nNeg);
204 cout << ":: primaries: " << nPrims << " secondaries: " << tracks.GetEntriesFast()-nPrims <<
205 " (pos: " << nPos << ", neg: " << nNeg << "), vertices: " << vertices.GetEntriesFast() <<
206 " (kinks: " << jKinks << ", V0: " << jV0s << ", cascades: " << jCascades <<
207 ", multi: " << jMultis << ")" << endl;
209 cout << " gamma: " << nGamma << " e-: " << nElectron << " e+: " << nPositron << " p: " << nProton <<
210 " pBar: " << nAntiProton << " n: " << nNeutron << " nBar: " << nAntiNeutron << " pi0: " << nPi0 <<
211 " pi+: " << nPiPlus << " pi-: " << nPiMinus << " K0: " << nK0 << " K+: " << nKPlus <<
212 " K-: " << nKMinus << endl;
214 // fill the tree for this event
216 } // end of event loop
218 aodTree->GetUserInfo()->Add(aod);
220 // write the tree to the specified file
221 outFile = aodTree->GetCurrentFile();
229 Int_t LoopOverSecondaries(TParticle *mother) {
231 if (mother->GetNDaughters() > 0) {
233 TClonesArray &vertices = *(aod->GetVertices());
234 TClonesArray &tracks = *(aod->GetTracks());
238 Float_t *covSec = NULL;
239 Float_t *pidSec = NULL;
240 AliAODVertex *secondary = NULL;
241 AliAODTrack* currTrackSec = NULL;
243 for (Int_t iDaughter = mother->GetFirstDaughter(); iDaughter <= mother->GetLastDaughter(); iDaughter++) {
244 TParticle *partSec = stack->Particle(iDaughter);
246 pSec[0] = partSec->Px(); pSec[1] = partSec->Py(); pSec[2] = partSec->Pz();
247 xSec[0] = partSec->Vx(); xSec[1] = partSec->Vy(); xSec[2] = partSec->Vz();
249 if (iDaughter == mother->GetFirstDaughter()) {
250 // add secondary vertex
251 secondary = new(vertices[jVertices++])
252 AliAODVertex(xSec, NULL, -999., tracks.Last(), AliAODVertex::kUndef);
254 SetVertexType(partSec, secondary);
257 // add secondary tracks
258 secondary->AddDaughter(new(tracks[jTracks++]) AliAODTrack(0, // ID
266 0, // no cluster map available
269 kFALSE, // no fit performed
270 AliAODTrack::kSecondary));
272 currTrackSec = (AliAODTrack*)tracks.Last();
273 SetChargeAndPID(partSec->GetPdgCode(), currTrackSec);
274 if (currTrackSec->Charge() != -99) {
275 if (currTrackSec->Charge() > 0) {
277 } else if (currTrackSec->Charge() < 0) {
282 LoopOverSecondaries(partSec);
291 void SetChargeAndPID(Int_t pdgCode, AliAODTrack *track) {
293 Float_t PID[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
299 PID[AliAODTrack::kUnknown] = 1.;
305 track->SetCharge(-1);
306 PID[AliAODTrack::kElectron] = 1.;
312 track->SetCharge(+1);
313 PID[AliAODTrack::kElectron] = 1.;
319 track->SetCharge(-1);
320 PID[AliAODTrack::kMuon] = 1.;
326 track->SetCharge(+1);
327 PID[AliAODTrack::kMuon] = 1.;
334 PID[AliAODTrack::kUnknown] = 1.;
340 track->SetCharge(+1);
341 PID[AliAODTrack::kPion] = 1.;
347 track->SetCharge(-1);
348 PID[AliAODTrack::kPion] = 1.;
355 PID[AliAODTrack::kUnknown] = 1.;
361 track->SetCharge(+1);
362 PID[AliAODTrack::kKaon] = 1.;
368 track->SetCharge(-1);
369 PID[AliAODTrack::kKaon] = 1.;
376 PID[AliAODTrack::kUnknown] = 1.;
382 track->SetCharge(+1);
383 PID[AliAODTrack::kProton] = 1.;
388 case -2212: // anti-p
389 track->SetCharge(-1);
390 PID[AliAODTrack::kProton] = 1.;
397 PID[AliAODTrack::kUnknown] = 1.;
404 PID[AliAODTrack::kUnknown] = 1.;
409 case -311: // anti-K0
411 PID[AliAODTrack::kUnknown] = 1.;
418 PID[AliAODTrack::kUnknown] = 1.;
424 PID[AliAODTrack::kUnknown] = 1.;
429 track->SetCharge(+1);
430 PID[AliAODTrack::kUnknown] = 1.;
435 track->SetCharge(-1);
436 PID[AliAODTrack::kUnknown] = 1.;
441 track->SetCharge(-1);
442 PID[AliAODTrack::kUnknown] = 1.;
448 PID[AliAODTrack::kUnknown] = 1.;
453 track->SetCharge(-1);
454 PID[AliAODTrack::kUnknown] = 1.;
459 track->SetCharge(-1);
460 PID[AliAODTrack::kUnknown] = 1.;
466 PID[AliAODTrack::kUnknown] = 1.;
470 case -3122: // anti-Lambda
472 PID[AliAODTrack::kUnknown] = 1.;
476 case -3222: // anti-Sigma-
477 track->SetCharge(-1);
478 PID[AliAODTrack::kUnknown] = 1.;
482 case -3212: // anti-Sigma0
484 PID[AliAODTrack::kUnknown] = 1.;
488 case -3112: // anti-Sigma+
489 track->SetCharge(+1);
490 PID[AliAODTrack::kUnknown] = 1.;
494 case -3322: // anti-Xi0
496 PID[AliAODTrack::kUnknown] = 1.;
500 case -3312: // anti-Xi+
501 track->SetCharge(+1);
504 case -3334: // anti-Omega+
505 track->SetCharge(+1);
506 PID[AliAODTrack::kUnknown] = 1.;
511 track->SetCharge(+1);
512 PID[AliAODTrack::kUnknown] = 1.;
517 track->SetCharge(-1);
518 PID[AliAODTrack::kUnknown] = 1.;
524 PID[AliAODTrack::kUnknown] = 1.;
528 case -421: // anti-D0
530 PID[AliAODTrack::kUnknown] = 1.;
535 track->SetCharge(-99);
536 PID[AliAODTrack::kUnknown] = 1.;
544 void SetVertexType(TParticle *part, AliAODVertex *vertex) {
545 // this whole thing doesn't make much sense. but anyhow...
547 TParticle *mother = stack->Particle(part->GetFirstMother());
548 Int_t pdgMother = mother->GetPdgCode();
549 Int_t pdgPart = part->GetPdgCode();
552 if (mother->GetNDaughters() == 2) {
553 Int_t firstPdgCode = stack->Particle(mother->GetFirstDaughter())->GetPdgCode();
554 Int_t lastPdgCode = stack->Particle(mother->GetLastDaughter())->GetPdgCode();
556 if (!(pdgMother == 22 || pdgMother == 111 || pdgMother == 130 ||
557 TMath::Abs(pdgMother) == 2112 || pdgMother == 310 || pdgMother == 221 ||
558 TMath::Abs(pdgMother) == 3122 || TMath::Abs(pdgMother) == 3322 ||
559 pdgMother == -3212 || TMath::Abs(pdgMother) == 421 ||
560 TMath::Abs(pdgMother) == 311) // not neutral
561 && (((firstPdgCode == 22 || firstPdgCode == 111 || firstPdgCode == 130 ||
562 TMath::Abs(firstPdgCode) == 2112 || firstPdgCode == 310 ||
563 firstPdgCode == 221 || TMath::Abs(firstPdgCode) == 3122 ||
564 TMath::Abs(firstPdgCode) == 3322 || firstPdgCode == -3212 ||
565 TMath::Abs(firstPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // neutral
566 && !(lastPdgCode == 22 || lastPdgCode == 111 || lastPdgCode == 130 ||
567 TMath::Abs(lastPdgCode) == 2112 || lastPdgCode == 310 ||
568 lastPdgCode == 221 || TMath::Abs(lastPdgCode) == 3122 ||
569 TMath::Abs(lastPdgCode) == 3322 || lastPdgCode == -3212 ||
570 TMath::Abs(lastPdgCode) == 421 || TMath::Abs(pdgMother) == 311)) // not neutral
571 || !((firstPdgCode == 22 || firstPdgCode == 111 || firstPdgCode == 130 ||
572 TMath::Abs(firstPdgCode) == 2112 || firstPdgCode == 310 ||
573 firstPdgCode == 221 || TMath::Abs(firstPdgCode) == 3122 ||
574 TMath::Abs(firstPdgCode) == 3322 || firstPdgCode == -3212 ||
575 TMath::Abs(firstPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // not neutral
576 && (lastPdgCode == 22 || lastPdgCode == 111 || lastPdgCode == 130 ||
577 TMath::Abs(lastPdgCode) == 2112 || lastPdgCode == 310 ||
578 lastPdgCode == 221 || TMath::Abs(lastPdgCode) == 3122 ||
579 TMath::Abs(lastPdgCode) == 3322 || lastPdgCode == -3212 ||
580 TMath::Abs(lastPdgCode) == 421 || TMath::Abs(pdgMother) == 311)))) { // neutral
582 vertex->SetType(AliAODVertex::kKink);
588 else if (mother->GetNDaughters() == 2) {
589 Int_t firstPdgCode = stack->Particle(mother->GetFirstDaughter())->GetPdgCode();
590 Int_t lastPdgCode = stack->Particle(mother->GetLastDaughter())->GetPdgCode();
592 if ((pdgMother == 22 || pdgMother == 111 || pdgMother == 130 ||
593 TMath::Abs(pdgMother) == 2112 || pdgMother == 310 ||
594 pdgMother == 221 || TMath::Abs(pdgMother) == 3122 ||
595 TMath::Abs(pdgMother) == 3322 || pdgMother == -3212 ||
596 TMath::Abs(pdgMother) == 421 || TMath::Abs(pdgMother) == 311) // neutral
597 && !(lastPdgCode == 22 || lastPdgCode == 111 || lastPdgCode == 130 ||
598 TMath::Abs(lastPdgCode) == 2112 || lastPdgCode == 310 ||
599 lastPdgCode == 221 || TMath::Abs(lastPdgCode) == 3122 ||
600 TMath::Abs(lastPdgCode) == 3322 || lastPdgCode == -3212 ||
601 TMath::Abs(lastPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // not neutral
602 && !(firstPdgCode == 22 || firstPdgCode == 111 || firstPdgCode == 130 ||
603 TMath::Abs(firstPdgCode) == 2112 || firstPdgCode == 310 ||
604 firstPdgCode == 221 || TMath::Abs(firstPdgCode) == 3122 ||
605 TMath::Abs(firstPdgCode) == 3322 || firstPdgCode == -3212 ||
606 TMath::Abs(firstPdgCode) == 421 || TMath::Abs(pdgMother) == 311)) { // not neutral
608 vertex->SetType(AliAODVertex::kV0);
614 else if (mother->GetNDaughters() == 2) {
615 Int_t firstPdgCode = stack->Particle(mother->GetFirstDaughter())->GetPdgCode();
616 Int_t lastPdgCode = stack->Particle(mother->GetLastDaughter())->GetPdgCode();
618 if ((TMath::Abs(pdgMother) == 3334 || TMath::Abs(pdgMother) == 3312 || TMath::Abs(pdgMother) == 3322) &&
619 (TMath::Abs(pdgPart) == 3122 || TMath::Abs(pdgPart) == 211 || TMath::Abs(pdgPart) == 321)
620 && ((!(firstPdgCode == 22 || firstPdgCode == 111 || firstPdgCode == 130 ||
621 TMath::Abs(firstPdgCode) == 2112 || firstPdgCode == 310 ||
622 firstPdgCode == 221 || TMath::Abs(firstPdgCode) == 3122 ||
623 TMath::Abs(firstPdgCode) == 3322 || firstPdgCode == -3212 ||
624 TMath::Abs(firstPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // not neutral
625 && TMath::Abs(lastPdgCode) == 3122) // labmda or anti-lambda
626 || ((!(lastPdgCode == 22 || lastPdgCode == 111 || lastPdgCode == 130 ||
627 TMath::Abs(lastPdgCode) == 2112 || lastPdgCode == 310 ||
628 lastPdgCode == 221 || TMath::Abs(lastPdgCode) == 3122 ||
629 TMath::Abs(lastPdgCode) == 3322 || lastPdgCode == -3212 ||
630 TMath::Abs(lastPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // not neutral
631 && TMath::Abs(firstPdgCode) == 3122)))) { // lambda or anti-lambda
632 vertex->SetType(AliAODVertex::kCascade);
638 else if (mother->GetNDaughters() > 2) {
640 vertex->SetType(AliAODVertex::kMulti);
645 vertex->SetType(AliAODVertex::kUndef);
648 // LocalWords: SetCharge