1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 // Container for TRD Threshold parameters stored in the OADB
18 // Author: Markus Fasel <M.Fasel@gsi.de>
22 #include <TSortedList.h>
26 #include "AliTRDPIDParams.h"
28 ClassImp(AliTRDPIDParams)
29 //ClassImp(AliTRDPIDParams::AliTRDPIDThresholds)
30 //ClassImp(AliTRDPIDParams::AliTRDPIDCentrality)
32 const Double_t AliTRDPIDParams::kVerySmall = 1e-5;
34 //____________________________________________________________
35 AliTRDPIDParams::AliTRDPIDParams():
44 //____________________________________________________________
45 AliTRDPIDParams::AliTRDPIDParams(const char *name) :
50 // Default constructor
55 //____________________________________________________________
56 AliTRDPIDParams::AliTRDPIDParams(const AliTRDPIDParams &ref):
64 fEntries=(TList*)ref.fEntries->Clone();
67 //____________________________________________________________
68 AliTRDPIDParams::~AliTRDPIDParams(){
75 //____________________________________________________________
76 void AliTRDPIDParams::AddCentralityClass(Double_t minCentrality, Double_t maxCentrality){
78 // Add new centrality class
81 // check whether centrality class already exists
82 AliTRDPIDCentrality *checklow = FindCentrality(minCentrality + 0.01),
83 *checkhigh = FindCentrality(maxCentrality - 0.01);
85 if(!checklow && ! checkhigh)
86 fEntries->Add(new AliTRDPIDCentrality(minCentrality, maxCentrality));
89 //____________________________________________________________
90 AliTRDPIDParams::AliTRDPIDCentrality *AliTRDPIDParams::FindCentrality(Double_t val) const {
92 // Find centrality bin
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()){
105 //____________________________________________________________
106 Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params, Double_t centrality) const{
109 // Use IsEqual definition
111 AliTRDPIDCentrality *cent = FindCentrality(centrality);
112 if(!cent)cent = FindCentrality(-1);// try default class
114 AliDebug(1, "Centrality class not available");
118 cent->GetThresholdParameters(ntracklets, efficiency, params);
122 //____________________________________________________________
123 void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params, Double_t centrality){
125 // Set new threshold parameters
127 AliTRDPIDCentrality *cent = FindCentrality(centrality);
128 if(cent) cent->SetThresholdParameters(ntracklets, effMin, effMax, params);
129 else AliDebug(1, "Centrality class not available");
132 //____________________________________________________________
133 void AliTRDPIDParams::Print(Option_t *) const {
134 TIter centIter(fEntries);
135 AliTRDPIDCentrality *cent;
136 while((cent = dynamic_cast<AliTRDPIDCentrality *>(centIter()))) cent->Print(NULL);
139 //____________________________________________________________
140 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds():
145 // Default constructor
147 memset(fParams, 0, sizeof(Double_t) * 4);
148 memset(fEfficiency, 0, sizeof(Double_t) * 2);
151 //____________________________________________________________
152 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) :
154 fNTracklets(nTracklets)
157 // Default Constructor
159 fEfficiency[0] = effMin;
160 fEfficiency[1] = effMax;
161 if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
162 else memset(fParams, 0, sizeof(Double_t) * 4);
165 //____________________________________________________________
166 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) :
168 fNTracklets(nTracklets)
171 // Constructor used to find object in sorted list
173 fEfficiency[0] = fEfficiency[1] = eff;
174 if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
175 else memset(fParams, 0, sizeof(Double_t) * 4);
178 //____________________________________________________________
179 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) :
181 fNTracklets(ref.fNTracklets)
186 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
187 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
190 //____________________________________________________________
191 AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){
193 // Assignment operator
195 if(&ref == this) return *this;
197 TObject::operator=(ref);
199 fNTracklets = ref.fNTracklets;
200 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
201 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
205 //____________________________________________________________
206 Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{
208 // Compares two objects
210 // First compare number of tracklets, if they are equal compare electron efficiency
212 const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref);
213 if(fNTracklets < refObj->GetNTracklets()) return -1;
214 else if(fNTracklets > refObj->GetNTracklets()) return 1;
216 if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1;
217 else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1;
222 //____________________________________________________________
223 Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const {
225 // Check for equality
226 // Tracklets and Efficiency are used
228 const AliTRDPIDThresholds *refObj = dynamic_cast<const AliTRDPIDThresholds *>(ref);
229 if(!refObj) return kFALSE;
230 Bool_t eqNTracklets = fNTracklets == refObj->GetNTracklets();
231 Bool_t eqEff = kFALSE;
232 Bool_t hasRange = TMath::Abs(fEfficiency[1] - fEfficiency[0]) > kVerySmall;
233 Bool_t hasRangeRef = TMath::Abs(refObj->GetElectronEfficiency(1) - refObj->GetElectronEfficiency(0)) > kVerySmall;
234 if(hasRange && hasRangeRef){
235 // Both have ranges, check if they match
236 eqEff = TMath::Abs(fEfficiency[0] - refObj->GetElectronEfficiency(0)) < kVerySmall && TMath::Abs(fEfficiency[1] - refObj->GetElectronEfficiency(1)) < kVerySmall;
238 // this object has ranges, check if the efficiency of ref is inside the range
239 eqEff = refObj->GetElectronEfficiency(0) >= fEfficiency[0] && refObj->GetElectronEfficiency(0) < fEfficiency[1];
241 // ref has ranges, check if this is in range
242 eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1);
245 return eqNTracklets && eqEff;
248 //____________________________________________________________
249 AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality():
259 //____________________________________________________________
260 AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(Double_t minCentrality, Double_t maxCentrality):
262 fMinCentrality(minCentrality),
263 fMaxCentrality(maxCentrality)
266 // Default constructor
268 fEntries = new TSortedList;
269 fEntries->SetOwner();
272 //____________________________________________________________
273 AliTRDPIDParams::AliTRDPIDCentrality::AliTRDPIDCentrality(const AliTRDPIDParams::AliTRDPIDCentrality &ref):
276 fMinCentrality(ref.fMinCentrality),
277 fMaxCentrality(ref.fMaxCentrality)
282 fEntries = new TSortedList;
283 // Coply entries to the new list
284 TIter entries(ref.fEntries);
286 while((o = entries())) fEntries->Add(o);
289 //____________________________________________________________
290 AliTRDPIDParams::AliTRDPIDCentrality &AliTRDPIDParams::AliTRDPIDCentrality::operator=(const AliTRDPIDCentrality &ref){
292 // Assignment operator
295 if(fEntries) delete fEntries;
296 fEntries = new TSortedList;
297 TIter entries(ref.fEntries);
299 while((o = entries())) fEntries->Add(o);
300 fMinCentrality = ref.fMinCentrality;
301 fMaxCentrality = ref.fMaxCentrality;
306 //____________________________________________________________
307 AliTRDPIDParams::AliTRDPIDCentrality::~AliTRDPIDCentrality(){
311 if(fEntries) delete fEntries;
314 //____________________________________________________________
315 Bool_t AliTRDPIDParams::AliTRDPIDCentrality::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{
317 // Get the threshold parameters
319 AliTRDPIDThresholds test(ntracklets, efficiency);
320 TObject *result = fEntries->FindObject(&test);
322 AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
325 AliTRDPIDThresholds *parResult = static_cast<AliTRDPIDThresholds *>(result);
326 AliDebug(1, Form("Threshold params found: NTracklets %d, Electron Efficiency %f", parResult->GetNTracklets(), parResult->GetElectronEfficiency()));
327 memcpy(params, parResult->GetThresholdParams(), sizeof(Double_t) * 4);
331 //____________________________________________________________
332 void AliTRDPIDParams::AliTRDPIDCentrality::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){
334 // Store new Params in the Object
337 AliError("Min. efficiency has to be >= max. efficiency");
340 AliDebug(1, Form("Save Parameters for %d tracklets at and electron efficiency of [%f|%f]", ntracklets, effMin, effMax));
341 fEntries->Add(new AliTRDPIDThresholds(ntracklets, effMin, effMax, params));
344 //____________________________________________________________
345 void AliTRDPIDParams::AliTRDPIDCentrality::Print(Option_t *) const {
346 printf("Min. Centrality: %f, Max. Centrality: %f\n", fMinCentrality, fMaxCentrality);
347 printf("Available thresholds:\n");
348 printf("_________________________________________\n");
349 TIter objects(fEntries);
350 AliTRDPIDThresholds *par;
351 while((par = dynamic_cast<AliTRDPIDThresholds *>(objects()))){
352 printf("Number of tracklets %d, Electron efficiency %f\n", par->GetNTracklets(), 0.5*(par->GetElectronEfficiency(0)+par->GetElectronEfficiency(1)));