]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/hfe/AliHFEOADBThresholdsTRD.cxx
Cannot wait for the fix -- better do it myself
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEOADBThresholdsTRD.cxx
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 "AliHFEOADBThresholdsTRD.h"
26
27 ClassImp(AliHFEOADBThresholdsTRD)
28
29 const Double_t AliHFEOADBThresholdsTRD::fgkVerySmall = 1e-5;
30
31 //____________________________________________________________
32 AliHFEOADBThresholdsTRD::AliHFEOADBThresholdsTRD():
33   TNamed(),
34   fEntries(NULL)
35 {
36   //
37   // Dummy constructor
38   //
39 }
40
41 //____________________________________________________________
42 AliHFEOADBThresholdsTRD::AliHFEOADBThresholdsTRD(const char *name) :
43   TNamed(name, ""),
44   fEntries(NULL)
45 {
46   //
47   // Default constructor
48   //
49   fEntries = new TSortedList;
50 }
51
52 //____________________________________________________________
53 AliHFEOADBThresholdsTRD::~AliHFEOADBThresholdsTRD(){
54   //
55   // Destructor
56   //
57   delete fEntries;
58 }
59
60 //____________________________________________________________
61 Bool_t AliHFEOADBThresholdsTRD::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params){
62   //
63   // Retrieve params
64   // Use IsEqual definition
65   //
66   AliHFEthresholdParamsTRD test(ntracklets, efficiency);
67   TObject *result = fEntries->FindObject(&test);
68   if(!result){ 
69     AliDebug(1, Form("No threshold params found for %d tracklets and an electron efficiency of %f", ntracklets, efficiency));
70     return kFALSE;
71   }
72   AliHFEthresholdParamsTRD *parResult = static_cast<AliHFEthresholdParamsTRD *>(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);
75   return kTRUE;
76 }
77
78 //____________________________________________________________
79 void AliHFEOADBThresholdsTRD::SetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params){
80   // 
81   // Store new Params in the Object
82   //
83   AliDebug(1, Form("Save Parameters for %d tracklets at and electron efficiency of %f", ntracklets, efficiency));
84   fEntries->Add(new AliHFEthresholdParamsTRD(ntracklets, efficiency, params));
85 }
86
87 //____________________________________________________________
88 void AliHFEOADBThresholdsTRD::Print(Option_t *) const {
89   //
90   // Print thresholds
91   //
92   printf("Available thresholds:\n");
93   printf("_________________________________________\n");
94   TIter objects(fEntries);
95   AliHFEthresholdParamsTRD *par;
96   while((par = dynamic_cast<AliHFEthresholdParamsTRD *>(objects()))){
97     printf("Number of tracklets %d, Electron efficiency %f\n", par->GetNTracklets(), par->GetElectronEfficiency());
98   }
99 }
100
101 //____________________________________________________________
102 AliHFEOADBThresholdsTRD::AliHFEthresholdParamsTRD::AliHFEthresholdParamsTRD():
103   TObject(),
104   fNTracklets(0),
105   fEfficiency(0.)
106 {
107    // 
108    // Default constructor
109    //
110    memset(fParams, 0, sizeof(Double_t) * 4);
111 }
112
113 //____________________________________________________________
114 AliHFEOADBThresholdsTRD::AliHFEthresholdParamsTRD::AliHFEthresholdParamsTRD(Int_t nTracklets, Double_t eff, Double_t *params) :
115   TObject(),
116   fNTracklets(nTracklets),
117   fEfficiency(eff)
118 {
119   //
120   // Default Constructor
121   //
122   if(params) memcpy(fParams, params, sizeof(Double_t) * 4);
123   else memset(fParams, 0, sizeof(Double_t) * 4);
124 }
125
126 //____________________________________________________________
127 AliHFEOADBThresholdsTRD::AliHFEthresholdParamsTRD::AliHFEthresholdParamsTRD(const AliHFEthresholdParamsTRD &ref) :
128   TObject(ref),
129   fNTracklets(ref.fNTracklets),
130   fEfficiency(ref.fEfficiency)
131 {
132   //
133   // Copy constructor
134   //
135   memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
136 }
137
138 //____________________________________________________________
139 AliHFEOADBThresholdsTRD::AliHFEthresholdParamsTRD &AliHFEOADBThresholdsTRD::AliHFEthresholdParamsTRD::operator=(const AliHFEthresholdParamsTRD &ref){
140   //
141   // Assignment operator
142   //
143   TObject::operator=(ref);
144
145   fNTracklets = ref.fNTracklets;
146   fEfficiency = ref.fEfficiency;
147   memcpy(fParams, ref.fParams, sizeof(Double_t) * 4);
148   return *this;
149 }
150         
151 //____________________________________________________________
152 Int_t AliHFEOADBThresholdsTRD::AliHFEthresholdParamsTRD::Compare(const TObject *ref) const{
153   //
154   // Compares two objects
155   // Order:
156   //   First compare number of tracklets, if they are equal compare electron efficiency
157   //
158   const AliHFEthresholdParamsTRD *refObj = static_cast<const AliHFEthresholdParamsTRD *>(ref);
159   if(fNTracklets < refObj->GetNTracklets()) return -1;
160   else if(fNTracklets > refObj->GetNTracklets()) return 1;
161   else{
162     if(fEfficiency < refObj->GetElectronEfficiency()) return -1;
163     else if(fEfficiency > refObj->GetElectronEfficiency()) return 1;
164     else return 0;
165   }
166 }
167
168 //____________________________________________________________
169 Bool_t AliHFEOADBThresholdsTRD::AliHFEthresholdParamsTRD::IsEqual(const TObject *ref) const {
170   //
171   // Check for equality 
172   // Tracklets and Efficiency are used
173   //
174   const AliHFEthresholdParamsTRD *refObj = dynamic_cast<const AliHFEthresholdParamsTRD *>(ref);
175   if(!refObj) return kFALSE;
176   return fNTracklets == refObj->GetNTracklets() && TMath::Abs(fEfficiency -  refObj->GetElectronEfficiency()) < fgkVerySmall;
177 }