]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/correlationHF/AliDxHFEParticleSelectionMCEl.cxx
MC implementations for D0-HFE correlation (Matthias)
[u/mrichter/AliRoot.git] / PWGHF / correlationHF / AliDxHFEParticleSelectionMCEl.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   AliDxHFEParticleSelectionMCEl.cxx
20 /// @author Hege Erdal, Matthias Richter
21 /// @date   2012-07-19
22 /// @brief  MC El selection for D0-HFE correlation
23 ///
24
25 #include "AliDxHFEParticleSelectionMCEl.h"
26 #include "AliVParticle.h"
27 #include "AliLog.h"
28 #include "THnSparse.h"
29 #include "AliAODMCParticle.h"
30 #include "TH1F.h"
31 #include "TAxis.h"
32 #include "AliAODTrack.h"
33 #include <iostream>
34 #include <cerrno>
35 #include <memory>
36
37 using namespace std;
38 using std::vector;
39
40
41 /// ROOT macro for the implementation of ROOT specific class methods
42 ClassImp(AliDxHFEParticleSelectionMCEl)
43
44 AliDxHFEParticleSelectionMCEl::AliDxHFEParticleSelectionMCEl(const char* opt)
45   : AliDxHFEParticleSelectionEl(opt)
46   , fMCTools()
47   , fElectronProperties(NULL)
48   , fWhichCut(NULL)
49   , fOriginMother(0)
50   , fResultMC(0)
51 {
52   // constructor
53   // 
54   // 
55   // 
56   // 
57
58   fMCTools.~AliDxHFEToolsMC();
59
60   // TODO: argument scan, build tool options accordingly
61   // e.g. set mc mode first/last, skip control histograms
62   TString toolopt("pdg=11 mc-last");
63   new (&fMCTools) AliDxHFEToolsMC(toolopt);
64 }
65
66 //at the moment not used, keep for now (to be used when plotting)
67 const char* AliDxHFEParticleSelectionMCEl::fgkPDGMotherBinLabels[]={
68   "d",
69   "u",
70   "s",
71   "c",
72   "b",
73   "gluon",
74   "gamma",
75   "#pi^{0}",
76   "#eta",
77   "proton",
78   "others"
79 };
80
81 const char* AliDxHFEParticleSelectionMCEl::fgkTrackControlBinNames[]={
82   "Pt",
83   "Phi",
84   "Eta", 
85   "MC statistics electron"
86   "Mother", 
87   "PDG of selected electron", 
88 };
89
90 AliDxHFEParticleSelectionMCEl::~AliDxHFEParticleSelectionMCEl()
91 {
92   // destructor
93 }
94
95 THnSparse* AliDxHFEParticleSelectionMCEl::DefineTHnSparse() const
96 {
97   //
98   // Defines the THnSparse. 
99
100   const int thnSize = 6;
101   const double Pi=TMath::Pi();
102   TString name;
103   name.Form("%s info", GetName());
104
105   //                           0    1      2     3       4         5
106   //                           Pt   Phi   Eta  'stat e'  mother "pdg e"
107   int    thnBins[thnSize] = { 1000,  200, 500,    2,       14,      10 };
108   double thnMin [thnSize] = {    0,    0, -1., -0.5,     -1.5,    -0.5 };
109   double thnMax [thnSize] = {  100, 2*Pi,  1.,  1.5,     12.5,     9.5 };
110  
111   return CreateControlTHnSparse(name,thnSize,thnBins,thnMin,thnMax,fgkTrackControlBinNames);
112
113 }
114
115 int AliDxHFEParticleSelectionMCEl::DefineParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
116 {
117   // fill the data array from the particle data
118   if (!data) return -EINVAL;
119   AliAODTrack *track=(AliAODTrack*)p;
120   if (!track) return -ENODATA;
121   int i=0;
122   // TODO: this corresponds to the THnSparse dimensions which is available in the same class
123   // use this consistently
124   const int requiredDimension=6;
125   if (dimension!=requiredDimension) {
126     // TODO: think about filling only the available data and throwing a warning
127     return -ENOSPC;
128   }
129   data[i++]=track->Pt();
130   data[i++]=track->Phi();
131   data[i++]=track->Eta();
132   data[i++]=fResultMC;     // stat electron (MC electron or not)
133   data[i++]=fOriginMother; // at the moment not included background. Should expand
134   data[i++]=1;             // PDG e - not sure if needed, maybe only needed as separate histo? 
135   
136   return i;
137 }
138
139 int AliDxHFEParticleSelectionMCEl::IsSelected(AliVParticle* p, const AliVEvent* pEvent)
140 {
141   /// overloaded from AliDxHFEParticleSelection: check particle
142   /// H: Have changed function. Now doing particle selection first, then run MC over 
143   /// selected tracks. Could configure it to be configurable, but not sure if it
144   /// is needed.  
145   /// Result from normal track selection is returned, result from MC is stored in
146   /// THnSparse. 
147
148   int iResult=0;
149   if (!p || !pEvent){
150     return -EINVAL;
151   }
152   // step 1:
153   // optional MC selection before the particle selection
154   if (fMCTools.MCFirst() && (iResult=CheckMC(p, pEvent))==0) {
155     // histograming?
156     return iResult;
157   }
158
159   // step 2 or 1, depending on sequence:
160   // normal particle selection
161   iResult=AliDxHFEParticleSelectionEl::IsSelected(p, pEvent);
162   if (fMCTools.MCFirst() || iResult==0) return iResult;
163
164   // step 2, only executed if MC check is last
165   // optional MC selection after the particle selection
166   iResult=CheckMC(p, pEvent);
167   // TODO: why do we need to store the result in a member?
168   fResultMC=iResult;
169  
170   return iResult;
171 }
172
173 int AliDxHFEParticleSelectionMCEl::CheckMC(AliVParticle* p, const AliVEvent* pEvent)
174 {
175   /// check if MC criteria are fulfilled
176   if (!p || !pEvent){
177     return -EINVAL;
178   }
179   fOriginMother=-1;
180   int iResult=0;
181
182   if (!fMCTools.IsInitialized() && (iResult=fMCTools.InitMCParticles(pEvent))<0) {
183     // TODO: message? but has to be filtered in order to avoid message flood
184     return 0; // no meaningful filtering on mc possible
185   }
186  
187   if (fMCTools.RejectByPDG(p,false)) {
188     // rejected by pdg
189     // would also like to use this info? or not meaningful?
190     // NEED TO CHANGE THIS!
191     return 0;
192   }
193
194   int pdgMother=0;
195   pdgMother=fMCTools.FindMotherPDG(p,AliDxHFEToolsMC::kGetFirstMother);
196
197   // Particles considered HFE background. can be expanded
198   // Should be created only once 
199   // TODO: that needs to be configured once to avoid performance penalty
200   vector<int> motherPDGs;
201   motherPDGs.push_back(AliDxHFEToolsMC::kPDGpi0); 
202   motherPDGs.push_back(AliDxHFEToolsMC::kPDGeta);
203   motherPDGs.push_back(AliDxHFEToolsMC::kPDGgamma);
204   motherPDGs.push_back(AliDxHFEToolsMC::kPDGJpsi);
205
206   if(fMCTools.RejectByPDG(pdgMother,motherPDGs)){
207     pdgMother=fMCTools.FindMotherPDG(p,AliDxHFEToolsMC::kGetOriginMother);
208     fOriginMother=fMCTools.GetOriginMother();
209   }
210   else{
211     //Could this be done in a more elegant way?
212     switch(pdgMother){
213     case(AliDxHFEToolsMC::kPDGpi0): fOriginMother=AliDxHFEToolsMC::kNrOrginMother; break;
214     case(AliDxHFEToolsMC::kPDGeta): fOriginMother=AliDxHFEToolsMC::kNrOrginMother+1; break;
215     case(AliDxHFEToolsMC::kPDGgamma): fOriginMother=AliDxHFEToolsMC::kNrOrginMother+2;break;
216     case(AliDxHFEToolsMC::kPDGJpsi): fOriginMother=AliDxHFEToolsMC::kNrOrginMother+3;break;
217     }
218   }
219
220   /*if (fMCTools.RejectByMotherPDG(p)) {
221     // rejected by pdg of original mother
222     // H: want pdg of origin process to be stored in THnSparse
223     // Not sure if this is needed... Need to check, using AliDxHFEToolsMC, who
224     // first mother are, and also what origin is. Use this info here. 
225     return 0;
226     }*/
227
228   return 1;
229 }
230
231 void AliDxHFEParticleSelectionMCEl::Clear(const char* option)
232 {
233   /// clear internal memory
234   fMCTools.Clear(option);
235 }