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"
34 #include "THnSparse.h"
35 #include "AliReducedParticle.h"
43 /// ROOT macro for the implementation of ROOT specific class methods
44 ClassImp(AliDxHFEParticleSelection)
46 AliDxHFEParticleSelection::AliDxHFEParticleSelection(const char* name, const char* opt)
47 : TNamed(name?name:"AliDxHFEParticleSelection", name?name:"AliDxHFEParticleSelection")
49 , fSelectedTracks(NULL)
50 , fControlObjects(NULL)
51 , fhEventControl(NULL)
52 , fhTrackControl(NULL)
56 , fParticleProperties(NULL)
65 const char* AliDxHFEParticleSelection::fgkEventControlBinNames[]={
71 const char* AliDxHFEParticleSelection::fgkTrackControlBinNames[]={
76 AliDxHFEParticleSelection::~AliDxHFEParticleSelection()
79 if (fParticleProperties) delete[] fParticleProperties;
80 fParticleProperties=NULL;
81 if (fSelectedTracks) delete fSelectedTracks;
83 if (fControlObjects) delete fControlObjects;
89 int AliDxHFEParticleSelection::Init()
92 // Init part sel. Calls InitControlObjects()
100 int AliDxHFEParticleSelection::InitControlObjects()
103 // init control objects
104 // TODO: Change to private now that have Init()?
107 AliInfo("Setting up control objects");
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));
115 fhEventControl=hEventControl.release();
116 for (int iLabel=0; iLabel<kNEventPropertyLabels; iLabel++)
117 fhEventControl->GetXaxis()->SetBinLabel(iLabel+1, fgkEventControlBinNames[iLabel]);
118 AddControlObject(fhEventControl);
119 fhTrackControl=hTrackControl.release();
120 for (int iLabel=0; iLabel<kNTrackPropertyLabels; iLabel++)
121 fhTrackControl->GetXaxis()->SetBinLabel(iLabel+1, fgkTrackControlBinNames[iLabel]);
122 AddControlObject(fhTrackControl);
127 THnSparse* AliDxHFEParticleSelection::CreateControlTHnSparse(const char* name,
132 const char** binLabels) const
135 // Creates THnSparse.
138 AliInfo("Setting up THnSparse");
140 std::auto_ptr<THnSparseF> th(new THnSparseF(name, name, thnSize, thnBins, thnMin, thnMax));
141 if (th.get()==NULL) {
144 for (int iLabel=0; iLabel<thnSize; iLabel++) {
145 th->GetAxis(iLabel)->SetTitle(binLabels[iLabel]);
152 THnSparse* AliDxHFEParticleSelection::DefineTHnSparse()
155 // Defines the THnSparse. For now, only calls CreatControlTHnSparse
157 //TODO: Should make it more general. Or maybe one can use this here, and skip in PartSelEl?
159 // here is the only place to change the dimension
160 const int thnSize = 3;
161 InitTHnSparseArray(thnSize);
163 const double Pi=TMath::Pi();
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"};
172 name.Form("%s info", GetName());
174 return CreateControlTHnSparse(name,thnSize,thnBins,thnMin,thnMax,thnNames);
177 int AliDxHFEParticleSelection::AddControlObject(TObject* pObj)
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();
186 if (fControlObjects->FindObject(pObj->GetName())) {
187 AliError(Form("ignoring duplicate object '%s' of type %s", pObj->GetName(), pObj->ClassName()));
190 if (GetVerbosity()>0) {
191 AliInfo(Form("Adding object '%s' of type %s",pObj->GetName(),pObj->ClassName()));
193 fControlObjects->Add(pObj);
197 int AliDxHFEParticleSelection::HistogramEventProperties(int bin)
199 /// histogram event properties
200 if (!fControlObjects) return 0;
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);
208 int AliDxHFEParticleSelection::HistogramParticleProperties(AliVParticle* p, int selected)
210 /// histogram particle properties
212 if (!p) return -EINVAL;
213 if (!fControlObjects) return 0;
215 // TODO: use enums for the bins of the control histogram
216 fhTrackControl->Fill(kTrackAll);
217 if (selected) fhTrackControl->Fill(kTrackSel);
221 int AliDxHFEParticleSelection::FillParticleProperties(AliVParticle* p, Double_t* data, int dimension) const
223 // fill the data array from the particle data
224 if (!data) return -EINVAL;
226 if (dimension!=GetDimTHnSparse()) {
227 // TODO: think about filling only the available data and throwing a warning
236 TObjArray* AliDxHFEParticleSelection::Select(const AliVEvent* pEvent)
238 /// create selection from 'Tracks' member of the event,
239 /// array contains only pointers but does not own the objects
240 /// object array needs to be deleted by caller
241 if (!pEvent) return NULL;
242 TObjArray* selectedTracks=new TObjArray;
243 if (!selectedTracks) return NULL;
244 selectedTracks->SetOwner(kFALSE); // creating new track objects below
245 int nofTracks=pEvent->GetNumberOfTracks();
246 for (int itrack=0; itrack<nofTracks; itrack++) {
247 AliVParticle* track=pEvent->GetTrack(itrack);
248 int selectionCode=IsSelected(track,pEvent);
249 HistogramParticleProperties(track, selectionCode);
250 if (selectionCode==0) continue;
251 selectedTracks->Add(CreateParticle(track));
253 return selectedTracks;
256 TObjArray* AliDxHFEParticleSelection::Select(TObjArray* pParticles, const AliVEvent* pEvent)
258 /// create selection from the array of particles,
259 /// array contains only pointers but does not own the objects
260 /// object array needs to be deleted by caller
261 if (!pParticles) return NULL;
262 TObjArray* selectedTracks=new TObjArray;
263 if (!selectedTracks) return NULL;
264 selectedTracks->SetOwner(); // creating new track objects below
265 TIter next(pParticles);
267 while ((pObj=next())) {
268 AliVParticle* track=dynamic_cast<AliVParticle*>(pObj);
269 if (!track) continue;
270 int selectionCode=IsSelected(track, pEvent);
271 HistogramParticleProperties(track, selectionCode);
272 if (selectionCode ==0) continue;
273 selectedTracks->Add(CreateParticle(track));
275 return selectedTracks;
278 int AliDxHFEParticleSelection::CheckAndAdd(AliVParticle* /*p*/)
280 /// check and add track to internal array
281 /// TODO: check if needed
285 int AliDxHFEParticleSelection::IsSelected(AliVParticle* /*p*/, const AliVEvent* /*e*/)
287 /// check particle if it passes the selection criteria
288 /// childs can overload, by default all tracks are selected
292 void AliDxHFEParticleSelection::AliDxHFEParticleSelection::Clear(Option_t * /*option*/)
294 /// inherited from TObject: cleanup
297 void AliDxHFEParticleSelection::Print(Option_t */*option*/) const
299 /// inherited from TObject: print info
300 cout << "====================================================================" << endl;
302 if (fControlObjects) fControlObjects->Print();
305 void AliDxHFEParticleSelection::SaveAs(const char* filename, Option_t */*option*/) const
307 /// inherited from TObject: save selection criteria
309 // TODO: options recreate
310 fileoption="RECREATE";
311 //else fileoption="UPDATE";
313 std::auto_ptr<TFile> output(TFile::Open(filename,fileoption));
314 if (!output.get() || output->IsZombie()) {
315 AliError(Form("can not open file %s from writing", filename));
319 if (fControlObjects) fControlObjects->Write();
323 void AliDxHFEParticleSelection::Draw(Option_t* /*option*/)
325 /// inherited from TObject: draw content
327 // TODO: implement drawing code
328 // - create canvas objects
329 // - plot internal objects
330 // - optionally save canvases to file
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
337 TObject* AliDxHFEParticleSelection::FindObject(const char* name) const
339 /// inherited from TObject: find object by name
341 if (fControlObjects) {
342 return fControlObjects->FindObject(name);
347 TObject* AliDxHFEParticleSelection::FindObject(const TObject* obj) const
349 /// inherited from TObject: find object by pointer
350 if (fControlObjects) {
351 return fControlObjects->FindObject(obj);
356 AliVParticle *AliDxHFEParticleSelection::CreateParticle(AliVParticle* track)
358 // Creating object with reduced particle properties
359 AliReducedParticle *part = new AliReducedParticle(track->Eta(), track->Phi(), track->Pt(), track->Charge(), 0);