3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* Sedat Altinpinar <Sedat.Altinpinar@cern.ch> *
9 //* Hege Erdal <hege.erdal@gmail.com> *
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 //**************************************************************************
20 /// @file AliDxHFEParticleSelection.cxx
21 /// @author Sedat Altinpinar, Hege Erdal, Matthias Richter
23 /// @brief Base class for particle selection
26 #include "AliDxHFEParticleSelection.h"
28 #include "AliVEvent.h"
29 #include "AliVParticle.h"
30 #include "TObjArray.h"
35 #include "THnSparse.h"
36 #include "AliReducedParticle.h"
38 #include "TPRegexp.h" // for TStringToken
45 /// ROOT macro for the implementation of ROOT specific class methods
46 ClassImp(AliDxHFEParticleSelection)
48 AliDxHFEParticleSelection::AliDxHFEParticleSelection(const char* name, const char* opt)
49 : TNamed(name?name:"AliDxHFEParticleSelection", name?name:"AliDxHFEParticleSelection")
51 , fSelectedTracks(NULL)
52 , fControlObjects(NULL)
53 , fhEventControl(NULL)
54 , fhTrackControl(NULL)
58 , fParticleProperties(NULL)
68 const char* AliDxHFEParticleSelection::fgkEventControlBinNames[]={
74 const char* AliDxHFEParticleSelection::fgkTrackControlBinNames[]={
79 AliDxHFEParticleSelection::~AliDxHFEParticleSelection()
82 if (fParticleProperties) delete[] fParticleProperties;
83 fParticleProperties=NULL;
84 if (fSelectedTracks) delete fSelectedTracks;
86 if (fControlObjects) delete fControlObjects;
92 int AliDxHFEParticleSelection::Init()
95 // Init part sel. Calls InitControlObjects()
103 int AliDxHFEParticleSelection::InitControlObjects()
106 // init control objects
107 // TODO: Change to private now that have Init()?
110 AliInfo("Setting up control objects");
113 /// init the control objects, can be overloaded by childs which should
114 /// call AliDxHFEParticleSelection::InitControlObjects() explicitly
115 std::auto_ptr<TH1D> hEventControl(new TH1D("hEventControl", "hEventControl", 10, 0, 10));
116 std::auto_ptr<TH1D> hTrackControl(new TH1D("hTrackControl", "hTrackControl", 10, 0, 10));
118 fhEventControl=hEventControl.release();
119 for (int iLabel=0; iLabel<kNEventPropertyLabels; iLabel++)
120 fhEventControl->GetXaxis()->SetBinLabel(iLabel+1, fgkEventControlBinNames[iLabel]);
121 AddControlObject(fhEventControl);
122 fhTrackControl=hTrackControl.release();
123 for (int iLabel=0; iLabel<kNTrackPropertyLabels; iLabel++)
124 fhTrackControl->GetXaxis()->SetBinLabel(iLabel+1, fgkTrackControlBinNames[iLabel]);
125 AddControlObject(fhTrackControl);
131 TH1* AliDxHFEParticleSelection::CreateControlHistogram(const char* name,
136 const char** binLabels) const
138 /// create control histogram
139 std::auto_ptr<TH1> h(new TH1D(name, title, nBins, min, max));
140 if (!h.get()) return NULL;
142 for (int iLabel=0; iLabel<nBins; iLabel++) {
143 h->GetXaxis()->SetBinLabel(iLabel+1, binLabels[iLabel]);
151 TH2* AliDxHFEParticleSelection::CreateControl2DHistogram(const char* name,
158 /// create control 2D histogram. Requires as input:
159 // name = name of histogram
160 // title = title of histogram
161 // nBins (array with 6 elements) containing apropriate binning and range for x and y axis
162 // xaxis = title of x axis
163 // yaxis = title of y axis
165 std::auto_ptr<TH2> h(new TH2D(name, title, (Int_t)nBins[0], nBins[1], nBins[2], (Int_t)nBins[3], nBins[4],nBins[5]));
166 if (!h.get()) return NULL;
167 h->GetXaxis()->SetTitle(xaxis);
168 h->GetYaxis()->SetTitle(yaxis);
173 THnSparse* AliDxHFEParticleSelection::CreateControlTHnSparse(const char* name,
178 const char** binLabels) const
181 // Creates THnSparse.
184 AliInfo("Setting up THnSparse");
186 std::auto_ptr<THnSparseF> th(new THnSparseF(name, name, thnSize, thnBins, thnMin, thnMax));
187 if (th.get()==NULL) {
190 for (int iLabel=0; iLabel<thnSize; iLabel++) {
191 th->GetAxis(iLabel)->SetTitle(binLabels[iLabel]);
198 THnSparse* AliDxHFEParticleSelection::DefineTHnSparse()
201 // Defines the THnSparse. For now, only calls CreatControlTHnSparse
203 //TODO: Should make it more general. Or maybe one can use this here, and skip in PartSelEl?
205 // here is the only place to change the dimension
206 const int thnSize = 3;
207 InitTHnSparseArray(thnSize);
209 const double Pi=TMath::Pi();
213 int thnBins [thnSize] = { 1000, 200, 500};
214 double thnMin [thnSize] = { 0, 0, -1.};
215 double thnMax [thnSize] = { 100, 2*Pi, 1.};
216 const char* thnNames[thnSize] = { "Pt","Phi","Eta"};
218 name.Form("%s info", GetName());
220 return CreateControlTHnSparse(name,thnSize,thnBins,thnMin,thnMax,thnNames);
223 int AliDxHFEParticleSelection::AddControlObject(TObject* pObj)
225 /// add control object to list, the base class becomes owner of the object
226 if (!pObj) return -EINVAL;
227 if (!fControlObjects) {
228 fControlObjects=new TList;
229 if (!fControlObjects) return -ENOMEM;
230 fControlObjects->SetOwner();
232 if (fControlObjects->FindObject(pObj->GetName())) {
233 AliError(Form("ignoring duplicate object '%s' of type %s", pObj->GetName(), pObj->ClassName()));
236 if (GetVerbosity()>0) {
237 AliInfo(Form("Adding object '%s' of type %s",pObj->GetName(),pObj->ClassName()));
239 fControlObjects->Add(pObj);
243 int AliDxHFEParticleSelection::HistogramEventProperties(int bin)
245 /// histogram event properties
246 if (!fControlObjects) return 0;
248 // TODO: use enums for the bins of the control histogram
249 // for now: 0=all, 1=events with D0s, 2=events with correlated D0s
250 fhEventControl->Fill(bin);
254 int AliDxHFEParticleSelection::HistogramParticleProperties(AliVParticle* p, int selected)
256 /// histogram particle properties
258 if (!p) return -EINVAL;
259 if (!fControlObjects) return 0;
261 // TODO: use enums for the bins of the control histogram
262 fhTrackControl->Fill(kTrackAll);
263 if (selected) fhTrackControl->Fill(kTrackSel);
267 int AliDxHFEParticleSelection::FillParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
269 // fill the data array from the particle data
270 if (!data) return -EINVAL;
272 if (dimension!=GetDimTHnSparse()) {
273 // TODO: think about filling only the available data and throwing a warning
282 TObjArray* AliDxHFEParticleSelection::Select(const AliVEvent* pEvent)
284 /// create selection from 'Tracks' member of the event,
285 /// array contains only pointers but does not own the objects
286 /// object array needs to be deleted by caller
287 if (!pEvent) return NULL;
288 TObjArray* selectedTracks=new TObjArray;
289 if (!selectedTracks) return NULL;
290 selectedTracks->SetOwner(kFALSE); // creating new track objects below
291 int nofTracks=pEvent->GetNumberOfTracks();
292 for (int itrack=0; itrack<nofTracks; itrack++) {
293 AliVParticle* track=pEvent->GetTrack(itrack);
294 int selectionCode=IsSelected(track,pEvent);
295 HistogramParticleProperties(track, selectionCode);
296 if (selectionCode==0) continue;
297 selectedTracks->Add(CreateParticle(track));
299 return selectedTracks;
302 TObjArray* AliDxHFEParticleSelection::Select(TObjArray* pParticles, const AliVEvent* pEvent)
304 /// create selection from the array of particles,
305 /// array contains only pointers but does not own the objects
306 /// object array needs to be deleted by caller
307 if (!pParticles) return NULL;
308 TObjArray* selectedTracks=new TObjArray;
309 if (!selectedTracks) return NULL;
310 selectedTracks->SetOwner(kFALSE); // creating new track objects below
311 TIter next(pParticles);
313 while ((pObj=next())) {
314 AliVParticle* track=dynamic_cast<AliVParticle*>(pObj);
315 if (!track) continue;
316 int selectionCode=IsSelected(track, pEvent);
317 HistogramParticleProperties(track, selectionCode);
318 if (selectionCode ==0) continue;
319 selectedTracks->Add(CreateParticle(track));
321 return selectedTracks;
324 int AliDxHFEParticleSelection::CheckAndAdd(AliVParticle* /*p*/)
326 /// check and add track to internal array
327 /// TODO: check if needed
331 int AliDxHFEParticleSelection::IsSelected(AliVParticle* /*p*/, const AliVEvent* /*e*/)
333 /// check particle if it passes the selection criteria
334 /// childs can overload, by default all tracks are selected
338 void AliDxHFEParticleSelection::AliDxHFEParticleSelection::Clear(Option_t * /*option*/)
340 /// inherited from TObject: cleanup
343 void AliDxHFEParticleSelection::Print(Option_t */*option*/) const
345 /// inherited from TObject: print info
346 cout << "====================================================================" << endl;
348 if (fControlObjects) fControlObjects->Print();
351 void AliDxHFEParticleSelection::SaveAs(const char* filename, Option_t */*option*/) const
353 /// inherited from TObject: save selection criteria
355 // TODO: options recreate
356 fileoption="RECREATE";
357 //else fileoption="UPDATE";
359 std::auto_ptr<TFile> output(TFile::Open(filename,fileoption));
360 if (!output.get() || output->IsZombie()) {
361 AliError(Form("can not open file %s from writing", filename));
365 if (fControlObjects) fControlObjects->Write();
369 void AliDxHFEParticleSelection::Draw(Option_t* /*option*/)
371 /// inherited from TObject: draw content
373 // TODO: implement drawing code
374 // - create canvas objects
375 // - plot internal objects
376 // - optionally save canvases to file
378 // It might be appropriate to have another Draw function taking a
379 // TList as argument and implementing the actual drawing. If this
380 // function is 'static', it can be used stand-alone also from macros
383 TObject* AliDxHFEParticleSelection::FindObject(const char* name) const
385 /// inherited from TObject: find object by name
387 if (fControlObjects) {
388 return fControlObjects->FindObject(name);
393 TObject* AliDxHFEParticleSelection::FindObject(const TObject* obj) const
395 /// inherited from TObject: find object by pointer
396 if (fControlObjects) {
397 return fControlObjects->FindObject(obj);
402 AliVParticle *AliDxHFEParticleSelection::CreateParticle(AliVParticle* track)
404 // Creating object with reduced particle properties
405 AliReducedParticle *part = new AliReducedParticle(track->Eta(), track->Phi(), track->Pt(), track->Charge(), 0);
411 int AliDxHFEParticleSelection::ParseArguments(const char* arguments)
413 // parse arguments and set internal flags
414 const char* key=NULL;
415 const TString delimiter(" ");
416 TStringToken token(arguments, delimiter);
417 while (token.NextToken()) {
418 TString argument=token;
420 if (argument.BeginsWith(key)) {
421 argument.ReplaceAll(key, "");
422 if (argument.CompareTo("pp")==0) fSystem=0;
423 else if (argument.CompareTo("Pb-Pb")==0) fSystem=1;
424 else if (argument.CompareTo("p-Pb")==0) fSystem=2;
426 AliWarning(Form("can not set collision system, unknown parameter '%s'", argument.Data()));
427 // TODO: check what makes sense
433 AliWarning(Form("unknown argument '%s'", argument.Data()));