]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/correlationHF/AliDxHFEParticleSelectionD0.cxx
Adding libTPCutil (Jochen)
[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"
dfe96b90 36#include "AliReducedParticle.h"
93fcaf9f 37#include "TAxis.h"
9535cec9 38#include "TString.h"
93fcaf9f 39#include <iostream>
40#include <cerrno>
41#include <memory>
72c0a987 42
9535cec9 43using namespace std;
44
72c0a987 45/// ROOT macro for the implementation of ROOT specific class methods
46ClassImp(AliDxHFEParticleSelectionD0)
47
48AliDxHFEParticleSelectionD0::AliDxHFEParticleSelectionD0(const char* opt)
93fcaf9f 49 : AliDxHFEParticleSelection("D0", opt)
50 , fD0Properties(NULL)
9535cec9 51 , fD0Daughter0(NULL)
52 , fD0Daughter1(NULL)
53 , fCuts(NULL)
54 , fFillOnlyD0D0bar(0)
d731501a 55 , fD0InvMass(0.0)
56 , fPtBin(-1)
2229ac91 57 , fHistoList(NULL)
72c0a987 58{
59 // constructor
60 //
61 //
62 //
63 //
9535cec9 64 TString strOption(opt);
65 // TODO: one might need a proper argument parsing including
66 // chopping whole string into individual arguments
67 if (strOption.Contains("FillD0D0bar")) fFillOnlyD0D0bar=0;
68 else if (strOption.Contains("FillOnlyD0")) fFillOnlyD0D0bar=1;
69 else if (strOption.Contains("FillOnlyD0bar")) fFillOnlyD0D0bar=2;
72c0a987 70}
71
72AliDxHFEParticleSelectionD0::~AliDxHFEParticleSelectionD0()
73{
74 // destructor
9535cec9 75 if (fD0Properties) {
76 delete fD0Properties;
77 fD0Properties=NULL;
78 }
79 if (fD0Daughter0) {
80 delete fD0Daughter0;
81 fD0Daughter0=NULL;
82 }
83 if (fD0Daughter1) {
84 delete fD0Daughter1;
85 fD0Daughter1=NULL;
86 }
2229ac91 87 if (fHistoList){
88 delete fHistoList;
89 fHistoList=NULL;
90 }
9535cec9 91
92 // Note: external object deleted elsewhere
93 fCuts=NULL;
72c0a987 94}
95
d731501a 96const char* AliDxHFEParticleSelectionD0::fgkDgTrackControlBinNames[]={
97 "Pt",
98 "Phi",
99 "Ptbin",
100 "D0InvMass",
101 "Eta"
102};
103
2229ac91 104const char* AliDxHFEParticleSelectionD0::fgkCutBinNames[]={
105 "nDstar->D0",
106 "nCandSel(Tr)",
107 "ptbin-1",
108 "No daugthers",
109 "Selectioncode 0",
110 "Selected D0",
111 "Selected D0bar",
112 "Selected as both"
113};
114
115
93fcaf9f 116int AliDxHFEParticleSelectionD0::InitControlObjects()
117{
118 /// init the control objects, can be overloaded by childs which should
119 /// call AliDxHFEParticleSelection::InitControlObjects() explicitly
93fcaf9f 120
d731501a 121 fD0Properties=DefineTHnSparse();
93fcaf9f 122 AddControlObject(fD0Properties);
123
9535cec9 124 //Adding control objects for the daughters
125 InitControlObjectsDaughters("pi information",0);
126 InitControlObjectsDaughters("K information",1);
2229ac91 127 AliInfo(Form("D0 filling scheme: %d\n",fFillOnlyD0D0bar));
128
129 fHistoList=new TList;
130 fHistoList->SetName("D0 Histograms");
131 fHistoList->SetOwner();
132
133 // Histogram storing which cuts have been applied to the tracks
134 fHistoList->Add(CreateControlHistogram("fWhichCutD0","effective cut for a rejected particle", kNCutLabels, fgkCutBinNames));
135
136 AddControlObject(fHistoList);
9535cec9 137
93fcaf9f 138 return AliDxHFEParticleSelection::InitControlObjects();
139}
140
dcf83226 141THnSparse* AliDxHFEParticleSelectionD0::DefineTHnSparse()
d731501a 142{
143 //
dfe96b90 144 // Defines the THnSparse.
d731501a 145
dcf83226 146 // here is the only place to change the dimension
d731501a 147 const int thnSize2 = 5;
dcf83226 148 InitTHnSparseArray(thnSize2);
149
d731501a 150 const double Pi=TMath::Pi();
151 TString name;
152 name.Form("%s info", GetName());
153
dfe96b90 154 // 0 1 2 3 4
dcf83226 155 // Pt Phi Ptbin D0InvMass Eta
dfe96b90 156 int thnBins [thnSize2] = {1000, 200, 15, 200, 500 };
157 double thnMin [thnSize2] = { 0, 0, 0, 1.5648, -1. };
158 double thnMax [thnSize2] = { 100, 2*Pi, 14, 2.1648, 1. };
159 const char* thnNames[thnSize2] = {"Pt", "Phi","Ptbin","D0InvMass","Eta"};
d731501a 160
dcf83226 161 return CreateControlTHnSparse(name,thnSize2,thnBins,thnMin,thnMax,thnNames);
d731501a 162}
163
dcf83226 164int AliDxHFEParticleSelectionD0::FillParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
d731501a 165{
166 // fill the data array from the particle data
167 if (!data) return -EINVAL;
d731501a 168 AliAODRecoDecayHF2Prong* track=dynamic_cast<AliAODRecoDecayHF2Prong*>(p);
169 if (!track) return -ENODATA;
170 int i=0;
dcf83226 171 if (dimension!=GetDimTHnSparse()) {
d731501a 172 // TODO: think about filling only the available data and throwing a warning
173 return -ENOSPC;
174 }
175 data[i++]=track->Pt();
176 data[i++]=track->Phi();
177 data[i++]=fPtBin;
178 data[i++]=fD0InvMass;
179 data[i++]=track->Eta();
180
181 return i;
182}
183
9535cec9 184int AliDxHFEParticleSelectionD0::InitControlObjectsDaughters(TString name, int daughter)
185{
d731501a 186 // Setting up Control objects for the daughters.
187 // Move to ParticleSelection??
9535cec9 188 AliInfo("Setting up daughter THnSparse");
189
190 const int thnSize2 = 5;
191 const double Pi=TMath::Pi();
192 // 0 1 2 3 4
193 // Pt Phi Ptbin D0InvMass Eta
194 int thnBins[thnSize2] = { 1000, 200, 21, 200, 500};
195 double thnMin [thnSize2] = { 0, 0, 0, 1.5648, -1.};
196 double thnMax [thnSize2] = { 100, 2*Pi, 20, 2.1648, 1.};
197
198 std::auto_ptr<THnSparseF> DaughterProperties(new THnSparseF(name, name, thnSize2, thnBins, thnMin, thnMax));
199
200 if (DaughterProperties.get()==NULL) {
201 return -ENOMEM;
202 }
d731501a 203
204 for(int iLabel=0; iLabel< 5;iLabel++)
205 DaughterProperties->GetAxis(iLabel)->SetTitle(fgkDgTrackControlBinNames[iLabel]);
9535cec9 206
207 if(daughter==0){
208 fD0Daughter0=DaughterProperties.release();
209 AddControlObject(fD0Daughter0);
210 }
211
212 if(daughter==1){
213 fD0Daughter1=DaughterProperties.release();
214 AddControlObject(fD0Daughter1);
215 }
216 return 0;
217}
218
219int AliDxHFEParticleSelectionD0::HistogramParticleProperties(AliVParticle* p, int selectionCode)
93fcaf9f 220{
9535cec9 221
93fcaf9f 222 /// histogram particle properties
223 if (!p) return -EINVAL;
224
225 // fill the common histograms
9535cec9 226 AliDxHFEParticleSelection::HistogramParticleProperties(p, selectionCode);
93fcaf9f 227
9535cec9 228 // no daughters to fill if 0 (= no candidate)
229 if (selectionCode==0) return 0;
93fcaf9f 230
93fcaf9f 231 AliAODRecoDecayHF2Prong* part=dynamic_cast<AliAODRecoDecayHF2Prong*>(p);
9535cec9 232
233 if(!part) return 0;
234 // Convention: 1. daughter is postive track, 2. = negative
235 AliAODTrack *prongpos=(AliAODTrack*)part->GetDaughter(0);
236 AliAODTrack *prongneg=(AliAODTrack*)part->GetDaughter(1);
237
238 if(!prongpos || !prongneg) {
239 return 0;
240 }
241
dfe96b90 242 fD0InvMass= part->InvMassD0();
243 fPtBin=fCuts->PtBin(part->Pt());
244
245 // TODO: avoid repeated allocation of the arrays
246 Double_t KProperties[]={prongneg->Pt(),prongneg->Phi(),fPtBin, fD0InvMass,prongneg->Eta()};
247 Double_t piProperties[]={prongpos->Pt(),prongpos->Phi(),fPtBin,fD0InvMass,prongpos->Eta()};
d731501a 248
dfe96b90 249
250 // Fills only for D0 or both..
251 if ((selectionCode==1 || selectionCode==3) && fFillOnlyD0D0bar<2) {
d731501a 252
dcf83226 253 if(fD0Properties && ParticleProperties()) {
254 memset(ParticleProperties(), 0, GetDimTHnSparse()*sizeof(ParticleProperties()[0]));
255 FillParticleProperties(p, ParticleProperties(), GetDimTHnSparse());
256 fD0Properties->Fill(ParticleProperties());
257 }
9535cec9 258 if(fD0Daughter0) fD0Daughter0->Fill(piProperties);
259 if(fD0Daughter1) fD0Daughter1->Fill(KProperties);
93fcaf9f 260 }
2229ac91 261 // Checks for D0bar (or hypothesis both)
262 if ((selectionCode==2 || selectionCode==3) && (fFillOnlyD0D0bar==0 || fFillOnlyD0D0bar==2)) {
263 // Set the fD0InvMass to InvMassD0bar instead..
264 fD0InvMass= part->InvMassD0bar();
265 if(fD0Properties && ParticleProperties()) {
266 memset(ParticleProperties(), 0, GetDimTHnSparse()*sizeof(ParticleProperties()[0]));
267 FillParticleProperties(p, ParticleProperties(), GetDimTHnSparse());
268 fD0Properties->Fill(ParticleProperties());
dfe96b90 269 }
2229ac91 270 if(fD0Daughter0) fD0Daughter0->Fill(piProperties);
271 if(fD0Daughter1) fD0Daughter1->Fill(KProperties);
272 //reset value to InvMassD0 for when CreateParticle() is called
273 fD0InvMass= part->InvMassD0();
274
dfe96b90 275 }
93fcaf9f 276 return 0;
277}
278
9535cec9 279TObjArray* AliDxHFEParticleSelectionD0::Select(TObjArray* pTracks, const AliVEvent *pEvent)
280{
281 /// create selection, array contains only pointers but does not own the objects
282 /// object array needs to be deleted by caller
283 if (!pTracks) return NULL;
284 TObjArray* selectedTracks=new TObjArray;
285 if (!selectedTracks) return NULL;
dfe96b90 286 selectedTracks->SetOwner();
9535cec9 287 TIter itrack(pTracks);
288 TObject* pObj=NULL;
289 while ((pObj=itrack())!=NULL) {
290 AliVParticle* track=dynamic_cast<AliVParticle*>(pObj);
291 if (!track) continue;
292 int selectionCode=IsSelected(track,pEvent);
293 HistogramParticleProperties(track, selectionCode);
9535cec9 294
295 // Add track if it is either defined as D0(selectionCode==1) or both
296 // D0bar and a D0 (selectionCode==3)
dfe96b90 297 if ((selectionCode==1 || selectionCode==3) && fFillOnlyD0D0bar<2)
298 selectedTracks->Add(CreateParticle(track));
2229ac91 299
300 // Add track if it is either defined as D0bar(selectionCode==2) or both
301 // D0bar and a D0 (selectionCode==3)
302 if ((selectionCode==2 || selectionCode==3) && (fFillOnlyD0D0bar==0 || fFillOnlyD0D0bar==2)){
303 fD0InvMass= dynamic_cast<AliAODRecoDecayHF2Prong*>(track)->InvMassD0bar();
304 selectedTracks->Add(CreateParticle(track));
305 }
9535cec9 306 }
307 return selectedTracks;
308}
309
310int AliDxHFEParticleSelectionD0::IsSelected(AliVParticle* p, const AliVEvent* pEvent)
72c0a987 311{
312 /// TODO: implement specific selection of D0 candidates
d731501a 313 /// Could also return values based on where where selection "failed
314 /// Selected. Return 0 (none), 1(D0), 2(D0bar) or 3 (both)
315
9535cec9 316 int selectionCode=0;
317
318 AliAODRecoDecayHF2Prong *d0 = dynamic_cast<AliAODRecoDecayHF2Prong*>(p);
3b40764c 319 if (!d0) return 0;
9535cec9 320 if(d0->GetSelectionMap()) if(!d0->HasSelectionBit(AliRDHFCuts::kD0toKpiCuts)){
321 AliDebug(1,"Skip D0 from Dstar");
2229ac91 322 ((TH1D*)fHistoList->FindObject("fWhichCutD0"))->Fill(kDstar);
323
9535cec9 324 return 0; //skip the D0 from Dstar
325 }
326
327 // TODO: the cuts instance should be const but the function definition of
328 // AliRDHFCuts::IsSelected does not allow this
329 AliRDHFCuts* cuts=const_cast<AliRDHFCuts*>(fCuts);
330 if (!cuts) {
d731501a 331 selectionCode=0;
dfe96b90 332 }
333 else if(cuts->IsInFiducialAcceptance(d0->Pt(),d0->Y(421)) ) {
d731501a 334
2229ac91 335 // TODO: the aod pointer should also be const but the function definition of
336 // AliRDHFCuts::IsSelected does not allow this
337 AliAODEvent* aod=NULL;
338 if (pEvent) aod=dynamic_cast<AliAODEvent*>(const_cast<AliVEvent*>(pEvent));
339
340 //TODO: Should add fSystem for PbPb if(fSys==0){
341 if(cuts->IsSelected(d0,AliRDHFCuts::kTracks,aod)) ((TH1D*)fHistoList->FindObject("fWhichCutD0"))->Fill(kCandSelTrack);
342
9535cec9 343 Int_t ptbin=cuts->PtBin(d0->Pt());
344 if(ptbin==-1) {
2229ac91 345 ((TH1D*)fHistoList->FindObject("fWhichCutD0"))->Fill(kNegPtbin);
9535cec9 346 AliDebug(1,"Pt out of bounds");
347 return 0;
348 } //out of bounds
349
d731501a 350 // Selected. Return 0 (none), 1 (D0), 2 (D0bar) or 3 (both)
9535cec9 351 selectionCode=cuts->IsSelected(d0,AliRDHFCuts::kAll,aod);
2229ac91 352 if(selectionCode==0)
353 ((TH1D*)fHistoList->FindObject("fWhichCutD0"))->Fill(kSelected0);
354
355 if(selectionCode==1)
356 ((TH1D*)fHistoList->FindObject("fWhichCutD0"))->Fill(kSelectedD0);
357
358 if(selectionCode==2)
359 ((TH1D*)fHistoList->FindObject("fWhichCutD0"))->Fill(kSelectedD0bar);
360
361 if(selectionCode==3)
362 ((TH1D*)fHistoList->FindObject("fWhichCutD0"))->Fill(kSelectedboth);
9535cec9 363
364 AliDebug(1,Form("Candidate is %d \n", selectionCode));
2229ac91 365
366 // check daughters before calling as there is unchecked code in
367 // AliAODRecoDecayHF::HasBadDaughters called
368 TObject* o=NULL;
369 if (!((o=d0->GetDaughter(0))!=NULL && dynamic_cast<AliAODTrack*>(o)!=NULL &&
370 (o=d0->GetDaughter(1))!=NULL && dynamic_cast<AliAODTrack*>(o)!=NULL)) {
371 ((TH1D*)fHistoList->FindObject("fWhichCutD0"))->Fill(kNoDaugthers);
9535cec9 372 AliDebug(1,"at least one daughter not found!");
2229ac91 373
9535cec9 374 }
375 }
376
377 return selectionCode;
378}
379
2229ac91 380void AliDxHFEParticleSelectionD0::SetCuts(TObject* cuts, int level)
9535cec9 381{
382 /// set cuts objects
2229ac91 383 if (level==kCutD0) {
384 fCuts=dynamic_cast<AliRDHFCuts*>(cuts);
385 if (!fCuts && cuts) {
386 AliError(Form("cuts object is not of required type AliRDHFCuts but %s", cuts->ClassName()));
387 }
388 return;
389 }
390 if (level==kCutList){
391 TList* CutList=dynamic_cast<TList*>(cuts);
392 if (!CutList && cuts) {
393 AliError(Form("cuts object is not of required type TList but %s", cuts->ClassName()));
394 }
395 else{
396 TObject *obj=NULL;
397 int iii=0;
398 TIter next(CutList);
399 while((obj = next())){
400 iii++;
401 if(iii==1) {
402 fCuts=dynamic_cast<AliRDHFCuts*>(obj);
403 if (!fCuts)
404 AliError(Form("Cut object is not of required type AliRDHFCuts but %s", obj->ClassName()));
405 }
406 }
407 }
408 return;
9535cec9 409 }
2229ac91 410 return;
72c0a987 411}
dfe96b90 412
413AliVParticle *AliDxHFEParticleSelectionD0::CreateParticle(AliVParticle* track)
414{
415 //
416 // Creates object containing only the variables needed for correlation
417 //
418
419 AliReducedParticle *part = new AliReducedParticle(track->Eta(), track->Phi(), track->Pt(),fD0InvMass,fPtBin);
420
421 return part;
422
423}