]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/correlationHF/AliDxHFEParticleSelectionMCD0.cxx
MC implementations for D0-HFE correlation (Matthias)
[u/mrichter/AliRoot.git] / PWGHF / correlationHF / AliDxHFEParticleSelectionMCD0.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE Project            * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                  Hege Erdal       <hege.erdal@gmail.com>               *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /// @file   AliDxHFEParticleSelectionMCD0.cxx
20 /// @author Hege Erdal, Matthias Richter
21 /// @date   2012-07-19
22 /// @brief  MC D0 selection for D0-HFE correlation
23 ///
24
25 #include "AliDxHFEParticleSelectionMCD0.h"
26 #include "AliAODRecoDecayHF2Prong.h"
27 #include "AliAODTrack.h"
28 #include "AliAODMCParticle.h"
29 #include "AliVParticle.h"
30 #include <iostream>
31 #include <cerrno>
32 #include <memory>
33
34 using namespace std;
35
36 /// ROOT macro for the implementation of ROOT specific class methods
37 ClassImp(AliDxHFEParticleSelectionMCD0)
38
39 // TODO: can that be a common definition
40 const char* AliDxHFEParticleSelectionMCD0::fgkTrackControlBinNames[]={
41 "Pt",
42 "Phi",
43 "Ptbin", 
44 "D0InvMass", 
45 "Eta",
46 "Statistics D0",
47 "Mother of D0"
48 };
49
50 AliDxHFEParticleSelectionMCD0::AliDxHFEParticleSelectionMCD0(const char* opt)
51   : AliDxHFEParticleSelectionD0(opt)
52   , fMCTools()
53   , fResultMC(0)
54   , fOriginMother(0)
55 {
56   // constructor
57   // 
58   // 
59   // 
60   // 
61
62   // TODO: argument scan, pass only relevant arguments to tools
63   fMCTools.~AliDxHFEToolsMC();
64   TString toolopt("pdg=421 mc-last");
65   new (&fMCTools) AliDxHFEToolsMC(toolopt);
66 }
67
68 AliDxHFEParticleSelectionMCD0::~AliDxHFEParticleSelectionMCD0()
69 {
70   // destructor
71 }
72 THnSparse* AliDxHFEParticleSelectionMCD0::DefineTHnSparse() const
73 {
74   //
75   // Defines the THnSparse.
76   // could/should remove Pt and leave Ptbin
77
78   const int thnSize2 = 7;
79   const double Pi=TMath::Pi();
80   TString name;
81   name.Form("%s info", GetName());
82
83   //                           0    1      2      3          4     5         6      
84   //                           Pt   Phi   Ptbin  D0InvMass  Eta  'stat D0'  mother 
85   int    thnBins[thnSize2] = { 1000,  200, 21,     200,     500,     2,       10  };
86   double thnMin [thnSize2] = {    0,    0,  0,    1.5648,   -1.,  -0.5,     -1.5  };
87   double thnMax [thnSize2] = {  100, 2*Pi, 20,    2.1648,    1.,   1.5,      8.5  };
88
89   return CreateControlTHnSparse(name,thnSize2,thnBins,thnMin,thnMax,fgkTrackControlBinNames);
90
91 }
92
93 int AliDxHFEParticleSelectionMCD0::DefineParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
94 {
95   // fill the data array from the particle data
96   if (!data) return -EINVAL;
97   AliAODTrack *track=(AliAODTrack*)p;
98   if (!track) return -ENODATA;
99   int i=0;
100   // TODO: this corresponds to the THnSparse dimensions which is available in the same class
101   // use this consistently
102   const int requiredDimension=7;
103   if (dimension!=requiredDimension) {
104     // TODO: think about filling only the available data and throwing a warning
105     return -ENOSPC;
106   }
107   data[i++]=track->Pt();
108   data[i++]=track->Phi();
109   data[i++]=AliDxHFEParticleSelectionMCD0::GetPtBin(); 
110   data[i++]=AliDxHFEParticleSelectionMCD0::GetInvMass();
111   data[i++]=track->Eta();
112   data[i++]=fResultMC;     // stat electron (MC electron or not)
113   data[i++]=fOriginMother; // at the moment not included background. Should expand
114
115   return i;
116 }
117
118 int AliDxHFEParticleSelectionMCD0::IsSelected(AliVParticle* p, const AliVEvent* pEvent)
119 {
120   /// overloaded from AliDxHFEParticleSelection: check particle
121   /// H: Have changed function. Now doing particle selection first, then run MC over 
122   /// selected tracks. Could configure it to be configurable, but not sure if it
123   /// is needed.  
124   /// result from normal track selection is returned, result from MC is stored in
125   /// THnSparse. 
126
127   int iResult=0;
128   fOriginMother=-1;
129
130   // step 1:
131   // MC selection
132   if (fMCTools.MCFirst() && (iResult=CheckMC(p, pEvent))==0) {
133     // histograming?
134     return iResult;
135   }
136
137   // step 2 or 1, depending on sequence:
138   // normal particle selection
139   iResult=AliDxHFEParticleSelectionD0::IsSelected(p, pEvent);
140   if (fMCTools.MCFirst() || iResult==0) return iResult;
141
142   // step 2, only executed if MC check is last
143   // MC selection  - > Should maybe also distinguish between D0 and D0bar
144   iResult=CheckMC(p, pEvent);
145   // TODO: why do we need to store the result in a member?
146   fResultMC=iResult;
147  
148   return iResult;
149 }
150
151 int AliDxHFEParticleSelectionMCD0::CheckMC(AliVParticle* p, const AliVEvent* pEvent)
152 {
153   /// check if MC criteria are fulfilled
154   // Check both D0 and D0bar (for now only D0)
155
156   if (!p || !pEvent){
157     return -EINVAL;
158   }
159   int iResult=0;
160
161   if (!fMCTools.IsInitialized() && (iResult=fMCTools.InitMCParticles(pEvent))<0) {
162     // TODO: message? but has to be filtered in order to avoid message flood
163     return 0; // no meaningful filtering on mc possible
164   }
165
166   AliAODRecoDecayHF2Prong *particle = dynamic_cast<AliAODRecoDecayHF2Prong*>(p);
167
168   if(!particle) return 0;
169
170   Int_t pdgDgD0toKpi[2]={AliDxHFEToolsMC::kPDGkaon,AliDxHFEToolsMC::kPDGpion};
171
172   TClonesArray* fMCArray = dynamic_cast<TClonesArray*>(fMCTools.GetMCArray());
173   if(!fMCArray) {cout << "no array" << endl; return -1;}
174
175   // find associated MC particle for D0->Kpi
176   Int_t MClabel=-9999;
177
178   //return MC particle label if the array corresponds to a D0, -1 if not (cf. AliAODRecoDecay.cxx). Checks both D0s and daughters
179   MClabel=particle->MatchToMC(AliDxHFEToolsMC::kPDGD0,fMCArray,2,pdgDgD0toKpi); 
180   
181   if(MClabel<0){
182     fOriginMother=-1;
183     return 0;
184   }
185
186   fMCTools.SetMClabel(MClabel);
187   fMCTools.FindMotherPDG(p,AliDxHFEToolsMC::kGetOriginMother);
188   fOriginMother=fMCTools.GetOriginMother();
189
190   return 1;
191 }
192
193 void AliDxHFEParticleSelectionMCD0::Clear(const char* option)
194 {
195   /// clear internal memory
196   fMCTools.Clear(option);
197 }