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