]>
Commit | Line | Data |
---|---|---|
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 | ||
40 | using namespace std; | |
72c0a987 | 41 | |
42 | /// ROOT macro for the implementation of ROOT specific class methods | |
43 | ClassImp(AliDxHFEParticleSelection) | |
44 | ||
93fcaf9f | 45 | AliDxHFEParticleSelection::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) | |
72c0a987 | 52 | { |
53 | // constructor | |
54 | // | |
55 | // | |
56 | // | |
57 | // | |
58 | } | |
59 | ||
60 | AliDxHFEParticleSelection::~AliDxHFEParticleSelection() | |
61 | { | |
62 | // destructor | |
63 | if (fSelectedTracks) delete fSelectedTracks; | |
64 | fSelectedTracks=NULL; | |
93fcaf9f | 65 | if (fControlObjects) delete fControlObjects; |
66 | fControlObjects=NULL; | |
67 | } | |
68 | ||
69 | int AliDxHFEParticleSelection::InitControlObjects() | |
70 | { | |
71 | /// init the control objects, can be overloaded by childs which should | |
72 | /// call AliDxHFEParticleSelection::InitControlObjects() explicitly | |
73 | std::auto_ptr<TH1D> hEventControl(new TH1D("hEventControl", "hEventControl", 10, 0, 10)); | |
74 | std::auto_ptr<TH1D> hTrackControl(new TH1D("hTrackControl", "hTrackControl", 10, 0, 10)); | |
75 | ||
76 | fhEventControl=hEventControl.release(); | |
77 | AddControlObject(fhEventControl); | |
78 | fhTrackControl=hTrackControl.release(); | |
79 | AddControlObject(fhTrackControl); | |
80 | ||
81 | return 0; | |
82 | } | |
83 | ||
84 | int AliDxHFEParticleSelection::AddControlObject(TObject* pObj) | |
85 | { | |
86 | /// add control object to list, the base class becomes owner of the object | |
87 | if (!pObj) return -EINVAL; | |
88 | if (!fControlObjects) { | |
89 | fControlObjects=new TList; | |
90 | if (!fControlObjects) return -ENOMEM; | |
91 | fControlObjects->SetOwner(); | |
92 | } | |
93 | if (fControlObjects->FindObject(pObj->GetName())) { | |
94 | AliError(Form("ignoring duplicate object '%s' of type %s", pObj->GetName(), pObj->ClassName())); | |
95 | return -EEXIST; | |
96 | } | |
97 | fControlObjects->Add(pObj); | |
98 | return 0; | |
99 | } | |
100 | ||
101 | int AliDxHFEParticleSelection::HistogramParticleProperties(AliVParticle* p, bool selected) | |
102 | { | |
103 | /// histogram particle properties | |
104 | if (!p) return -EINVAL; | |
105 | if (!fControlObjects) return 0; | |
106 | ||
107 | // TODO: use enums for the bins of the control histogram | |
108 | fhTrackControl->Fill(0); | |
109 | if (selected) fhTrackControl->Fill(1); | |
110 | return 0; | |
72c0a987 | 111 | } |
112 | ||
113 | TObjArray* AliDxHFEParticleSelection::Select(const AliVEvent* pEvent) | |
114 | { | |
115 | /// create selection, array contains only pointers but does not own the objects | |
116 | /// object array needs to be deleted by caller | |
117 | if (!pEvent) return NULL; | |
118 | TObjArray* selectedTracks=new TObjArray; | |
119 | if (!selectedTracks) return NULL; | |
120 | int nofTracks=pEvent->GetNumberOfTracks(); | |
121 | for (int itrack=0; itrack<nofTracks; itrack++) { | |
122 | AliVParticle* track=pEvent->GetTrack(itrack); | |
93fcaf9f | 123 | bool selected=IsSelected(track); |
124 | HistogramParticleProperties(track, selected); | |
125 | if (!selected) continue; | |
72c0a987 | 126 | selectedTracks->Add(track); |
127 | } | |
128 | return selectedTracks; | |
129 | } | |
130 | ||
131 | TObjArray* AliDxHFEParticleSelection::Select(TObjArray* pTracks) | |
132 | { | |
133 | /// create selection, array contains only pointers but does not own the objects | |
134 | /// object array needs to be deleted by caller | |
135 | if (!pTracks) return NULL; | |
136 | TObjArray* selectedTracks=new TObjArray; | |
137 | if (!selectedTracks) return NULL; | |
138 | TIter itrack(pTracks); | |
139 | TObject* pObj=NULL; | |
140 | while ((pObj=itrack())!=NULL) { | |
141 | AliVParticle* track=dynamic_cast<AliVParticle*>(pObj); | |
142 | if (!track) continue; | |
93fcaf9f | 143 | bool selected=IsSelected(track); |
144 | HistogramParticleProperties(track, selected); | |
145 | if (!selected) continue; | |
72c0a987 | 146 | selectedTracks->Add(track); |
147 | } | |
148 | return selectedTracks; | |
149 | } | |
150 | ||
151 | int AliDxHFEParticleSelection::CheckAndAdd(AliVParticle* /*p*/) | |
152 | { | |
153 | /// check and add track to internal array | |
154 | /// TODO: check if needed | |
155 | return -ENOSYS; | |
156 | } | |
157 | ||
158 | bool AliDxHFEParticleSelection::IsSelected(AliVParticle* /*p*/) | |
159 | { | |
160 | /// check particle if it passes the selection criteria | |
161 | /// childs can overload, by default all tracks are selected | |
162 | return true; | |
163 | } | |
164 | ||
165 | void AliDxHFEParticleSelection::AliDxHFEParticleSelection::Clear(Option_t * /*option*/) | |
166 | { | |
167 | /// inherited from TObject: cleanup | |
168 | } | |
169 | ||
170 | void AliDxHFEParticleSelection::Print(Option_t */*option*/) const | |
171 | { | |
172 | /// inherited from TObject: print info | |
93fcaf9f | 173 | cout << "====================================================================" << endl; |
174 | TNamed::Print(); | |
175 | if (fControlObjects) fControlObjects->Print(); | |
72c0a987 | 176 | } |
177 | ||
93fcaf9f | 178 | void AliDxHFEParticleSelection::SaveAs(const char* filename,Option_t */*option*/) const |
72c0a987 | 179 | { |
93fcaf9f | 180 | /// inherited from TObject: save selection criteria |
181 | std::auto_ptr<TFile> output(TFile::Open(filename, "RECREATE")); | |
182 | if (!output.get() || output->IsZombie()) { | |
183 | AliError(Form("can not open file %s from writing", filename)); | |
184 | return; | |
185 | } | |
186 | output->cd(); | |
187 | if (fControlObjects) fControlObjects->Write(); | |
188 | output->Close(); | |
189 | } | |
190 | ||
191 | void AliDxHFEParticleSelection::Draw(Option_t* /*option*/) | |
192 | { | |
193 | /// inherited from TObject: draw content | |
194 | ||
195 | // TODO: implement drawing code | |
196 | // - create canvas objects | |
197 | // - plot internal objects | |
198 | // - optionally save canvases to file | |
199 | // | |
200 | // It might be appropriate to have another Draw function taking a | |
201 | // TList as argument and implementing the actual drawing. If this | |
202 | // function is 'static', it can be used stand-alone also from macros | |
203 | } | |
204 | ||
205 | TObject* AliDxHFEParticleSelection::FindObject(const char* name) const | |
206 | { | |
207 | /// inherited from TObject: find object by name | |
208 | ||
209 | if (fControlObjects) { | |
210 | return fControlObjects->FindObject(name); | |
211 | } | |
212 | return NULL; | |
213 | } | |
214 | ||
215 | TObject* AliDxHFEParticleSelection::FindObject(const TObject* obj) const | |
216 | { | |
217 | /// inherited from TObject: find object by pointer | |
218 | if (fControlObjects) { | |
219 | return fControlObjects->FindObject(obj); | |
220 | } | |
221 | return NULL; | |
72c0a987 | 222 | } |