]>
Commit | Line | Data |
---|---|---|
b2a297fa | 1 | /************************************************************************* |
2 | * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | ||
16 | //##################################################### | |
17 | //# # | |
18 | //# Class AliDielectronMC # | |
19 | //# Cut Class for Jpsi->e+e- analysis # | |
20 | //# # | |
21 | //# by WooJin J. Park, GSI / W.J.Park@gsi.de # | |
22 | //# # | |
23 | //##################################################### | |
24 | ||
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> | |
32 | #include <AliStack.h> | |
33 | #include <AliESDEvent.h> | |
34 | #include <AliESDtrack.h> | |
35 | #include <AliLog.h> | |
36 | ||
37 | #include "AliDielectronMC.h" | |
38 | ||
39 | AliDielectronMC* AliDielectronMC::fgInstance=0x0; | |
40 | ||
41 | //____________________________________________________________ | |
42 | AliDielectronMC* AliDielectronMC::Instance() | |
43 | { | |
44 | // | |
45 | // return pointer to singleton implementation | |
46 | // | |
47 | if (fgInstance) return fgInstance; | |
48 | ||
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; | |
572b0139 | 52 | |
53 | AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()); | |
b2a297fa | 54 | |
55 | fgInstance=new AliDielectronMC(type); | |
572b0139 | 56 | fgInstance->SetHasMC(mcHandler!=0x0); |
b2a297fa | 57 | |
58 | return fgInstance; | |
59 | } | |
60 | ||
61 | //____________________________________________________________ | |
62 | AliDielectronMC::AliDielectronMC(AnalysisType type): | |
63 | fMCEvent(0x0), | |
64 | fStack(0x0), | |
572b0139 | 65 | fAnaType(type), |
66 | fHasMC(kTRUE) | |
b2a297fa | 67 | { |
68 | // | |
69 | // default constructor | |
70 | // | |
71 | } | |
72 | ||
73 | ||
74 | //____________________________________________________________ | |
75 | AliDielectronMC::~AliDielectronMC() | |
76 | { | |
77 | // | |
78 | // default destructor | |
79 | // | |
80 | ||
81 | } | |
82 | ||
83 | //____________________________________________________________ | |
84 | void AliDielectronMC::Initialize() | |
85 | { | |
86 | // | |
87 | // initialize MC class | |
88 | // | |
89 | if (!ConnectMCEvent()) AliError("Initialization of MC object failed!"); | |
90 | } | |
91 | ||
92 | //____________________________________________________________ | |
93 | Int_t AliDielectronMC::GetNMCTracks() | |
94 | { | |
95 | // | |
96 | // return the number of generated tracks from MC event | |
97 | // | |
98 | if (!fMCEvent){ AliError("No fMCEvent"); return 0; } | |
99 | return fMCEvent->GetNumberOfTracks(); | |
100 | } | |
101 | ||
102 | //____________________________________________________________ | |
103 | Int_t AliDielectronMC::GetNMCTracksFromStack() | |
104 | { | |
105 | // | |
106 | // return the number of generated tracks from stack | |
107 | // | |
108 | if (!fStack){ AliError("No fStack"); return -999; } | |
109 | return fStack->GetNtrack(); | |
110 | } | |
111 | ||
112 | //____________________________________________________________ | |
113 | AliVParticle* AliDielectronMC::GetMCTrackFromMCEvent(Int_t _itrk) | |
114 | { | |
115 | // | |
116 | // return MC track directly from MC event | |
117 | // | |
118 | if (!fMCEvent){ AliError("No fMCEvent"); return NULL;} | |
119 | AliVParticle * track = fMCEvent->GetTrack(_itrk); // tracks from MC event | |
120 | return track; | |
121 | } | |
122 | ||
123 | //____________________________________________________________ | |
124 | Bool_t AliDielectronMC::ConnectMCEvent() | |
125 | { | |
126 | // | |
127 | // connect stack object from the mc handler | |
128 | // | |
129 | AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()); | |
130 | if (!mcHandler){ AliError("Could not retrive MC event handler!"); return kFALSE; } | |
131 | ||
132 | AliMCEvent* mcEvent = mcHandler->MCEvent(); | |
133 | if (!mcEvent){ AliError("Could not retrieve MC event!"); return kFALSE; } | |
134 | fMCEvent = mcEvent; | |
135 | ||
136 | if (!UpdateStack()) return kFALSE; | |
137 | return kTRUE; | |
138 | } | |
139 | ||
140 | //____________________________________________________________ | |
141 | Bool_t AliDielectronMC::UpdateStack() | |
142 | { | |
143 | // | |
144 | // update stack with new event | |
145 | // | |
146 | if (!fMCEvent){ AliError("No fMCEvent"); return kFALSE;} | |
147 | AliStack* stack = fMCEvent->Stack(); | |
148 | if (!stack){ AliError("Could not retrive stack!"); return kFALSE; } | |
149 | fStack = stack; | |
150 | return kTRUE; | |
151 | } | |
152 | ||
153 | //____________________________________________________________ | |
154 | AliMCParticle* AliDielectronMC::GetMCTrack(AliESDtrack* _track) | |
155 | { | |
156 | // | |
157 | // return MC track | |
158 | // | |
159 | Int_t label = TMath::Abs(_track->GetLabel()); | |
160 | AliMCParticle *mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(label)); | |
161 | return mctrack; | |
162 | } | |
163 | ||
164 | //____________________________________________________________ | |
165 | TParticle* AliDielectronMC::GetMCTrackFromStack(AliESDtrack* _track) | |
166 | { | |
167 | // | |
168 | // return MC track from stack | |
169 | // | |
170 | Int_t label = TMath::Abs(_track->GetLabel()); | |
171 | if (!fStack) AliWarning("fStack is not available. Update stack first."); | |
172 | TParticle* mcpart = fStack->Particle(label); | |
173 | if (!mcpart) return NULL; | |
174 | return mcpart; | |
175 | } | |
176 | ||
177 | //____________________________________________________________ | |
178 | AliMCParticle* AliDielectronMC::GetMCTrackMother(AliESDtrack* _track) | |
179 | { | |
180 | // | |
181 | // return MC track mother | |
182 | // | |
183 | AliMCParticle* mcpart = GetMCTrack(_track); | |
184 | if (!mcpart) return NULL; | |
185 | printf("mcpart->GetMother() : %d\n",mcpart->GetMother()); | |
186 | AliMCParticle* mcmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(mcpart->GetMother())); | |
187 | if (!mcmother) return NULL; | |
188 | return mcmother; | |
189 | } | |
190 | ||
191 | //____________________________________________________________ | |
192 | TParticle* AliDielectronMC::GetMCTrackMotherFromStack(AliESDtrack* _track) | |
193 | { | |
194 | // | |
195 | // return MC track mother from stack | |
196 | // | |
197 | TParticle* mcpart = GetMCTrackFromStack(_track); | |
198 | if ( !mcpart || mcpart->GetFirstMother()<=0 ) return NULL; | |
199 | TParticle* mcmother = fStack->Particle(mcpart->GetFirstMother()); | |
200 | if (!mcmother) return NULL; | |
201 | return mcmother; | |
202 | } | |
203 | ||
204 | //____________________________________________________________ | |
205 | Int_t AliDielectronMC::GetMCPID(AliESDtrack* _track) | |
206 | { | |
207 | // | |
208 | // return PDG code of the track from the MC truth info | |
209 | // | |
210 | AliMCParticle* mcpart = GetMCTrack(_track); | |
211 | if (!mcpart) return -999; | |
212 | return mcpart->PdgCode(); | |
213 | } | |
214 | ||
215 | //____________________________________________________________ | |
216 | Int_t AliDielectronMC::GetMCPIDFromStack(AliESDtrack* _track) | |
217 | { | |
218 | // | |
219 | // return MC PDG code from stack | |
220 | // | |
221 | TParticle* mcpart = GetMCTrackFromStack(_track); | |
222 | if (!mcpart) return -999; | |
223 | return mcpart->GetPdgCode(); | |
224 | } | |
225 | ||
226 | //____________________________________________________________ | |
227 | Int_t AliDielectronMC::GetMotherPDG(AliESDtrack* _track) | |
228 | { | |
229 | // | |
230 | // return PDG code of the mother track from the MC truth info | |
231 | // | |
232 | AliMCParticle* mcmother = GetMCTrackMother(_track); | |
233 | if (!mcmother) return -999; | |
234 | return mcmother->PdgCode(); | |
235 | } | |
236 | ||
237 | //____________________________________________________________ | |
238 | Int_t AliDielectronMC::GetMotherPDGFromStack(AliESDtrack* _track) | |
239 | { | |
240 | // | |
241 | // return PDG code of the mother track from stack | |
242 | // | |
243 | TParticle* mcmother = GetMCTrackMotherFromStack(_track); | |
244 | if (!mcmother) return -999; | |
245 | return mcmother->GetPdgCode(); | |
246 | } | |
247 | ||
248 | //____________________________________________________________ | |
249 | Int_t AliDielectronMC::GetMCProcess(AliESDtrack* _track) | |
250 | { | |
251 | // | |
252 | // return process number of the track | |
253 | // | |
254 | AliMCParticle* mcpart = GetMCTrack(_track); | |
255 | if (!mcpart) return -999; | |
256 | return 0; | |
257 | } | |
258 | ||
259 | //____________________________________________________________ | |
260 | Int_t AliDielectronMC::GetMCProcessFromStack(AliESDtrack* _track) | |
261 | { | |
262 | // | |
263 | // return process number of the track | |
264 | // | |
265 | TParticle* mcpart = GetMCTrackFromStack(_track); | |
266 | if (!mcpart) return -999; | |
267 | return mcpart->GetUniqueID(); | |
268 | } | |
269 | ||
270 | //____________________________________________________________ | |
271 | Int_t AliDielectronMC::GetMCProcessMother(AliESDtrack* _track) | |
272 | { | |
273 | // | |
274 | // return process number of the mother of the track | |
275 | // | |
276 | AliMCParticle* mcmother = GetMCTrackMother(_track); | |
277 | if (!mcmother) return -999; | |
278 | return 0; | |
279 | } | |
280 | ||
281 | //____________________________________________________________ | |
282 | Int_t AliDielectronMC::GetMCProcessMotherFromStack(AliESDtrack* _track) | |
283 | { | |
284 | // | |
285 | // return process number of the mother of the track | |
286 | // | |
287 | TParticle* mcmother = GetMCTrackMotherFromStack(_track); | |
288 | if (!mcmother) return -999; | |
289 | return mcmother->GetUniqueID(); | |
290 | } | |
291 | ||
292 | //____________________________________________________________ | |
293 | Bool_t AliDielectronMC::IsMCMotherToEE(const AliVParticle *particle, Int_t pdgMother) | |
294 | { | |
295 | // | |
296 | // Check if the Mother 'particle' is of type pdgMother and decays to e+e- | |
297 | // | |
298 | ||
299 | if (!fMCEvent) return kFALSE; | |
300 | ||
301 | if (particle->IsA()==AliMCParticle::Class()){ | |
302 | return IsMCMotherToEEesd(static_cast<const AliMCParticle*>(particle),pdgMother); | |
303 | } else if (particle->IsA()==AliAODMCParticle::Class()){ | |
304 | return IsMCMotherToEEaod(static_cast<const AliAODMCParticle*>(particle),pdgMother); | |
305 | } else { | |
306 | AliError("Unknown particle type"); | |
307 | } | |
308 | return kFALSE; | |
309 | ||
310 | } | |
311 | ||
312 | //____________________________________________________________ | |
313 | Bool_t AliDielectronMC::IsMCMotherToEEesd(const AliMCParticle *particle, Int_t pdgMother) | |
314 | { | |
315 | // | |
316 | // Check if the Mother 'particle' is of type pdgMother and decays to e+e- | |
317 | // ESD case | |
318 | // | |
319 | ||
320 | //check pdg code | |
321 | if (particle->PdgCode()!=pdgMother) return kFALSE; | |
322 | Int_t ifirst = particle->GetFirstDaughter(); | |
323 | Int_t ilast = particle->GetLastDaughter(); | |
324 | ||
325 | //check number of daughters | |
326 | if ((ilast-ifirst)!=1) return kFALSE; | |
327 | AliMCParticle *firstD=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(ifirst)); | |
328 | AliMCParticle *secondD=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(ilast)); | |
329 | ||
330 | if (firstD->Charge()>0){ | |
331 | if (firstD->PdgCode()!=-11) return kFALSE; | |
332 | if (secondD->PdgCode()!=11) return kFALSE; | |
333 | }else{ | |
334 | if (firstD->PdgCode()!=11) return kFALSE; | |
335 | if (secondD->PdgCode()!=-11) return kFALSE; | |
336 | } | |
337 | ||
338 | return kTRUE; | |
339 | } | |
340 | ||
341 | //____________________________________________________________ | |
342 | Bool_t AliDielectronMC::IsMCMotherToEEaod(const AliAODMCParticle *particle, Int_t pdgMother) | |
343 | { | |
344 | // | |
345 | // Check if the Mother 'particle' is of type pdgMother and decays to e+e- | |
346 | // AOD case | |
347 | // | |
348 | if (particle->GetPdgCode()!=pdgMother) return kFALSE; | |
349 | if (particle->GetNDaughters()!=2) return kFALSE; | |
350 | ||
351 | Int_t ifirst = particle->GetDaughter(0); | |
352 | Int_t ilast = particle->GetDaughter(1); | |
353 | ||
354 | //check number of daughters | |
355 | if ((ilast-ifirst)!=1) return kFALSE; | |
356 | AliAODMCParticle *firstD=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(ifirst)); | |
357 | AliAODMCParticle *secondD=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(ilast)); | |
358 | ||
359 | if (firstD->Charge()>0){ | |
360 | if (firstD->GetPdgCode()!=11) return kFALSE; | |
361 | if (secondD->GetPdgCode()!=-11) return kFALSE; | |
362 | }else{ | |
363 | if (firstD->GetPdgCode()!=-11) return kFALSE; | |
364 | if (secondD->GetPdgCode()!=11) return kFALSE; | |
365 | } | |
366 | return kTRUE; | |
367 | } | |
368 | ||
369 | //____________________________________________________________ | |
a655b716 | 370 | Int_t AliDielectronMC::GetLabelMotherWithPdg(const AliVParticle *particle1, const AliVParticle *particle2, Int_t pdgMother) |
b2a297fa | 371 | { |
372 | // | |
373 | // test if mother of particle 1 and 2 has pdgCode pdgMother and is the same; | |
374 | // | |
a655b716 | 375 | if (!fMCEvent) return -1; |
b2a297fa | 376 | |
a655b716 | 377 | if (fAnaType==kESD) return GetLabelMotherWithPdgESD(particle1, particle2, pdgMother); |
378 | else if (fAnaType==kAOD) return GetLabelMotherWithPdgAOD(particle1, particle2, pdgMother); | |
b2a297fa | 379 | |
a655b716 | 380 | return -1; |
b2a297fa | 381 | } |
382 | ||
383 | //____________________________________________________________ | |
a655b716 | 384 | Int_t AliDielectronMC::GetLabelMotherWithPdgESD(const AliVParticle *particle1, const AliVParticle *particle2, Int_t pdgMother) |
b2a297fa | 385 | { |
386 | // | |
a655b716 | 387 | // test if mother of particle 1 and 2 has pdgCode +-11 (electron), |
388 | // have the same mother and the mother had pdg code pdgMother | |
b2a297fa | 389 | // ESD case |
390 | // | |
391 | ||
392 | AliMCParticle *mcPart1=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(particle1->GetLabel())); | |
393 | AliMCParticle *mcPart2=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(particle2->GetLabel())); | |
394 | ||
a655b716 | 395 | if (!mcPart1||!mcPart2) return -1; |
b2a297fa | 396 | |
397 | Int_t lblMother1=mcPart1->GetMother(); | |
398 | Int_t lblMother2=mcPart2->GetMother(); | |
399 | ||
400 | AliMCParticle *mcMother1=static_cast<AliMCParticle*>(GetMCTrackFromMCEvent(lblMother1)); | |
a655b716 | 401 | if (!mcMother1) return -1; |
402 | if (lblMother1!=lblMother2) return -1; | |
403 | if (TMath::Abs(mcPart1->PdgCode())!=11) return -1; | |
572b0139 | 404 | if (mcPart1->PdgCode()!=-mcPart2->PdgCode()) return -1; |
a655b716 | 405 | if (mcMother1->PdgCode()!=pdgMother) return -1; |
b2a297fa | 406 | |
a655b716 | 407 | return lblMother1; |
b2a297fa | 408 | } |
409 | ||
410 | //____________________________________________________________ | |
a655b716 | 411 | Int_t AliDielectronMC::GetLabelMotherWithPdgAOD(const AliVParticle *particle1, const AliVParticle *particle2, Int_t pdgMother) |
b2a297fa | 412 | { |
413 | // | |
a655b716 | 414 | // test if mother of particle 1 and 2 has pdgCode +-11 (electron), |
415 | // have the same mother and the mother had pdg code pdgMother | |
b2a297fa | 416 | // AOD case |
417 | // | |
418 | AliAODMCParticle *mcPart1=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(particle1->GetLabel())); | |
419 | AliAODMCParticle *mcPart2=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(particle2->GetLabel())); | |
420 | ||
a655b716 | 421 | if (!mcPart1||!mcPart2) return -1; |
b2a297fa | 422 | |
423 | Int_t lblMother1=mcPart1->GetMother(); | |
424 | Int_t lblMother2=mcPart2->GetMother(); | |
425 | ||
426 | AliAODMCParticle *mcMother1=static_cast<AliAODMCParticle*>(GetMCTrackFromMCEvent(lblMother1)); | |
427 | ||
a655b716 | 428 | if (!mcMother1) return -1; |
429 | if (lblMother1!=lblMother2) return -1; | |
430 | if (TMath::Abs(mcPart1->GetPdgCode())!=11) return -1; | |
572b0139 | 431 | if (mcPart1->GetPdgCode()!=-mcPart2->GetPdgCode()) return -1; |
a655b716 | 432 | if (mcMother1->GetPdgCode()!=pdgMother) return -1; |
b2a297fa | 433 | |
a655b716 | 434 | return lblMother1; |
b2a297fa | 435 | } |
436 | ||
6551594b | 437 | //____________________________________________________________ |
438 | void AliDielectronMC::GetDaughters(const TObject *mother, AliVParticle* &d1, AliVParticle* &d2) | |
439 | { | |
440 | // | |
441 | // Get First two daughters of the mother | |
442 | // | |
443 | ||
444 | Int_t lblD1=-1; | |
445 | Int_t lblD2=-1; | |
446 | d1=0; | |
447 | d2=0; | |
448 | if (!fMCEvent) return; | |
449 | if (fAnaType==kAOD){ | |
450 | const AliAODMCParticle *aodMother=static_cast<const AliAODMCParticle*>(mother); | |
451 | lblD1=aodMother->GetDaughter(0); | |
452 | lblD2=aodMother->GetDaughter(1); | |
453 | } else if (fAnaType==kESD){ | |
454 | const AliMCParticle *aodMother=static_cast<const AliMCParticle*>(mother); | |
455 | lblD1=aodMother->GetFirstDaughter(); | |
456 | lblD2=aodMother->GetLastDaughter(); | |
457 | } | |
458 | d1=fMCEvent->GetTrack(lblD1); | |
459 | d2=fMCEvent->GetTrack(lblD2); | |
460 | } |