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 // global arrays and pointers
61 Float_t *cov = NULL; // set to NULL because not provided
62 Float_t *pid = NULL; // set to NULL because not provided
63 AliAODVertex *primary = NULL;
64 AliAODVertex *secondary = NULL;
65 AliAODTrack *currTrack = NULL;
67 void CreateAODfromKineTree(const char *inFileName,
68 const char *outFileName) {
69 printf("This macro works only correctly in comiled mode!\n");
70 /* This probem is due to CINT which gets confused if arrays are reused */
72 // create an AliAOD object
73 aod = new AliAODEvent();
74 aod->CreateStdContent();
77 TFile *outFile = TFile::Open(outFileName, "RECREATE");
80 TTree *aodTree = new TTree("AOD", "AliAOD tree");
81 aodTree->Branch(aod->GetList());
83 AliRunLoader *runLoader;
86 runLoader = AliRunLoader::Open(inFileName);
87 if (!runLoader) return;
89 runLoader->LoadHeader();
90 runLoader->LoadKinematics();
92 Int_t nEvents = runLoader->GetNumberOfEvents();
94 // loop over events and fill them
95 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
97 cout << "Event " << iEvent+1 << "/" << nEvents;
98 runLoader->GetEvent(iEvent);
100 AliHeader *aliHeader = runLoader->GetHeader();
101 stack = runLoader->Stack();
102 Int_t nTracks = stack->GetNtrack();
103 Int_t nPrims = stack->GetNprimary();
125 aod->AddHeader(new AliAODHeader(aliHeader->GetRun(),
132 -999., // muon mag. field
143 // Access to the header
144 AliAODHeader *header = aod->GetHeader();
146 // Access to the AOD container of vertices
147 TClonesArray &vertices = *(aod->GetVertices());
154 // Access to the AOD container of tracks
155 TClonesArray &tracks = *(aod->GetTracks());
158 aod->ResetStd(nTracks, 1);
161 for (Int_t iTrack = 0; iTrack < nPrims; ++iTrack) {
163 TParticle *part = stack->Particle(iTrack);
165 //if (part->IsPrimary()) { // this will exclude 'funny' primaries, too
166 if (kTRUE) { // this won't
167 p[0] = part->Px(); p[1] = part->Py(); p[2] = part->Pz();
168 x[0] = part->Vx(); x[1] = part->Vy(); x[2] = part->Vz();
171 // add primary vertex
172 primary = new(vertices[jVertices++])
173 AliAODVertex(x, NULL, -999., NULL, AliAODVertex::kPrimary);
176 // add primary tracks
177 primary->AddDaughter(new(tracks[jTracks++]) AliAODTrack(0, // ID,
185 0, // no ITSClusterMap
188 kFALSE, // no fit preformed
189 AliAODTrack::kPrimary));
190 currTrack = (AliAODTrack*)tracks.Last();
191 SetChargeAndPID(part->GetPdgCode(), currTrack);
192 if (currTrack->Charge() != -99) {
193 if (currTrack->Charge() > 0) {
195 } else if (currTrack->Charge() < 0) {
200 LoopOverSecondaries(part);
202 } // end of track loop
204 header->SetRefMultiplicityPos(nPos);
205 header->SetRefMultiplicityNeg(nNeg);
207 cout << ":: primaries: " << nPrims << " secondaries: " << tracks.GetEntriesFast()-nPrims <<
208 " (pos: " << nPos << ", neg: " << nNeg << "), vertices: " << vertices.GetEntriesFast() <<
209 " (kinks: " << jKinks << ", V0: " << jV0s << ", cascades: " << jCascades <<
210 ", multi: " << jMultis << ")" << endl;
212 cout << " gamma: " << nGamma << " e-: " << nElectron << " e+: " << nPositron << " p: " << nProton <<
213 " pBar: " << nAntiProton << " n: " << nNeutron << " nBar: " << nAntiNeutron << " pi0: " << nPi0 <<
214 " pi+: " << nPiPlus << " pi-: " << nPiMinus << " K0: " << nK0 << " K+: " << nKPlus <<
215 " K-: " << nKMinus << endl;
217 // fill the tree for this event
219 } // end of event loop
221 aodTree->GetUserInfo()->Add(aod);
223 // write the tree to the specified file
224 outFile = aodTree->GetCurrentFile();
232 Int_t LoopOverSecondaries(TParticle *mother) {
234 if (mother->GetNDaughters() > 0) {
236 TClonesArray &vertices = *(aod->GetVertices());
237 TClonesArray &tracks = *(aod->GetTracks());
239 for (Int_t iDaughter = mother->GetFirstDaughter(); iDaughter <= mother->GetLastDaughter(); iDaughter++) {
240 TParticle *part = stack->Particle(iDaughter);
248 if (iDaughter == mother->GetFirstDaughter()) {
249 // add secondary vertex
250 secondary = new(vertices[jVertices++])
251 AliAODVertex(x, NULL, -999., tracks.Last(), AliAODVertex::kUndef);
253 SetVertexType(part, secondary);
256 // add secondary tracks
257 secondary->AddDaughter(new(tracks[jTracks++]) AliAODTrack(0, // ID
265 0, // no cluster map available
268 kFALSE, // no fit performed
269 AliAODTrack::kSecondary));
271 currTrack = (AliAODTrack*)tracks.Last();
272 SetChargeAndPID(part->GetPdgCode(), currTrack);
273 if (currTrack->Charge() != -99) {
274 if (currTrack->Charge() > 0) {
276 } else if (currTrack->Charge() < 0) {
281 LoopOverSecondaries(part);
290 void SetChargeAndPID(Int_t pdgCode, AliAODTrack *track) {
292 Float_t PID[10] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.};
298 PID[AliAODTrack::kUnknown] = 1.;
304 track->SetCharge(-1);
305 PID[AliAODTrack::kElectron] = 1.;
311 track->SetCharge(+1);
312 PID[AliAODTrack::kElectron] = 1.;
318 track->SetCharge(-1);
319 PID[AliAODTrack::kMuon] = 1.;
325 track->SetCharge(+1);
326 PID[AliAODTrack::kMuon] = 1.;
333 PID[AliAODTrack::kUnknown] = 1.;
339 track->SetCharge(+1);
340 PID[AliAODTrack::kPion] = 1.;
346 track->SetCharge(-1);
347 PID[AliAODTrack::kPion] = 1.;
354 PID[AliAODTrack::kUnknown] = 1.;
360 track->SetCharge(+1);
361 PID[AliAODTrack::kKaon] = 1.;
367 track->SetCharge(-1);
368 PID[AliAODTrack::kKaon] = 1.;
375 PID[AliAODTrack::kUnknown] = 1.;
381 track->SetCharge(+1);
382 PID[AliAODTrack::kProton] = 1.;
387 case -2212: // anti-p
388 track->SetCharge(-1);
389 PID[AliAODTrack::kProton] = 1.;
396 PID[AliAODTrack::kUnknown] = 1.;
403 PID[AliAODTrack::kUnknown] = 1.;
408 case -311: // anti-K0
410 PID[AliAODTrack::kUnknown] = 1.;
417 PID[AliAODTrack::kUnknown] = 1.;
423 PID[AliAODTrack::kUnknown] = 1.;
428 track->SetCharge(+1);
429 PID[AliAODTrack::kUnknown] = 1.;
434 track->SetCharge(-1);
435 PID[AliAODTrack::kUnknown] = 1.;
440 track->SetCharge(-1);
441 PID[AliAODTrack::kUnknown] = 1.;
447 PID[AliAODTrack::kUnknown] = 1.;
452 track->SetCharge(-1);
453 PID[AliAODTrack::kUnknown] = 1.;
458 track->SetCharge(-1);
459 PID[AliAODTrack::kUnknown] = 1.;
465 PID[AliAODTrack::kUnknown] = 1.;
469 case -3122: // anti-Lambda
471 PID[AliAODTrack::kUnknown] = 1.;
475 case -3222: // anti-Sigma-
476 track->SetCharge(-1);
477 PID[AliAODTrack::kUnknown] = 1.;
481 case -3212: // anti-Sigma0
483 PID[AliAODTrack::kUnknown] = 1.;
487 case -3112: // anti-Sigma+
488 track->SetCharge(+1);
489 PID[AliAODTrack::kUnknown] = 1.;
493 case -3322: // anti-Xi0
495 PID[AliAODTrack::kUnknown] = 1.;
499 case -3312: // anti-Xi+
500 track->SetCharge(+1);
503 case -3334: // anti-Omega+
504 track->SetCharge(+1);
505 PID[AliAODTrack::kUnknown] = 1.;
510 track->SetCharge(+1);
511 PID[AliAODTrack::kUnknown] = 1.;
516 track->SetCharge(-1);
517 PID[AliAODTrack::kUnknown] = 1.;
523 PID[AliAODTrack::kUnknown] = 1.;
527 case -421: // anti-D0
529 PID[AliAODTrack::kUnknown] = 1.;
534 track->SetCharge(-99);
535 PID[AliAODTrack::kUnknown] = 1.;
543 void SetVertexType(TParticle *part, AliAODVertex *vertex) {
544 // this whole thing doesn't make much sense. but anyhow...
546 TParticle *mother = stack->Particle(part->GetFirstMother());
547 Int_t pdgMother = mother->GetPdgCode();
548 Int_t pdgPart = part->GetPdgCode();
551 if (mother->GetNDaughters() == 2) {
552 Int_t firstPdgCode = stack->Particle(mother->GetFirstDaughter())->GetPdgCode();
553 Int_t lastPdgCode = stack->Particle(mother->GetLastDaughter())->GetPdgCode();
555 if (!(pdgMother == 22 || pdgMother == 111 || pdgMother == 130 ||
556 TMath::Abs(pdgMother) == 2112 || pdgMother == 310 || pdgMother == 221 ||
557 TMath::Abs(pdgMother) == 3122 || TMath::Abs(pdgMother) == 3322 ||
558 pdgMother == -3212 || TMath::Abs(pdgMother) == 421 ||
559 TMath::Abs(pdgMother) == 311) // not neutral
560 && (((firstPdgCode == 22 || firstPdgCode == 111 || firstPdgCode == 130 ||
561 TMath::Abs(firstPdgCode) == 2112 || firstPdgCode == 310 ||
562 firstPdgCode == 221 || TMath::Abs(firstPdgCode) == 3122 ||
563 TMath::Abs(firstPdgCode) == 3322 || firstPdgCode == -3212 ||
564 TMath::Abs(firstPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // neutral
565 && !(lastPdgCode == 22 || lastPdgCode == 111 || lastPdgCode == 130 ||
566 TMath::Abs(lastPdgCode) == 2112 || lastPdgCode == 310 ||
567 lastPdgCode == 221 || TMath::Abs(lastPdgCode) == 3122 ||
568 TMath::Abs(lastPdgCode) == 3322 || lastPdgCode == -3212 ||
569 TMath::Abs(lastPdgCode) == 421 || TMath::Abs(pdgMother) == 311)) // not neutral
570 || !((firstPdgCode == 22 || firstPdgCode == 111 || firstPdgCode == 130 ||
571 TMath::Abs(firstPdgCode) == 2112 || firstPdgCode == 310 ||
572 firstPdgCode == 221 || TMath::Abs(firstPdgCode) == 3122 ||
573 TMath::Abs(firstPdgCode) == 3322 || firstPdgCode == -3212 ||
574 TMath::Abs(firstPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // not neutral
575 && (lastPdgCode == 22 || lastPdgCode == 111 || lastPdgCode == 130 ||
576 TMath::Abs(lastPdgCode) == 2112 || lastPdgCode == 310 ||
577 lastPdgCode == 221 || TMath::Abs(lastPdgCode) == 3122 ||
578 TMath::Abs(lastPdgCode) == 3322 || lastPdgCode == -3212 ||
579 TMath::Abs(lastPdgCode) == 421 || TMath::Abs(pdgMother) == 311)))) { // neutral
581 vertex->SetType(AliAODVertex::kKink);
587 else if (mother->GetNDaughters() == 2) {
588 Int_t firstPdgCode = stack->Particle(mother->GetFirstDaughter())->GetPdgCode();
589 Int_t lastPdgCode = stack->Particle(mother->GetLastDaughter())->GetPdgCode();
591 if ((pdgMother == 22 || pdgMother == 111 || pdgMother == 130 ||
592 TMath::Abs(pdgMother) == 2112 || pdgMother == 310 ||
593 pdgMother == 221 || TMath::Abs(pdgMother) == 3122 ||
594 TMath::Abs(pdgMother) == 3322 || pdgMother == -3212 ||
595 TMath::Abs(pdgMother) == 421 || TMath::Abs(pdgMother) == 311) // neutral
596 && !(lastPdgCode == 22 || lastPdgCode == 111 || lastPdgCode == 130 ||
597 TMath::Abs(lastPdgCode) == 2112 || lastPdgCode == 310 ||
598 lastPdgCode == 221 || TMath::Abs(lastPdgCode) == 3122 ||
599 TMath::Abs(lastPdgCode) == 3322 || lastPdgCode == -3212 ||
600 TMath::Abs(lastPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // not neutral
601 && !(firstPdgCode == 22 || firstPdgCode == 111 || firstPdgCode == 130 ||
602 TMath::Abs(firstPdgCode) == 2112 || firstPdgCode == 310 ||
603 firstPdgCode == 221 || TMath::Abs(firstPdgCode) == 3122 ||
604 TMath::Abs(firstPdgCode) == 3322 || firstPdgCode == -3212 ||
605 TMath::Abs(firstPdgCode) == 421 || TMath::Abs(pdgMother) == 311)) { // not neutral
607 vertex->SetType(AliAODVertex::kV0);
613 else if (mother->GetNDaughters() == 2) {
614 Int_t firstPdgCode = stack->Particle(mother->GetFirstDaughter())->GetPdgCode();
615 Int_t lastPdgCode = stack->Particle(mother->GetLastDaughter())->GetPdgCode();
617 if ((TMath::Abs(pdgMother) == 3334 || TMath::Abs(pdgMother) == 3312 || TMath::Abs(pdgMother) == 3322) &&
618 (TMath::Abs(pdgPart) == 3122 || TMath::Abs(pdgPart) == 211 || TMath::Abs(pdgPart) == 321)
619 && ((!(firstPdgCode == 22 || firstPdgCode == 111 || firstPdgCode == 130 ||
620 TMath::Abs(firstPdgCode) == 2112 || firstPdgCode == 310 ||
621 firstPdgCode == 221 || TMath::Abs(firstPdgCode) == 3122 ||
622 TMath::Abs(firstPdgCode) == 3322 || firstPdgCode == -3212 ||
623 TMath::Abs(firstPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // not neutral
624 && TMath::Abs(lastPdgCode) == 3122) // labmda or anti-lambda
625 || ((!(lastPdgCode == 22 || lastPdgCode == 111 || lastPdgCode == 130 ||
626 TMath::Abs(lastPdgCode) == 2112 || lastPdgCode == 310 ||
627 lastPdgCode == 221 || TMath::Abs(lastPdgCode) == 3122 ||
628 TMath::Abs(lastPdgCode) == 3322 || lastPdgCode == -3212 ||
629 TMath::Abs(lastPdgCode) == 421 || TMath::Abs(pdgMother) == 311) // not neutral
630 && TMath::Abs(firstPdgCode) == 3122)))) { // lambda or anti-lambda
631 vertex->SetType(AliAODVertex::kCascade);
637 else if (mother->GetNDaughters() > 2) {
639 vertex->SetType(AliAODVertex::kMulti);
644 vertex->SetType(AliAODVertex::kUndef);
647 // LocalWords: SetCharge