1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 //_________________________________________________________________________
17 // Class for analysis utils for MC data
18 // stored in stack or event header.
20 // - method to check the origin of a given track/cluster
21 // - method to obtain the generated jets
23 //*-- Author: Gustavo Conesa (LNF-INFN)
24 //////////////////////////////////////////////////////////////////////////////
27 // --- ROOT system ---
30 #include "TParticle.h"
31 #include "TDatabasePDG.h"
34 //---- ANALYSIS system ----
35 #include "AliMCAnalysisUtils.h"
36 #include "AliCaloTrackReader.h"
38 #include "AliGenPythiaEventHeader.h"
39 #include "AliAODMCParticle.h"
41 ClassImp(AliMCAnalysisUtils)
43 //________________________________________
44 AliMCAnalysisUtils::AliMCAnalysisUtils() :
49 fMCGenerator("PYTHIA")
54 //_______________________________________
55 AliMCAnalysisUtils::~AliMCAnalysisUtils()
57 // Remove all pointers.
65 //_____________________________________________________________________________________________
66 Int_t AliMCAnalysisUtils::CheckCommonAncestor(const Int_t index1, const Int_t index2,
67 const AliCaloTrackReader* reader,
68 Int_t & ancPDG, Int_t & ancStatus,
69 TLorentzVector & momentum, TVector3 & prodVertex)
71 //Check the first common ancestor of 2 clusters, given the most likely labels of the primaries generating such clusters.
79 if(label1[0]==label2[0])
81 //printf("AliMCAnalysisUtils::CheckCommonAncestor() - Already the same label: %d\n",label1[0]);
87 if(reader->ReadAODMCParticles())
89 TClonesArray * mcparticles = reader->GetAODMCParticles();
91 Int_t label=label1[0];
92 if(label < 0) return -1;
94 while(label > -1 && counter1 < 99)
97 AliAODMCParticle * mom = (AliAODMCParticle *) mcparticles->At(label);
100 label = mom->GetMother() ;
101 label1[counter1]=label;
103 //printf("\t counter %d, label %d\n", counter1,label);
106 //printf("Org label2=%d,\n",label2[0]);
108 if(label < 0) return -1;
110 while(label > -1 && counter2 < 99)
113 AliAODMCParticle * mom = (AliAODMCParticle *) mcparticles->At(label);
116 label = mom->GetMother() ;
117 label2[counter2]=label;
119 //printf("\t counter %d, label %d\n", counter2,label);
123 { //Kine stack from ESDs
124 AliStack * stack = reader->GetStack();
126 Int_t label=label1[0];
127 while(label > -1 && counter1 < 99)
130 TParticle * mom = stack->Particle(label);
133 label = mom->GetFirstMother() ;
134 label1[counter1]=label;
136 //printf("\t counter %d, label %d\n", counter1,label);
139 //printf("Org label2=%d,\n",label2[0]);
142 while(label > -1 && counter2 < 99)
145 TParticle * mom = stack->Particle(label);
148 label = mom->GetFirstMother() ;
149 label2[counter2]=label;
151 //printf("\t counter %d, label %d\n", counter2,label);
153 }// Kine stack from ESDs
154 }//First labels not the same
156 if((counter1==99 || counter2==99) && fDebug >=0)
157 printf("AliMCAnalysisUtils::CheckCommonAncestor() - Genealogy too large c1: %d, c2= %d\n", counter1, counter2);
158 //printf("CheckAncestor:\n");
160 Int_t commonparents = 0;
162 //printf("counters %d %d \n",counter1, counter2);
163 for (Int_t c1 = 0; c1 < counter1; c1++)
165 for (Int_t c2 = 0; c2 < counter2; c2++)
167 if(label1[c1]==label2[c2] && label1[c1]>-1)
169 ancLabel = label1[c1];
172 if(reader->ReadAODMCParticles())
174 AliAODMCParticle * mom = (AliAODMCParticle *) reader->GetAODMCParticles()->At(label1[c1]);
178 ancPDG = mom->GetPdgCode();
179 ancStatus = mom->GetStatus();
180 momentum.SetPxPyPzE(mom->Px(),mom->Py(),mom->Pz(),mom->E());
181 prodVertex.SetXYZ(mom->Xv(),mom->Yv(),mom->Zv());
186 TParticle * mom = (reader->GetStack())->Particle(label1[c1]);
190 ancPDG = mom->GetPdgCode();
191 ancStatus = mom->GetStatusCode();
192 mom->Momentum(momentum);
193 prodVertex.SetXYZ(mom->Vx(),mom->Vy(),mom->Vz());
197 //First ancestor found, end the loops
201 }//second cluster loop
202 }//first cluster loop
208 momentum.SetXYZT(0,0,0,0);
209 prodVertex.SetXYZ(-10,-10,-10);
215 //_____________________________________________________________________
216 Int_t AliMCAnalysisUtils::CheckOrigin(const Int_t * label,
218 const AliCaloTrackReader* reader)
220 //Play with the montecarlo particles if available
224 printf("AliMCAnalysisUtils::CheckOrigin(nlabel<=0) - No MC labels available, please check!!!\n");
228 //Select where the information is, ESD-galice stack or AOD mcparticles branch
229 if(reader->ReadStack()){
230 tag = CheckOriginInStack(label, nlabels, reader->GetStack());
232 else if(reader->ReadAODMCParticles()){
233 tag = CheckOriginInAOD(label, nlabels, reader->GetAODMCParticles());
239 //_____________________________________________________________________
240 Int_t AliMCAnalysisUtils::CheckOrigin(const Int_t label,
241 const AliCaloTrackReader* reader)
243 //Play with the montecarlo particles if available
247 printf("AliMCAnalysisUtils::CheckOrigin(label<0) - No MC labels available, please check!!!\n");
251 Int_t labels[]={label};
253 //Select where the information is, ESD-galice stack or AOD mcparticles branch
254 if(reader->ReadStack()){
255 tag = CheckOriginInStack(labels, 1,reader->GetStack());
257 else if(reader->ReadAODMCParticles()){
258 tag = CheckOriginInAOD(labels, 1,reader->GetAODMCParticles());
264 //_________________________________________________________________
265 Int_t AliMCAnalysisUtils::CheckOriginInStack(const Int_t *labels,
269 // Play with the MC stack if available. Tag particles depending on their origin.
270 // Do same things as in CheckOriginInAOD but different input.
272 //generally speaking, label is the MC label of a reconstructed
273 //entity (track, cluster, etc) for which we want to know something
274 //about its heritage, but one can also use it directly with stack
275 //particles not connected to reconstructed entities
280 printf("AliMCAnalysisUtils::CheckOriginInStack() - Stack is not available, check analysis settings in configuration file, STOP!!\n");
285 Int_t label=labels[0];//Most significant particle contributing to the cluster
287 if(label >= 0 && label < stack->GetNtrack())
289 //MC particle of interest is the "mom" of the entity
290 TParticle * mom = stack->Particle(label);
292 Int_t mPdgSign = mom->GetPdgCode();
293 Int_t mPdg = TMath::Abs(mPdgSign);
294 Int_t mStatus = mom->GetStatusCode() ;
295 Int_t iParent = mom->GetFirstMother() ;
297 if(fDebug > 0 && label < 8 && fMCGenerator!="") printf("AliMCAnalysisUtils::CheckOriginInStack() - Mother is parton %d\n",iParent);
299 //GrandParent of the entity
300 TParticle * parent = NULL;
305 parent = stack->Particle(iParent);
309 pPdg = TMath::Abs(parent->GetPdgCode());
310 pStatus = parent->GetStatusCode();
313 else if(fDebug > 0 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - Parent with label %d\n",iParent);
317 printf("AliMCAnalysisUtils::CheckOriginInStack() - Cluster most contributing mother and its parent: \n");
318 printf("\t Mother label %d, pdg %d, status %d\n",iMom, mPdg, mStatus);
319 printf("\t Parent label %d, pdg %d, status %d\n",iParent, pPdg, pStatus);
322 //Check if "mother" of entity is converted, if not, get the first non converted mother
323 if((mPdg == 22 || mPdg == 11) && (pPdg == 22 || pPdg == 11) && mStatus == 0)
325 SetTagBit(tag,kMCConversion);
327 //Check if the mother is photon or electron with status not stable
328 while ((pPdg == 22 || pPdg == 11) && mStatus != 1)
331 iMom = mom->GetFirstMother();
332 mom = stack->Particle(iMom);
333 mPdgSign = mom->GetPdgCode();
334 mPdg = TMath::Abs(mPdgSign);
335 mStatus = mom->GetStatusCode() ;
336 iParent = mom->GetFirstMother() ;
338 if(fDebug > 0 && label < 8 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - Mother is parton %d\n",iParent);
343 parent = stack->Particle(iParent);
346 pPdg = TMath::Abs(parent->GetPdgCode());
347 pStatus = parent->GetStatusCode();
350 else {// in case of gun/box simulations
359 printf("AliMCAnalysisUtils::CheckOriginInStack() - Converted photon/electron: \n");
360 printf("\t Mother label %d, pdg %d, status %d\n",iMom, mPdg, mStatus);
361 printf("\t Parent label %d, pdg %d, status %d\n",iParent, pPdg, pStatus);
364 }//mother and parent are electron or photon and have status 0
365 else if((mPdg == 22 || mPdg == 11) && mStatus == 0)
367 //Still a conversion but only one electron/photon generated. Just from hadrons but not decays.
368 if(pPdg == 2112 || pPdg == 211 || pPdg == 321 ||
369 pPdg == 2212 || pPdg == 130 || pPdg == 13 )
371 SetTagBit(tag,kMCConversion);
372 iMom = mom->GetFirstMother();
373 mom = stack->Particle(iMom);
374 mPdgSign = mom->GetPdgCode();
375 mPdg = TMath::Abs(mPdgSign);
379 printf("AliMCAnalysisUtils::CheckOriginInStack() - Converted hadron: \n");
380 printf("\t Mother label %d, pdg %d, status %d\n",iMom, mPdg, mStatus);
384 //Comment for the next lines, we do not check the parent of the hadron for the moment.
385 //iParent = mom->GetFirstMother() ;
386 //if(fDebug > 0 && label < 8 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - Mother is parton %d\n",iParent);
390 // parent = stack->Particle(iParent);
391 // pPdg = TMath::Abs(parent->GetPdgCode());
394 // conversion into electrons/photons checked
396 //first check for typical charged particles
397 if (mPdg == 13) SetTagBit(tag,kMCMuon);
398 else if(mPdg == 211) SetTagBit(tag,kMCPion);
399 else if(mPdg == 321) SetTagBit(tag,kMCKaon);
400 else if(mPdgSign == 2212) SetTagBit(tag,kMCProton);
401 else if(mPdgSign == -2212) SetTagBit(tag,kMCAntiProton);
402 else if(mPdgSign == 2112) SetTagBit(tag,kMCNeutron);
403 else if(mPdgSign == -2112) SetTagBit(tag,kMCAntiNeutron);
405 //check for pi0 and eta (shouldn't happen unless their decays were turned off)
408 SetTagBit(tag,kMCPi0Decay);
410 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - First mother is directly pi0, not decayed by generator \n");
412 CheckOverlapped2GammaDecay(labels,nlabels, iMom, stack, tag); //set to kMCPi0 if 2 gammas in same cluster
416 SetTagBit(tag,kMCEtaDecay);
418 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - First mother is directly eta, not decayed by generator \n");
420 CheckOverlapped2GammaDecay(labels,nlabels, iMom, stack, tag); //set to kMCEta if 2 gammas in same cluster
425 SetTagBit(tag,kMCPhoton);
427 { //undecayed particle
428 if(fMCGenerator == "PYTHIA")
430 if(iParent < 8 && iParent > 5)
432 if(pPdg == 22) SetTagBit(tag,kMCPrompt);
433 else SetTagBit(tag,kMCFragmentation);
435 else if(iParent <= 5)
437 SetTagBit(tag, kMCISR); //Initial state radiation
439 else if(pStatus == 11)
443 SetTagBit(tag,kMCPi0Decay);
445 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - PYTHIA pi0 decay photon, parent pi0 with status 11 \n");
447 CheckOverlapped2GammaDecay(labels,nlabels, iParent, stack, tag); //set to kMCPi0 if 2 gammas in same cluster
449 else if (pPdg == 221)
451 SetTagBit(tag, kMCEtaDecay);
453 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - PYTHIA eta decay photon, parent pi0 with status 11 \n");
455 CheckOverlapped2GammaDecay(labels,nlabels, iParent, stack, tag);//set to kMCEta if 2 gammas in same cluster
457 else SetTagBit(tag,kMCOtherDecay);
461 if(fDebug > 1 && parent) printf("AliMCAnalysisUtils::CheckOrigingInStack() - what is it in PYTHIA? Wrong generator setting? Mother mPdg %d, status %d \n Parent iParent %d, pPdg %d %s, status %d\n",
462 mPdg, mStatus,iParent, pPdg, parent->GetName(),pStatus);
466 SetTagBit(tag,kMCPi0Decay);
468 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - PYTHIA pi0 decay photon, parent pi0 with status 11 \n");
470 CheckOverlapped2GammaDecay(labels,nlabels, iParent, stack, tag); //set to kMCPi0 if 2 gammas in same cluster
472 else if (pPdg == 221)
474 SetTagBit(tag, kMCEtaDecay);
476 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - PYTHIA eta decay photon, parent pi0 with status 11 \n");
478 CheckOverlapped2GammaDecay(labels,nlabels, iParent, stack, tag);//set to kMCEta if 2 gammas in same cluster
480 else SetTagBit(tag,kMCOtherDecay);
484 else if(fMCGenerator == "HERWIG")
492 if(parent->GetFirstMother()<=5) break;
493 iParent = parent->GetFirstMother();
494 parent=stack->Particle(iParent);
495 pStatus= parent->GetStatusCode();
496 pPdg = TMath::Abs(parent->GetPdgCode());
498 }//Look for the parton
500 if(iParent < 8 && iParent > 5)
502 if(pPdg == 22) SetTagBit(tag,kMCPrompt);
503 else SetTagBit(tag,kMCFragmentation);
505 else SetTagBit(tag,kMCISR);//Initial state radiation
510 SetTagBit(tag,kMCPi0Decay);
512 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - HERWIG pi0 decay photon \n");
514 CheckOverlapped2GammaDecay(labels,nlabels, iParent, stack, tag); //set to kMCPi0 if 2 gammas in same cluster
516 else if (pPdg == 221)
518 SetTagBit(tag,kMCEtaDecay);
520 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - HERWIG eta decay photon \n");
522 CheckOverlapped2GammaDecay(labels,nlabels, iParent, stack, tag); //set to kMCEta if 2 gammas in same cluster
524 else SetTagBit(tag,kMCOtherDecay);
528 else SetTagBit(tag,kMCUnknown);
530 }//Status 1 : created by event generator
532 else if(mStatus == 0)
536 SetTagBit(tag,kMCPi0Decay);
538 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - Transport MC pi0 decay photon \n");
540 CheckOverlapped2GammaDecay(labels,nlabels, iParent, stack, tag); //set to kMCPi0 if 2 gammas in same cluster
542 else if (pPdg == 221)
544 SetTagBit(tag,kMCEtaDecay);
546 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInStack() - Transport MC eta decay photon \n");
548 CheckOverlapped2GammaDecay(labels,nlabels, iParent, stack, tag); //set to kMCEta if 2 gammas in same cluster
550 else SetTagBit(tag,kMCOtherDecay);
551 }//status 0 : geant generated
555 //Electron check. Where did that electron come from?
556 else if(mPdg == 11){ //electron
557 if(pPdg == 11 && parent)
559 Int_t iGrandma = parent->GetFirstMother();
562 TParticle* gma = (TParticle*)stack->Particle(iGrandma); //get mother
563 Int_t gPdg = TMath::Abs(gma->GetPdgCode());
565 if (gPdg == 23) { SetTagBit(tag,kMCZDecay); } //parent is Z-boson
566 else if (gPdg == 24) { SetTagBit(tag,kMCWDecay); } //parent is W-boson
570 SetTagBit(tag,kMCElectron);
572 if(fDebug > 0) printf("AliMCAnalysisUtils::CheckOriginInStack() - Checking ancestors of electrons\n");
574 if (pPdg == 111) { SetTagBit(tag,kMCPi0Decay); } //Pi0 Dalitz decay
575 else if (pPdg == 221) { SetTagBit(tag,kMCEtaDecay); } //Eta Dalitz decay
576 else if((499 < pPdg && pPdg < 600)||(4999 < pPdg && pPdg < 6000)) { SetTagBit(tag,kMCEFromB); } //b-->e decay
577 else if((399 < pPdg && pPdg < 500)||(3999 < pPdg && pPdg < 5000)) { //check charm decay
580 Int_t iGrandma = parent->GetFirstMother();
583 TParticle* gma = (TParticle*)stack->Particle(iGrandma); //get mother of charm
584 Int_t gPdg = TMath::Abs(gma->GetPdgCode());
585 if((499 < gPdg && gPdg < 600)||(4999 < gPdg && gPdg < 6000)) SetTagBit(tag,kMCEFromCFromB); //b-->c-->e
586 else SetTagBit(tag,kMCEFromC); //c-->e
588 else SetTagBit(tag,kMCEFromC); //c-->e
593 //if it is not from any of the above, where is it from?
594 if(pPdg > 10000) SetTagBit(tag,kMCUnknown);
596 else SetTagBit(tag,kMCOtherDecay);
598 if(fDebug > 0 && parent) printf("AliMCAnalysisUtils::CheckOriginInStack() - Status %d Electron from other origin: %s (pPdg = %d) %s (mpdg = %d)\n",mStatus,parent->GetName(),pPdg,mom->GetName(),mPdg);
601 //Cluster was made by something else
605 printf("AliMCAnalysisUtils::CheckOriginInStack() - \tSetting kMCUnknown for cluster from %s (pdg = %d, Parent pdg = %d)\n",
606 mom->GetName(),mPdg,pPdg);
608 SetTagBit(tag,kMCUnknown);
613 if(label < 0 && (fDebug >= 0))
614 printf("AliMCAnalysisUtils::CheckOriginInStack() *** bad label or no stack ***: label %d \n", label);
616 if(label >= stack->GetNtrack() && (fDebug >= 0))
617 printf("AliMCAnalysisUtils::CheckOriginInStack() *** large label ***: label %d, n tracks %d \n", label, stack->GetNtrack());
619 SetTagBit(tag,kMCUnknown);
627 //_________________________________________________________________________
628 Int_t AliMCAnalysisUtils::CheckOriginInAOD(const Int_t *labels,
630 const TClonesArray *mcparticles)
632 // Play with the MCParticles in AOD if available. Tag particles depending on their origin.
633 // Do same things as in CheckOriginInStack but different input.
637 printf("AliMCAnalysisUtils::CheckOriginInAOD() - AODMCParticles is not available, check analysis settings in configuration file!!\n");
642 Int_t label=labels[0];//Most significant particle contributing to the cluster
644 Int_t nprimaries = mcparticles->GetEntriesFast();
645 if(label >= 0 && label < nprimaries)
648 AliAODMCParticle * mom = (AliAODMCParticle *) mcparticles->At(label);
650 Int_t mPdgSign = mom->GetPdgCode();
651 Int_t mPdg = TMath::Abs(mPdgSign);
652 Int_t iParent = mom->GetMother() ;
654 if(fDebug > 0 && label < 8 && fMCGenerator!="") printf("AliMCAnalysisUtils::CheckOriginInAOD() - Mother is parton %d\n",iParent);
657 AliAODMCParticle * parent = NULL ;
661 parent = (AliAODMCParticle *) mcparticles->At(iParent);
662 pPdg = TMath::Abs(parent->GetPdgCode());
664 else if(fDebug > 0 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Parent with label %d\n",iParent);
668 printf("AliMCAnalysisUtils::CheckOriginInAOD() - Cluster most contributing mother and its parent: \n");
670 printf("\t Mother label %d, pdg %d, Primary? %d, Physical Primary? %d\n",
671 iMom, mPdg, mom->IsPrimary(), mom->IsPhysicalPrimary());
674 printf("\t Parent label %d, pdg %d, Primary? %d, Physical Primary? %d\n",
675 iParent, pPdg, parent->IsPrimary(), parent->IsPhysicalPrimary());
678 //Check if mother is converted, if not, get the first non converted mother
679 if((mPdg == 22 || mPdg == 11) && (pPdg == 22 || pPdg == 11) && !mom->IsPrimary())
681 SetTagBit(tag,kMCConversion);
683 //Check if the mother is photon or electron with status not stable
684 while ((pPdg == 22 || pPdg == 11) && !mom->IsPhysicalPrimary())
687 iMom = mom->GetMother();
688 mom = (AliAODMCParticle *) mcparticles->At(iMom);
689 mPdgSign = mom->GetPdgCode();
690 mPdg = TMath::Abs(mPdgSign);
691 iParent = mom->GetMother() ;
692 if(fDebug > 0 && label < 8 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Mother is parton %d\n",iParent);
695 if(iParent >= 0 && parent)
697 parent = (AliAODMCParticle *) mcparticles->At(iParent);
698 pPdg = TMath::Abs(parent->GetPdgCode());
700 // printf("\t While Mother label %d, pdg %d, Primary? %d, Physical Primary? %d\n",iMom, mPdg, mom->IsPrimary(), mom->IsPhysicalPrimary());
701 // printf("\t While Parent label %d, pdg %d, Primary? %d, Physical Primary? %d\n",iParent, pPdg, parent->IsPrimary(), parent->IsPhysicalPrimary());
707 printf("AliMCAnalysisUtils::CheckOriginInAOD() - Converted photon/electron : \n");
709 printf("\t Mother label %d, pdg %d, Primary? %d, Physical Primary? %d\n",
710 iMom, mPdg, mom->IsPrimary(), mom->IsPhysicalPrimary());
713 printf("\t Parent label %d, pdg %d, Primary? %d, Physical Primary? %d\n",
714 iParent, pPdg, parent->IsPrimary(), parent->IsPhysicalPrimary());
717 }//mother and parent are electron or photon and have status 0 and parent is photon or electron
718 else if((mPdg == 22 || mPdg == 11) && !mom->IsPrimary())
720 //Still a conversion but only one electron/photon generated. Just from hadrons
721 if(pPdg == 2112 || pPdg == 211 || pPdg == 321 ||
722 pPdg == 2212 || pPdg == 130 || pPdg == 13 )
724 SetTagBit(tag,kMCConversion);
725 iMom = mom->GetMother();
726 mom = (AliAODMCParticle *) mcparticles->At(iMom);
727 mPdgSign = mom->GetPdgCode();
728 mPdg = TMath::Abs(mPdgSign);
732 printf("AliMCAnalysisUtils::CheckOriginInAOD() - Converted hadron : \n");
733 printf("\t Mother label %d, pdg %d, Primary? %d, Physical Primary? %d\n",iMom, mPdg, mom->IsPrimary(), mom->IsPhysicalPrimary());
737 //Comment for next lines, we do not check the parent of the hadron for the moment.
738 //iParent = mom->GetMother() ;
739 //if(fDebug > 0 && label < 8 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Mother is parton %d\n",iParent);
743 // parent = (AliAODMCParticle *) mcparticles->At(iParent);
744 // pPdg = TMath::Abs(parent->GetPdgCode());
748 //printf("Final mother mPDG %d\n",mPdg);
750 // conversion into electrons/photons checked
752 //first check for typical charged particles
753 if (mPdg == 13) SetTagBit(tag,kMCMuon);
754 else if(mPdg == 211) SetTagBit(tag,kMCPion);
755 else if(mPdg == 321) SetTagBit(tag,kMCKaon);
756 else if(mPdgSign == 2212) SetTagBit(tag,kMCProton);
757 else if(mPdgSign == 2112) SetTagBit(tag,kMCNeutron);
758 else if(mPdgSign == -2212) SetTagBit(tag,kMCAntiProton);
759 else if(mPdgSign == -2112) SetTagBit(tag,kMCAntiNeutron);
761 //check for pi0 and eta (shouldn't happen unless their decays were turned off)
764 SetTagBit(tag,kMCPi0Decay);
766 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - First mother is directly pi0, not decayed by generator \n");
768 CheckOverlapped2GammaDecay(labels,nlabels, iMom, mcparticles, tag); //set to kMCPi0 if 2 gammas in same cluster
772 SetTagBit(tag,kMCEtaDecay);
774 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - First mother is directly eta, not decayed by generator \n");
776 CheckOverlapped2GammaDecay(labels,nlabels, iMom, mcparticles, tag); //set to kMCEta if 2 gammas in same cluster
781 SetTagBit(tag,kMCPhoton);
782 if(mom->IsPhysicalPrimary() && (fMCGenerator=="PYTHIA" || fMCGenerator=="HERWIG")) //undecayed particle
784 if(iParent < 8 && iParent > 5 )
786 if(pPdg == 22) SetTagBit(tag,kMCPrompt);
787 else SetTagBit(tag,kMCFragmentation);
789 else if(iParent <= 5 && (fMCGenerator=="PYTHIA" || fMCGenerator=="HERWIG"))
791 SetTagBit(tag, kMCISR); //Initial state radiation
793 else if(parent && parent->IsPrimary() && !parent->IsPhysicalPrimary())
797 SetTagBit(tag,kMCPi0Decay);
799 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Generator pi0 decay photon \n");
801 CheckOverlapped2GammaDecay(labels,nlabels, iParent, mcparticles, tag); //set to kMCPi0 if 2 gammas in same cluster
803 else if (pPdg == 221)
805 SetTagBit(tag, kMCEtaDecay);
807 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Generator eta decay photon \n");
809 CheckOverlapped2GammaDecay(labels,nlabels, iParent, mcparticles, tag); //set to kMCEta if 2 gammas in same cluster
811 else SetTagBit(tag,kMCOtherDecay);
816 printf("AliMCAnalysisUtils::CheckOriginInAOD() - what is it? Mother mPdg %d, is primary? %d, is physical %d \n Parent iParent %d, pPdg %d, is primary? %d, is physical? %d\n",
817 mPdg, mom->IsPrimary(), mom->IsPhysicalPrimary(),iParent, pPdg,parent->IsPrimary(), parent->IsPhysicalPrimary());
819 SetTagBit(tag,kMCOtherDecay);//Check
822 else if(!mom->IsPrimary())
826 SetTagBit(tag,kMCPi0Decay);
828 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Transport MC pi0 decay photon \n");
830 CheckOverlapped2GammaDecay(labels,nlabels, iParent, mcparticles, tag); //set to kMCPi0 if 2 gammas in same cluster
832 else if (pPdg == 221)
834 SetTagBit(tag,kMCEtaDecay);
836 if(fDebug > 2 ) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Transport MC eta decay photon \n");
838 CheckOverlapped2GammaDecay(labels,nlabels, iParent, mcparticles, tag); //set to kMCEta if 2 gammas in same cluster
840 else SetTagBit(tag,kMCOtherDecay);
841 }//not primary : geant generated, decays
844 //printf("UNKNOWN 1, mom pdg %d, primary %d, physical primary %d; parent %d, pdg %d, primary %d, physical primary %d \n",
845 //mPdg, mom->IsPrimary(), mom->IsPhysicalPrimary(), iParent, pPdg, parent->IsPrimary(), parent->IsPhysicalPrimary());
846 SetTagBit(tag,kMCUnknown);
850 //Electron check. Where did that electron come from?
853 if(pPdg == 11 && parent)
855 Int_t iGrandma = parent->GetMother();
858 AliAODMCParticle* gma = (AliAODMCParticle*)mcparticles->At(iGrandma);
859 Int_t gPdg = TMath::Abs(gma->GetPdgCode());
861 if (gPdg == 23) { SetTagBit(tag,kMCZDecay); } //parent is Z-boson
862 else if (gPdg == 24) { SetTagBit(tag,kMCWDecay); } //parent is W-boson
866 SetTagBit(tag,kMCElectron);
868 if (fDebug > 0) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Checking ancestors of electrons");
869 if (pPdg == 111) { SetTagBit(tag,kMCPi0Decay); } //Pi0 Dalitz decay
870 else if (pPdg == 221) { SetTagBit(tag,kMCEtaDecay); } //Eta Dalitz decay
871 else if((499 < pPdg && pPdg < 600)||(4999 < pPdg && pPdg < 6000)) { SetTagBit(tag,kMCEFromB);} //b-hadron decay
872 else if((399 < pPdg && pPdg < 500)||(3999 < pPdg && pPdg < 5000))
873 { //c-hadron decay check
876 Int_t iGrandma = parent->GetMother();
879 AliAODMCParticle* gma = (AliAODMCParticle*)mcparticles->At(iGrandma); //charm's mother
880 Int_t gPdg = TMath::Abs(gma->GetPdgCode());
881 if((499 < gPdg && gPdg < 600)||(4999 < gPdg && gPdg < 6000)) SetTagBit(tag,kMCEFromCFromB); //b-->c-->e decay
882 else SetTagBit(tag,kMCEFromC); //c-hadron decay
884 else SetTagBit(tag,kMCEFromC); //c-hadron decay
887 { //prompt or other decay
888 TParticlePDG* foo = TDatabasePDG::Instance()->GetParticle(pPdg);
889 TParticlePDG* foo1 = TDatabasePDG::Instance()->GetParticle(mPdg);
891 if(fDebug > 0) printf("AliMCAnalysisUtils::CheckOriginInAOD() - Electron from other origin: %s (pPdg = %d) %s (mPdg = %d)\n",
892 foo->GetName(), pPdg,foo1->GetName(),mPdg);
894 if(pPdg > 10000) SetTagBit(tag,kMCUnknown);
895 else SetTagBit(tag,kMCOtherDecay);
898 //cluster was made by something else
901 if(fDebug > 0) printf("AliMCAnalysisUtils::CheckOriginInAOD() - \tSetting kMCUnknown for cluster with pdg = %d, Parent pdg = %d\n",
903 SetTagBit(tag,kMCUnknown);
908 if(label < 0 && (fDebug >= 0) )
909 printf("AliMCAnalysisUtils::CheckOriginInAOD() *** bad label or no mcparticles ***: label %d \n", label);
911 if(label >= mcparticles->GetEntriesFast() && (fDebug >= 0) )
912 printf("AliMCAnalysisUtils::CheckOriginInAOD() *** large label ***: label %d, n tracks %d \n", label, mcparticles->GetEntriesFast());
914 SetTagBit(tag,kMCUnknown);
922 //_________________________________________________________________________
923 void AliMCAnalysisUtils::CheckOverlapped2GammaDecay(const Int_t *labels,
925 const Int_t mesonIndex,
929 //Check if cluster is formed from the contribution of 2 decay photons from pi0 or eta. Input in stack
931 if(labels[0] < 0 || labels[0] > stack->GetNtrack() || nlabels <= 1) {
932 if(fDebug > 2) printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - Exit : label[0] %d, n primaries %d, nlabels %d \n",
933 labels[0],stack->GetNtrack(), nlabels);
937 TParticle * meson = stack->Particle(mesonIndex);
938 Int_t mesonPdg = meson->GetPdgCode();
939 if(mesonPdg!=111 && mesonPdg!=221)
941 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - Wrong pi0/eta PDG : %d \n",mesonPdg);
945 if(fDebug > 2) printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - %s, label %d\n",meson->GetName(), mesonIndex);
947 //Check if meson decayed into 2 daughters or if both were kept.
948 if(meson->GetNDaughters() != 2)
951 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - Not overalapped. Number of daughters is %d, not 2 \n",meson->GetNDaughters());
956 Int_t iPhoton0 = meson->GetDaughter(0);
957 Int_t iPhoton1 = meson->GetDaughter(1);
958 TParticle *photon0 = stack->Particle(iPhoton0);
959 TParticle *photon1 = stack->Particle(iPhoton1);
961 //Check if both daughters are photons
962 if(photon0->GetPdgCode() != 22 || photon1->GetPdgCode()!=22)
965 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - Not overalapped. PDG: daughter 1 = %d, of daughter 2 = %d \n",photon0->GetPdgCode(),photon1->GetPdgCode());
970 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - Daughter labels : photon0 = %d, photon1 = %d \n",iPhoton0,iPhoton1);
972 //Check if both photons contribute to the cluster
973 Bool_t okPhoton0 = kFALSE;
974 Bool_t okPhoton1 = kFALSE;
976 if(fDebug > 3) printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - Labels loop:\n");
978 Bool_t conversion = kFALSE;
980 for(Int_t i = 0; i < nlabels; i++)
982 if(fDebug > 3) printf("\t at begin:label %d/%d: %d, ok? photon1 %d, photon2 %d\n", i+1, nlabels, labels[i], okPhoton0, okPhoton1);
984 //If we already found both, break the loop
985 if(okPhoton0 && okPhoton1) break;
987 Int_t index = labels[i];
988 if (iPhoton0 == index)
993 else if (iPhoton1 == index)
999 //Trace back the mother in case it was a conversion
1001 if(index >= stack->GetNtrack())
1003 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) Particle index %d larger than size of list %d !!\n",
1004 index,stack->GetNtrack());
1008 TParticle * daught = stack->Particle(index);
1009 Int_t tmpindex = daught->GetFirstMother();
1010 if(fDebug > 3) printf("\t Conversion? : mother %d\n",tmpindex);
1013 //MC particle of interest is the mother
1014 if(fDebug > 3) printf("\t \t parent index %d\n",tmpindex);
1015 daught = stack->Particle(tmpindex);
1016 if (iPhoton0 == tmpindex)
1022 else if (iPhoton1 == tmpindex)
1029 tmpindex = daught->GetFirstMother();
1031 }//While to check if pi0/eta daughter was one of these contributors to the cluster
1033 if(i == 0 && (!okPhoton0 && !okPhoton1) && fDebug>=0)
1034 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - Something happens, first label should be from a photon decay!\n");
1036 }//loop on list of labels
1038 //If both photons contribute tag as the corresponding meson.
1039 if(okPhoton0 && okPhoton1)
1042 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - %s OVERLAPPED DECAY \n", meson->GetName());
1044 if(!CheckTagBit(tag,kMCConversion) && conversion) SetTagBit(tag,kMCConversion) ;
1046 if(mesonPdg == 111) SetTagBit(tag,kMCPi0);
1047 else SetTagBit(tag,kMCEta);
1052 //__________________________________________________________________________________
1053 void AliMCAnalysisUtils::CheckOverlapped2GammaDecay(const Int_t *labels,
1054 const Int_t nlabels,
1055 const Int_t mesonIndex,
1056 const TClonesArray *mcparticles,
1059 //Check if cluster is formed from the contribution of 2 decay photons from pi0 or eta. Input in AODMCParticles
1061 if(labels[0] < 0 || labels[0] > mcparticles->GetEntriesFast() || nlabels <= 1)
1064 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - Exit : label[0] %d, n primaries %d, nlabels %d \n",
1065 labels[0],mcparticles->GetEntriesFast(), nlabels);
1069 AliAODMCParticle * meson = (AliAODMCParticle *) mcparticles->At(mesonIndex);
1070 Int_t mesonPdg = meson->GetPdgCode();
1071 if(mesonPdg != 111 && mesonPdg != 221)
1073 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - Wrong pi0/eta PDG : %d \n",mesonPdg);
1077 if(fDebug > 2) printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - pdg %d, label %d, ndaughters %d\n", mesonPdg, mesonIndex, meson->GetNDaughters());
1081 if(meson->GetNDaughters() != 2)
1084 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(ESD) - Not overalapped. Number of daughters is %d, not 2 \n",meson->GetNDaughters());
1088 Int_t iPhoton0 = meson->GetDaughter(0);
1089 Int_t iPhoton1 = meson->GetDaughter(1);
1090 //if((iPhoton0 == -1) || (iPhoton1 == -1)){
1092 // printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - Exit : Not overlapped. At least a daughter do not exists : d1 %d, d2 %d \n", iPhoton0, iPhoton1);
1095 AliAODMCParticle *photon0 = (AliAODMCParticle *) mcparticles->At(iPhoton0);
1096 AliAODMCParticle *photon1 = (AliAODMCParticle *) mcparticles->At(iPhoton1);
1098 //Check if both daughters are photons
1099 if(photon0->GetPdgCode() != 22 && photon1->GetPdgCode()!=22)
1101 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - Not overlapped. PDG: daughter 1 = %d, of daughter 2 = %d \n",photon0->GetPdgCode(),photon1->GetPdgCode());
1106 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - Daughter labels : photon0 = %d, photon1 = %d \n",iPhoton0,iPhoton1);
1108 //Check if both photons contribute to the cluster
1109 Bool_t okPhoton0 = kFALSE;
1110 Bool_t okPhoton1 = kFALSE;
1113 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - Labels loop:\n");
1115 Bool_t conversion = kFALSE;
1117 for(Int_t i = 0; i < nlabels; i++)
1120 printf("\t label %d/%d: %d, ok? %d, %d\n", i, nlabels, labels[i], okPhoton0, okPhoton1);
1122 if(labels[i]<0) continue;
1124 //If we already found both, break the loop
1125 if(okPhoton0 && okPhoton1) break;
1127 Int_t index = labels[i];
1128 if (iPhoton0 == index)
1133 else if (iPhoton1 == index)
1139 //Trace back the mother in case it was a conversion
1141 if(index >= mcparticles->GetEntriesFast())
1143 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) Particle index %d larger than size of list %d !!\n",index,mcparticles->GetEntriesFast());
1147 AliAODMCParticle * daught = (AliAODMCParticle*) mcparticles->At(index);
1148 Int_t tmpindex = daught->GetMother();
1150 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - Conversion? : mother %d\n",tmpindex);
1154 //MC particle of interest is the mother
1156 printf("\t parent index %d\n",tmpindex);
1157 daught = (AliAODMCParticle*) mcparticles->At(tmpindex);
1158 //printf("tmpindex %d\n",tmpindex);
1159 if (iPhoton0 == tmpindex)
1165 else if (iPhoton1 == tmpindex)
1172 tmpindex = daught->GetMother();
1174 }//While to check if pi0/eta daughter was one of these contributors to the cluster
1176 if(i == 0 && (!okPhoton0 && !okPhoton1) && fDebug>=0 )
1177 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - Something happens, first label should be from a photon decay!\n");
1179 }//loop on list of labels
1181 //If both photons contribute tag as the corresponding meson.
1182 if(okPhoton0 && okPhoton1)
1185 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) - %s OVERLAPPED DECAY \n",
1186 (TDatabasePDG::Instance()->GetParticle(mesonPdg))->GetName());
1188 if(!CheckTagBit(tag,kMCConversion) && conversion)
1191 printf("AliMCAnalysisUtils::CheckOverlapped2GammaDecay(AOD) Second decay photon produced a conversion \n");
1192 SetTagBit(tag,kMCConversion) ;
1195 if(mesonPdg == 111) SetTagBit(tag,kMCPi0);
1196 else SetTagBit(tag,kMCEta);
1201 //_________________________________________________________________________
1202 TList * AliMCAnalysisUtils::GetJets(const AliCaloTrackReader * reader)
1204 //Return list of jets (TParticles) and index of most likely parton that originated it.
1205 AliStack * stack = reader->GetStack();
1206 Int_t iEvent = reader->GetEventNumber();
1207 AliGenEventHeader * geh = reader->GetGenEventHeader();
1208 if(fCurrentEvent!=iEvent){
1209 fCurrentEvent = iEvent;
1210 fJetsList = new TList;
1211 Int_t nTriggerJets = 0;
1212 Float_t tmpjet[]={0,0,0,0};
1214 //printf("Event %d %d\n",fCurrentEvent,iEvent);
1215 //Get outgoing partons
1216 if(stack->GetNtrack() < 8) return fJetsList;
1217 TParticle * parton1 = stack->Particle(6);
1218 TParticle * parton2 = stack->Particle(7);
1220 printf("AliMCAnalysisUtils::GetJets() - parton 6 : %s, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
1221 parton1->GetName(),parton1->Pt(),parton1->Energy(),parton1->Phi()*TMath::RadToDeg(),parton1->Eta());
1222 printf("AliMCAnalysisUtils::GetJets() - parton 7 : %s, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
1223 parton2->GetName(),parton2->Pt(),parton2->Energy(),parton2->Phi()*TMath::RadToDeg(),parton2->Eta());
1225 // //Trace the jet from the mother parton
1232 // TParticle * tmptmp = new TParticle;
1233 // for(Int_t i = 0; i< stack->GetNprimary(); i++){
1234 // tmptmp = stack->Particle(i);
1236 // if(tmptmp->GetStatusCode() == 1){
1237 // pt = tmptmp->Pt();
1238 // e = tmptmp->Energy();
1239 // Int_t imom = tmptmp->GetFirstMother();
1241 // //printf("1st imom %d\n",imom);
1244 // tmptmp = stack->Particle(imom);
1245 // imom = tmptmp->GetFirstMother();
1246 // //printf("imom %d \n",imom);
1248 // //printf("Last imom %d %d\n",imom1, imom);
1253 // else if (imom1 == 7){
1260 // printf("JET 1, pt %2.2f, e %2.2f; JET 2, pt %2.2f, e %2.2f \n",pt1,e1,pt2,e2);
1262 //Get the jet, different way for different generator
1264 if(fMCGenerator == "PYTHIA"){
1265 TParticle * jet = 0x0;
1266 AliGenPythiaEventHeader* pygeh= (AliGenPythiaEventHeader*) geh;
1267 nTriggerJets = pygeh->NTriggerJets();
1269 printf("AliMCAnalysisUtils::GetJets() - PythiaEventHeader: Njets: %d\n",nTriggerJets);
1272 for(Int_t i = 0; i< nTriggerJets; i++){
1274 pygeh->TriggerJet(i, tmpjet);
1275 jet = new TParticle(94, 21, -1, -1, -1, -1, tmpjet[0],tmpjet[1],tmpjet[2],tmpjet[3], 0,0,0,0);
1276 //Assign an outgoing parton as mother
1277 Float_t phidiff1 = TMath::Abs(jet->Phi()-parton1->Phi());
1278 Float_t phidiff2 = TMath::Abs(jet->Phi()-parton2->Phi());
1279 if(phidiff1 > phidiff2) jet->SetFirstMother(7);
1280 else jet->SetFirstMother(6);
1283 printf("AliMCAnalysisUtils::GetJets() - PYTHIA Jet %d: mother %d, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
1284 i, jet->GetFirstMother(),jet->Pt(),jet->Energy(),jet->Phi()*TMath::RadToDeg(),jet->Eta());
1285 fJetsList->Add(jet);
1287 }//Pythia triggered jets
1289 else if (fMCGenerator=="HERWIG"){
1292 TParticle * tmp = parton1;
1293 if(parton1->GetPdgCode()!=22){
1295 if(tmp->GetFirstDaughter()==-1) return fJetsList;
1296 tmp = stack->Particle(tmp->GetFirstDaughter());
1297 pdg = tmp->GetPdgCode();
1300 //Add found jet to list
1301 TParticle *jet1 = new TParticle(*tmp);
1302 jet1->SetFirstMother(6);
1303 fJetsList->Add(jet1);
1304 //printf("jet 1: first daughter %d, last daughter %d\n", tmp->GetFirstDaughter(), tmp->GetLastDaughter());
1305 //tmp = stack->Particle(tmp->GetFirstDaughter());
1309 printf("AliMCAnalysisUtils::GetJets() - HERWIG Jet 1: mother %d, status %d, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
1310 jet1->GetFirstMother(),jet1->GetStatusCode(),jet1->Pt(),jet1->Energy(),jet1->Phi()*TMath::RadToDeg(),jet1->Eta());
1317 if(parton2->GetPdgCode()!=22){
1319 if(tmp->GetFirstDaughter()==-1) return fJetsList;
1320 i = tmp->GetFirstDaughter();
1321 tmp = stack->Particle(tmp->GetFirstDaughter());
1322 pdg = tmp->GetPdgCode();
1324 //Add found jet to list
1325 TParticle *jet2 = new TParticle(*tmp);
1326 jet2->SetFirstMother(7);
1327 fJetsList->Add(jet2);
1330 printf("AliMCAnalysisUtils::GetJets() - HERWIG Jet 2: mother %d, status %d, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
1331 jet2->GetFirstMother(),jet2->GetStatusCode(),jet2->Pt(),jet2->Energy(),jet2->Phi()*TMath::RadToDeg(),jet2->Eta());
1332 //Int_t first = tmp->GetFirstDaughter();
1333 //Int_t last = tmp->GetLastDaughter();
1334 //printf("jet 2: first daughter %d, last daughter %d, pdg %d\n",first, last, tmp->GetPdgCode());
1335 // for(Int_t d = first ; d < last+1; d++){
1336 // tmp = stack->Particle(d);
1337 // if(i == tmp->GetFirstMother())
1338 // printf("Daughter n %d, Mother %d, name %s, status %d, pT %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
1339 // d,tmp->GetFirstMother(), tmp->GetName(), tmp->GetStatusCode(),tmp->Pt(),tmp->Energy(),tmp->Phi()*TMath::RadToDeg(),tmp->Eta());
1343 }//Herwig generated jets
1350 //________________________________________________________________________________________________________
1351 TLorentzVector AliMCAnalysisUtils::GetDaughter(const Int_t idaugh, const Int_t label,
1352 const AliCaloTrackReader* reader,
1353 Int_t & pdg, Int_t & status, Bool_t & ok, Int_t & daughlabel)
1355 //Return the kinematics of the particle that generated the signal, its pdg and its status and its label mother
1357 TLorentzVector daughter(0,0,0,0);
1359 if(reader->ReadStack())
1361 if(!reader->GetStack())
1364 printf("AliMCAnalysisUtils::GetDaughter() - Stack is not available, check analysis settings in configuration file, STOP!!\n");
1369 if(label >= 0 && label < reader->GetStack()->GetNtrack())
1371 TParticle * momP = reader->GetStack()->Particle(label);
1372 daughlabel = momP->GetDaughter(idaugh);
1374 TParticle * daughP = reader->GetStack()->Particle(daughlabel);
1375 daughP->Momentum(daughter);
1376 pdg = daughP->GetPdgCode();
1377 status = daughP->GetStatusCode();
1385 else if(reader->ReadAODMCParticles())
1387 TClonesArray* mcparticles = reader->GetAODMCParticles();
1391 printf("AliMCAnalysisUtils::GetDaughter() - AODMCParticles is not available, check analysis settings in configuration file!!\n");
1397 Int_t nprimaries = mcparticles->GetEntriesFast();
1398 if(label >= 0 && label < nprimaries)
1400 AliAODMCParticle * momP = (AliAODMCParticle *) mcparticles->At(label);
1401 daughlabel = momP->GetDaughter(idaugh);
1403 AliAODMCParticle * daughP = (AliAODMCParticle *) mcparticles->At(daughlabel);
1404 daughter.SetPxPyPzE(daughP->Px(),daughP->Py(),daughP->Pz(),daughP->E());
1405 pdg = daughP->GetPdgCode();
1406 status = daughP->GetStatus();
1420 //_______________________________________________________________________________________________
1421 TLorentzVector AliMCAnalysisUtils::GetMother(const Int_t label, const AliCaloTrackReader* reader,
1424 //Return the kinematics of the particle that generated the signal
1426 Int_t pdg = -1; Int_t status = -1; Int_t momlabel = -1;
1427 return GetMother(label,reader,pdg,status, ok,momlabel);
1430 //_______________________________________________________________________________________________
1431 TLorentzVector AliMCAnalysisUtils::GetMother(const Int_t label, const AliCaloTrackReader* reader,
1432 Int_t & pdg, Int_t & status, Bool_t & ok)
1434 //Return the kinematics of the particle that generated the signal
1436 Int_t momlabel = -1;
1437 return GetMother(label,reader,pdg,status, ok,momlabel);
1440 //_______________________________________________________________________________________________
1441 TLorentzVector AliMCAnalysisUtils::GetMother(const Int_t label, const AliCaloTrackReader* reader,
1442 Int_t & pdg, Int_t & status, Bool_t & ok, Int_t & momlabel)
1444 //Return the kinematics of the particle that generated the signal, its pdg and its status and its label mother
1446 TLorentzVector mom(0,0,0,0);
1448 if(reader->ReadStack())
1450 if(!reader->GetStack())
1453 printf("AliMCAnalysisUtils::GetMother() - Stack is not available, check analysis settings in configuration file, STOP!!\n");
1458 if(label >= 0 && label < reader->GetStack()->GetNtrack())
1460 TParticle * momP = reader->GetStack()->Particle(label);
1461 momP->Momentum(mom);
1462 pdg = momP->GetPdgCode();
1463 status = momP->GetStatusCode();
1464 momlabel = momP->GetFirstMother();
1472 else if(reader->ReadAODMCParticles())
1474 TClonesArray* mcparticles = reader->GetAODMCParticles();
1478 printf("AliMCAnalysisUtils::GetMother() - AODMCParticles is not available, check analysis settings in configuration file!!\n");
1484 Int_t nprimaries = mcparticles->GetEntriesFast();
1485 if(label >= 0 && label < nprimaries)
1487 AliAODMCParticle * momP = (AliAODMCParticle *) mcparticles->At(label);
1488 mom.SetPxPyPzE(momP->Px(),momP->Py(),momP->Pz(),momP->E());
1489 pdg = momP->GetPdgCode();
1490 status = momP->GetStatus();
1491 momlabel = momP->GetMother();
1505 //_____________________________________________________________________________________
1506 TLorentzVector AliMCAnalysisUtils::GetMotherWithPDG(const Int_t label, const Int_t pdg, const AliCaloTrackReader* reader,
1507 Bool_t & ok, Int_t & momlabel)
1509 //Return the kinematics of the particle that generated the signal
1511 TLorentzVector grandmom(0,0,0,0);
1514 if(reader->ReadStack())
1516 if(!reader->GetStack())
1519 printf("AliMCAnalysisUtils::GetMotherWithPDG() - Stack is not available, check analysis settings in configuration file, STOP!!\n");
1525 if(label >= 0 && label < reader->GetStack()->GetNtrack())
1527 TParticle * momP = reader->GetStack()->Particle(label);
1529 Int_t grandmomLabel = momP->GetFirstMother();
1530 Int_t grandmomPDG = -1;
1531 TParticle * grandmomP = 0x0;
1532 while (grandmomLabel >=0 )
1534 grandmomP = reader->GetStack()->Particle(grandmomLabel);
1535 grandmomPDG = grandmomP->GetPdgCode();
1536 if(grandmomPDG==pdg)
1538 momlabel = grandmomLabel;
1539 grandmom.SetPxPyPzE(grandmomP->Px(),grandmomP->Py(),grandmomP->Pz(),grandmomP->Energy());
1543 grandmomLabel = grandmomP->GetFirstMother();
1547 if(grandmomPDG!=pdg) printf("AliMCAnalysisUtils::GetMotherWithPDG(ESD) - mother with PDG %d, not found! \n",pdg);
1550 else if(reader->ReadAODMCParticles())
1552 TClonesArray* mcparticles = reader->GetAODMCParticles();
1556 printf("AliMCAnalysisUtils::GetMotherWithPDG() - AODMCParticles is not available, check analysis settings in configuration file!!\n");
1562 Int_t nprimaries = mcparticles->GetEntriesFast();
1563 if(label >= 0 && label < nprimaries)
1565 AliAODMCParticle * momP = (AliAODMCParticle *) mcparticles->At(label);
1567 Int_t grandmomLabel = momP->GetMother();
1568 Int_t grandmomPDG = -1;
1569 AliAODMCParticle * grandmomP = 0x0;
1570 while (grandmomLabel >=0 )
1572 grandmomP = (AliAODMCParticle *) mcparticles->At(grandmomLabel);
1573 grandmomPDG = grandmomP->GetPdgCode();
1574 if(grandmomPDG==pdg)
1576 //printf("AliMCAnalysisUtils::GetMotherWithPDG(AOD) - mother with PDG %d FOUND! \n",pdg);
1577 momlabel = grandmomLabel;
1578 grandmom.SetPxPyPzE(grandmomP->Px(),grandmomP->Py(),grandmomP->Pz(),grandmomP->E());
1582 grandmomLabel = grandmomP->GetMother();
1586 if(grandmomPDG!=pdg) printf("AliMCAnalysisUtils::GetMotherWithPDG(AOD) - mother with PDG %d, NOT found! \n",pdg);
1596 //____________________________________________________________________________________________________
1597 TLorentzVector AliMCAnalysisUtils::GetGrandMother(const Int_t label, const AliCaloTrackReader* reader,
1598 Int_t & pdg, Int_t & status, Bool_t & ok,
1599 Int_t & grandMomLabel, Int_t & greatMomLabel)
1601 //Return the kinematics of the particle that generated the signal
1603 TLorentzVector grandmom(0,0,0,0);
1605 if(reader->ReadStack())
1607 if(!reader->GetStack())
1610 printf("AliMCAnalysisUtils::GetGrandMother() - Stack is not available, check analysis settings in configuration file, STOP!!\n");
1616 if(label >= 0 && label < reader->GetStack()->GetNtrack())
1618 TParticle * momP = reader->GetStack()->Particle(label);
1620 grandMomLabel = momP->GetFirstMother();
1622 TParticle * grandmomP = 0x0;
1624 if (grandMomLabel >=0 )
1626 grandmomP = reader->GetStack()->Particle(grandMomLabel);
1627 pdg = grandmomP->GetPdgCode();
1628 status = grandmomP->GetStatusCode();
1630 grandmom.SetPxPyPzE(grandmomP->Px(),grandmomP->Py(),grandmomP->Pz(),grandmomP->Energy());
1631 greatMomLabel = grandmomP->GetFirstMother();
1636 else if(reader->ReadAODMCParticles())
1638 TClonesArray* mcparticles = reader->GetAODMCParticles();
1642 printf("AliMCAnalysisUtils::GetGrandMother() - AODMCParticles is not available, check analysis settings in configuration file!!\n");
1648 Int_t nprimaries = mcparticles->GetEntriesFast();
1649 if(label >= 0 && label < nprimaries)
1651 AliAODMCParticle * momP = (AliAODMCParticle *) mcparticles->At(label);
1653 grandMomLabel = momP->GetMother();
1655 AliAODMCParticle * grandmomP = 0x0;
1657 if(grandMomLabel >=0 )
1659 grandmomP = (AliAODMCParticle *) mcparticles->At(grandMomLabel);
1660 pdg = grandmomP->GetPdgCode();
1661 status = grandmomP->GetStatus();
1663 grandmom.SetPxPyPzE(grandmomP->Px(),grandmomP->Py(),grandmomP->Pz(),grandmomP->E());
1664 greatMomLabel = grandmomP->GetMother();
1675 //_____________________________________________________________________________________
1676 Float_t AliMCAnalysisUtils::GetMCDecayAsymmetryForPDG(const Int_t label, const Int_t pdg, const AliCaloTrackReader* reader, Bool_t & ok)
1678 //In case of an eta or pi0 decay into 2 photons, get the asymmetry in the energy of the photons
1682 if(reader->ReadStack())
1684 if(!reader->GetStack())
1687 printf("AliMCAnalysisUtils::GetMCDecayAsymmetryForPDG() - Stack is not available, check analysis settings in configuration file, STOP!!\n");
1692 if(label >= 0 && label < reader->GetStack()->GetNtrack())
1694 TParticle * momP = reader->GetStack()->Particle(label);
1696 Int_t grandmomLabel = momP->GetFirstMother();
1697 Int_t grandmomPDG = -1;
1698 TParticle * grandmomP = 0x0;
1699 while (grandmomLabel >=0 )
1701 grandmomP = reader->GetStack()->Particle(grandmomLabel);
1702 grandmomPDG = grandmomP->GetPdgCode();
1704 if(grandmomPDG==pdg) break;
1706 grandmomLabel = grandmomP->GetFirstMother();
1710 if(grandmomPDG==pdg && grandmomP->GetNDaughters()==2)
1712 TParticle * d1 = reader->GetStack()->Particle(grandmomP->GetDaughter(0));
1713 TParticle * d2 = reader->GetStack()->Particle(grandmomP->GetDaughter(1));
1714 if(d1->GetPdgCode() == 22 && d1->GetPdgCode() == 22)
1716 asym = (d1->Energy()-d2->Energy())/grandmomP->Energy();
1722 printf("AliMCAnalysisUtils::GetMCDecayAsymmetryForPDG(ESD) - mother with PDG %d, not found! \n",pdg);
1727 else if(reader->ReadAODMCParticles())
1729 TClonesArray* mcparticles = reader->GetAODMCParticles();
1733 printf("AliMCAnalysisUtils::GetMCDecayAsymmetryForPDG() - AODMCParticles is not available, check analysis settings in configuration file!!\n");
1739 Int_t nprimaries = mcparticles->GetEntriesFast();
1740 if(label >= 0 && label < nprimaries)
1742 AliAODMCParticle * momP = (AliAODMCParticle *) mcparticles->At(label);
1744 Int_t grandmomLabel = momP->GetMother();
1745 Int_t grandmomPDG = -1;
1746 AliAODMCParticle * grandmomP = 0x0;
1747 while (grandmomLabel >=0 )
1749 grandmomP = (AliAODMCParticle *) mcparticles->At(grandmomLabel);
1750 grandmomPDG = grandmomP->GetPdgCode();
1752 if(grandmomPDG==pdg) break;
1754 grandmomLabel = grandmomP->GetMother();
1758 if(grandmomPDG==pdg && grandmomP->GetNDaughters()==2)
1760 AliAODMCParticle * d1 = (AliAODMCParticle *) mcparticles->At(grandmomP->GetDaughter(0));
1761 AliAODMCParticle * d2 = (AliAODMCParticle *) mcparticles->At(grandmomP->GetDaughter(1));
1762 if(d1->GetPdgCode() == 22 && d1->GetPdgCode() == 22)
1764 asym = (d1->E()-d2->E())/grandmomP->E();
1770 printf("AliMCAnalysisUtils::GetMCDecayAsymmetryForPDG(AOD) - mother with PDG %d, not found! \n",pdg);
1782 //_______________________________________________________________________________________________________
1783 Int_t AliMCAnalysisUtils::GetNDaughters(const Int_t label, const AliCaloTrackReader* reader, Bool_t & ok)
1785 // Return the the number of daughters of a given MC particle
1788 if(reader->ReadStack())
1790 if(!reader->GetStack())
1793 printf("AliMCAnalysisUtils::GetNDaughters() - Stack is not available, check analysis settings in configuration file, STOP!!\n");
1798 if(label >= 0 && label < reader->GetStack()->GetNtrack())
1800 TParticle * momP = reader->GetStack()->Particle(label);
1802 return momP->GetNDaughters();
1810 else if(reader->ReadAODMCParticles())
1812 TClonesArray* mcparticles = reader->GetAODMCParticles();
1816 printf("AliMCAnalysisUtils::GetNDaughters() - AODMCParticles is not available, check analysis settings in configuration file!!\n");
1822 Int_t nprimaries = mcparticles->GetEntriesFast();
1823 if(label >= 0 && label < nprimaries)
1825 AliAODMCParticle * momP = (AliAODMCParticle *) mcparticles->At(label);
1827 return momP->GetNDaughters();
1841 //_______________________________________________________________________________
1842 Int_t AliMCAnalysisUtils::GetNOverlaps(const Int_t * label, const UInt_t nlabels,
1843 const Int_t mctag, const Int_t mesonLabel,
1844 AliCaloTrackReader * reader, Int_t *overpdg)
1846 // Compare the primary depositing more energy with the rest,
1847 // if no photon/electron (conversion) or neutral meson as comon ancestor, consider it as other particle contributing
1848 // Give as input the meson label in case it was a pi0 or eta merged cluster
1849 // Init overpdg with nlabels
1851 Int_t ancPDG = 0, ancStatus = -1;
1852 TLorentzVector momentum; TVector3 prodVertex;
1854 Int_t noverlaps = 0;
1857 for (UInt_t ilab = 1; ilab < nlabels; ilab++ )
1859 ancLabel = CheckCommonAncestor(label[0],label[ilab],reader,ancPDG,ancStatus,momentum,prodVertex);
1861 //printf("Overlaps, i %d: Main Label %d, second label %d, ancestor: Label %d, pdg %d - tag %d \n",
1862 // ilab,label[0],label[ilab],ancLabel,ancPDG, mctag);
1864 Bool_t overlap = kFALSE;
1869 //printf("\t \t \t No Label = %d\n",ancLabel);
1871 else if( ( ancPDG==111 || ancPDG==221 ) && ( CheckTagBit(mctag,kMCPi0) || CheckTagBit(mctag,kMCEta)) && mesonLabel != ancLabel)
1873 //printf("\t \t meson Label %d, ancestor Label %d\n",mesonLabel,ancLabel);
1876 else if( ancPDG!=22 && TMath::Abs(ancPDG)!=11 && ancPDG != 111 && ancPDG != 221 )
1878 //printf("\t \t \t Non EM PDG = %d\n",ancPDG);
1882 if( !overlap ) continue ;
1884 // We have at least one overlap
1886 //printf("Overlap!!!!!!!!!!!!!!\n");
1890 // What is the origin of the overlap?
1891 Bool_t mOK = 0, gOK = 0;
1892 Int_t mpdg = -999999, gpdg = -1;
1893 Int_t mstatus = -1, gstatus = -1;
1894 Int_t gLabel = -1, ggLabel = -1;
1895 TLorentzVector mother = GetMother (label[ilab],reader,mpdg,mstatus,mOK);
1896 TLorentzVector grandmother = GetGrandMother(label[ilab],reader,gpdg,gstatus,gOK, gLabel,ggLabel);
1898 //printf("\t Overlap!, mother pdg %d; grand mother pdg %d",mpdg,gpdg);
1900 if( ( mpdg == 22 || TMath::Abs(mpdg==11) ) &&
1901 ( gpdg == 22 || TMath::Abs(gpdg==11) ) &&
1904 Int_t labeltmp = gLabel;
1905 while( ( gpdg == 22 || TMath::Abs(gpdg==11) ) && gLabel >=0 )
1908 grandmother = GetGrandMother(labeltmp,reader,gpdg,gstatus,ok, gLabel,ggLabel);
1912 overpdg[noverlaps-1] = mpdg;
1919 //________________________________________________________
1920 void AliMCAnalysisUtils::Print(const Option_t * opt) const
1922 //Print some relevant parameters set for the analysis
1927 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
1929 printf("Debug level = %d\n",fDebug);
1930 printf("MC Generator = %s\n",fMCGenerator.Data());
1935 //________________________________________________________
1936 void AliMCAnalysisUtils::PrintMCTag(const Int_t tag) const
1938 // print the assigned origins to this particle
1940 printf("AliMCAnalysisUtils::PrintMCTag() - tag %d \n photon %d, conv %d, prompt %d, frag %d, isr %d, \n pi0 decay %d, eta decay %d, other decay %d pi0 %d, eta %d \n electron %d, muon %d,pion %d, proton %d, neutron %d, \n kaon %d, a-proton %d, a-neutron %d, other %d, unk %d, bad %d\n",
1942 CheckTagBit(tag,kMCPhoton),
1943 CheckTagBit(tag,kMCConversion),
1944 CheckTagBit(tag,kMCPrompt),
1945 CheckTagBit(tag,kMCFragmentation),
1946 CheckTagBit(tag,kMCISR),
1947 CheckTagBit(tag,kMCPi0Decay),
1948 CheckTagBit(tag,kMCEtaDecay),
1949 CheckTagBit(tag,kMCOtherDecay),
1950 CheckTagBit(tag,kMCPi0),
1951 CheckTagBit(tag,kMCEta),
1952 CheckTagBit(tag,kMCElectron),
1953 CheckTagBit(tag,kMCMuon),
1954 CheckTagBit(tag,kMCPion),
1955 CheckTagBit(tag,kMCProton),
1956 CheckTagBit(tag,kMCAntiNeutron),
1957 CheckTagBit(tag,kMCKaon),
1958 CheckTagBit(tag,kMCAntiProton),
1959 CheckTagBit(tag,kMCAntiNeutron),
1960 CheckTagBit(tag,kMCOther),
1961 CheckTagBit(tag,kMCUnknown),
1962 CheckTagBit(tag,kMCBadLabel)