]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/correlationHF/AliDxHFEParticleSelectionEl.cxx
bugfix: passing event info as requirement for cut on DCA (Per-Ivar)
[u/mrichter/AliRoot.git] / PWGHF / correlationHF / AliDxHFEParticleSelectionEl.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 //*                  Sedat Altinpinar <Sedat.Altinpinar@cern.ch>           *
9 //*                  Hege Erdal       <hege.erdal@gmail.com>               *
10 //*                                                                        *
11 //* Permission to use, copy, modify and distribute this software and its   *
12 //* documentation strictly for non-commercial purposes is hereby granted   *
13 //* without fee, provided that the above copyright notice appears in all   *
14 //* copies and that both the copyright notice and this permission notice   *
15 //* appear in the supporting documentation. The authors make no claims     *
16 //* about the suitability of this software for any purpose. It is          *
17 //* provided "as is" without express or implied warranty.                  *
18 //**************************************************************************
19
20 /// @file   AliDxHFEParticleSelectionEl.cxx
21 /// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
22 /// @date   2012-03-19
23 /// @brief  D0 selection for D0-HFE correlation
24 ///
25 #include "AliDxHFEParticleSelectionEl.h"
26 #include "AliVParticle.h"
27 #include "AliVEvent.h"
28 #include "AliPID.h"
29 #include "AliPIDResponse.h"
30 #include "AliHFEcontainer.h"
31 #include "AliHFEpid.h"
32 #include "AliHFEpidBase.h"
33 #include "AliHFEtools.h"
34 #include "AliHFEcuts.h"
35 #include "AliAODTrack.h"
36 #include "AliAnalysisDataSlot.h"
37 #include "AliAnalysisDataContainer.h"
38 #include "AliAnalysisManager.h"
39 #include "AliCFManager.h"
40 #include "THnSparse.h"
41 #include "TH1F.h"
42 #include "TAxis.h"
43 #include "TObjArray.h"
44 #include <iostream>
45 #include <cerrno>
46 #include <memory>
47
48 using namespace std;
49
50 /// ROOT macro for the implementation of ROOT specific class methods
51 ClassImp(AliDxHFEParticleSelectionEl)
52
53 AliDxHFEParticleSelectionEl::AliDxHFEParticleSelectionEl(const char* opt)
54   : AliDxHFEParticleSelection("electron", opt)
55   , fPID(NULL)
56   , fElectronProperties(NULL)
57   , fWhichCut(NULL)  
58   , fCuts(NULL)
59   , fCFM(NULL)
60 {
61   // constructor
62   // 
63   // 
64   // 
65   // 
66 }
67
68 AliDxHFEParticleSelectionEl::~AliDxHFEParticleSelectionEl()
69 {
70   // destructor
71   if (fElectronProperties) {
72     delete fElectronProperties;
73     fElectronProperties=NULL;
74   }
75   if(fCFM){
76     delete fCFM;
77     fCFM=NULL;
78   }
79   if(fWhichCut){
80     delete fWhichCut;
81     fWhichCut=NULL;
82   }
83
84   // NOTE: external objects fPID and fCuts are not deleted here
85   fPID=NULL;
86   fCuts=NULL;
87 }
88
89 const char* AliDxHFEParticleSelectionEl::fgkTrackControlBinNames[]={
90   "Pt",
91   "Phi",
92   "Eta"
93 };
94
95 const char* AliDxHFEParticleSelectionEl::fgkCutBinNames[]={
96   "kRecKineITSTPC",
97   "kRecPrim",
98   "kHFEcuts",
99   "kHFEcutsTOFPID",
100   "kHFEcutsTPCPID",
101   "kPID",
102   "Selected e"
103 };
104
105 int AliDxHFEParticleSelectionEl::Init()
106 {
107   //
108   // init function
109   // 
110   int iResult=0;
111
112   // Implicit call to InitControlObjects() before setting up CFM and fCuts
113   // (if not there)
114   iResult=AliDxHFEParticleSelection::Init();
115   if (iResult<0) return iResult;
116
117   //--------Initialize correction Framework and Cuts
118   // Consider moving this, either to separate function or
119   // add a set function for AliCFManager
120   // Do we need this? Can we just call AliHFEcuts::CheckParticleCuts
121   AliInfo("Setting up CFM");
122   fCFM = new AliCFManager;
123   // the setup of cut objects is done in AliHFEcuts::Initialize
124   // the ids used by this class must be the same, the code might be broken if
125   // the sequence in AliHFEcuts::Initialize is changed
126   const Int_t kNcutSteps = AliHFEcuts::kNcutStepsMCTrack + AliHFEcuts::kNcutStepsRecTrack + AliHFEcuts::kNcutStepsDETrack;
127   // reset pointers in the CF manager
128   fCFM->SetNStepParticle(kNcutSteps);
129   for(Int_t istep = 0; istep < kNcutSteps; istep++) {
130     fCFM->SetParticleCutsList(istep, NULL);
131   }
132   if(!fCuts) {
133     AliWarning("Cuts not available. Default cuts will be used");
134     fCuts = new AliHFEcuts;
135     fCuts->CreateStandardCuts();
136   }
137   // TODO: error handling?
138   fCuts->Initialize(fCFM);
139
140   return 0;
141
142 }
143
144 THnSparse* AliDxHFEParticleSelectionEl::DefineTHnSparse() const
145 {
146   //
147   // Defines the THnSparse. For now, only calls CreatControlTHnSparse
148   const int thnSize = 3;
149   const double Pi=TMath::Pi();
150   TString name;
151   name.Form("%s info", GetName());
152
153   //                           0    1       2
154   //                           Pt   Phi    Eta
155   int    thnBins[thnSize] = { 1000,  200, 500};
156   double thnMin [thnSize] = {    0,    0, -1.};
157   double thnMax [thnSize] = {  100, 2*Pi,  1.};
158
159   return CreateControlTHnSparse(name,thnSize,thnBins,thnMin,thnMax,fgkTrackControlBinNames);
160
161 }
162
163 int AliDxHFEParticleSelectionEl::InitControlObjects()
164 {
165   /// init control and monitoring objects
166   AliInfo("Electron THnSparse");
167
168   fElectronProperties=DefineTHnSparse();
169   AddControlObject(fElectronProperties);
170
171   //
172   fWhichCut= new TH1F("fWhichCut","effective cut for a rejected particle",kNCutLabels,-0.5,kNCutLabels-0.5);
173   for (int iLabel=0; iLabel<kNCutLabels; iLabel++)
174     fWhichCut->GetXaxis()->SetBinLabel(iLabel+1, fgkCutBinNames[iLabel]);
175   AddControlObject(fWhichCut);
176
177   return AliDxHFEParticleSelection::InitControlObjects();
178 }
179
180 int AliDxHFEParticleSelectionEl::HistogramParticleProperties(AliVParticle* p, int selectionCode)
181 {
182   /// histogram particle properties
183   if (!p) return -EINVAL;
184   //if (!fControlObjects) return 0;
185   if(selectionCode==0) return  0;
186   // TODO: make array a member, consistent dimensions for THnSparse and array
187   Double_t eProperties[3]={0.0, 0.0, 0.0};
188   DefineParticleProperties(p, eProperties, 3);
189   if(fElectronProperties) fElectronProperties->Fill(eProperties);
190     
191   return 0;
192 }
193
194 int AliDxHFEParticleSelectionEl::DefineParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
195 {
196   // fill the data array from the particle data
197   if (!data) return -EINVAL;
198   AliAODTrack *track=(AliAODTrack*)p;
199   if (!track) return -ENODATA;
200   int i=0;
201   // TODO: this corresponds to the THnSparse dimensions which is available in the same class
202   // use this consistently
203   const int requiredDimension=3;
204   if (dimension!=requiredDimension) {
205     // TODO: think about filling only the available data and throwing a warning
206     return -ENOSPC;
207   }
208   data[i++]=track->Pt();
209   data[i++]=track->Phi();
210   data[i++]=track->Eta();
211   return i;
212 }
213
214
215 int AliDxHFEParticleSelectionEl::IsSelected(AliVParticle* pEl, const AliVEvent* pEvent)
216 {
217   /// select El candidates
218   // TODO: How to handle MC? would be too much duplicate code if copy entire IsSelected. 
219
220   AliAODTrack *track=(AliAODTrack*)pEl;
221   fCFM->SetRecEventInfo(pEvent);
222
223   //--------track cut selection-----------------------
224   //Using AliHFECuts:
225   // RecKine: ITSTPC cuts  
226   if(!ProcessCutStep(AliHFEcuts::kStepRecKineITSTPC, track)){
227     fWhichCut->Fill(kRecKineITSTPC);
228     return 0;
229   }
230   
231   // RecPrim
232   if(!ProcessCutStep(AliHFEcuts::kStepRecPrim, track)) {
233     fWhichCut->Fill(kRecPrim);
234     return 0;
235   }
236   
237   // HFEcuts: ITS layers cuts
238   if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsITS, track)) {
239     fWhichCut->Fill(kHFEcutsITS);
240     return 0;
241   }
242   
243   // HFE cuts: TOF PID and mismatch flag
244   if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsTOF, track)) {
245     fWhichCut->Fill(kHFEcutsTOF);
246     return 0;
247   }
248   
249   // HFE cuts: TPC PID cleanup
250   if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsTPC, track)){
251     fWhichCut->Fill(kHFEcutsTPC);
252     return 0;
253   } 
254  
255   // HFEcuts: Nb of tracklets TRD0
256   //if(!ProcessCutStep(AliHFEcuts::kStepHFEcutsTRD, track)) continue;
257
258
259   //--------PID selection-----------------------
260   AliHFEpidObject hfetrack;
261   hfetrack.SetAnalysisType(AliHFEpidObject::kAODanalysis);
262   hfetrack.SetRecTrack(track);
263
264   // TODO: configurable colliding system
265   //if(IsPbPb()) hfetrack.SetPbPb();
266   hfetrack.SetPP();
267
268   if(fPID && fPID->IsSelected(&hfetrack)) {
269     AliDebug(3,"Inside FilldPhi, electron is selected");
270     fWhichCut->Fill(kSelected);
271     return 1;
272   }
273   else{
274     fWhichCut->Fill(kPID);
275     return 0;
276   }
277 }
278
279 void AliDxHFEParticleSelectionEl::SetCuts(TObject* cuts, int level)
280 {
281   /// set cut objects
282   if (level==kCutHFE) {
283     fCuts=dynamic_cast<AliHFEcuts*>(cuts);
284     if (!fCuts && cuts) {
285       AliError(Form("Cut object is not of required type AliHFEcuts but %s", cuts->ClassName()));
286     }
287     return;
288   }
289
290   if (level==kCutPID) {
291     fPID=dynamic_cast<AliHFEpid*>(cuts);
292     if (!fPID && cuts) {
293       AliError(Form("cuts object is not of required type AliHFEpid but %s", cuts->ClassName()));
294     }
295     return;
296   }
297 }
298
299 //________________________________________________________________________
300 Bool_t AliDxHFEParticleSelectionEl::ProcessCutStep(Int_t cutStep, AliVParticle *track)
301 {
302   // Check single track cuts for a given cut step
303   const Int_t kMCOffset = AliHFEcuts::kNcutStepsMCTrack;
304   if(!fCFM->CheckParticleCuts(cutStep + kMCOffset, track)) return kFALSE;
305   //if(!fCuts->CheckParticleCuts(cutStep + kMCOffset, track)) return kFALSE;
306   return kTRUE;
307 }