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"
42 /// ROOT macro for the implementation of ROOT specific class methods
43 ClassImp(AliDxHFEParticleSelection)
45 AliDxHFEParticleSelection::AliDxHFEParticleSelection(const char* name, const char* opt)
46 : TNamed(name?name:"AliDxHFEParticleSelection", name?name:"AliDxHFEParticleSelection")
48 , fSelectedTracks(NULL)
49 , fControlObjects(NULL)
50 , fhEventControl(NULL)
51 , fhTrackControl(NULL)
62 const char* AliDxHFEParticleSelection::fgkEventControlBinNames[]={
68 AliDxHFEParticleSelection::~AliDxHFEParticleSelection()
71 if (fSelectedTracks) delete fSelectedTracks;
73 if (fControlObjects) delete fControlObjects;
79 int AliDxHFEParticleSelection::InitControlObjects()
81 // init control objects
83 AliInfo("Setting up control objects");
86 /// init the control objects, can be overloaded by childs which should
87 /// call AliDxHFEParticleSelection::InitControlObjects() explicitly
88 std::auto_ptr<TH1D> hEventControl(new TH1D("hEventControl", "hEventControl", 10, 0, 10));
89 std::auto_ptr<TH1D> hTrackControl(new TH1D("hTrackControl", "hTrackControl", 10, 0, 10));
91 fhEventControl=hEventControl.release();
92 for (int iLabel=0; iLabel<kNEventPropertyLabels; iLabel++)
93 fhEventControl->GetXaxis()->SetBinLabel(iLabel, fgkEventControlBinNames[iLabel]);
94 AddControlObject(fhEventControl);
95 fhTrackControl=hTrackControl.release();
96 AddControlObject(fhTrackControl);
101 int AliDxHFEParticleSelection::AddControlObject(TObject* pObj)
103 /// add control object to list, the base class becomes owner of the object
104 if (!pObj) return -EINVAL;
105 if (!fControlObjects) {
106 fControlObjects=new TList;
107 if (!fControlObjects) return -ENOMEM;
108 fControlObjects->SetOwner();
110 if (fControlObjects->FindObject(pObj->GetName())) {
111 AliError(Form("ignoring duplicate object '%s' of type %s", pObj->GetName(), pObj->ClassName()));
114 if (GetVerbosity()>0) {
115 AliInfo(Form("Adding object '%s' of type %s",pObj->GetName(),pObj->ClassName()));
117 fControlObjects->Add(pObj);
121 int AliDxHFEParticleSelection::HistogramEventProperties(int bin)
123 /// histogram event properties
124 if (!fControlObjects) return 0;
126 // TODO: use enums for the bins of the control histogram
127 // for now: 0=all, 1=events with D0s, 2=events with correlated D0s
128 fhEventControl->Fill(bin);
132 int AliDxHFEParticleSelection::HistogramParticleProperties(AliVParticle* p, int selected)
134 /// histogram particle properties
135 if (!p) return -EINVAL;
136 if (!fControlObjects) return 0;
138 // TODO: use enums for the bins of the control histogram
139 fhTrackControl->Fill(0);
140 if (selected) fhTrackControl->Fill(1);
144 TObjArray* AliDxHFEParticleSelection::Select(const AliVEvent* pEvent)
146 /// create selection from 'Tracks' member of the event,
147 /// array contains only pointers but does not own the objects
148 /// object array needs to be deleted by caller
149 if (!pEvent) return NULL;
150 TObjArray* selectedTracks=new TObjArray;
151 if (!selectedTracks) return NULL;
152 int nofTracks=pEvent->GetNumberOfTracks();
153 for (int itrack=0; itrack<nofTracks; itrack++) {
154 AliVParticle* track=pEvent->GetTrack(itrack);
155 int selectionCode=IsSelected(track);
156 HistogramParticleProperties(track, selectionCode);
157 if (selectionCode==0) continue;
158 selectedTracks->Add(track);
160 return selectedTracks;
163 TObjArray* AliDxHFEParticleSelection::Select(TObjArray* pParticles, const AliVEvent* pEvent)
165 /// create selection from the array of particles,
166 /// array contains only pointers but does not own the objects
167 /// object array needs to be deleted by caller
168 if (!pParticles) return NULL;
169 TObjArray* selectedTracks=new TObjArray;
170 if (!selectedTracks) return NULL;
171 TIter next(pParticles);
173 while ((pObj=next())) {
174 AliVParticle* track=dynamic_cast<AliVParticle*>(pObj);
175 if (!track) continue;
176 int selectionCode=IsSelected(track, pEvent);
177 HistogramParticleProperties(track, selectionCode);
178 if (selectionCode ==0) continue;
179 selectedTracks->Add(track);
181 return selectedTracks;
184 int AliDxHFEParticleSelection::CheckAndAdd(AliVParticle* /*p*/)
186 /// check and add track to internal array
187 /// TODO: check if needed
191 int AliDxHFEParticleSelection::IsSelected(AliVParticle* /*p*/, const AliVEvent* /*e*/)
193 /// check particle if it passes the selection criteria
194 /// childs can overload, by default all tracks are selected
198 void AliDxHFEParticleSelection::AliDxHFEParticleSelection::Clear(Option_t * /*option*/)
200 /// inherited from TObject: cleanup
203 void AliDxHFEParticleSelection::Print(Option_t */*option*/) const
205 /// inherited from TObject: print info
206 cout << "====================================================================" << endl;
208 if (fControlObjects) fControlObjects->Print();
211 void AliDxHFEParticleSelection::SaveAs(const char* filename, Option_t */*option*/) const
213 /// inherited from TObject: save selection criteria
215 // TODO: options recreate
216 fileoption="RECREATE";
217 //else fileoption="UPDATE";
219 std::auto_ptr<TFile> output(TFile::Open(filename,fileoption));
220 if (!output.get() || output->IsZombie()) {
221 AliError(Form("can not open file %s from writing", filename));
225 if (fControlObjects) fControlObjects->Write();
229 void AliDxHFEParticleSelection::Draw(Option_t* /*option*/)
231 /// inherited from TObject: draw content
233 // TODO: implement drawing code
234 // - create canvas objects
235 // - plot internal objects
236 // - optionally save canvases to file
238 // It might be appropriate to have another Draw function taking a
239 // TList as argument and implementing the actual drawing. If this
240 // function is 'static', it can be used stand-alone also from macros
243 TObject* AliDxHFEParticleSelection::FindObject(const char* name) const
245 /// inherited from TObject: find object by name
247 if (fControlObjects) {
248 return fControlObjects->FindObject(name);
253 TObject* AliDxHFEParticleSelection::FindObject(const TObject* obj) const
255 /// inherited from TObject: find object by pointer
256 if (fControlObjects) {
257 return fControlObjects->FindObject(obj);