]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/STEERBase/AliTRDPIDParams.cxx
Correction
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliTRDPIDParams.cxx
CommitLineData
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//
20#include <TMath.h>
21#include <TSortedList.h>
22
23#include "AliLog.h"
24
25#include "AliTRDPIDParams.h"
26
27ClassImp(AliTRDPIDParams)
28
29const Double_t AliTRDPIDParams::kVerySmall = 1e-5;
30
31//____________________________________________________________
32AliTRDPIDParams::AliTRDPIDParams():
33 TNamed(),
34 fEntries(NULL)
35{
36 //
37 // Dummy constructor
38 //
39}
40
41//____________________________________________________________
42AliTRDPIDParams::AliTRDPIDParams(const char *name) :
43 TNamed(name, ""),
44 fEntries(NULL)
45{
46 //
47 // Default constructor
48 //
49 fEntries = new TSortedList;
50}
51
db0e2c5f 52//____________________________________________________________
53AliTRDPIDParams::AliTRDPIDParams(const AliTRDPIDParams &ref):
54TNamed(ref),
55fEntries(NULL)
56{
57 //
58 // Copy constructor
59 //
60
61 fEntries=(TSortedList*)ref.fEntries->Clone();
62}
63
ce487a7f 64//____________________________________________________________
65AliTRDPIDParams::~AliTRDPIDParams(){
66 //
67 // Destructor
68 //
69 delete fEntries;
70}
71
72//____________________________________________________________
73Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{
74 //
75 // Retrieve params
76 // Use IsEqual definition
77 //
78 AliTRDPIDThresholds test(ntracklets, efficiency);
79 TObject *result = fEntries->FindObject(&test);
80 if(!result){
81 AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
82 return kFALSE;
83 }
84 AliTRDPIDThresholds *parResult = static_cast<AliTRDPIDThresholds *>(result);
85 AliDebug(1, Form("Threshold params found: NTracklets %d, Electron Efficiency %f", parResult->GetNTracklets(), parResult->GetElectronEfficiency()));
86 memcpy(params, parResult->GetThresholdParams(), sizeof(Double_t) * 4);
87 return kTRUE;
88}
89
90//____________________________________________________________
91void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){
92 //
93 // Store new Params in the Object
94 //
95 if(effMin > effMax){
96 AliError("Min. efficiency has to be >= max. efficiency");
97 return;
98 }
99 AliDebug(1, Form("Save Parameters for %d tracklets at and electron efficiency of [%f|%f]", ntracklets, effMin, effMax));
100 fEntries->Add(new AliTRDPIDThresholds(ntracklets, effMin, effMax, params));
101}
102
103//____________________________________________________________
104void AliTRDPIDParams::Print(Option_t *) const {
105 printf("Available thresholds:\n");
106 printf("_________________________________________\n");
107 TIter objects(fEntries);
108 AliTRDPIDThresholds *par;
109 while((par = dynamic_cast<AliTRDPIDThresholds *>(objects()))){
110 printf("Number of tracklets %d, Electron efficiency %f\n", par->GetNTracklets(), par->GetElectronEfficiency());
111 }
112}
113
114//____________________________________________________________
115AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds():
116 TObject(),
117 fNTracklets(0)
118{
119 //
120 // Default constructor
121 //
122 memset(fParams, 0, sizeof(Double_t) * 4);
123 memset(fEfficiency, 0, sizeof(Double_t) * 2);
124}
125
126//____________________________________________________________
127AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) :
128 TObject(),
129 fNTracklets(nTracklets)
130{
131 //
132 // Default Constructor
133 //
134 fEfficiency[0] = effMin;
135 fEfficiency[1] = effMax;
136 if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
137 else memset(fParams, 0, sizeof(Double_t) * 4);
138}
139
140//____________________________________________________________
141AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) :
142 TObject(),
143 fNTracklets(nTracklets)
144{
145 //
146 // Constructor used to find object in sorted list
147 //
148 fEfficiency[0] = fEfficiency[1] = eff;
149 if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
150 else memset(fParams, 0, sizeof(Double_t) * 4);
151}
152
153//____________________________________________________________
154AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) :
155 TObject(ref),
156 fNTracklets(ref.fNTracklets)
157{
158 //
159 // Copy constructor
160 //
161 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
162 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
163}
164
165//____________________________________________________________
166AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){
167 //
168 // Assignment operator
169 //
e99fb5c9 170 if(&ref == this) return *this;
171
ce487a7f 172 TObject::operator=(ref);
173
174 fNTracklets = ref.fNTracklets;
175 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
176 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
177 return *this;
178}
179
180//____________________________________________________________
181Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{
182 //
183 // Compares two objects
184 // Order:
185 // First compare number of tracklets, if they are equal compare electron efficiency
186 //
187 const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref);
188 if(fNTracklets < refObj->GetNTracklets()) return -1;
189 else if(fNTracklets > refObj->GetNTracklets()) return 1;
190 else{
191 if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1;
192 else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1;
193 else return 0;
194 }
195}
196
197//____________________________________________________________
198Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const {
199 //
200 // Check for equality
201 // Tracklets and Efficiency are used
202 //
203 const AliTRDPIDThresholds *refObj = dynamic_cast<const AliTRDPIDThresholds *>(ref);
204 if(!refObj) return kFALSE;
205 Bool_t eqNTracklets = fNTracklets == refObj->GetNTracklets();
206 Bool_t eqEff = kFALSE;
207 Bool_t hasRange = TMath::Abs(fEfficiency[1] - fEfficiency[0]) > kVerySmall;
208 Bool_t hasRangeRef = TMath::Abs(refObj->GetElectronEfficiency(1) - refObj->GetElectronEfficiency(0)) > kVerySmall;
209 if(hasRange && hasRangeRef){
210 // Both have ranges, check if they match
211 eqEff = TMath::Abs(fEfficiency[0] - refObj->GetElectronEfficiency(0)) < kVerySmall && TMath::Abs(fEfficiency[1] - refObj->GetElectronEfficiency(1)) < kVerySmall;
212 } else if(hasRange){
213 // this object has ranges, check if the efficiency of ref is inside the range
214 eqEff = refObj->GetElectronEfficiency(0) >= fEfficiency[0] && refObj->GetElectronEfficiency(0) < fEfficiency[1];
215 } else {
216 // ref has ranges, check if this is in range
217 eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1);
218 }
219
220 return eqNTracklets && eqEff;
221}