]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALCalibTimeDep.cxx
add profile for all samples and correct row numbering for EMCAL (Josh Hamblen/UT)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibTimeDep.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 /* $Id: AliEMCALCalibTimeDep.cxx $ */
17
18 //_________________________________________________________________________
19 ///*-- Author: 
20 ///////////////////////////////////////////////////////////////////////////////
21 //                                                                           //
22 // class for EMCAL time-dep calibration                                      //
23 //                                                                           //
24 ///////////////////////////////////////////////////////////////////////////////
25
26 #include <iostream>
27 #include <TGraphSmooth.h>
28 #include "AliLog.h"
29 #include "AliCDBEntry.h"
30 #include "AliCDBManager.h"
31 #include "AliEMCALSensorTempArray.h"
32 #include "AliEMCALCalibTimeDep.h"
33
34 /* first a bunch of constants.. */
35 const double fkSecToHour = 1.0/3600.0; // conversion factor from seconds to hours
36
37 // some global variables for APD handling; assume the same for all, at least to start with
38 const double fkTempSlope = 0.017; // 1.7% per deg. C, seems about right for all APDs, from studies at Catania, and by Rachid. 
39 // Note that this is only valid at gain M~30; i.e. voltages at V30. 
40 // At V50, it's more like 2.25%/C, and at V20 about 1.35%/C (also info from Catania)
41 const double fkNormTemp = 20; // let's say that 20 degrees C is normal as default
42
43 const double fkErrorCode = -999; // to indicate that something went wrong
44
45 using namespace std;
46
47 ClassImp(AliEMCALCalibTimeDep)
48
49 //________________________________________________________________
50 AliEMCALCalibTimeDep::AliEMCALCalibTimeDep() :
51   fRun(0),
52   fStartTime(0),
53   fEndTime(0),
54   fMinTemp(0),
55   fMaxTemp(0),
56   fMinTime(0),
57   fMaxTime(0),
58   fRefTemp(fkNormTemp), 
59   fTempArray(NULL)
60 {
61   // Constructor
62 }
63
64 //________________________________________________________________
65 AliEMCALCalibTimeDep::AliEMCALCalibTimeDep(const AliEMCALCalibTimeDep& calibt) :
66   TObject(calibt),
67   fRun(calibt.GetRunNumber()),
68   fStartTime(calibt.GetStartTime()),
69   fEndTime(calibt.GetEndTime()),
70   fMinTemp(calibt.GetMinTemp()),
71   fMaxTemp(calibt.GetMaxTemp()),
72   fMinTime(calibt.GetMinTime()),
73   fMaxTime(calibt.GetMaxTime()),
74   fRefTemp(calibt.GetRefTemp()),
75   fTempArray(calibt.GetTempArray())
76 {
77   // copy constructor
78 }
79
80
81 //________________________________________________________________
82 AliEMCALCalibTimeDep &AliEMCALCalibTimeDep::operator =(const AliEMCALCalibTimeDep& calibt)
83 {
84   // assignment operator; use copy ctor
85   if (&calibt == this) return *this;
86
87   new (this) AliEMCALCalibTimeDep(calibt);
88   return *this;
89 }
90
91 //________________________________________________________________
92 AliEMCALCalibTimeDep::~AliEMCALCalibTimeDep()
93 {
94   // Destructor
95 }
96
97 //________________________________________________________________
98 void  AliEMCALCalibTimeDep::Reset() 
99 {
100   // clear variables to default
101   fRun = 0;
102   fStartTime = 0;
103   fEndTime = 0;
104   fMinTemp = 0;
105   fMaxTemp = 0;
106   fMinTime = 0;
107   fMaxTime = 0;
108   fRefTemp = fkNormTemp;
109   fTempArray = NULL;
110   return;
111 }
112
113 //________________________________________________________________
114 void  AliEMCALCalibTimeDep::PrintInfo() const
115 {
116   // print some info
117   cout << endl << " AliEMCALCalibTimeDep::Print() " << endl;
118   // basic variables, all 'publicly available' also
119   cout << " VARIABLE DUMP: " << endl
120        << " GetStartTime() " << GetStartTime() << endl
121        << " GetEndTime() " << GetEndTime() << endl
122        << " GetMinTemp() " << GetMinTemp() << endl
123        << " GetMaxTemp() " << GetMaxTemp() << endl
124        << " GetRefTemp() " << GetRefTemp() << endl;
125   // run ranges
126   cout << " RUN INFO: " << endl
127        << " length (in hours) " << GetLengthOfRunInHours() << endl
128        << " range of temperature measurements (in hours) " << GetRangeOfTempMeasureInHours()
129        << " (in deg. C) " << GetRangeOfTempMeasureInDegrees()
130        << endl;
131   // range in correction values
132   double corrAtMinTemp = GetCorrection( fMinTemp );
133   double corrAtMaxTemp = GetCorrection( fMaxTemp );
134   double corrMaxMinDiff = 100*(corrAtMinTemp - corrAtMaxTemp);
135   cout << " CORRECTION INFO : " << endl
136        << " corrAtMinTemp " << corrAtMinTemp << endl
137        << " corrAtMaxTemp " << corrAtMaxTemp << endl
138        << " corrMaxMinDiff (~%) [=(corrAtMin - corrAtMax)*100] " 
139        << corrMaxMinDiff << endl;
140
141   return;
142 }
143 //________________________________________________________________ 
144 double AliEMCALCalibTimeDep::GetLengthOfRunInHours() const
145 {
146   return (fEndTime - fStartTime)*fkSecToHour;
147 }
148 //________________________________________________________________ 
149 double AliEMCALCalibTimeDep::GetRangeOfTempMeasureInHours() const
150 {
151   return (fMaxTime - fMinTime)*fkSecToHour;
152 }
153 //________________________________________________________________ 
154 double AliEMCALCalibTimeDep::GetRangeOfTempMeasureInDegrees() const
155 {
156   return (fMaxTemp - fMinTemp);
157 }
158
159 //________________________________________________________________
160 void AliEMCALCalibTimeDep::Initialize(Int_t run, 
161                                       UInt_t startTime, UInt_t endTime)
162 {
163   Reset(); // start fresh
164
165   fRun = run;
166   fStartTime = startTime;
167   fEndTime = endTime;
168   
169   // collect the needed information
170   GetTemperatureInfo(); // temperature readings during the run
171
172   return;
173 }
174
175 //________________________________________________________________
176 double AliEMCALCalibTimeDep::GetTemperature(UInt_t timeStamp) const
177 {// return estimate for all SuperModules and sensors, that had data 
178
179   // first convert from seconds to hours..
180   double timeHour = (timeStamp - fStartTime) * fkSecToHour;
181
182   double average = 0;
183   int n = 0;
184
185   for (int i=0; i<fTempArray->NumSensors(); i++) {
186     
187     AliEMCALSensorTemp *st = fTempArray->GetSensor(i);
188
189     // check if we had valid data for the time that is being asked for
190     if ( timeStamp>=st->GetStartTime() && timeStamp<=st->GetEndTime() ) {
191       AliSplineFit *f = st->GetFit();
192       if (f) { // ok, looks like we have valid data/info
193         // let's check what the expected value at the time appears to be
194         double val = f->Eval(timeHour);
195         average += val;
196         n++;
197       }
198     } // time
199   } // loop over fTempArray
200   
201   if (n>0) { // some valid data was found
202     average /= n;
203     return average;
204   }
205   else { // no good data
206     return fkErrorCode;
207   }
208
209 }
210
211 //________________________________________________________________
212 double AliEMCALCalibTimeDep::GetTemperatureSM(int imod, UInt_t timeStamp) const
213 {// return estimate for this one SuperModule, if it had data 
214
215   // first convert from seconds to hours..
216   double timeHour = (timeStamp - fStartTime) * fkSecToHour;
217
218   double average = 0;
219   int n = 0;
220
221   for (int i=0; i<fTempArray->NumSensors(); i++) {
222     
223     AliEMCALSensorTemp *st = fTempArray->GetSensor(i);
224     int module = st->GetSector()*2 + st->GetSide();
225     if ( module == imod ) { // right module
226       // check if we had valid data for the time that is being asked for
227       if ( timeStamp>=st->GetStartTime() && timeStamp<=st->GetEndTime() ) {
228         AliSplineFit *f = st->GetFit();
229         if (f) { // ok, looks like we have valid data/info
230           // let's check what the expected value at the time appears to be
231           double val = f->Eval(timeHour);
232           cout << " i " << i << " val " << val << endl;
233           average += val;
234           n++;
235         }
236       } // time
237     }
238     
239   } // loop over fTempArray
240   
241   if (n>0) { // some valid data was found
242     average /= n;
243     return average;
244   }
245   else { // no good data
246     return fkErrorCode;
247   }
248
249 }
250
251 //________________________________________________________________
252 double AliEMCALCalibTimeDep::GetTemperatureSMSensor(int imod, int isens, UInt_t timeStamp) const
253 {// return estimate for this one SuperModule and sensor, if it had data 
254
255   // first convert from seconds to hours..
256   double timeHour = (timeStamp - fStartTime) * fkSecToHour;
257
258   for (int i=0; i<fTempArray->NumSensors(); i++) {
259     
260     AliEMCALSensorTemp *st = fTempArray->GetSensor(i);
261     int module = st->GetSector()*2 + st->GetSide();
262     if ( module == imod && st->GetNum()==isens ) { // right module, and sensor
263       // check if we had valid data for the time that is being asked for
264       if ( timeStamp>=st->GetStartTime() && timeStamp<=st->GetEndTime() ) {
265         AliSplineFit *f = st->GetFit();
266         if (f) { // ok, looks like we have valid data/info
267           // let's check what the expected value at the time appears to be
268           double val = f->Eval(timeHour);
269
270           return val; // no point to move further in for loop, we have found the sensor we were looking for
271         }
272       } // time
273     }
274     
275   } // loop over fTempArray
276   
277   // if we made it all here, it means that we didn't find the sensor we were looking for
278   // i.e. no good data
279   return fkErrorCode;
280
281 }
282
283 //________________________________________________________________
284 double AliEMCALCalibTimeDep::GetCorrection(double temperature) const
285 { // gain decreases with increasing temperature
286   double gain = (1.0 - (temperature-fRefTemp)*fkTempSlope);  
287   // i.e. multiplicative correction to ADC increases with increasing temperature
288   return 1.0/gain;
289 }
290
291 /* Next comes the method that does the work in picking up all the needed info..*/
292 //________________________________________________________________
293 void AliEMCALCalibTimeDep::GetTemperatureInfo() 
294 {
295   // pick up Preprocessor output, based on fRun (most recent version)
296   AliCDBEntry* entry = AliCDBManager::Instance()->Get("EMCAL/Calib/Temperature", fRun);
297   if (entry) {
298     fTempArray = (AliEMCALSensorTempArray *) entry->GetObject();
299   }
300
301   if (fTempArray) { 
302     AliInfo( Form("NumSensors %d - IdDCS: first %d last %d",
303                   fTempArray->NumSensors(),
304                   fTempArray->GetFirstIdDCS(), fTempArray->GetLastIdDCS() ) );
305   }
306   else {
307     AliWarning( Form("AliEMCALSensorTempArray not found!") );
308   }
309   
310   return;
311 }