]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/hfe/AliHFEsignalCuts.cxx
Cleanup the code. Fix memory leak. Now inherit from AliAnalysisTaskSE (Antoine, Phili...
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEsignalCuts.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 /* $Id$ */
17
18 //
19 // Signal cuts
20 // Checks whether a particle (reconstructed or MC) is coming from MC Signal
21 // For more information see implementation file
22 //
23 // Autor:
24 //   Markus Fasel <M.Fasel@gsi.de>
25 //
26 #include <TClass.h>
27 #include <TMath.h>
28 #include <TParticle.h>
29 #include <TString.h>
30
31 #include "AliAODMCParticle.h"
32 #include "AliLog.h"
33 #include "AliMCEvent.h"
34 #include "AliMCParticle.h"
35 #include "AliVParticle.h"
36
37 #include "AliHFEsignalCuts.h"
38 #include "AliHFEmcQA.h"
39
40 ClassImp(AliHFEsignalCuts)
41
42 //____________________________________________________________
43 AliHFEsignalCuts::AliHFEsignalCuts():
44   AliAnalysisCuts(),
45   fMC(NULL),
46   fMCQA(NULL)
47 {
48   //
49   // Dummy constructor
50   //
51 }
52
53 //____________________________________________________________
54 AliHFEsignalCuts::AliHFEsignalCuts(const Char_t *name, const Char_t *title):
55   AliAnalysisCuts(name, title),
56   fMC(NULL),
57   fMCQA(NULL)
58 {
59   //
60   // Default constructor
61   //
62   fMCQA = new AliHFEmcQA;
63   if(fMCQA) fMCQA->Init();
64 }
65
66 //____________________________________________________________
67 AliHFEsignalCuts::AliHFEsignalCuts(const AliHFEsignalCuts &ref):
68   AliAnalysisCuts(ref),
69   fMC(ref.fMC),
70   fMCQA(ref.fMCQA)
71 {
72   //
73   // Copy constructor
74   //
75 }
76
77 //____________________________________________________________
78 AliHFEsignalCuts &AliHFEsignalCuts::operator=(const AliHFEsignalCuts &ref){
79   //
80   // Assignment operator
81   //
82   if(this != &ref){
83     fMC = ref.fMC; 
84     fMCQA = ref.fMCQA; 
85   }
86   return *this;
87 }
88
89 //____________________________________________________________
90 AliHFEsignalCuts::~AliHFEsignalCuts(){
91   //
92   // Destructor
93   //
94   if(fMCQA) delete fMCQA;
95 }
96
97 //____________________________________________________________
98 void AliHFEsignalCuts::SetMCEvent(AliMCEvent *mc){ 
99   //
100   // Set mc event
101   //
102   fMC = mc; 
103   if(fMCQA) fMCQA->SetMCEvent(mc);
104 }
105
106 //____________________________________________________________
107 Bool_t AliHFEsignalCuts::IsSelected(TObject *o){
108   //
109   // Define signal as electron coming from charm or beauty
110   // @TODO: Implement setter so that also either of them can be defined
111   // as signal alone
112   
113
114   return IsCharmElectron(o) || IsBeautyElectron(o);
115 /*  
116   //saving time?
117   Int_t esources = GetElecSource(dynamic_cast<const AliVParticle *>(o));
118   if(esources>0)printf("esources= %d\n",esources);
119   if(esources == AliHFEmcQA::kDirectCharm || esources == AliHFEmcQA::kDirectBeauty || esources == AliHFEmcQA::kBeautyCharm)  // 1: direct D->e, 2: B->e 3: B->D->e
120     return kTRUE;
121   else
122     return kFALSE;
123 */
124
125 }
126
127 //____________________________________________________________
128 Bool_t AliHFEsignalCuts::IsCharmElectron(const TObject * const o) const {
129   //
130   // Check if mother is coming from Charm
131   //
132   if(!dynamic_cast<const AliVParticle *>(o)) return kFALSE;
133   Int_t esources = GetElecSource(dynamic_cast<const AliVParticle *>(o));
134   if(esources == AliHFEmcQA::kDirectCharm)  // 1: direct D->e
135     return kTRUE;
136   else
137     return kFALSE;
138 }
139
140 //____________________________________________________________
141 Bool_t AliHFEsignalCuts::IsBeautyElectron(const TObject * const o) const {
142   //
143   // Check if mother is coming from Beauty
144   //
145   if(!dynamic_cast<const AliVParticle *>(o)) return kFALSE;
146   Int_t esources = GetElecSource(dynamic_cast<const AliVParticle *>(o));
147   if(esources == AliHFEmcQA::kDirectBeauty || esources == AliHFEmcQA::kBeautyCharm)  // 2: B->e 3: B->D->e
148     return kTRUE;
149   else
150     return kFALSE;
151 }
152
153 //____________________________________________________________
154 Bool_t AliHFEsignalCuts::IsGammaElectron(const TObject * const o) const {
155   //
156   // Check for MC if the electron is coming from Gamma
157   //
158   if(!dynamic_cast<const AliVParticle *>(o)) return kFALSE;
159   Int_t esources = GetElecSource(dynamic_cast<const AliVParticle *>(o));
160   if(esources == AliHFEmcQA::kGamma)  // 4: conversion electrons
161     return kTRUE;
162   else
163     return kFALSE;
164 }
165
166 /*
167 //____________________________________________________________
168 Bool_t AliHFEsignalCuts::IsCharmElectron(const TObject * const o) const {
169   //
170   // Check if mother is coming from Charm
171   //
172   if(TMath::Abs(GetTrackPDG(dynamic_cast<const AliVParticle *>(o))) != 11) return kFALSE;
173   Int_t motherpdg = TMath::Abs(GetMotherPDG(dynamic_cast<const AliVParticle *>(o)));
174   AliDebug(1, Form("Mother PDG %d\n", motherpdg));
175
176   if((motherpdg % 1000) / 100 == 4) return kTRUE;    // charmed meson, 3rd position in pdg code == 4
177   if(motherpdg / 1000 == 4) return kTRUE;            // charmed baryon, 4th position in pdg code == 4
178   AliDebug(1, "No Charm\n");
179   return kFALSE;
180 }
181
182 //____________________________________________________________
183 Bool_t AliHFEsignalCuts::IsBeautyElectron(const TObject * const o) const {
184   //
185   // Check if mother is coming from Beauty
186   //
187   if(TMath::Abs(GetTrackPDG(dynamic_cast<const AliVParticle *>(o))) != 11) return kFALSE;
188   Int_t motherpdg = TMath::Abs(GetMotherPDG(dynamic_cast<const AliVParticle *>(o)));
189   AliDebug(1, Form("Mother PDG %d\n", motherpdg));
190
191   if((motherpdg % 1000) / 100 == 5) return kTRUE;   // beauty meson, 3rd position in pdg code == 5
192   if(motherpdg / 1000 == 5) return kTRUE;           // beauty baryon, 4th position in pdg code == 5   
193   AliDebug(1, "No Beauty\n");
194   return kFALSE;
195 }
196
197 //____________________________________________________________
198 Bool_t AliHFEsignalCuts::IsGammaElectron(const TObject * const o) const {
199   //
200   // Check for MC if the electron is coming from Gamma
201   //
202   if(TMath::Abs(GetTrackPDG(dynamic_cast<const AliVParticle *>(o))) != 11) return kFALSE;
203   Int_t motherpdg = TMath::Abs(GetMotherPDG(dynamic_cast<const AliVParticle *>(o)));
204   AliDebug(1, Form("Mother PDG %d\n", motherpdg));
205
206   if(motherpdg!=22){
207     AliDebug(1, "No Gamma");
208     return kFALSE;
209   } else { 
210     AliDebug(1, "Gamma");
211     return kTRUE;
212   }
213 }
214 */
215
216 //____________________________________________________________
217 Int_t AliHFEsignalCuts::GetMotherPDG(const AliVParticle * const track) const {
218   //
219   // Get Mother Pdg code for reconstructed respectively MC tracks
220   // 
221   if(!fMC){
222     AliDebug(1, "No MC Event Available\n");
223     return 0;
224   }
225   const AliVParticle *motherParticle = NULL, *mctrack = NULL;
226   TString objectType = track->IsA()->GetName();
227   if(objectType.CompareTo("AliESDtrack") == 0 || objectType.CompareTo("AliAODTrack") == 0){
228     // Reconstructed track
229     if(track->GetLabel())
230       mctrack = fMC->GetTrack(TMath::Abs(track->GetLabel()));
231   } else {
232     // MCParticle
233     mctrack = track;
234   }
235
236   if(!mctrack) return 0;
237   
238   Int_t motherPDG = 0;
239   if(TString(mctrack->IsA()->GetName()).CompareTo("AliMCParticle") == 0){
240     // case MC Particle
241     const AliMCParticle *esdmctrack = dynamic_cast<const AliMCParticle *>(mctrack);
242     if(esdmctrack) motherParticle = fMC->GetTrack(esdmctrack->Particle()->GetFirstMother());
243     if(motherParticle){
244       const AliMCParticle *esdmcmother = dynamic_cast<const AliMCParticle *>(motherParticle);
245       if(esdmcmother) motherPDG = TMath::Abs(esdmcmother->Particle()->GetPdgCode());
246     }
247   } else {
248     // case AODMCParticle
249     const AliAODMCParticle *aodmctrack = dynamic_cast<const AliAODMCParticle *>(mctrack);
250     if(aodmctrack) motherParticle = fMC->GetTrack(aodmctrack->GetMother());
251     if(motherParticle){
252       const AliAODMCParticle *aodmcmother = dynamic_cast<const AliAODMCParticle *>(motherParticle);
253       if(aodmcmother) motherPDG = TMath::Abs(aodmcmother->GetPdgCode());
254     }
255   }
256   return motherPDG;
257 }
258
259 //____________________________________________________________
260 Int_t AliHFEsignalCuts::GetTrackPDG(const AliVParticle * const track) const {
261         //
262         // Return PDG code of a particle itself
263         //
264   if(!fMC){
265     AliDebug(1, "No MC Event Available\n");
266     return 0;
267   }
268         TString sourcetype = track->IsA()->GetName();
269         const AliVParticle *mctrack = NULL;
270         if(!sourcetype.CompareTo("AliESDtrack") || !sourcetype.CompareTo("AliAODTrack")){
271                 mctrack = fMC->GetTrack(TMath::Abs(track->GetLabel()));
272         } else  mctrack = track;
273         if(!mctrack) return 0;
274
275         TString mctype = mctrack->IsA()->GetName();
276         Int_t trackPdg = 0;
277         if(!mctype.CompareTo("AliMCParticle")){
278                 const AliMCParticle *esdmc = dynamic_cast<const AliMCParticle *>(mctrack);
279                 if(esdmc) trackPdg = esdmc->Particle()->GetPdgCode();
280         } else {
281                 const AliAODMCParticle *aodmc = dynamic_cast< const AliAODMCParticle *>(mctrack);
282                 if(aodmc) trackPdg = aodmc->GetPdgCode();
283         }
284         return trackPdg;
285 }
286
287 //____________________________________________________________
288 Int_t AliHFEsignalCuts::GetElecSource(const AliVParticle * const track) const {
289         //
290         // Return PDG code of a particle itself
291         //
292         
293   if(!fMC){
294     AliDebug(1, "No MC Event Available\n");
295     return 0;
296   }
297   if(!fMCQA){
298     AliDebug(1, "No MCQA Available\n");
299     return 0;
300   }
301   if(!track){
302     AliDebug(1, "Track not Available\n");
303     return 0;
304   }
305
306   TString sourcetype = track->IsA()->GetName();
307   const AliVParticle *mctrack = NULL;
308   TParticle *mcpart = NULL;
309   if(!sourcetype.CompareTo("AliESDtrack") || !sourcetype.CompareTo("AliAODTrack")){
310     mctrack = fMC->GetTrack(TMath::Abs(track->GetLabel()));
311   } else  mctrack = track;
312   if(!mctrack) return 0;
313
314   TString mctype = mctrack->IsA()->GetName();
315   Int_t eSource = 0;
316   if(!mctype.CompareTo("AliMCParticle")){
317     const AliMCParticle *esdmc = dynamic_cast<const AliMCParticle *>(mctrack);
318     if(esdmc){
319       mcpart = esdmc->Particle();
320       eSource=fMCQA->GetElecSource(mcpart);
321     }
322   } else {
323     return -1;
324   }
325   return eSource;
326 }