]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/correlationHF/AliDxHFEParticleSelectionD0.cxx
Fix
[u/mrichter/AliRoot.git] / PWGHF / correlationHF / AliDxHFEParticleSelectionD0.cxx
CommitLineData
72c0a987 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 AliDxHFEParticleSelectionD0.cxx
21/// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
22/// @date 2012-03-19
23/// @brief D0 selection for D0-HFE correlation
24///
25
26#include "AliDxHFEParticleSelectionD0.h"
27#include "AliVParticle.h"
9535cec9 28//#include "AliAnalysisCuts.h" // required dependency libANALYSISalice.so
29//#include "AliFlowTrackSimple.h" // required dependency libPWGflowBase.so
30//#include "AliFlowCandidateTrack.h" // required dependency libPWGflowTasks.so
31//#include "AliCFContainer.h" // required dependency libCORRFW.so
93fcaf9f 32#include "AliAODRecoDecayHF2Prong.h" // libPWGHFvertexingHF
9535cec9 33#include "AliRDHFCutsD0toKpi.h"
72c0a987 34#include "TObjArray.h"
93fcaf9f 35#include "THnSparse.h"
36#include "TAxis.h"
9535cec9 37#include "TString.h"
93fcaf9f 38#include <iostream>
39#include <cerrno>
40#include <memory>
72c0a987 41
9535cec9 42using namespace std;
43
72c0a987 44/// ROOT macro for the implementation of ROOT specific class methods
45ClassImp(AliDxHFEParticleSelectionD0)
46
47AliDxHFEParticleSelectionD0::AliDxHFEParticleSelectionD0(const char* opt)
93fcaf9f 48 : AliDxHFEParticleSelection("D0", opt)
49 , fD0Properties(NULL)
9535cec9 50 , fD0Daughter0(NULL)
51 , fD0Daughter1(NULL)
52 , fCuts(NULL)
53 , fFillOnlyD0D0bar(0)
d731501a 54 , fD0InvMass(0.0)
55 , fPtBin(-1)
72c0a987 56{
57 // constructor
58 //
59 //
60 //
61 //
9535cec9 62 TString strOption(opt);
63 // TODO: one might need a proper argument parsing including
64 // chopping whole string into individual arguments
65 if (strOption.Contains("FillD0D0bar")) fFillOnlyD0D0bar=0;
66 else if (strOption.Contains("FillOnlyD0")) fFillOnlyD0D0bar=1;
67 else if (strOption.Contains("FillOnlyD0bar")) fFillOnlyD0D0bar=2;
72c0a987 68}
69
70AliDxHFEParticleSelectionD0::~AliDxHFEParticleSelectionD0()
71{
72 // destructor
9535cec9 73 if (fD0Properties) {
74 delete fD0Properties;
75 fD0Properties=NULL;
76 }
77 if (fD0Daughter0) {
78 delete fD0Daughter0;
79 fD0Daughter0=NULL;
80 }
81 if (fD0Daughter1) {
82 delete fD0Daughter1;
83 fD0Daughter1=NULL;
84 }
85
86 // Note: external object deleted elsewhere
87 fCuts=NULL;
72c0a987 88}
89
d731501a 90const char* AliDxHFEParticleSelectionD0::fgkDgTrackControlBinNames[]={
91 "Pt",
92 "Phi",
93 "Ptbin",
94 "D0InvMass",
95 "Eta"
96};
97
93fcaf9f 98int AliDxHFEParticleSelectionD0::InitControlObjects()
99{
100 /// init the control objects, can be overloaded by childs which should
101 /// call AliDxHFEParticleSelection::InitControlObjects() explicitly
93fcaf9f 102
d731501a 103 fD0Properties=DefineTHnSparse();
93fcaf9f 104 AddControlObject(fD0Properties);
105
9535cec9 106 //Adding control objects for the daughters
107 InitControlObjectsDaughters("pi information",0);
108 InitControlObjectsDaughters("K information",1);
109
93fcaf9f 110 return AliDxHFEParticleSelection::InitControlObjects();
111}
112
dcf83226 113THnSparse* AliDxHFEParticleSelectionD0::DefineTHnSparse()
d731501a 114{
115 //
116 // Defines the THnSparse. For now, only calls CreateControlTHnSparse
117 // TODO: remove pt?? (Have ptbin)
118
dcf83226 119 // here is the only place to change the dimension
d731501a 120 const int thnSize2 = 5;
dcf83226 121 InitTHnSparseArray(thnSize2);
122
d731501a 123 const double Pi=TMath::Pi();
124 TString name;
125 name.Form("%s info", GetName());
126
dcf83226 127 // 0 1 2 3 4
128 // Pt Phi Ptbin D0InvMass Eta
129 int thnBins [thnSize2] = { 1000, 200, 21, 200, 500 };
130 double thnMin [thnSize2] = { 0, 0, 0, 1.5648, -1. };
131 double thnMax [thnSize2] = { 100, 2*Pi, 20, 2.1648, 1. };
132 const char* thnNames[thnSize2] = { "Pt","Phi","Ptbin","D0InvMass","Eta"};
d731501a 133
dcf83226 134 return CreateControlTHnSparse(name,thnSize2,thnBins,thnMin,thnMax,thnNames);
d731501a 135}
136
dcf83226 137int AliDxHFEParticleSelectionD0::FillParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
d731501a 138{
139 // fill the data array from the particle data
140 if (!data) return -EINVAL;
141 // AliAODTrack *track=(AliAODTrack*)p;
142 AliAODRecoDecayHF2Prong* track=dynamic_cast<AliAODRecoDecayHF2Prong*>(p);
143 if (!track) return -ENODATA;
144 int i=0;
dcf83226 145 if (dimension!=GetDimTHnSparse()) {
d731501a 146 // TODO: think about filling only the available data and throwing a warning
147 return -ENOSPC;
148 }
149 data[i++]=track->Pt();
150 data[i++]=track->Phi();
151 data[i++]=fPtBin;
152 data[i++]=fD0InvMass;
153 data[i++]=track->Eta();
154
155 return i;
156}
157
9535cec9 158int AliDxHFEParticleSelectionD0::InitControlObjectsDaughters(TString name, int daughter)
159{
d731501a 160 // Setting up Control objects for the daughters.
161 // Move to ParticleSelection??
9535cec9 162 AliInfo("Setting up daughter THnSparse");
163
164 const int thnSize2 = 5;
165 const double Pi=TMath::Pi();
166 // 0 1 2 3 4
167 // Pt Phi Ptbin D0InvMass Eta
168 int thnBins[thnSize2] = { 1000, 200, 21, 200, 500};
169 double thnMin [thnSize2] = { 0, 0, 0, 1.5648, -1.};
170 double thnMax [thnSize2] = { 100, 2*Pi, 20, 2.1648, 1.};
171
172 std::auto_ptr<THnSparseF> DaughterProperties(new THnSparseF(name, name, thnSize2, thnBins, thnMin, thnMax));
173
174 if (DaughterProperties.get()==NULL) {
175 return -ENOMEM;
176 }
d731501a 177
178 for(int iLabel=0; iLabel< 5;iLabel++)
179 DaughterProperties->GetAxis(iLabel)->SetTitle(fgkDgTrackControlBinNames[iLabel]);
9535cec9 180
181 if(daughter==0){
182 fD0Daughter0=DaughterProperties.release();
183 AddControlObject(fD0Daughter0);
184 }
185
186 if(daughter==1){
187 fD0Daughter1=DaughterProperties.release();
188 AddControlObject(fD0Daughter1);
189 }
190 return 0;
191}
192
193int AliDxHFEParticleSelectionD0::HistogramParticleProperties(AliVParticle* p, int selectionCode)
93fcaf9f 194{
9535cec9 195
93fcaf9f 196 /// histogram particle properties
197 if (!p) return -EINVAL;
198
199 // fill the common histograms
9535cec9 200 AliDxHFEParticleSelection::HistogramParticleProperties(p, selectionCode);
93fcaf9f 201
9535cec9 202 // no daughters to fill if 0 (= no candidate)
203 if (selectionCode==0) return 0;
93fcaf9f 204
93fcaf9f 205 AliAODRecoDecayHF2Prong* part=dynamic_cast<AliAODRecoDecayHF2Prong*>(p);
9535cec9 206
207 if(!part) return 0;
208 // Convention: 1. daughter is postive track, 2. = negative
209 AliAODTrack *prongpos=(AliAODTrack*)part->GetDaughter(0);
210 AliAODTrack *prongneg=(AliAODTrack*)part->GetDaughter(1);
211
212 if(!prongpos || !prongneg) {
213 return 0;
214 }
215
216 // Only D0s are filled
217 // TODO: Also include D0bar
218 if ((selectionCode==1 || selectionCode==3) && fFillOnlyD0D0bar<2) {
d731501a 219 fD0InvMass= part->InvMassD0();
220 fPtBin=fCuts->PtBin(part->Pt());
221
222 // TODO: avoid repeated allocation of the arrays
223 Double_t KProperties[]={prongneg->Pt(),prongneg->Phi(),fPtBin, fD0InvMass,prongneg->Eta()};
224 Double_t piProperties[]={prongpos->Pt(),prongpos->Phi(),fPtBin,fD0InvMass,prongpos->Eta()};
225
dcf83226 226 if(fD0Properties && ParticleProperties()) {
227 memset(ParticleProperties(), 0, GetDimTHnSparse()*sizeof(ParticleProperties()[0]));
228 FillParticleProperties(p, ParticleProperties(), GetDimTHnSparse());
229 fD0Properties->Fill(ParticleProperties());
230 }
9535cec9 231 if(fD0Daughter0) fD0Daughter0->Fill(piProperties);
232 if(fD0Daughter1) fD0Daughter1->Fill(KProperties);
93fcaf9f 233 }
234
235 return 0;
236}
237
9535cec9 238TObjArray* AliDxHFEParticleSelectionD0::Select(TObjArray* pTracks, const AliVEvent *pEvent)
239{
240 /// create selection, array contains only pointers but does not own the objects
241 /// object array needs to be deleted by caller
242 if (!pTracks) return NULL;
243 TObjArray* selectedTracks=new TObjArray;
244 if (!selectedTracks) return NULL;
245 TIter itrack(pTracks);
246 TObject* pObj=NULL;
247 while ((pObj=itrack())!=NULL) {
248 AliVParticle* track=dynamic_cast<AliVParticle*>(pObj);
249 if (!track) continue;
250 int selectionCode=IsSelected(track,pEvent);
251 HistogramParticleProperties(track, selectionCode);
9535cec9 252
d731501a 253 //TODO: Also add selection for D0bar
9535cec9 254 // Add track if it is either defined as D0(selectionCode==1) or both
255 // D0bar and a D0 (selectionCode==3)
256 if (! ((selectionCode==1 || selectionCode==3) && fFillOnlyD0D0bar<2)) continue;
257 selectedTracks->Add(track);
258 }
259 return selectedTracks;
260}
261
262int AliDxHFEParticleSelectionD0::IsSelected(AliVParticle* p, const AliVEvent* pEvent)
72c0a987 263{
264 /// TODO: implement specific selection of D0 candidates
d731501a 265 /// Could also return values based on where where selection "failed
266 /// Selected. Return 0 (none), 1(D0), 2(D0bar) or 3 (both)
267
9535cec9 268 int selectionCode=0;
269
270 AliAODRecoDecayHF2Prong *d0 = dynamic_cast<AliAODRecoDecayHF2Prong*>(p);
271 if(d0->GetSelectionMap()) if(!d0->HasSelectionBit(AliRDHFCuts::kD0toKpiCuts)){
272 AliDebug(1,"Skip D0 from Dstar");
273 return 0; //skip the D0 from Dstar
274 }
275
276 // TODO: the cuts instance should be const but the function definition of
277 // AliRDHFCuts::IsSelected does not allow this
278 AliRDHFCuts* cuts=const_cast<AliRDHFCuts*>(fCuts);
279 if (!cuts) {
d731501a 280 selectionCode=0;
9535cec9 281 } else if(cuts->IsInFiducialAcceptance(d0->Pt(),d0->Y(421)) ) {
d731501a 282
9535cec9 283 Int_t ptbin=cuts->PtBin(d0->Pt());
284 if(ptbin==-1) {
285 AliDebug(1,"Pt out of bounds");
286 return 0;
287 } //out of bounds
288
289 // TODO: the aod pointer should also be const but the function definition of
290 // AliRDHFCuts::IsSelected does not allow this
291 AliAODEvent* aod=NULL;
292 if (pEvent) aod=dynamic_cast<AliAODEvent*>(const_cast<AliVEvent*>(pEvent));
293
d731501a 294 // Selected. Return 0 (none), 1 (D0), 2 (D0bar) or 3 (both)
9535cec9 295 selectionCode=cuts->IsSelected(d0,AliRDHFCuts::kAll,aod);
296
297 AliDebug(1,Form("Candidate is %d \n", selectionCode));
298 TObjArray daughters;
299 daughters.AddAt((AliAODTrack*)d0->GetDaughter(0),0);
300 daughters.AddAt((AliAODTrack*)d0->GetDaughter(1),1);
301
302 //check daughters
303 if(!daughters.UncheckedAt(0) || !daughters.UncheckedAt(1)) {
304 AliDebug(1,"at least one daughter not found!");
305 daughters.Clear();
306 return 0;
307 }
308 }
309
310 return selectionCode;
311}
312
313void AliDxHFEParticleSelectionD0::SetCuts(TObject* cuts, int /*level*/)
314{
315 /// set cuts objects
316 fCuts=dynamic_cast<AliRDHFCuts*>(cuts);
317 if (!fCuts && cuts) {
318 AliError(Form("cuts object is not of required type AliRDHFCuts but %s", cuts->ClassName()));
319 }
72c0a987 320}