]>
Commit | Line | Data |
---|---|---|
ce487a7f | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | // | |
16 | // Container for TRD Threshold parameters stored in the OADB | |
17 | // | |
18 | // Author: Markus Fasel <M.Fasel@gsi.de> | |
19 | // | |
bd58d4b9 | 20 | #include <TList.h> |
ce487a7f | 21 | #include <TMath.h> |
22 | #include <TSortedList.h> | |
23 | ||
24 | #include "AliLog.h" | |
25 | ||
26 | #include "AliTRDPIDParams.h" | |
27 | ||
28 | ClassImp(AliTRDPIDParams) | |
bd58d4b9 | 29 | //ClassImp(AliTRDPIDParams::AliTRDPIDThresholds) |
30 | //ClassImp(AliTRDPIDParams::AliTRDPIDCentrality) | |
ce487a7f | 31 | |
32 | const Double_t AliTRDPIDParams::kVerySmall = 1e-5; | |
33 | ||
34 | //____________________________________________________________ | |
35 | AliTRDPIDParams::AliTRDPIDParams(): | |
36 | TNamed(), | |
37 | fEntries(NULL) | |
38 | { | |
39 | // | |
40 | // Dummy constructor | |
41 | // | |
42 | } | |
43 | ||
44 | //____________________________________________________________ | |
45 | AliTRDPIDParams::AliTRDPIDParams(const char *name) : | |
46 | TNamed(name, ""), | |
47 | fEntries(NULL) | |
48 | { | |
49 | // | |
50 | // Default constructor | |
51 | // | |
bd58d4b9 | 52 | fEntries = new TList; |
ce487a7f | 53 | } |
54 | ||
db0e2c5f | 55 | //____________________________________________________________ |
56 | AliTRDPIDParams::AliTRDPIDParams(const AliTRDPIDParams &ref): | |
57 | TNamed(ref), | |
58 | fEntries(NULL) | |
59 | { | |
60 | // | |
61 | // Copy constructor | |
62 | // | |
63 | ||
bd58d4b9 | 64 | fEntries=(TList*)ref.fEntries->Clone(); |
db0e2c5f | 65 | } |
66 | ||
ce487a7f | 67 | //____________________________________________________________ |
68 | AliTRDPIDParams::~AliTRDPIDParams(){ | |
69 | // | |
70 | // Destructor | |
71 | // | |
72 | delete fEntries; | |
73 | } | |
74 | ||
75 | //____________________________________________________________ | |
bd58d4b9 | 76 | void AliTRDPIDParams::AddCentralityClass(Double_t minCentrality, Double_t maxCentrality){ |
77 | // | |
78 | // Add new centrality class | |
79 | // | |
80 | ||
81 | // check whether centrality class already exists | |
82 | AliTRDPIDCentrality *checklow = FindCentrality(minCentrality + 0.01), | |
83 | *checkhigh = FindCentrality(maxCentrality - 0.01); | |
84 | ||
85 | if(!checklow && ! checkhigh) | |
86 | fEntries->Add(new AliTRDPIDCentrality(minCentrality, maxCentrality)); | |
87 | } | |
88 | ||
89 | //____________________________________________________________ | |
90 | AliTRDPIDParams::AliTRDPIDCentrality *AliTRDPIDParams::FindCentrality(Double_t val) const { | |
91 | // | |
92 | // Find centrality bin | |
93 | // | |
94 | TIter centralities(fEntries); | |
95 | AliTRDPIDCentrality *obj(NULL), *tmp(NULL); | |
96 | while((obj = dynamic_cast<AliTRDPIDCentrality *>(centralities()))){ | |
97 | if(val >= obj->GetMinCentrality() && val <= obj->GetMaxCentrality()){ | |
98 | tmp = obj; | |
99 | break; | |
100 | } | |
101 | } | |
102 | return tmp; | |
103 | } | |
104 | ||
105 | //____________________________________________________________ | |
106 | Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params, Double_t centrality) const{ | |
ce487a7f | 107 | // |
108 | // Retrieve params | |
109 | // Use IsEqual definition | |
110 | // | |
bd58d4b9 | 111 | AliTRDPIDCentrality *cent = FindCentrality(centrality); |
112 | if(!cent){ | |
113 | AliDebug(1, "Centrality class not available"); | |
ce487a7f | 114 | return kFALSE; |
115 | } | |
bd58d4b9 | 116 | cent->GetThresholdParameters(ntracklets, efficiency, params); |
ce487a7f | 117 | return kTRUE; |
118 | } | |
119 | ||
120 | //____________________________________________________________ | |
bd58d4b9 | 121 | void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params, Double_t centrality){ |
ce487a7f | 122 | // |
bd58d4b9 | 123 | // Set new threshold parameters |
124 | // | |
125 | AliTRDPIDCentrality *cent = FindCentrality(centrality); | |
126 | if(cent) cent->SetThresholdParameters(ntracklets, effMin, effMax, params); | |
127 | else AliDebug(1, "Centrality class not available"); | |
ce487a7f | 128 | } |
129 | ||
130 | //____________________________________________________________ | |
131 | void AliTRDPIDParams::Print(Option_t *) const { | |
bd58d4b9 | 132 | TIter centIter(fEntries); |
133 | AliTRDPIDCentrality *cent; | |
134 | while((cent = dynamic_cast<AliTRDPIDCentrality *>(centIter()))) cent->Print(NULL); | |
ce487a7f | 135 | } |
136 | ||
137 | //____________________________________________________________ | |
138 | AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(): | |
139 | TObject(), | |
140 | fNTracklets(0) | |
141 | { | |
142 | // | |
143 | // Default constructor | |
144 | // | |
145 | memset(fParams, 0, sizeof(Double_t) * 4); | |
146 | memset(fEfficiency, 0, sizeof(Double_t) * 2); | |
147 | } | |
148 | ||
149 | //____________________________________________________________ | |
150 | AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) : | |
151 | TObject(), | |
152 | fNTracklets(nTracklets) | |
153 | { | |
154 | // | |
155 | // Default Constructor | |
156 | // | |
157 | fEfficiency[0] = effMin; | |
158 | fEfficiency[1] = effMax; | |
159 | if(params) memcpy(fParams, params, sizeof(Double_t) * 4); | |
160 | else memset(fParams, 0, sizeof(Double_t) * 4); | |
161 | } | |
162 | ||
163 | //____________________________________________________________ | |
164 | AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) : | |
165 | TObject(), | |
166 | fNTracklets(nTracklets) | |
167 | { | |
168 | // | |
169 | // Constructor used to find object in sorted list | |
170 | // | |
171 | fEfficiency[0] = fEfficiency[1] = eff; | |
172 | if(params) memcpy(fParams, params, sizeof(Double_t) * 4); | |
173 | else memset(fParams, 0, sizeof(Double_t) * 4); | |
174 | } | |
175 | ||
176 | //____________________________________________________________ | |
177 | AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) : | |
178 | TObject(ref), | |
179 | fNTracklets(ref.fNTracklets) | |
180 | { | |
181 | // | |
182 | // Copy constructor | |
183 | // | |
184 | memcpy(fParams, ref.fParams, sizeof(Double_t) * 4); | |
185 | memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2); | |
186 | } | |
187 | ||
188 | //____________________________________________________________ | |
189 | AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){ | |
190 | // | |
191 | // Assignment operator | |
192 | // | |
e99fb5c9 | 193 | if(&ref == this) return *this; |
194 | ||
ce487a7f | 195 | TObject::operator=(ref); |
196 | ||
197 | fNTracklets = ref.fNTracklets; | |
198 | memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2); | |
199 | memcpy(fParams, ref.fParams, sizeof(Double_t) * 4); | |
200 | return *this; | |
201 | } | |
202 | ||
203 | //____________________________________________________________ | |
204 | Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{ | |
205 | // | |
206 | // Compares two objects | |
207 | // Order: | |
208 | // First compare number of tracklets, if they are equal compare electron efficiency | |
209 | // | |
210 | const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref); | |
211 | if(fNTracklets < refObj->GetNTracklets()) return -1; | |
212 | else if(fNTracklets > refObj->GetNTracklets()) return 1; | |
213 | else{ | |
214 | if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1; | |
215 | else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1; | |
216 | else return 0; | |
217 | } | |
218 | } | |
219 | ||
220 | //____________________________________________________________ | |
221 | Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const { | |
222 | // | |
223 | // Check for equality | |
224 | // Tracklets and Efficiency are used | |
225 | // | |
226 | const AliTRDPIDThresholds *refObj = dynamic_cast<const AliTRDPIDThresholds *>(ref); | |
227 | if(!refObj) return kFALSE; | |
228 | Bool_t eqNTracklets = fNTracklets == refObj->GetNTracklets(); | |
229 | Bool_t eqEff = kFALSE; | |
230 | Bool_t hasRange = TMath::Abs(fEfficiency[1] - fEfficiency[0]) > kVerySmall; | |
231 | Bool_t hasRangeRef = TMath::Abs(refObj->GetElectronEfficiency(1) - refObj->GetElectronEfficiency(0)) > kVerySmall; | |
232 | if(hasRange && hasRangeRef){ | |
233 | // Both have ranges, check if they match | |
234 | eqEff = TMath::Abs(fEfficiency[0] - refObj->GetElectronEfficiency(0)) < kVerySmall && TMath::Abs(fEfficiency[1] - refObj->GetElectronEfficiency(1)) < kVerySmall; | |
235 | } else if(hasRange){ | |
236 | // this object has ranges, check if the efficiency of ref is inside the range | |
237 | eqEff = refObj->GetElectronEfficiency(0) >= fEfficiency[0] && refObj->GetElectronEfficiency(0) < fEfficiency[1]; | |
238 | } else { | |
239 | // ref has ranges, check if this is in range | |
240 | eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1); | |
241 | } | |
242 | ||
243 | return eqNTracklets && eqEff; | |
244 | } | |
bd58d4b9 | 245 | |
246 | //____________________________________________________________ | |
247 | AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(): | |
248 | fEntries(NULL), | |
249 | fMinCentrality(-1.), | |
250 | fMaxCentrality(-1.) | |
251 | { | |
252 | // | |
253 | // Dummy constructor | |
254 | // | |
255 | } | |
256 | ||
257 | //____________________________________________________________ | |
258 | AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(Double_t minCentrality, Double_t maxCentrality): | |
259 | fEntries(NULL), | |
260 | fMinCentrality(minCentrality), | |
261 | fMaxCentrality(maxCentrality) | |
262 | { | |
263 | // | |
264 | // Default constructor | |
265 | // | |
266 | fEntries = new TSortedList; | |
267 | fEntries->SetOwner(); | |
268 | } | |
269 | ||
270 | //____________________________________________________________ | |
271 | AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(const AliTRDPIDParams::AliTRDPIDCentrality &ref): | |
272 | TObject(), | |
273 | fEntries(NULL), | |
274 | fMinCentrality(ref.fMinCentrality), | |
275 | fMaxCentrality(ref.fMaxCentrality) | |
276 | { | |
277 | // | |
278 | // Copy constructor | |
279 | // | |
280 | fEntries = new TSortedList; | |
281 | // Coply entries to the new list | |
282 | TIter entries(ref.fEntries); | |
283 | TObject *o; | |
284 | while((o = entries())) fEntries->Add(o); | |
285 | } | |
286 | ||
287 | //____________________________________________________________ | |
288 | AliTRDPIDParams::AliTRDPIDCentrality &AliTRDPIDParams::AliTRDPIDCentrality::operator=(const AliTRDPIDCentrality &ref){ | |
289 | // | |
290 | // Assignment operator | |
291 | // | |
292 | if(&ref != this){ | |
293 | if(fEntries) delete fEntries; | |
294 | fEntries = new TSortedList; | |
295 | TIter entries(ref.fEntries); | |
296 | TObject *o; | |
297 | while((o = entries())) fEntries->Add(o); | |
298 | fMinCentrality = ref.fMinCentrality; | |
299 | fMaxCentrality = ref.fMaxCentrality; | |
300 | } | |
301 | return *this; | |
302 | } | |
303 | ||
304 | //____________________________________________________________ | |
305 | AliTRDPIDParams::AliTRDPIDCentrality::~AliTRDPIDCentrality(){ | |
306 | // | |
307 | // Destructor | |
308 | // | |
309 | if(fEntries) delete fEntries; | |
310 | } | |
311 | ||
312 | //____________________________________________________________ | |
313 | Bool_t AliTRDPIDParams::AliTRDPIDCentrality::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{ | |
314 | // | |
315 | // Get the threshold parameters | |
316 | // | |
317 | AliTRDPIDThresholds test(ntracklets, efficiency); | |
318 | TObject *result = fEntries->FindObject(&test); | |
319 | if(!result){ | |
320 | AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency)); | |
321 | return kFALSE; | |
322 | } | |
323 | AliTRDPIDThresholds *parResult = static_cast<AliTRDPIDThresholds *>(result); | |
324 | AliDebug(1, Form("Threshold params found: NTracklets %d, Electron Efficiency %f", parResult->GetNTracklets(), parResult->GetElectronEfficiency())); | |
325 | memcpy(params, parResult->GetThresholdParams(), sizeof(Double_t) * 4); | |
326 | return kTRUE; | |
327 | } | |
328 | ||
329 | //____________________________________________________________ | |
330 | void AliTRDPIDParams::AliTRDPIDCentrality::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){ | |
331 | // | |
332 | // Store new Params in the Object | |
333 | // | |
334 | if(effMin > effMax){ | |
335 | AliError("Min. efficiency has to be >= max. efficiency"); | |
336 | return; | |
337 | } | |
338 | AliDebug(1, Form("Save Parameters for %d tracklets at and electron efficiency of [%f|%f]", ntracklets, effMin, effMax)); | |
339 | fEntries->Add(new AliTRDPIDThresholds(ntracklets, effMin, effMax, params)); | |
340 | } | |
341 | ||
342 | //____________________________________________________________ | |
343 | void AliTRDPIDParams::AliTRDPIDCentrality::Print(Option_t *) const { | |
344 | printf("Min. Centrality: %f, Max. Centrality: %f\n", fMinCentrality, fMaxCentrality); | |
345 | printf("Available thresholds:\n"); | |
346 | printf("_________________________________________\n"); | |
347 | TIter objects(fEntries); | |
348 | AliTRDPIDThresholds *par; | |
349 | while((par = dynamic_cast<AliTRDPIDThresholds *>(objects()))){ | |
350 | printf("Number of tracklets %d, Electron efficiency %f\n", par->GetNTracklets(), 0.5*(par->GetElectronEfficiency(0)+par->GetElectronEfficiency(1))); | |
351 | } | |
352 | } | |
353 |