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