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 **************************************************************************/
15 /* $Id: AliMCAnalysisUtils.cxx 21839 2007-10-29 13:49:42Z gustavo $ */
17 //_________________________________________________________________________
18 // Class for analysis utils for MC data
19 // stored in stack or event header.
21 // - method to check the origin of a given track/cluster
22 // - method to obtain the generated jets
24 //*-- Author: Gustavo Conesa (LNF-INFN)
25 //////////////////////////////////////////////////////////////////////////////
28 // --- ROOT system ---
32 //---- ANALYSIS system ----
33 #include "AliMCAnalysisUtils.h"
35 #include "TParticle.h"
36 #include "AliGenPythiaEventHeader.h"
38 ClassImp(AliMCAnalysisUtils)
40 //________________________________________________
41 AliMCAnalysisUtils::AliMCAnalysisUtils() :
42 TObject(), fCurrentEvent(-1), fDebug(-1),
43 fJetsList(new TList), fMCGenerator("PYTHIA")
48 //____________________________________________________________________________
49 AliMCAnalysisUtils::AliMCAnalysisUtils(const AliMCAnalysisUtils & mcutils) :
50 TObject(mcutils), fCurrentEvent(mcutils.fCurrentEvent), fDebug(mcutils.fDebug),
51 fJetsList(mcutils.fJetsList), fMCGenerator(mcutils.fMCGenerator)
57 //_________________________________________________________________________
58 AliMCAnalysisUtils & AliMCAnalysisUtils::operator = (const AliMCAnalysisUtils & mcutils)
60 // assignment operator
62 if(&mcutils == this) return *this;
63 fCurrentEvent = mcutils.fCurrentEvent ;
64 fDebug = mcutils.fDebug;
65 fJetsList = mcutils.fJetsList;
66 fMCGenerator = mcutils.fMCGenerator;
71 //____________________________________________________________________________
72 AliMCAnalysisUtils::~AliMCAnalysisUtils()
74 // Remove all pointers.
82 //_________________________________________________________________________
83 Int_t AliMCAnalysisUtils::CheckOrigin(const Int_t label, AliStack * stack) const {
84 //Play with the MC stack if available
85 //Check origin of the candidates, good for PYTHIA
88 printf("AliMCAnalysisUtils::CheckOrigin() - Stack is not available, check analysis settings in configuration file, STOP!!\n");
91 // printf("label %d, ntrack %d, nprim %d\n",label, stack->GetNtrack(), stack->GetNprimary());
92 // for(Int_t i = 0; i< stack->GetNprimary(); i++){
93 // TParticle *particle = stack->Particle(i);
94 // //particle->Print();
96 if(label >= 0 && label < stack->GetNtrack()){
98 TParticle * mom = stack->Particle(label);
99 Int_t mPdg = TMath::Abs(mom->GetPdgCode());
100 Int_t mStatus = mom->GetStatusCode() ;
101 Int_t iParent = mom->GetFirstMother() ;
102 if(fDebug > 0 && label < 8 ) printf("AliMCAnalysisUtils::CheckOrigin: Mother is parton %d\n",iParent);
105 TParticle * parent = new TParticle ;
109 parent = stack->Particle(iParent);
110 pPdg = TMath::Abs(parent->GetPdgCode());
111 pStatus = parent->GetStatusCode();
113 else if(fDebug > 0 ) printf("AliMCAnalysisUtils::CheckOrigin: Parent with label %d\n",iParent);
118 if(fMCGenerator == "PYTHIA"){
119 if(iParent < 8 && iParent > 5) {//outgoing partons
120 if(pPdg == 22) return kMCPrompt;
121 else return kMCFragmentation;
123 else if(pStatus == 11){//Decay
124 if(pPdg == 111) return kMCPi0Decay ;
125 else if (pPdg == 221) return kMCEtaDecay ;
126 else return kMCOtherDecay ;
128 else return kMCISR; //Initial state radiation
131 else if(fMCGenerator == "HERWIG"){
132 if(pStatus < 197){//Not decay
134 if(parent->GetFirstMother()<=5) break;
135 iParent = parent->GetFirstMother();
136 parent=stack->Particle(iParent);
137 pStatus= parent->GetStatusCode();
138 pPdg = parent->GetPdgCode();
139 }//Look for the parton
141 if(iParent < 8 && iParent > 5) {
142 if(pPdg == 22) return kMCPrompt;
143 else return kMCFragmentation;
145 return kMCISR;//Initial state radiation
148 if(pPdg == 111) return kMCPi0Decay ;
149 else if (pPdg == 221) return kMCEtaDecay ;
150 else return kMCOtherDecay ;
153 else return kMCUnknown;
154 }//Status 1 : Pythia generated
155 else if(mStatus == 0){
156 if(pPdg ==22 || pPdg ==11|| pPdg == 2112 || pPdg == 211 ||
157 pPdg == 321 || pPdg == 2212 || pPdg == 130 || pPdg == 13 )
158 return kMCConversion ;
159 if(pPdg == 111) return kMCPi0Decay ;
160 else if (pPdg == 221) return kMCEtaDecay ;
161 else return kMCOtherDecay ;
162 }//status 0 : geant generated
164 else if(mPdg == 111) return kMCPi0 ;
165 else if(mPdg == 221) return kMCEta ;
167 // if(pPdg !=22 &&mStatus == 0) {
168 // printf("Origin electron, pT %f, status %d, parent %s, pstatus %d, vx %f, vy %f, vz %f\n",
169 // mom->Pt(),mStatus, parent->GetName(),pStatus,mom->Vx(),mom->Vy(), mom->Vz());
174 if(pPdg ==22) return kMCConversion ;
175 else if (pStatus == 0) return kMCConversion;
176 else return kMCElectron ;
178 else return kMCElectron ;
180 else return kMCUnknown;
183 if(label < 0 ) printf("AliMCAnalysisUtils::CheckOrigin: *** bad label or no stack ***: label %d \n", label);
184 if(label >= stack->GetNtrack()) printf("AliMCAnalysisUtils::CheckOrigin: *** large label ***: label %d, n tracks %d \n", label, stack->GetNtrack());
192 //_________________________________________________________________________
193 TList * AliMCAnalysisUtils::GetJets(Int_t iEvent, AliStack * stack, AliGenEventHeader * geh) {
194 //Return list of jets (TParticles) and index of most likely parton that originated it.
196 if(fCurrentEvent!=iEvent){
197 fCurrentEvent = iEvent;
198 fJetsList = new TList;
199 Int_t nTriggerJets = 0;
200 Float_t tmpjet[]={0,0,0,0};
202 //printf("Event %d %d\n",fCurrentEvent,iEvent);
203 //Get outgoing partons
204 if(stack->GetNtrack() < 8) return fJetsList;
205 TParticle * parton1 = stack->Particle(6);
206 TParticle * parton2 = stack->Particle(7);
208 printf("AliMCAnalysisUtils::GetJets() - parton 6 : %s, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
209 parton1->GetName(),parton1->Pt(),parton1->Energy(),parton1->Phi()*TMath::RadToDeg(),parton1->Eta());
210 printf("AliMCAnalysisUtils::GetJets() - parton 7 : %s, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
211 parton2->GetName(),parton2->Pt(),parton2->Energy(),parton2->Phi()*TMath::RadToDeg(),parton2->Eta());
213 // //Trace the jet from the mother parton
220 // TParticle * tmptmp = new TParticle;
221 // for(Int_t i = 0; i< stack->GetNprimary(); i++){
222 // tmptmp = stack->Particle(i);
224 // if(tmptmp->GetStatusCode() == 1){
225 // pt = tmptmp->Pt();
226 // e = tmptmp->Energy();
227 // Int_t imom = tmptmp->GetFirstMother();
229 // //printf("1st imom %d\n",imom);
232 // tmptmp = stack->Particle(imom);
233 // imom = tmptmp->GetFirstMother();
234 // //printf("imom %d \n",imom);
236 // //printf("Last imom %d %d\n",imom1, imom);
241 // else if (imom1 == 7){
248 // printf("JET 1, pt %2.2f, e %2.2f; JET 2, pt %2.2f, e %2.2f \n",pt1,e1,pt2,e2);
250 //Get the jet, different way for different generator
252 if(fMCGenerator == "PYTHIA"){
253 TParticle * jet = new TParticle;
254 AliGenPythiaEventHeader* pygeh= (AliGenPythiaEventHeader*) geh;
255 nTriggerJets = pygeh->NTriggerJets();
257 printf("AliMCAnalysisUtils::GetJets() - PythiaEventHeader: Njets: %d\n",nTriggerJets);
260 for(Int_t i = 0; i< nTriggerJets; i++){
262 pygeh->TriggerJet(i, tmpjet);
263 jet = new TParticle(94, 21, -1, -1, -1, -1, tmpjet[0],tmpjet[1],tmpjet[2],tmpjet[3], 0,0,0,0);
264 //Assign an outgoing parton as mother
265 Float_t phidiff1 = TMath::Abs(jet->Phi()-parton1->Phi());
266 Float_t phidiff2 = TMath::Abs(jet->Phi()-parton2->Phi());
267 if(phidiff1 > phidiff2) jet->SetFirstMother(7);
268 else jet->SetFirstMother(6);
271 printf("AliMCAnalysisUtils::GetJets() - PYTHIA Jet %d: mother %d, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
272 i, jet->GetFirstMother(),jet->Pt(),jet->Energy(),jet->Phi()*TMath::RadToDeg(),jet->Eta());
275 }//Pythia triggered jets
277 else if (fMCGenerator=="HERWIG"){
280 TParticle * tmp = parton1;
281 if(parton1->GetPdgCode()!=22){
283 if(tmp->GetFirstDaughter()==-1) return fJetsList;
284 tmp = stack->Particle(tmp->GetFirstDaughter());
285 pdg = tmp->GetPdgCode();
288 //Add found jet to list
289 TParticle *jet1 = new TParticle(*tmp);
290 jet1->SetFirstMother(6);
291 fJetsList->Add(jet1);
292 //printf("jet 1: first daughter %d, last daughter %d\n", tmp->GetFirstDaughter(), tmp->GetLastDaughter());
293 //tmp = stack->Particle(tmp->GetFirstDaughter());
297 printf("AliMCAnalysisUtils::GetJets() - HERWIG Jet 1: mother %d, status %d, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
298 jet1->GetFirstMother(),jet1->GetStatusCode(),jet1->Pt(),jet1->Energy(),jet1->Phi()*TMath::RadToDeg(),jet1->Eta());
305 if(parton2->GetPdgCode()!=22){
307 if(tmp->GetFirstDaughter()==-1) return fJetsList;
308 i = tmp->GetFirstDaughter();
309 tmp = stack->Particle(tmp->GetFirstDaughter());
310 pdg = tmp->GetPdgCode();
312 //Add found jet to list
313 TParticle *jet2 = new TParticle(*tmp);
314 jet2->SetFirstMother(7);
315 fJetsList->Add(jet2);
318 printf("AliMCAnalysisUtils::GetJets() - HERWIG Jet 2: mother %d, status %d, pt %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
319 jet2->GetFirstMother(),jet2->GetStatusCode(),jet2->Pt(),jet2->Energy(),jet2->Phi()*TMath::RadToDeg(),jet2->Eta());
320 //Int_t first = tmp->GetFirstDaughter();
321 //Int_t last = tmp->GetLastDaughter();
322 //printf("jet 2: first daughter %d, last daughter %d, pdg %d\n",first, last, tmp->GetPdgCode());
323 // for(Int_t d = first ; d < last+1; d++){
324 // tmp = stack->Particle(d);
325 // if(i == tmp->GetFirstMother())
326 // printf("Daughter n %d, Mother %d, name %s, status %d, pT %2.2f,E %2.2f, phi %2.2f, eta %2.2f \n",
327 // d,tmp->GetFirstMother(), tmp->GetName(), tmp->GetStatusCode(),tmp->Pt(),tmp->Energy(),tmp->Phi()*TMath::RadToDeg(),tmp->Eta());
331 }//Herwig generated jets
337 //________________________________________________________________
338 void AliMCAnalysisUtils::Print(const Option_t * opt) const
340 //Print some relevant parameters set for the analysis
345 printf("***** Print: %s %s ******\n", GetName(), GetTitle() ) ;
347 printf("Debug level = %d\n",fDebug);
348 printf("MC Generator = %s\n",fMCGenerator.Data());