]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEERBase/AliTRDPIDParams.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliTRDPIDParams.cxx
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 //
20 #include <TList.h>
21 #include <TMath.h>
22 #include <TSortedList.h>
23
24 #include "AliLog.h"
25
26 #include "AliTRDPIDParams.h"
27
28 ClassImp(AliTRDPIDParams)
29 //ClassImp(AliTRDPIDParams::AliTRDPIDThresholds)
30 //ClassImp(AliTRDPIDParams::AliTRDPIDCentrality)
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   //
52   fEntries = new TList;
53 }
54
55 //____________________________________________________________
56 AliTRDPIDParams::AliTRDPIDParams(const AliTRDPIDParams &ref):
57 TNamed(ref),
58 fEntries(NULL)
59 {
60     //
61     // Copy constructor
62     //
63
64     fEntries=(TList*)ref.fEntries->Clone();
65 }
66
67 //____________________________________________________________
68 AliTRDPIDParams::~AliTRDPIDParams(){
69   //
70   // Destructor
71   //
72   delete fEntries;
73 }
74
75 //____________________________________________________________
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   if(!tmp){
103       AliDebug(10,"Using default centrality class");
104       return FindCentrality(-1);
105   }
106   return tmp;
107 }
108
109 //____________________________________________________________
110 Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params, Double_t centrality) const{
111   //
112   // Retrieve params
113   // Use IsEqual definition
114   //
115   AliTRDPIDCentrality *cent = FindCentrality(centrality);
116   if(!cent){
117     AliDebug(1, "Centrality class not available");
118     return kFALSE;
119   }
120   cent->GetThresholdParameters(ntracklets, efficiency, params);
121   return kTRUE;
122 }
123
124 //____________________________________________________________
125 void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params, Double_t centrality){
126   //
127   // Set new threshold parameters
128   //
129   AliTRDPIDCentrality *cent = FindCentrality(centrality);
130   if(cent) cent->SetThresholdParameters(ntracklets, effMin, effMax, params);
131   else AliDebug(1, "Centrality class not available");
132 }
133
134 //____________________________________________________________
135 void AliTRDPIDParams::Print(Option_t *) const {
136   TIter centIter(fEntries);
137   AliTRDPIDCentrality *cent;
138   while((cent = dynamic_cast<AliTRDPIDCentrality *>(centIter()))) cent->Print(NULL);
139 }
140
141 //____________________________________________________________
142 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds():
143   TObject(),
144   fNTracklets(0)
145 {
146    // 
147    // Default constructor
148    //
149    memset(fParams, 0, sizeof(Double_t) * 4);
150    memset(fEfficiency, 0, sizeof(Double_t) * 2);
151 }
152
153 //____________________________________________________________
154 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) :
155   TObject(),
156   fNTracklets(nTracklets)
157 {
158   //
159   // Default Constructor 
160   //
161   fEfficiency[0] = effMin;
162   fEfficiency[1] = effMax;  
163   if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
164   else memset(fParams, 0, sizeof(Double_t) * 4);
165 }
166
167 //____________________________________________________________
168 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) :
169   TObject(),
170   fNTracklets(nTracklets)
171 {
172   //
173   // Constructor used to find object in sorted list
174   //
175   fEfficiency[0] = fEfficiency[1] = eff;  
176   if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
177   else memset(fParams, 0, sizeof(Double_t) * 4);
178 }
179
180 //____________________________________________________________
181 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) :
182   TObject(ref),
183   fNTracklets(ref.fNTracklets)
184 {
185   //
186   // Copy constructor
187   //
188   memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
189   memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
190 }
191
192 //____________________________________________________________
193 AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){
194   //
195   // Assignment operator
196   //
197   if(&ref == this) return *this;
198
199   TObject::operator=(ref);
200
201   fNTracklets = ref.fNTracklets;
202   memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
203   memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
204   return *this;
205 }
206         
207 //____________________________________________________________
208 Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{
209   //
210   // Compares two objects
211   // Order:
212   //   First compare number of tracklets, if they are equal compare electron efficiency
213   //
214   const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref);
215   if(fNTracklets < refObj->GetNTracklets()) return -1;
216   else if(fNTracklets > refObj->GetNTracklets()) return 1;
217   else{
218     if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1;
219     else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1;
220     else return 0;
221   }
222 }
223
224 //____________________________________________________________
225 Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const {
226   //
227   // Check for equality 
228   // Tracklets and Efficiency are used
229   //
230   const AliTRDPIDThresholds *refObj = dynamic_cast<const AliTRDPIDThresholds *>(ref);
231   if(!refObj) return kFALSE;
232   Bool_t eqNTracklets = fNTracklets == refObj->GetNTracklets();
233   Bool_t eqEff = kFALSE;
234   Bool_t hasRange = TMath::Abs(fEfficiency[1] - fEfficiency[0]) > kVerySmall;
235   Bool_t hasRangeRef = TMath::Abs(refObj->GetElectronEfficiency(1) - refObj->GetElectronEfficiency(0)) > kVerySmall;
236   if(hasRange && hasRangeRef){
237     // Both have ranges, check if they match
238     eqEff = TMath::Abs(fEfficiency[0] - refObj->GetElectronEfficiency(0)) < kVerySmall && TMath::Abs(fEfficiency[1] - refObj->GetElectronEfficiency(1)) < kVerySmall;
239   } else if(hasRange){
240     // this object has ranges, check if the efficiency of ref is inside the range
241     eqEff = refObj->GetElectronEfficiency(0) >= fEfficiency[0] && refObj->GetElectronEfficiency(0) < fEfficiency[1];
242   } else {
243     // ref has ranges, check if this is in range
244     eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1);
245   }
246   
247   return  eqNTracklets && eqEff;
248 }
249
250 //____________________________________________________________
251 AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality():
252   fEntries(NULL),
253   fMinCentrality(-1.),
254   fMaxCentrality(-1.)
255 {
256   //
257   // Dummy constructor
258   //
259 }
260
261 //____________________________________________________________
262 AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(Double_t minCentrality, Double_t maxCentrality):
263   fEntries(NULL),
264   fMinCentrality(minCentrality),
265   fMaxCentrality(maxCentrality)
266 {
267   //
268   // Default constructor
269   //
270   fEntries = new TSortedList;
271   fEntries->SetOwner();
272 }
273
274 //____________________________________________________________
275 AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(const AliTRDPIDParams::AliTRDPIDCentrality &ref):
276 TObject(),
277 fEntries(NULL),
278   fMinCentrality(ref.fMinCentrality),
279   fMaxCentrality(ref.fMaxCentrality)
280 {
281   //
282   // Copy constructor
283   //
284   fEntries = new TSortedList;
285   // Coply entries to the new list
286   TIter entries(ref.fEntries);
287   TObject *o;
288   while((o = entries())) fEntries->Add(o);
289 }
290
291 //____________________________________________________________
292 AliTRDPIDParams::AliTRDPIDCentrality &AliTRDPIDParams::AliTRDPIDCentrality::operator=(const AliTRDPIDCentrality &ref){
293   //
294   // Assignment operator
295   //
296   if(&ref != this){
297     if(fEntries) delete fEntries;
298     fEntries = new TSortedList;
299     TIter entries(ref.fEntries);
300     TObject *o;
301     while((o = entries())) fEntries->Add(o);
302     fMinCentrality = ref.fMinCentrality;
303     fMaxCentrality = ref.fMaxCentrality;
304   }
305   return *this;
306 }
307
308 //____________________________________________________________
309 AliTRDPIDParams::AliTRDPIDCentrality::~AliTRDPIDCentrality(){
310   //
311   // Destructor
312   //
313   if(fEntries) delete fEntries;
314 }
315
316 //____________________________________________________________
317 Bool_t AliTRDPIDParams::AliTRDPIDCentrality::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{
318   // 
319   // Get the threshold parameters
320   //
321   AliTRDPIDThresholds test(ntracklets, efficiency);
322   TObject *result = fEntries->FindObject(&test);
323   if(!result){ 
324     AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
325     return kFALSE;
326   }
327   AliTRDPIDThresholds *parResult = static_cast<AliTRDPIDThresholds *>(result);
328   AliDebug(1, Form("Threshold params found: NTracklets %d, Electron Efficiency %f", parResult->GetNTracklets(), parResult->GetElectronEfficiency()));
329   memcpy(params, parResult->GetThresholdParams(), sizeof(Double_t) * 4);
330   return kTRUE;
331 }
332
333 //____________________________________________________________
334 void AliTRDPIDParams::AliTRDPIDCentrality::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){
335   // 
336   // Store new Params in the Object
337   //
338   if(effMin > effMax){
339     AliError("Min. efficiency has to be >= max. efficiency");
340     return;
341   }
342   AliDebug(1, Form("Save Parameters for %d tracklets at and electron efficiency of [%f|%f]", ntracklets, effMin, effMax));
343   fEntries->Add(new AliTRDPIDThresholds(ntracklets, effMin, effMax, params));
344 }
345
346 //____________________________________________________________
347 void AliTRDPIDParams::AliTRDPIDCentrality::Print(Option_t *) const {
348   printf("Min. Centrality: %f, Max. Centrality: %f\n", fMinCentrality, fMaxCentrality);
349   printf("Available thresholds:\n");
350   printf("_________________________________________\n");
351   TIter objects(fEntries);
352   AliTRDPIDThresholds *par;
353   while((par = dynamic_cast<AliTRDPIDThresholds *>(objects()))){
354     printf("Number of tracklets %d, Electron efficiency %f\n", par->GetNTracklets(), 0.5*(par->GetElectronEfficiency(0)+par->GetElectronEfficiency(1)));
355   }
356 }
357