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(){
72 //____________________________________________________________
73 Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{
76 // Use IsEqual definition
78 AliTRDPIDThresholds test(ntracklets, efficiency);
79 TObject *result = fEntries->FindObject(&test);
81 AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
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);
90 //____________________________________________________________
91 void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){
93 // Store new Params in the Object
96 AliError("Min. efficiency has to be >= max. efficiency");
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));
103 //____________________________________________________________
104 void 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());
114 //____________________________________________________________
115 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds():
120 // Default constructor
122 memset(fParams, 0, sizeof(Double_t) * 4);
123 memset(fEfficiency, 0, sizeof(Double_t) * 2);
126 //____________________________________________________________
127 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) :
129 fNTracklets(nTracklets)
132 // Default Constructor
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);
140 //____________________________________________________________
141 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) :
143 fNTracklets(nTracklets)
146 // Constructor used to find object in sorted list
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);
153 //____________________________________________________________
154 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) :
156 fNTracklets(ref.fNTracklets)
161 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
162 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
165 //____________________________________________________________
166 AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){
168 // Assignment operator
170 if(&ref == this) return *this;
172 TObject::operator=(ref);
174 fNTracklets = ref.fNTracklets;
175 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
176 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
180 //____________________________________________________________
181 Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{
183 // Compares two objects
185 // First compare number of tracklets, if they are equal compare electron efficiency
187 const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref);
188 if(fNTracklets < refObj->GetNTracklets()) return -1;
189 else if(fNTracklets > refObj->GetNTracklets()) return 1;
191 if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1;
192 else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1;
197 //____________________________________________________________
198 Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const {
200 // Check for equality
201 // Tracklets and Efficiency are used
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;
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];
216 // ref has ranges, check if this is in range
217 eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1);
220 return eqNTracklets && eqEff;