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>
21 #include <TSortedList.h>
25 #include "AliTRDPIDParams.h"
27 ClassImp(AliTRDPIDParams)
29 const Double_t AliTRDPIDParams::kVerySmall = 1e-5;
31 //____________________________________________________________
32 AliTRDPIDParams::AliTRDPIDParams():
41 //____________________________________________________________
42 AliTRDPIDParams::AliTRDPIDParams(const char *name) :
47 // Default constructor
49 fEntries = new TSortedList;
52 //____________________________________________________________
53 AliTRDPIDParams::AliTRDPIDParams(const AliTRDPIDParams &ref):
61 fEntries=(TSortedList*)ref.fEntries->Clone();
64 //____________________________________________________________
65 AliTRDPIDParams::AliTRDPIDParams(const AliTRDPIDParams &ref):
73 fEntries=(TSortedList*)ref.fEntries->Clone();
76 //____________________________________________________________
77 AliTRDPIDParams::~AliTRDPIDParams(){
84 //____________________________________________________________
85 Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{
88 // Use IsEqual definition
90 AliTRDPIDThresholds test(ntracklets, efficiency);
91 TObject *result = fEntries->FindObject(&test);
93 AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
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);
102 //____________________________________________________________
103 void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){
105 // Store new Params in the Object
108 AliError("Min. efficiency has to be >= max. efficiency");
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));
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());
126 //____________________________________________________________
127 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds():
132 // Default constructor
134 memset(fParams, 0, sizeof(Double_t) * 4);
135 memset(fEfficiency, 0, sizeof(Double_t) * 2);
138 //____________________________________________________________
139 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) :
141 fNTracklets(nTracklets)
144 // Default Constructor
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);
152 //____________________________________________________________
153 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) :
155 fNTracklets(nTracklets)
158 // Constructor used to find object in sorted list
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);
165 //____________________________________________________________
166 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) :
168 fNTracklets(ref.fNTracklets)
173 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
174 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
177 //____________________________________________________________
178 AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){
180 // Assignment operator
182 if(&ref == this) return *this;
184 TObject::operator=(ref);
186 fNTracklets = ref.fNTracklets;
187 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
188 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
192 //____________________________________________________________
193 Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{
195 // Compares two objects
197 // First compare number of tracklets, if they are equal compare electron efficiency
199 const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref);
200 if(fNTracklets < refObj->GetNTracklets()) return -1;
201 else if(fNTracklets > refObj->GetNTracklets()) return 1;
203 if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1;
204 else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1;
209 //____________________________________________________________
210 Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const {
212 // Check for equality
213 // Tracklets and Efficiency are used
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;
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];
228 // ref has ranges, check if this is in range
229 eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1);
232 return eqNTracklets && eqEff;