1 /*************************************************************************
2 * Copyright(c) 1998-2009, 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 //#####################################################
18 //# Class AliDielectronMC #
19 //# Cut Class for Jpsi->e+e- analysis #
21 //# by WooJin J. Park, GSI / W.J.Park@gsi.de #
23 //#####################################################
25 #include <AliAnalysisManager.h>
26 #include <AliAODHandler.h>
27 #include <AliESDInputHandler.h>
28 #include <AliMCEventHandler.h>
29 #include <AliMCEvent.h>
30 #include <AliMCParticle.h>
31 #include <AliAODMCParticle.h>
33 #include <AliESDEvent.h>
34 #include <AliESDtrack.h>
37 #include "AliDielectronMC.h"
39 AliDielectronMC* AliDielectronMC::fgInstance=0x0;
41 //____________________________________________________________
42 AliDielectronMC* AliDielectronMC::Instance()
45 // return pointer to singleton implementation
47 if (fgInstance) return fgInstance;
49 AnalysisType type=kUNSET;
50 if (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()->IsA()==AliESDInputHandler::Class()) type=kESD;
51 else if (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()->IsA()==AliAODHandler::Class()) type=kAOD;
53 fgInstance=new AliDielectronMC(type);
58 //____________________________________________________________
59 AliDielectronMC::AliDielectronMC(AnalysisType type):
65 // default constructor
70 //____________________________________________________________
71 AliDielectronMC::~AliDielectronMC()
79 //____________________________________________________________
80 void AliDielectronMC::Initialize()
83 // initialize MC class
85 if (!ConnectMCEvent()) AliError("Initialization of MC object failed!");
88 //____________________________________________________________
89 Int_t AliDielectronMC::GetNMCTracks()
92 // return the number of generated tracks from MC event
94 if (!fMCEvent){ AliError("No fMCEvent"); return 0; }
95 return fMCEvent->GetNumberOfTracks();
98 //____________________________________________________________
99 Int_t AliDielectronMC::GetNMCTracksFromStack()
102 // return the number of generated tracks from stack
104 if (!fStack){ AliError("No fStack"); return -999; }
105 return fStack->GetNtrack();
108 //____________________________________________________________
109 AliVParticle* AliDielectronMC::GetMCTrackFromMCEvent(Int_t _itrk)
112 // return MC track directly from MC event
114 if (!fMCEvent){ AliError("No fMCEvent"); return NULL;}
115 AliVParticle * track = fMCEvent->GetTrack(_itrk); // tracks from MC event
119 //____________________________________________________________
120 Bool_t AliDielectronMC::ConnectMCEvent()
123 // connect stack object from the mc handler
125 AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
126 if (!mcHandler){ AliError("Could not retrive MC event handler!"); return kFALSE; }
128 AliMCEvent* mcEvent = mcHandler->MCEvent();
129 if (!mcEvent){ AliError("Could not retrieve MC event!"); return kFALSE; }
132 if (!UpdateStack()) return kFALSE;
136 //____________________________________________________________
137 Bool_t AliDielectronMC::UpdateStack()
140 // update stack with new event
142 if (!fMCEvent){ AliError("No fMCEvent"); return kFALSE;}
143 AliStack* stack = fMCEvent->Stack();
144 if (!stack){ AliError("Could not retrive stack!"); return kFALSE; }
149 //____________________________________________________________
150 AliMCParticle* AliDielectronMC::GetMCTrack(AliESDtrack* _track)
155 Int_t label = TMath::Abs(_track->GetLabel());
156 AliMCParticle *mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(label));
160 //____________________________________________________________
161 TParticle* AliDielectronMC::GetMCTrackFromStack(AliESDtrack* _track)
164 // return MC track from stack
166 Int_t label = TMath::Abs(_track->GetLabel());
167 if (!fStack) AliWarning("fStack is not available. Update stack first.");
168 TParticle* mcpart = fStack->Particle(label);
169 if (!mcpart) return NULL;
173 //____________________________________________________________
174 AliMCParticle* AliDielectronMC::GetMCTrackMother(AliESDtrack* _track)
177 // return MC track mother
179 AliMCParticle* mcpart = GetMCTrack(_track);
180 if (!mcpart) return NULL;
181 printf("mcpart->GetMother() : %d\n",mcpart->GetMother());
182 AliMCParticle* mcmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(mcpart->GetMother()));
183 if (!mcmother) return NULL;
187 //____________________________________________________________
188 TParticle* AliDielectronMC::GetMCTrackMotherFromStack(AliESDtrack* _track)
191 // return MC track mother from stack
193 TParticle* mcpart = GetMCTrackFromStack(_track);
194 if ( !mcpart || mcpart->GetFirstMother()<=0 ) return NULL;
195 TParticle* mcmother = fStack->Particle(mcpart->GetFirstMother());
196 if (!mcmother) return NULL;
200 //____________________________________________________________
201 Int_t AliDielectronMC::GetMCPID(AliESDtrack* _track)
204 // return PDG code of the track from the MC truth info
206 AliMCParticle* mcpart = GetMCTrack(_track);
207 if (!mcpart) return -999;
208 return mcpart->PdgCode();
211 //____________________________________________________________
212 Int_t AliDielectronMC::GetMCPIDFromStack(AliESDtrack* _track)
215 // return MC PDG code from stack
217 TParticle* mcpart = GetMCTrackFromStack(_track);
218 if (!mcpart) return -999;
219 return mcpart->GetPdgCode();
222 //____________________________________________________________
223 Int_t AliDielectronMC::GetMotherPDG(AliESDtrack* _track)
226 // return PDG code of the mother track from the MC truth info
228 AliMCParticle* mcmother = GetMCTrackMother(_track);
229 if (!mcmother) return -999;
230 return mcmother->PdgCode();
233 //____________________________________________________________
234 Int_t AliDielectronMC::GetMotherPDGFromStack(AliESDtrack* _track)
237 // return PDG code of the mother track from stack
239 TParticle* mcmother = GetMCTrackMotherFromStack(_track);
240 if (!mcmother) return -999;
241 return mcmother->GetPdgCode();
244 //____________________________________________________________
245 Int_t AliDielectronMC::GetMCProcess(AliESDtrack* _track)
248 // return process number of the track
250 AliMCParticle* mcpart = GetMCTrack(_track);
251 if (!mcpart) return -999;
255 //____________________________________________________________
256 Int_t AliDielectronMC::GetMCProcessFromStack(AliESDtrack* _track)
259 // return process number of the track
261 TParticle* mcpart = GetMCTrackFromStack(_track);
262 if (!mcpart) return -999;
263 return mcpart->GetUniqueID();
266 //____________________________________________________________
267 Int_t AliDielectronMC::GetMCProcessMother(AliESDtrack* _track)
270 // return process number of the mother of the track
272 AliMCParticle* mcmother = GetMCTrackMother(_track);
273 if (!mcmother) return -999;
277 //____________________________________________________________
278 Int_t AliDielectronMC::GetMCProcessMotherFromStack(AliESDtrack* _track)
281 // return process number of the mother of the track
283 TParticle* mcmother = GetMCTrackMotherFromStack(_track);
284 if (!mcmother) return -999;
285 return mcmother->GetUniqueID();
288 //____________________________________________________________
289 Bool_t AliDielectronMC::IsMCMotherToEE(const AliVParticle *particle, Int_t pdgMother)
292 // Check if the Mother 'particle' is of type pdgMother and decays to e+e-
295 if (!fMCEvent) return kFALSE;
297 if (particle->IsA()==AliMCParticle::Class()){
298 return IsMCMotherToEEesd(static_cast<const AliMCParticle*>(particle),pdgMother);
299 } else if (particle->IsA()==AliAODMCParticle::Class()){
300 return IsMCMotherToEEaod(static_cast<const AliAODMCParticle*>(particle),pdgMother);
302 AliError("Unknown particle type");
308 //____________________________________________________________
309 Bool_t AliDielectronMC::IsMCMotherToEEesd(const AliMCParticle *particle, Int_t pdgMother)
312 // Check if the Mother 'particle' is of type pdgMother and decays to e+e-
317 if (particle->PdgCode()!=pdgMother) return kFALSE;
318 Int_t ifirst = particle->GetFirstDaughter();
319 Int_t ilast = particle->GetLastDaughter();
321 //check number of daughters
322 if ((ilast-ifirst)!=1) return kFALSE;
323 AliMCParticle *firstD=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(ifirst));
324 AliMCParticle *secondD=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(ilast));
326 if (firstD->Charge()>0){
327 if (firstD->PdgCode()!=-11) return kFALSE;
328 if (secondD->PdgCode()!=11) return kFALSE;
330 if (firstD->PdgCode()!=11) return kFALSE;
331 if (secondD->PdgCode()!=-11) return kFALSE;
337 //____________________________________________________________
338 Bool_t AliDielectronMC::IsMCMotherToEEaod(const AliAODMCParticle *particle, Int_t pdgMother)
341 // Check if the Mother 'particle' is of type pdgMother and decays to e+e-
344 if (particle->GetPdgCode()!=pdgMother) return kFALSE;
345 if (particle->GetNDaughters()!=2) return kFALSE;
347 Int_t ifirst = particle->GetDaughter(0);
348 Int_t ilast = particle->GetDaughter(1);
350 //check number of daughters
351 if ((ilast-ifirst)!=1) return kFALSE;
352 AliAODMCParticle *firstD=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(ifirst));
353 AliAODMCParticle *secondD=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(ilast));
355 if (firstD->Charge()>0){
356 if (firstD->GetPdgCode()!=11) return kFALSE;
357 if (secondD->GetPdgCode()!=-11) return kFALSE;
359 if (firstD->GetPdgCode()!=-11) return kFALSE;
360 if (secondD->GetPdgCode()!=11) return kFALSE;
365 //____________________________________________________________
366 Int_t AliDielectronMC::GetLabelMotherWithPdg(const AliVParticle *particle1, const AliVParticle *particle2, Int_t pdgMother)
369 // test if mother of particle 1 and 2 has pdgCode pdgMother and is the same;
371 if (!fMCEvent) return -1;
373 if (fAnaType==kESD) return GetLabelMotherWithPdgESD(particle1, particle2, pdgMother);
374 else if (fAnaType==kAOD) return GetLabelMotherWithPdgAOD(particle1, particle2, pdgMother);
379 //____________________________________________________________
380 Int_t AliDielectronMC::GetLabelMotherWithPdgESD(const AliVParticle *particle1, const AliVParticle *particle2, Int_t pdgMother)
383 // test if mother of particle 1 and 2 has pdgCode +-11 (electron),
384 // have the same mother and the mother had pdg code pdgMother
388 AliMCParticle *mcPart1=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(particle1->GetLabel()));
389 AliMCParticle *mcPart2=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(particle2->GetLabel()));
391 if (!mcPart1||!mcPart2) return -1;
393 Int_t lblMother1=mcPart1->GetMother();
394 Int_t lblMother2=mcPart2->GetMother();
396 AliMCParticle *mcMother1=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(lblMother1));
397 if (!mcMother1) return -1;
398 if (lblMother1!=lblMother2) return -1;
399 if (TMath::Abs(mcPart1->PdgCode())!=11) return -1;
400 if (mcMother1->PdgCode()!=pdgMother) return -1;
405 //____________________________________________________________
406 Int_t AliDielectronMC::GetLabelMotherWithPdgAOD(const AliVParticle *particle1, const AliVParticle *particle2, Int_t pdgMother)
409 // test if mother of particle 1 and 2 has pdgCode +-11 (electron),
410 // have the same mother and the mother had pdg code pdgMother
413 AliAODMCParticle *mcPart1=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(particle1->GetLabel()));
414 AliAODMCParticle *mcPart2=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(particle2->GetLabel()));
416 if (!mcPart1||!mcPart2) return -1;
418 Int_t lblMother1=mcPart1->GetMother();
419 Int_t lblMother2=mcPart2->GetMother();
421 AliAODMCParticle *mcMother1=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(lblMother1));
423 if (!mcMother1) return -1;
424 if (lblMother1!=lblMother2) return -1;
425 if (TMath::Abs(mcPart1->GetPdgCode())!=11) return -1;
426 if (mcMother1->GetPdgCode()!=pdgMother) return -1;
431 //____________________________________________________________
432 void AliDielectronMC::GetDaughters(const TObject *mother, AliVParticle* &d1, AliVParticle* &d2)
435 // Get First two daughters of the mother
442 if (!fMCEvent) return;
444 const AliAODMCParticle *aodMother=static_cast<const AliAODMCParticle*>(mother);
445 lblD1=aodMother->GetDaughter(0);
446 lblD2=aodMother->GetDaughter(1);
447 } else if (fAnaType==kESD){
448 const AliMCParticle *aodMother=static_cast<const AliMCParticle*>(mother);
449 lblD1=aodMother->GetFirstDaughter();
450 lblD2=aodMother->GetLastDaughter();
452 d1=fMCEvent->GetTrack(lblD1);
453 d2=fMCEvent->GetTrack(lblD2);