]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/correlationHF/AliDxHFEParticleSelectionMCEl.cxx
0874d841c31e0318ceda579ddc18a0bada331dd4
[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 AliDxHFEParticleSelectionMCEl::~AliDxHFEParticleSelectionMCEl()
82 {
83   // destructor
84 }
85
86 THnSparse* AliDxHFEParticleSelectionMCEl::DefineTHnSparse()
87 {
88   //
89   // Defines the THnSparse. 
90
91   const int thnSize = 6;
92   InitTHnSparseArray(thnSize);
93   const double Pi=TMath::Pi();
94   TString name;
95   name.Form("%s info", GetName());
96
97   //                           0    1      2     3       4         5
98   //                           Pt   Phi   Eta  'stat e'  mother "pdg e"
99   int    thnBins[thnSize] = { 1000,  200, 500,    2,       14,      10 };
100   double thnMin [thnSize] = {    0,    0, -1., -0.5,     -1.5,    -0.5 };
101   double thnMax [thnSize] = {  100, 2*Pi,  1.,  1.5,     12.5,     9.5 };
102   const char* thnNames[thnSize]={
103     "Pt",
104     "Phi",
105     "Eta", 
106     "MC statistics electron",
107     "Mother", 
108     "PDG of selected electron"
109   };
110  
111   return CreateControlTHnSparse(name,thnSize,thnBins,thnMin,thnMax,thnNames);
112 }
113
114 int AliDxHFEParticleSelectionMCEl::FillParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
115 {
116   // fill the data array from the particle data
117   if (!data) return -EINVAL;
118   AliAODTrack *track=(AliAODTrack*)p;
119   if (!track) return -ENODATA;
120   int i=0;
121   if (dimension!=GetDimTHnSparse()) {
122     // TODO: think about filling only the available data and throwing a warning
123     return -ENOSPC;
124   }
125   data[i++]=track->Pt();
126   data[i++]=track->Phi();
127   data[i++]=track->Eta();
128   data[i++]=fResultMC;     // stat electron (MC electron or not)
129   data[i++]=fOriginMother; // at the moment not included background. Should expand
130   data[i++]=1;             // PDG e - not sure if needed, maybe only needed as separate histo? 
131   
132   return i;
133 }
134
135 int AliDxHFEParticleSelectionMCEl::IsSelected(AliVParticle* p, const AliVEvent* pEvent)
136 {
137   /// overloaded from AliDxHFEParticleSelection: check particle
138   /// H: Have changed function. Now doing particle selection first, then run MC over 
139   /// selected tracks. Could configure it to be configurable, but not sure if it
140   /// is needed.  
141   /// Result from normal track selection is returned, result from MC is stored in
142   /// THnSparse. 
143
144   int iResult=0;
145   if (!p || !pEvent){
146     return -EINVAL;
147   }
148   // step 1:
149   // optional MC selection before the particle selection
150   if (fMCTools.MCFirst() && (iResult=CheckMC(p, pEvent))==0) {
151     // histograming?
152     return iResult;
153   }
154
155   // step 2 or 1, depending on sequence:
156   // normal particle selection
157   iResult=AliDxHFEParticleSelectionEl::IsSelected(p, pEvent);
158   if (fMCTools.MCFirst() || iResult==0) return iResult;
159
160   // step 2, only executed if MC check is last
161   // optional MC selection after the particle selection
162   // result stored to be filled into THnSparse
163   // TODO: strictly speaken the particles should be rejected
164   // if not mc selected, however skip this for the moment, because of
165   // the logic outside
166   fResultMC=CheckMC(p, pEvent);
167
168   return iResult;
169 }
170
171 int AliDxHFEParticleSelectionMCEl::CheckMC(AliVParticle* p, const AliVEvent* pEvent)
172 {
173   /// check if MC criteria are fulfilled
174   if (!p || !pEvent){
175     return -EINVAL;
176   }
177   fOriginMother=-1;
178   int iResult=0;
179
180   if (!fMCTools.IsInitialized() && (iResult=fMCTools.InitMCParticles(pEvent))<0) {
181     // TODO: message? but has to be filtered in order to avoid message flood
182     return 0; // no meaningful filtering on mc possible
183   }
184  
185   if (fMCTools.RejectByPDG(p,false)) {
186     // rejected by pdg
187     // would also like to use this info? or not meaningful?
188     // NEED TO CHANGE THIS!
189     return 0;
190   }
191
192   int pdgMother=0;
193   pdgMother=fMCTools.FindMotherPDG(p,AliDxHFEToolsMC::kGetFirstMother);
194
195   // Particles considered HFE background. can be expanded
196   // Should be created only once 
197   // TODO: that needs to be configured once to avoid performance penalty
198   vector<int> motherPDGs;
199   motherPDGs.push_back(AliDxHFEToolsMC::kPDGpi0); 
200   motherPDGs.push_back(AliDxHFEToolsMC::kPDGeta);
201   motherPDGs.push_back(AliDxHFEToolsMC::kPDGgamma);
202   motherPDGs.push_back(AliDxHFEToolsMC::kPDGJpsi);
203
204   if(fMCTools.RejectByPDG(pdgMother,motherPDGs)){
205     pdgMother=fMCTools.FindMotherPDG(p,AliDxHFEToolsMC::kGetOriginMother);
206     fOriginMother=fMCTools.GetOriginMother();
207   }
208   else{
209     //Could this be done in a more elegant way?
210     switch(pdgMother){
211     case(AliDxHFEToolsMC::kPDGpi0): fOriginMother=AliDxHFEToolsMC::kNrOrginMother; break;
212     case(AliDxHFEToolsMC::kPDGeta): fOriginMother=AliDxHFEToolsMC::kNrOrginMother+1; break;
213     case(AliDxHFEToolsMC::kPDGgamma): fOriginMother=AliDxHFEToolsMC::kNrOrginMother+2;break;
214     case(AliDxHFEToolsMC::kPDGJpsi): fOriginMother=AliDxHFEToolsMC::kNrOrginMother+3;break;
215     }
216   }
217
218   /*if (fMCTools.RejectByMotherPDG(p)) {
219     // rejected by pdg of original mother
220     // H: want pdg of origin process to be stored in THnSparse
221     // Not sure if this is needed... Need to check, using AliDxHFEToolsMC, who
222     // first mother are, and also what origin is. Use this info here. 
223     return 0;
224     }*/
225
226   return 1;
227 }
228
229 void AliDxHFEParticleSelectionMCEl::Clear(const char* option)
230 {
231   /// clear internal memory
232   fMCTools.Clear(option);
233 }