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(){
60 //____________________________________________________________
61 Bool_t AliTRDPIDParams::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params) const{
64 // Use IsEqual definition
66 AliTRDPIDThresholds test(ntracklets, efficiency);
67 TObject *result = fEntries->FindObject(&test);
69 AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
72 AliTRDPIDThresholds *parResult = static_cast<AliTRDPIDThresholds *>(result);
73 AliDebug(1, Form("Threshold params found: NTracklets %d, Electron Efficiency %f", parResult->GetNTracklets(), parResult->GetElectronEfficiency()));
74 memcpy(params, parResult->GetThresholdParams(), sizeof(Double_t) * 4);
78 //____________________________________________________________
79 void AliTRDPIDParams::SetThresholdParameters(Int_t ntracklets, Double_t effMin, Double_t effMax, Double_t *params){
81 // Store new Params in the Object
84 AliError("Min. efficiency has to be >= max. efficiency");
87 AliDebug(1, Form("Save Parameters for %d tracklets at and electron efficiency of [%f|%f]", ntracklets, effMin, effMax));
88 fEntries->Add(new AliTRDPIDThresholds(ntracklets, effMin, effMax, params));
91 //____________________________________________________________
92 void AliTRDPIDParams::Print(Option_t *) const {
93 printf("Available thresholds:\n");
94 printf("_________________________________________\n");
95 TIter objects(fEntries);
96 AliTRDPIDThresholds *par;
97 while((par = dynamic_cast<AliTRDPIDThresholds *>(objects()))){
98 printf("Number of tracklets %d, Electron efficiency %f\n", par->GetNTracklets(), par->GetElectronEfficiency());
102 //____________________________________________________________
103 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds():
108 // Default constructor
110 memset(fParams, 0, sizeof(Double_t) * 4);
111 memset(fEfficiency, 0, sizeof(Double_t) * 2);
114 //____________________________________________________________
115 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t effMin, Double_t effMax, Double_t *params) :
117 fNTracklets(nTracklets)
120 // Default Constructor
122 fEfficiency[0] = effMin;
123 fEfficiency[1] = effMax;
124 if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
125 else memset(fParams, 0, sizeof(Double_t) * 4);
128 //____________________________________________________________
129 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(Int_t nTracklets, Double_t eff, Double_t *params) :
131 fNTracklets(nTracklets)
134 // Constructor used to find object in sorted list
136 fEfficiency[0] = fEfficiency[1] = eff;
137 if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
138 else memset(fParams, 0, sizeof(Double_t) * 4);
141 //____________________________________________________________
142 AliTRDPIDParams::AliTRDPIDThresholds::AliTRDPIDThresholds(const AliTRDPIDThresholds &ref) :
144 fNTracklets(ref.fNTracklets)
149 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
150 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
153 //____________________________________________________________
154 AliTRDPIDParams::AliTRDPIDThresholds &AliTRDPIDParams::AliTRDPIDThresholds::operator=(const AliTRDPIDThresholds &ref){
156 // Assignment operator
158 if(&ref == this) return *this;
160 TObject::operator=(ref);
162 fNTracklets = ref.fNTracklets;
163 memcpy(fEfficiency, ref.fEfficiency, sizeof(Double_t) * 2);
164 memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
168 //____________________________________________________________
169 Int_t AliTRDPIDParams::AliTRDPIDThresholds::Compare(const TObject *ref) const{
171 // Compares two objects
173 // First compare number of tracklets, if they are equal compare electron efficiency
175 const AliTRDPIDThresholds *refObj = static_cast<const AliTRDPIDThresholds *>(ref);
176 if(fNTracklets < refObj->GetNTracklets()) return -1;
177 else if(fNTracklets > refObj->GetNTracklets()) return 1;
179 if(fEfficiency[1] < refObj->GetElectronEfficiency(0)) return -1;
180 else if(fEfficiency[0] > refObj->GetElectronEfficiency(1)) return 1;
185 //____________________________________________________________
186 Bool_t AliTRDPIDParams::AliTRDPIDThresholds::IsEqual(const TObject *ref) const {
188 // Check for equality
189 // Tracklets and Efficiency are used
191 const AliTRDPIDThresholds *refObj = dynamic_cast<const AliTRDPIDThresholds *>(ref);
192 if(!refObj) return kFALSE;
193 Bool_t eqNTracklets = fNTracklets == refObj->GetNTracklets();
194 Bool_t eqEff = kFALSE;
195 Bool_t hasRange = TMath::Abs(fEfficiency[1] - fEfficiency[0]) > kVerySmall;
196 Bool_t hasRangeRef = TMath::Abs(refObj->GetElectronEfficiency(1) - refObj->GetElectronEfficiency(0)) > kVerySmall;
197 if(hasRange && hasRangeRef){
198 // Both have ranges, check if they match
199 eqEff = TMath::Abs(fEfficiency[0] - refObj->GetElectronEfficiency(0)) < kVerySmall && TMath::Abs(fEfficiency[1] - refObj->GetElectronEfficiency(1)) < kVerySmall;
201 // this object has ranges, check if the efficiency of ref is inside the range
202 eqEff = refObj->GetElectronEfficiency(0) >= fEfficiency[0] && refObj->GetElectronEfficiency(0) < fEfficiency[1];
204 // ref has ranges, check if this is in range
205 eqEff = fEfficiency[0] >= refObj->GetElectronEfficiency(0) && fEfficiency[0] < refObj->GetElectronEfficiency(1);
208 return eqNTracklets && eqEff;