]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGHF/correlationHF/AliDxHFEParticleSelection.cxx
adding checks and debugging information
[u/mrichter/AliRoot.git] / PWGHF / correlationHF / AliDxHFEParticleSelection.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 AliDxHFEParticleSelection.cxx
21/// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
22/// @date 2012-03-19
23/// @brief Base class for particle selection
24///
25
26#include "AliDxHFEParticleSelection.h"
93fcaf9f 27#include "AliLog.h"
72c0a987 28#include "AliVEvent.h"
29#include "AliVParticle.h"
30#include "TObjArray.h"
93fcaf9f 31#include "TList.h"
32#include "TMath.h"
33#include "TH1D.h"
34#include "THnSparse.h"
dfe96b90 35#include "AliReducedParticle.h"
93fcaf9f 36#include "TFile.h"
37#include <iostream>
72c0a987 38#include <cerrno>
93fcaf9f 39#include <memory>
40
41using namespace std;
72c0a987 42
43/// ROOT macro for the implementation of ROOT specific class methods
44ClassImp(AliDxHFEParticleSelection)
45
93fcaf9f 46AliDxHFEParticleSelection::AliDxHFEParticleSelection(const char* name, const char* opt)
47 : TNamed(name?name:"AliDxHFEParticleSelection", name?name:"AliDxHFEParticleSelection")
72c0a987 48 , fOption(opt)
49 , fSelectedTracks(NULL)
93fcaf9f 50 , fControlObjects(NULL)
51 , fhEventControl(NULL)
52 , fhTrackControl(NULL)
d731501a 53 , fUseMC(0)
9535cec9 54 , fVerbosity(0)
dcf83226 55 , fDimThn(-1)
56 , fParticleProperties(NULL)
72c0a987 57{
58 // constructor
59 //
60 //
61 //
62 //
63}
64
9535cec9 65const char* AliDxHFEParticleSelection::fgkEventControlBinNames[]={
66 "nEventsAll",
67 "nEventsSelected",
d731501a 68 "nEventsWParticle"
69};
70
71const char* AliDxHFEParticleSelection::fgkTrackControlBinNames[]={
72 "nTrackAll",
73 "nTrackSelected",
74};
75
72c0a987 76AliDxHFEParticleSelection::~AliDxHFEParticleSelection()
77{
78 // destructor
dcf83226 79 if (fParticleProperties) delete[] fParticleProperties;
80 fParticleProperties=NULL;
72c0a987 81 if (fSelectedTracks) delete fSelectedTracks;
82 fSelectedTracks=NULL;
93fcaf9f 83 if (fControlObjects) delete fControlObjects;
84 fControlObjects=NULL;
9535cec9 85 fhEventControl=NULL;
86 fhTrackControl=NULL;
93fcaf9f 87}
88
d731501a 89int AliDxHFEParticleSelection::Init()
90{
91 //
92 // Init part sel. Calls InitControlObjects()
93 //
94
95 InitControlObjects();
96 return 0;
97}
98
99
93fcaf9f 100int AliDxHFEParticleSelection::InitControlObjects()
101{
d731501a 102 //
9535cec9 103 // init control objects
d731501a 104 // TODO: Change to private now that have Init()?
105 //
9535cec9 106 if (fVerbosity>0) {
107 AliInfo("Setting up control objects");
108 }
109
93fcaf9f 110 /// init the control objects, can be overloaded by childs which should
111 /// call AliDxHFEParticleSelection::InitControlObjects() explicitly
112 std::auto_ptr<TH1D> hEventControl(new TH1D("hEventControl", "hEventControl", 10, 0, 10));
113 std::auto_ptr<TH1D> hTrackControl(new TH1D("hTrackControl", "hTrackControl", 10, 0, 10));
114
115 fhEventControl=hEventControl.release();
9535cec9 116 for (int iLabel=0; iLabel<kNEventPropertyLabels; iLabel++)
d731501a 117 fhEventControl->GetXaxis()->SetBinLabel(iLabel+1, fgkEventControlBinNames[iLabel]);
93fcaf9f 118 AddControlObject(fhEventControl);
119 fhTrackControl=hTrackControl.release();
d731501a 120 for (int iLabel=0; iLabel<kNTrackPropertyLabels; iLabel++)
121 fhTrackControl->GetXaxis()->SetBinLabel(iLabel+1, fgkTrackControlBinNames[iLabel]);
93fcaf9f 122 AddControlObject(fhTrackControl);
123
124 return 0;
125}
126
d731501a 127THnSparse* AliDxHFEParticleSelection::CreateControlTHnSparse(const char* name,
128 int thnSize,
129 int* thnBins,
130 double* thnMin,
131 double* thnMax,
132 const char** binLabels) const
133{
134 //
135 // Creates THnSparse.
136 //
137
138 AliInfo("Setting up THnSparse");
139
140 std::auto_ptr<THnSparseF> th(new THnSparseF(name, name, thnSize, thnBins, thnMin, thnMax));
141 if (th.get()==NULL) {
142 return NULL;
143 }
144 for (int iLabel=0; iLabel<thnSize; iLabel++) {
145 th->GetAxis(iLabel)->SetTitle(binLabels[iLabel]);
146
147 }
148 return th.release();
149
150}
151
dcf83226 152THnSparse* AliDxHFEParticleSelection::DefineTHnSparse()
d731501a 153{
154 //
155 // Defines the THnSparse. For now, only calls CreatControlTHnSparse
156
157 //TODO: Should make it more general. Or maybe one can use this here, and skip in PartSelEl?
158
dcf83226 159 // here is the only place to change the dimension
d731501a 160 const int thnSize = 3;
dcf83226 161 InitTHnSparseArray(thnSize);
162
d731501a 163 const double Pi=TMath::Pi();
164 TString name;
dcf83226 165 // 0 1 2
166 // Pt Phi Eta
167 int thnBins [thnSize] = { 1000, 200, 500};
168 double thnMin [thnSize] = { 0, 0, -1.};
169 double thnMax [thnSize] = { 100, 2*Pi, 1.};
170 const char* thnNames[thnSize] = { "Pt","Phi","Eta"};
d731501a 171
172 name.Form("%s info", GetName());
173
dcf83226 174 return CreateControlTHnSparse(name,thnSize,thnBins,thnMin,thnMax,thnNames);
d731501a 175}
176
93fcaf9f 177int AliDxHFEParticleSelection::AddControlObject(TObject* pObj)
178{
179 /// add control object to list, the base class becomes owner of the object
180 if (!pObj) return -EINVAL;
181 if (!fControlObjects) {
182 fControlObjects=new TList;
183 if (!fControlObjects) return -ENOMEM;
184 fControlObjects->SetOwner();
185 }
186 if (fControlObjects->FindObject(pObj->GetName())) {
187 AliError(Form("ignoring duplicate object '%s' of type %s", pObj->GetName(), pObj->ClassName()));
188 return -EEXIST;
189 }
9535cec9 190 if (GetVerbosity()>0) {
191 AliInfo(Form("Adding object '%s' of type %s",pObj->GetName(),pObj->ClassName()));
192 }
93fcaf9f 193 fControlObjects->Add(pObj);
194 return 0;
195}
196
9535cec9 197int AliDxHFEParticleSelection::HistogramEventProperties(int bin)
198{
199 /// histogram event properties
200 if (!fControlObjects) return 0;
201
202 // TODO: use enums for the bins of the control histogram
203 // for now: 0=all, 1=events with D0s, 2=events with correlated D0s
204 fhEventControl->Fill(bin);
205 return 0;
206}
207
208int AliDxHFEParticleSelection::HistogramParticleProperties(AliVParticle* p, int selected)
93fcaf9f 209{
210 /// histogram particle properties
d731501a 211
93fcaf9f 212 if (!p) return -EINVAL;
213 if (!fControlObjects) return 0;
214
215 // TODO: use enums for the bins of the control histogram
d731501a 216 fhTrackControl->Fill(kTrackAll);
217 if (selected) fhTrackControl->Fill(kTrackSel);
93fcaf9f 218 return 0;
72c0a987 219}
220
dcf83226 221int AliDxHFEParticleSelection::FillParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
d731501a 222{
223 // fill the data array from the particle data
224 if (!data) return -EINVAL;
225 int i=0;
dcf83226 226 if (dimension!=GetDimTHnSparse()) {
d731501a 227 // TODO: think about filling only the available data and throwing a warning
228 return -ENOSPC;
229 }
230 data[i++]=p->Pt();
231 data[i++]=p->Phi();
232 data[i++]=p->Eta();
233 return i;
234}
235
72c0a987 236TObjArray* AliDxHFEParticleSelection::Select(const AliVEvent* pEvent)
237{
9535cec9 238 /// create selection from 'Tracks' member of the event,
239 /// array contains only pointers but does not own the objects
72c0a987 240 /// object array needs to be deleted by caller
241 if (!pEvent) return NULL;
242 TObjArray* selectedTracks=new TObjArray;
243 if (!selectedTracks) return NULL;
dfe96b90 244 selectedTracks->SetOwner(); // creating new track objects below
72c0a987 245 int nofTracks=pEvent->GetNumberOfTracks();
246 for (int itrack=0; itrack<nofTracks; itrack++) {
247 AliVParticle* track=pEvent->GetTrack(itrack);
d731501a 248 int selectionCode=IsSelected(track,pEvent);
9535cec9 249 HistogramParticleProperties(track, selectionCode);
250 if (selectionCode==0) continue;
dfe96b90 251 selectedTracks->Add(CreateParticle(track));
72c0a987 252 }
253 return selectedTracks;
254}
255
9535cec9 256TObjArray* AliDxHFEParticleSelection::Select(TObjArray* pParticles, const AliVEvent* pEvent)
72c0a987 257{
9535cec9 258 /// create selection from the array of particles,
259 /// array contains only pointers but does not own the objects
72c0a987 260 /// object array needs to be deleted by caller
9535cec9 261 if (!pParticles) return NULL;
72c0a987 262 TObjArray* selectedTracks=new TObjArray;
263 if (!selectedTracks) return NULL;
dfe96b90 264 selectedTracks->SetOwner(); // creating new track objects below
9535cec9 265 TIter next(pParticles);
72c0a987 266 TObject* pObj=NULL;
9535cec9 267 while ((pObj=next())) {
72c0a987 268 AliVParticle* track=dynamic_cast<AliVParticle*>(pObj);
269 if (!track) continue;
9535cec9 270 int selectionCode=IsSelected(track, pEvent);
271 HistogramParticleProperties(track, selectionCode);
272 if (selectionCode ==0) continue;
dfe96b90 273 selectedTracks->Add(CreateParticle(track));
72c0a987 274 }
275 return selectedTracks;
276}
277
278int AliDxHFEParticleSelection::CheckAndAdd(AliVParticle* /*p*/)
279{
280 /// check and add track to internal array
281 /// TODO: check if needed
282 return -ENOSYS;
283}
284
9535cec9 285int AliDxHFEParticleSelection::IsSelected(AliVParticle* /*p*/, const AliVEvent* /*e*/)
72c0a987 286{
287 /// check particle if it passes the selection criteria
288 /// childs can overload, by default all tracks are selected
9535cec9 289 return 1;
72c0a987 290}
291
292void AliDxHFEParticleSelection::AliDxHFEParticleSelection::Clear(Option_t * /*option*/)
293{
294 /// inherited from TObject: cleanup
295}
296
297void AliDxHFEParticleSelection::Print(Option_t */*option*/) const
298{
299 /// inherited from TObject: print info
93fcaf9f 300 cout << "====================================================================" << endl;
301 TNamed::Print();
302 if (fControlObjects) fControlObjects->Print();
72c0a987 303}
304
9535cec9 305void AliDxHFEParticleSelection::SaveAs(const char* filename, Option_t */*option*/) const
72c0a987 306{
93fcaf9f 307 /// inherited from TObject: save selection criteria
9535cec9 308 TString fileoption;
309 // TODO: options recreate
310 fileoption="RECREATE";
311 //else fileoption="UPDATE";
312
313 std::auto_ptr<TFile> output(TFile::Open(filename,fileoption));
93fcaf9f 314 if (!output.get() || output->IsZombie()) {
315 AliError(Form("can not open file %s from writing", filename));
316 return;
317 }
318 output->cd();
319 if (fControlObjects) fControlObjects->Write();
320 output->Close();
321}
322
323void AliDxHFEParticleSelection::Draw(Option_t* /*option*/)
324{
325 /// inherited from TObject: draw content
326
327 // TODO: implement drawing code
328 // - create canvas objects
329 // - plot internal objects
330 // - optionally save canvases to file
331 //
332 // It might be appropriate to have another Draw function taking a
333 // TList as argument and implementing the actual drawing. If this
334 // function is 'static', it can be used stand-alone also from macros
335}
336
337TObject* AliDxHFEParticleSelection::FindObject(const char* name) const
338{
339 /// inherited from TObject: find object by name
340
341 if (fControlObjects) {
342 return fControlObjects->FindObject(name);
343 }
344 return NULL;
345}
346
347TObject* AliDxHFEParticleSelection::FindObject(const TObject* obj) const
348{
349 /// inherited from TObject: find object by pointer
350 if (fControlObjects) {
351 return fControlObjects->FindObject(obj);
352 }
353 return NULL;
72c0a987 354}
dfe96b90 355
356AliVParticle *AliDxHFEParticleSelection::CreateParticle(AliVParticle* track)
357{
358 // Creating object with reduced particle properties
359 AliReducedParticle *part = new AliReducedParticle(track->Eta(), track->Phi(), track->Pt(), track->Charge(), 0);
360
361 return part;
362
363}