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 /* $Id: AliEMCALCalibTimeDep.cxx $ */
18 //_________________________________________________________________________
20 ///////////////////////////////////////////////////////////////////////////////
22 // class for EMCAL time-dep calibration
23 // - supposed to run in preprocessor
24 // we use input from the following sources:
25 // AliEMCALCalibTempCoeff (APD temperature coefficients),
26 // AliCaloCalibSignal (LED DA), AliEMCALSensorTempArray (ELMB DCS)
27 // AliEMCALCalibReference: LED amplitude and temperature info at reference time
29 // output/result is in AliEMCALCalibTimeDepCorrection
31 ///////////////////////////////////////////////////////////////////////////////
34 #include <TGraphSmooth.h>
37 #include "AliCDBEntry.h"
38 #include "AliCDBManager.h"
39 #include "AliEMCALSensorTempArray.h"
40 #include "AliCaloCalibSignal.h"
41 #include "AliEMCALCalibTempCoeff.h"
42 #include "AliEMCALCalibReference.h"
43 #include "AliEMCALCalibTimeDepCorrection.h"
44 #include "AliEMCALCalibTimeDep.h"
46 /* first a bunch of constants.. */
47 const double kSecToHour = 1.0/3600.0; // conversion factor from seconds to hours
49 // some global variables for APD handling; values from Catania studies, best fit
50 // TempCoeff = p0+p1*M (M=gain), where p0 and and p1 are functions of the dark current
51 const double kTempCoeffP0Const = -0.903; //
52 const double kTempCoeffP0Factor = -1.381e7; //
53 const double kTempCoeffP1Const = -0.023; //
54 const double kTempCoeffP1Factor = -4.966e5; //
56 const double kTempMaxDiffMedian = 2; // Temperature values should not be further away from median value within SM when considered in the average calc.
58 const double kErrorCode = -999; // to indicate that something went wrong
62 ClassImp(AliEMCALCalibTimeDep)
64 //________________________________________________________________
65 AliEMCALCalibTimeDep::AliEMCALCalibTimeDep() :
77 fTemperatureResolution(0.1), // 0.1 deg C is default
78 fMaxTemperatureDiff(5), // 5 deg C is default max diff relative to reference
79 fTimeBinsPerHour(2), // 2 30-min bins per hour is default
80 fHighLowGainFactor(16), // factor ~16 between High gain and low gain
83 fCalibTempCoeff(NULL),
84 fCalibReference(NULL),
85 fCalibTimeDepCorrection(NULL),
91 //________________________________________________________________
92 AliEMCALCalibTimeDep::AliEMCALCalibTimeDep(const AliEMCALCalibTimeDep& calibt) :
94 fRun(calibt.GetRunNumber()),
95 fStartTime(calibt.GetStartTime()),
96 fEndTime(calibt.GetEndTime()),
97 fMinTemp(calibt.GetMinTemp()),
98 fMaxTemp(calibt.GetMaxTemp()),
99 fMinTempVariation(calibt.GetMinTempVariation()),
100 fMaxTempVariation(calibt.GetMaxTempVariation()),
101 fMinTempValid(calibt.GetMinTempValid()),
102 fMaxTempValid(calibt.GetMaxTempValid()),
103 fMinTime(calibt.GetMinTime()),
104 fMaxTime(calibt.GetMaxTime()),
105 fTemperatureResolution(calibt.GetTemperatureResolution()),
106 fMaxTemperatureDiff(calibt.GetMaxTemperatureDiff()),
107 fTimeBinsPerHour(calibt.GetTimeBinsPerHour()),
108 fHighLowGainFactor(calibt.GetHighLowGainFactor()),
109 fTempArray(calibt.GetTempArray()),
110 fCalibSignal(calibt.GetCalibSignal()),
111 fCalibTempCoeff(calibt.GetCalibTempCoeff()),
112 fCalibReference(calibt.GetCalibReference()),
113 fCalibTimeDepCorrection(calibt.GetCalibTimeDepCorrection()),
114 fVerbosity(calibt.GetVerbosity())
120 //________________________________________________________________
121 AliEMCALCalibTimeDep &AliEMCALCalibTimeDep::operator =(const AliEMCALCalibTimeDep& calibt)
123 // assignment operator; use copy ctor
124 if (&calibt == this) return *this;
126 new (this) AliEMCALCalibTimeDep(calibt);
130 //________________________________________________________________
131 AliEMCALCalibTimeDep::~AliEMCALCalibTimeDep()
136 //________________________________________________________________
137 void AliEMCALCalibTimeDep::Reset()
139 // clear variables to default
145 fMinTempVariation = 0;
146 fMaxTempVariation = 0;
151 fTemperatureResolution = 0.1; // 0.1 deg C is default
152 fMaxTemperatureDiff = 5; // 5 deg C is default max diff relative to reference
153 fTimeBinsPerHour = 2; // 2 30-min bins per hour is default
156 fCalibTempCoeff = NULL;
157 fCalibReference = NULL;
158 fCalibTimeDepCorrection = NULL;
163 //________________________________________________________________
164 void AliEMCALCalibTimeDep::PrintInfo() const
167 cout << endl << " AliEMCALCalibTimeDep::PrintInfo() " << endl;
168 // basic variables, all 'publicly available' also
169 cout << " VARIABLE DUMP: " << endl
170 << " GetStartTime() " << GetStartTime() << endl
171 << " GetEndTime() " << GetEndTime() << endl
172 << " GetMinTime() " << GetMinTime() << endl
173 << " GetMaxTime() " << GetMaxTime() << endl
174 << " GetMinTemp() " << GetMinTemp() << endl
175 << " GetMaxTemp() " << GetMaxTemp() << endl
176 << " GetMinTempVariation() " << GetMinTempVariation() << endl
177 << " GetMaxTempVariation() " << GetMaxTempVariation() << endl
178 << " GetTemperatureResolution() " << GetTemperatureResolution() << endl;
180 cout << " RUN INFO: " << endl
181 << " runnumber " << GetRunNumber() << endl
182 << " length (in hours) " << GetLengthOfRunInHours() << endl
183 << " length (in bins) " << GetLengthOfRunInBins() << endl
184 << " range of temperature measurements (in hours) " << GetRangeOfTempMeasureInHours()
185 << " (in deg. C) " << GetRangeOfTempMeasureInDegrees()
191 //________________________________________________________________
192 Double_t AliEMCALCalibTimeDep::GetLengthOfRunInHours() const
194 return (fEndTime - fStartTime)*kSecToHour;
197 //________________________________________________________________
198 Double_t AliEMCALCalibTimeDep::GetLengthOfRunInBins() const
200 return (fEndTime - fStartTime)*kSecToHour*fTimeBinsPerHour;
203 //________________________________________________________________
204 Double_t AliEMCALCalibTimeDep::GetRangeOfTempMeasureInHours() const
206 return (fMaxTime - fMinTime)*kSecToHour;
209 //________________________________________________________________
210 Double_t AliEMCALCalibTimeDep::GetRangeOfTempMeasureInDegrees() const
212 return (fMaxTemp - fMinTemp);
215 //________________________________________________________________
216 void AliEMCALCalibTimeDep::Initialize(Int_t run,
217 UInt_t startTime, UInt_t endTime)
218 { // setup, and get temperature info
219 Reset(); // start fresh
222 fStartTime = startTime;
225 // collect the needed information
226 GetTemperatureInfo(); // temperature readings during the run
227 ScanTemperatureInfo(); // see what the boundaries are (Min/Max Time/Temp)
232 //________________________________________________________________
233 Double_t AliEMCALCalibTimeDep::GetTemperatureSM(int imod, UInt_t timeStamp) const
234 {// return estimate for this one SuperModule, if it had data
236 // first convert from seconds to hours..
237 Double_t timeHour = (timeStamp - fStartTime) * kSecToHour;
240 Double_t valArr[8]={0}; // 8 sensors per SM
242 for (int i=0; i<fTempArray->NumSensors(); i++) {
244 AliEMCALSensorTemp *st = fTempArray->GetSensor(i);
245 int module = st->GetSector()*2 + st->GetSide();
246 if ( module == imod ) { // right module
247 // check if we had valid data for the time that is being asked for
248 if ( timeStamp>=st->GetStartTime() && timeStamp<=st->GetEndTime() ) {
249 AliSplineFit *f = st->GetFit();
250 if (f) { // ok, looks like we have valid data/info
251 // let's check what the expected value at the time appears to be
252 Double_t val = f->Eval(timeHour);
253 if ( fVerbosity > 0 ) {
254 cout << " sensor i " << i << " val " << val << endl;
256 if (val>fMinTempValid && val<fMaxTempValid && n<8) {
264 } // loop over fTempArray
266 if (n>0) { // some valid data was found
267 Double_t median = TMath::Median(n, valArr);
268 Double_t average = 0;
270 for (int is=0; is<n; is++) {
271 if (TMath::Abs(valArr[is] - median) < kTempMaxDiffMedian) {
272 average += valArr[is];
280 else { // this case should not happen, but kept for completeness (coverity etc)
284 else { // no good data
290 //________________________________________________________________
291 Int_t AliEMCALCalibTimeDep::CalcCorrection()
292 { // OK, this is where the real action takes place - the heart of this class..
293 /* The philosophy is as follows:
294 0. Init corrections to 1.0 values, and see how many correction bins we need
295 1. Check how large temperature variations we have through the run - do we really need all the correction bias (otherwise adjust to single bin)
296 2. try to use temperature info + APD temperature coefficient info, to estimate correction.
297 For now (from Dec 2009), we do not use LED info.
301 // how many SuperModules do we have?
302 Int_t nSM = fCalibReference->GetNSuperModule();
303 // how many time-bins should we have for this run?
304 Int_t nBins = (Int_t) (GetLengthOfRunInBins() + 1); // round-up (from double to int; always at least 1)
305 Int_t binSize = (Int_t) (3600/fTimeBinsPerHour); // in seconds
307 // 1: get info on how much individual sensors might have changed during
308 // the run (compare max-min for each sensor separately)
309 if (fMaxTempVariation < fTemperatureResolution) {
310 nBins = 1; // just one bin needed..
313 binSize = fEndTime - fStartTime;
315 if (fVerbosity > 0) {
316 cout << " nBins " << nBins << " binSize " << binSize << endl;
319 // set up a reasonable default (correction = 1.0)
320 fCalibTimeDepCorrection = new AliEMCALCalibTimeDepCorrection(nSM);
321 fCalibTimeDepCorrection->InitCorrection(nSM, nBins, 1.0);
322 fCalibTimeDepCorrection->SetStartTime(fStartTime);
323 fCalibTimeDepCorrection->SetNTimeBins(nBins);
324 fCalibTimeDepCorrection->SetTimeBinSize(binSize);
326 // 2: try with Temperature correction
327 Int_t nRemaining = CalcTemperatureCorrection(nSM, nBins, binSize);
333 //________________________________________________________________
334 Double_t AliEMCALCalibTimeDep::GetTempCoeff(Double_t IDark, Double_t M) const
335 { // estimate the Temperature Coefficient, based on the dark current (IDark)
336 // and the gain (M), based on Catania parameterizations
338 Double_t dP0 = kTempCoeffP0Const + kTempCoeffP0Factor * IDark;
339 Double_t dP1 = kTempCoeffP1Const + kTempCoeffP1Factor * IDark;
341 Double_t dTC = dP0 + dP1*M;
342 // from % numbers to regular ones..:
345 return TMath::Abs(dTC); // return the absolute value, to avoid any sign confusion
348 /* Next come the methods that do the work in picking up all the needed info..*/
349 //________________________________________________________________
350 void AliEMCALCalibTimeDep::GetTemperatureInfo()
352 // pick up Preprocessor output, based on fRun (most recent version)
353 AliCDBEntry* entry = AliCDBManager::Instance()->Get("EMCAL/Calib/Temperature", fRun);
355 fTempArray = (AliEMCALSensorTempArray *) entry->GetObject();
359 AliInfo( Form("NumSensors %d - IdDCS: first %d last %d",
360 fTempArray->NumSensors(),
361 fTempArray->GetFirstIdDCS(), fTempArray->GetLastIdDCS() ) );
364 AliWarning( Form("AliEMCALSensorTempArray not found!") );
370 //________________________________________________________________
371 Int_t AliEMCALCalibTimeDep::ScanTemperatureInfo()
372 {// assign max/min time and temperature values
374 fMinTemp = 999; // init to some large value (999 deg C)
376 fMinTempVariation = 999; // init to some large value (999 deg C)
377 fMaxTempVariation = 0;
378 fMinTime = 2147483647; // init to a large value in the far future (0x7fffffff), year 2038 times..
381 Int_t n = 0; // number of valid readings
383 for (int i=0; i<fTempArray->NumSensors(); i++) {
385 AliEMCALSensorTemp *st = fTempArray->GetSensor(i);
386 if ( st->GetStartTime() == 0 ) { // no valid data
391 if (fMinTime > st->GetStartTime()) { fMinTime = st->GetStartTime(); }
392 if (fMaxTime < st->GetEndTime()) { fMaxTime = st->GetEndTime(); }
394 // check temperature ranges
395 AliSplineFit *f = st->GetFit();
397 if (f) { // ok, looks like we have valid data/info
398 int np = f->GetKnots();
399 Double_t *y0 = f->GetY0();
400 // min and max values within the single sensor
404 for (int ip=0; ip<np; ip++) {
405 if (y0[ip]>fMinTempValid && y0[ip]<fMaxTempValid) {
406 if (min > y0[ip]) { min = y0[ip]; }
407 if (max < y0[ip]) { max = y0[ip]; }
412 if (fMinTemp > min) { fMinTemp = min; }
413 if (fMaxTemp < max) { fMaxTemp = max; }
414 Double_t variation = max - min;
415 if (fMinTempVariation > variation) { fMinTempVariation = variation; }
416 if (fMaxTempVariation < variation) { fMaxTempVariation = variation; }
421 } // loop over fTempArray
423 if (n>0) { // some valid data was found
426 else { // no good data
427 return (Int_t) kErrorCode;
432 //________________________________________________________________
433 void AliEMCALCalibTimeDep::GetCalibSignalInfo()
435 // pick up Preprocessor output, based on fRun (most recent version)
436 AliCDBEntry* entry = AliCDBManager::Instance()->Get("EMCAL/Calib/LED", fRun);
438 fCalibSignal = (AliCaloCalibSignal *) entry->GetObject();
442 AliInfo( Form("CalibSignal: NEvents %d NAcceptedEvents %d Entries %lld AvgEntries LEDRefEntries %lld LEDRefEntries %lld, LEDRefAvgEntries %lld",
443 fCalibSignal->GetNEvents(), fCalibSignal->GetNAcceptedEvents(),
444 fCalibSignal->GetTreeAmpVsTime()->GetEntries(),
445 fCalibSignal->GetTreeAvgAmpVsTime()->GetEntries(),
446 fCalibSignal->GetTreeLEDAmpVsTime()->GetEntries(),
447 fCalibSignal->GetTreeLEDAvgAmpVsTime()->GetEntries() ) );
450 AliWarning( Form("AliCaloCalibSignal not found!") );
456 //________________________________________________________________
457 void AliEMCALCalibTimeDep::GetCalibTempCoeffInfo()
459 // pick up Preprocessor output, based on fRun (most recent version)
460 AliCDBEntry* entry = AliCDBManager::Instance()->Get("EMCAL/Calib/TempCoeff", fRun);
461 // stored object should be a TTree; read the info
463 fCalibTempCoeff = (AliEMCALCalibTempCoeff *) entry->GetObject();
466 if (fCalibTempCoeff) {
467 AliInfo( Form("CalibTempCoeff: NSuperModule %d ", fCalibTempCoeff->GetNSuperModule() ) );
470 AliWarning( Form("AliEMCALCalibTempCoeff not found!") );
476 //________________________________________________________________
477 void AliEMCALCalibTimeDep::GetCalibReferenceInfo()
479 // pick up Preprocessor output, based on fRun (most recent version)
480 AliCDBEntry* entry = AliCDBManager::Instance()->Get("EMCAL/Calib/Reference", fRun);
482 fCalibReference = (AliEMCALCalibReference *) entry->GetObject();
485 if (fCalibReference) {
486 AliInfo( Form("CalibReference: NSuperModule %d ", fCalibReference->GetNSuperModule() ) );
489 AliWarning( Form("AliEMCALCalibReference not found!") );
495 //________________________________________________________________
496 Int_t AliEMCALCalibTimeDep::CalcLEDCorrection(Int_t nSM, Int_t nBins)
497 {// Construct normalized ratios R(t)=LED(t)/LEDRef(t), for current time T and calibration time t0
498 // The correction factor we keep is c(T) = R(t0)/R(T)
499 // T info from fCalibSignal, t0 info from fCalibReference
501 // NOTE: for now we don't use the RMS info either from fCalibSignal or fCalibReference
502 // but one could upgrade this in the future
503 Int_t nRemaining = 0; // we count the towers for which we could not get valid data
505 // sanity check; same SuperModule indices for corrections as for regular calibrations
506 for (int i = 0; i < nSM; i++) {
507 AliEMCALSuperModuleCalibReference * dataCalibReference = fCalibReference->GetSuperModuleCalibReferenceNum(i);
508 AliEMCALSuperModuleCalibTimeDepCorrection * dataCalibTimeDepCorrection = fCalibTimeDepCorrection->GetSuperModuleCalibTimeDepCorrectionNum(i);
510 int iSMRef = dataCalibReference->GetSuperModuleNum();
511 int iSMCorr = dataCalibTimeDepCorrection->GetSuperModuleNum();
512 if (iSMRef != iSMCorr) {
513 AliWarning( Form("AliEMCALCalibTimeDep - SuperModule index mismatch: %d != %d", iSMRef, iSMCorr) );
514 nRemaining = nSM * AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows * nBins;
525 // The fCalibSignal info is stored in TTrees
526 // Note that the time-bins for the TTree's may not exactly match with our correction time bins
527 int timeDiff = fCalibSignal->GetStartTime() - fStartTime; // in seconds
528 // fCalibSignal time info in seconds: Hour/kSecToHour
529 // corrected for startTime difference: Hour/kSecToHour + timeDiff
530 // converted into a time-bin we use: (Hour + timeDiff*kSecToHour) * fTimeBinsPerHour
532 // values for R(T), size of TArray = nBins
533 // the [2] dimension below is for the low or high gain
534 TArrayF ampT[AliEMCALGeoParams::fgkEMCALModules][AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows][2];
535 TArrayF nT[AliEMCALGeoParams::fgkEMCALModules][AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows][2];
536 TArrayF ampLEDRefT[AliEMCALGeoParams::fgkEMCALModules][AliEMCALGeoParams::fgkEMCALLEDRefs][2];
537 TArrayF nLEDRefT[AliEMCALGeoParams::fgkEMCALModules][AliEMCALGeoParams::fgkEMCALLEDRefs][2];
539 // set up TArray's first
540 for (iSM = 0; iSM < AliEMCALGeoParams::fgkEMCALModules; iSM++) {
541 for (iCol = 0; iCol < AliEMCALGeoParams::fgkEMCALCols; iCol++) {
542 for (iRow = 0; iRow < AliEMCALGeoParams::fgkEMCALRows; iRow++) {
543 for (iGain = 0; iGain < 2; iGain++) {
545 ampT[iSM][iCol][iRow][iGain].Set(nBins);
546 nT[iSM][iCol][iRow][iGain].Set(nBins);
548 for (int j = 0; j < nBins; j++) {
549 ampT[iSM][iCol][iRow][iGain].AddAt(0, j);
550 nT[iSM][iCol][iRow][iGain].AddAt(0, j);
555 for (iStrip = 0; iStrip < AliEMCALGeoParams::fgkEMCALLEDRefs; iStrip++) {
556 for (iGain = 0; iGain < 2; iGain++) {
558 ampLEDRefT[iSM][iStrip][iGain].Set(nBins);
559 nLEDRefT[iSM][iStrip][iGain].Set(nBins);
561 for (int j = 0; j < nBins; j++) {
562 ampLEDRefT[iSM][iStrip][iGain].AddAt(0, j);
563 nLEDRefT[iSM][iStrip][iGain].AddAt(0, j);
569 // OK, now loop over the TTrees and fill the arrays needed for R(T)
570 TTree *treeAvg = fCalibSignal->GetTreeAvgAmpVsTime();
571 TTree *treeLEDRefAvg = fCalibSignal->GetTreeAvgAmpVsTime();
573 int iChannelNum = 0; // for regular towers
574 int iRefNum = 0; // for LED
578 treeAvg->SetBranchAddress("fChannelNum", &iChannelNum);
579 treeAvg->SetBranchAddress("fHour", &dHour);
580 treeAvg->SetBranchAddress("fAvgAmp",&dAvgAmp);
583 // counters for how many values were seen per SuperModule
584 int nCount[AliEMCALGeoParams::fgkEMCALModules] = {0};
585 int nCountLEDRef[AliEMCALGeoParams::fgkEMCALModules] = {0};
587 for (int ient=0; ient<treeAvg->GetEntries(); ient++) {
588 treeAvg->GetEntry(ient);
589 // figure out where this info comes from
590 fCalibSignal->DecodeChannelNum(iChannelNum, &iSM, &iCol, &iRow, &iGain);
591 iBin = (int) ( (dHour + timeDiff*kSecToHour) * fTimeBinsPerHour ); // CHECK!!!
592 // add value in the arrays
593 ampT[iSM][iCol][iRow][iGain].AddAt( ampT[iSM][iCol][iRow][iGain].At(iBin)+dAvgAmp, iBin );
594 nT[iSM][iCol][iRow][iGain].AddAt( nT[iSM][iCol][iRow][iGain].At(iBin)+1, iBin );
598 treeLEDRefAvg->SetBranchAddress("fRefNum", &iRefNum);
599 treeLEDRefAvg->SetBranchAddress("fHour", &dHour);
600 treeLEDRefAvg->SetBranchAddress("fAvgAmp",&dAvgAmp);
602 for (int ient=0; ient<treeLEDRefAvg->GetEntries(); ient++) {
603 treeLEDRefAvg->GetEntry(ient);
604 // figure out where this info comes from
605 fCalibSignal->DecodeRefNum(iRefNum, &iSM, &iStrip, &iGain);
606 iBin = (int) ( (dHour + timeDiff*kSecToHour) * fTimeBinsPerHour ); // CHECK!!!
607 // add value in the arrays
608 ampLEDRefT[iSM][iStrip][iGain].AddAt( ampLEDRefT[iSM][iStrip][iGain].At(iBin)+dAvgAmp, iBin );
609 nLEDRefT[iSM][iStrip][iGain].AddAt( nLEDRefT[iSM][iStrip][iGain].At(iBin)+1, iBin );
613 // Normalize TArray values, and calculate average also
614 Float_t norm = 0; // extra var, for readability
616 for (iSM = 0; iSM < AliEMCALGeoParams::fgkEMCALModules; iSM++) {
617 if (nCount[iSM]>0 && nCountLEDRef[iSM]>0) { // avoid SuperModules with no data..
618 for (iCol = 0; iCol < AliEMCALGeoParams::fgkEMCALCols; iCol++) {
619 // iStrip = AliEMCALGeoParams::GetStripModule(iSM, iCol);
620 iStrip = (iSM%2==0) ? iCol/2 : AliEMCALGeoParams::fgkEMCALLEDRefs - 1 - iCol/2; //TMP, FIXME
621 for (iRow = 0; iRow < AliEMCALGeoParams::fgkEMCALRows; iRow++) {
622 for (iGain = 0; iGain < 2; iGain++) {
624 for (int j = 0; j < nBins; j++) {
625 if (nT[iSM][iCol][iRow][iGain].At(j) > 0) {
626 norm = ampT[iSM][iCol][iRow][iGain].At(j) / nT[iSM][iCol][iRow][iGain].At(j);
627 ampT[iSM][iCol][iRow][iGain].AddAt(norm, j); // AddAt = SetAt
633 for (iStrip = 0; iStrip < AliEMCALGeoParams::fgkEMCALLEDRefs; iStrip++) {
634 for (iGain = 0; iGain < 2; iGain++) {
635 for (int j = 0; j < nBins; j++) {
636 if (nLEDRefT[iSM][iStrip][iGain].At(j) > 0) {
637 norm = ampLEDRefT[iSM][iStrip][iGain].At(j) / nLEDRefT[iSM][iStrip][iGain].At(j);
638 ampLEDRefT[iSM][iStrip][iGain].AddAt(norm, j); // AddAt = SetAt
647 // Calculate correction values, and store them
648 // set kErrorCode values for those that could not be set
652 Float_t correction = 0; // c(T) = R(t0)/R(T)
653 Int_t refGain = 0; // typically use low gain for LED reference amplitude (high gain typically well beyond saturation)
655 for (int i = 0; i < nSM; i++) {
656 AliEMCALSuperModuleCalibReference * dataCalibReference = fCalibReference->GetSuperModuleCalibReferenceNum(i);
657 AliEMCALSuperModuleCalibTimeDepCorrection * dataCalibTimeDepCorrection = fCalibTimeDepCorrection->GetSuperModuleCalibTimeDepCorrectionNum(i);
658 iSM = dataCalibReference->GetSuperModuleNum();
660 for (iCol = 0; iCol < AliEMCALGeoParams::fgkEMCALCols; iCol++) {
661 // iStrip = AliEMCALGeoParams::GetStripModule(iSM, iCol);
662 iStrip = (iSM%2==0) ? iCol/2 : AliEMCALGeoParams::fgkEMCALLEDRefs - 1 - iCol/2; //TMP, FIXME
663 refGain = dataCalibReference->GetLEDRefHighLow(iStrip); // LED reference gain value used for reference calibration
665 for (iRow = 0; iRow < AliEMCALGeoParams::fgkEMCALRows; iRow++) {
668 AliEMCALCalibReferenceVal * refVal = dataCalibReference->GetAPDVal(iCol, iRow);
669 iGain = refVal->GetHighLow(); // gain value used for reference calibration
670 // valid amplitude values should be larger than 0
671 if (refVal->GetLEDAmp()>0 && dataCalibReference->GetLEDRefAmp(iStrip)>0) {
672 ratiot0 = refVal->GetLEDAmp() / dataCalibReference->GetLEDRefAmp(iStrip);
675 ratiot0 = kErrorCode;
679 for (int j = 0; j < nBins; j++) {
681 // calculate R(T) also; first try with individual tower:
682 // same gain as for reference calibration is the default
683 if (ampT[iSM][iCol][iRow][iGain].At(j)>0 && ampLEDRefT[iSM][iStrip][refGain].At(j)>0) {
684 // looks like valid data with the right gain combination
685 ratioT = ampT[iSM][iCol][iRow][iGain].At(j) / ampLEDRefT[iSM][iStrip][refGain].At(j);
687 // if data appears to be saturated, and we are in high gain, then try with low gain instead
689 int newRefGain = refGain;
690 if ( ampT[iSM][iCol][iRow][iGain].At(j)>AliEMCALGeoParams::fgkOverflowCut && iGain==1 ) {
693 if ( ampLEDRefT[iSM][iStrip][refGain].At(j)>AliEMCALGeoParams::fgkOverflowCut && refGain==1 ) {
697 if (newGain!=iGain || newRefGain!=refGain) {
698 // compensate for using different gain than in the reference calibration
699 // we may need to have a custom H/L ratio value for each tower
700 // later, but for now just use a common value, as the rest of the code does..
701 ratioT = ampT[iSM][iCol][iRow][newGain].At(j) / ampLEDRefT[iSM][iStrip][newRefGain].At(j);
704 ratioT *= fHighLowGainFactor;
706 else if (newRefGain<refGain) {
707 ratioT /= fHighLowGainFactor;
715 // Calc. correction factor
716 if (ratiot0>0 && ratioT>0) {
717 correction = ratiot0/ratioT;
720 correction = kErrorCode;
725 dataCalibTimeDepCorrection->GetCorrection(iCol,iRow)->AddAt(correction, j);
727 fTimeDepCorrection->SetCorrection(i, iCol, iRow, j, correction);
734 nRemaining = CalcLEDCorrectionStripBasis(nSM, nBins);
738 //________________________________________________________________
739 Int_t AliEMCALCalibTimeDep::CalcLEDCorrectionStripBasis(Int_t nSM, Int_t nBins)
740 { // use averages for each strip if no good values exist for some single tower
742 // go over fTimeDepCorrection info
743 Int_t nRemaining = 0; // we count the towers for which we could not get valid data
745 // for calculating StripAverage info
747 Float_t stripAverage = 0;
757 for (int i = 0; i < nSM; i++) {
758 AliEMCALSuperModuleCalibTimeDepCorrection * dataCalibTimeDepCorrection = fCalibTimeDepCorrection->GetSuperModuleCalibTimeDepCorrectionNum(i);
759 iSM = dataCalibTimeDepCorrection->GetSuperModuleNum();
761 for (int j = 0; j < nBins; j++) {
766 for (iStrip = 0; iStrip < AliEMCALGeoParams::fgkEMCALLEDRefs; iStrip++) {
768 if ((iSM%2)==1) { // C side
769 firstCol = (AliEMCALGeoParams::fgkEMCALLEDRefs-1 - iStrip)*2;
771 lastCol = firstCol+1;
773 for (iCol = firstCol; iCol <= lastCol; iCol++) {
774 for (iRow = 0; iRow < AliEMCALGeoParams::fgkEMCALRows; iRow++) {
775 val = dataCalibTimeDepCorrection->GetCorrection(iCol,iRow)->At(j);
776 if (val>0) { // valid value; error code is negative
783 // calc average over strip
785 stripAverage /= nValidTower;
786 for (iCol = firstCol; iCol <= lastCol; iCol++) {
787 for (iRow = 0; iRow < AliEMCALGeoParams::fgkEMCALRows; iRow++) {
788 val = dataCalibTimeDepCorrection->GetCorrection(iCol,iRow)->At(j);
789 if (val<0) { // invalid value; error code is negative
790 dataCalibTimeDepCorrection->GetCorrection(iCol,iRow)->AddAt(val, j);
795 else { // could not fill in unvalid entries
796 nRemaining += 2*AliEMCALGeoParams::fgkEMCALRows;
806 //________________________________________________________________
807 Int_t AliEMCALCalibTimeDep::CalcTemperatureCorrection(Int_t nSM, Int_t nBins, Int_t binSize)
808 { // OK, so we didn't have valid LED data that allowed us to do the correction only
810 // So, instead we'll rely on the temperature info and try to do the correction
811 // based on that instead.
812 // For this, we'll need the info from 3 classes (+temperature array), and output the values in a 4th class
813 Int_t nRemaining = 0;
819 Double_t dTempCoeff[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows];
820 memset(dTempCoeff, 0, sizeof(dTempCoeff));
821 Double_t correction = 0;
822 Double_t secondsPerBin = (Double_t) binSize;
824 for (int i = 0; i < nSM; i++) {
825 AliEMCALSuperModuleCalibTimeDepCorrection * dataCalibTimeDepCorrection = fCalibTimeDepCorrection->GetSuperModuleCalibTimeDepCorrectionNum(i);
826 iSM = dataCalibTimeDepCorrection->GetSuperModuleNum();
828 AliEMCALSuperModuleCalibReference * dataCalibReference = fCalibReference->GetSuperModuleCalibReferenceNum(iSM);
829 AliEMCALSuperModuleCalibTempCoeff * dataCalibTempCoeff = fCalibTempCoeff->GetSuperModuleCalibTempCoeffNum(iSM);
831 // first get CalibTempCoeff info
832 for (iCol = 0; iCol < AliEMCALGeoParams::fgkEMCALCols; iCol++) {
833 for (iRow = 0; iRow < AliEMCALGeoParams::fgkEMCALRows; iRow++) {
835 dTempCoeff[iCol][iRow] = dataCalibTempCoeff->GetTC(iCol, iRow);
836 if (fVerbosity > 1) {
837 cout << " iSM " << iSM << " iCol " << iCol << " iRow " << iRow
838 << " dTempCoeff " << dTempCoeff[iCol][iRow] << endl;
843 // figure out what the reference temperature is, from fCalibReference
844 Double_t referenceTemperature = 0;
846 for (int iSensor = 0; iSensor<AliEMCALGeoParams::fgkEMCALTempSensors ; iSensor++) {
847 if (dataCalibReference->GetTemperature(iSensor)>0) { // hopefully OK value
848 referenceTemperature += dataCalibReference->GetTemperature(iSensor);
854 referenceTemperature /= nVal; // valid values exist, we can look into corrections
856 for (int j = 0; j < nBins; j++) {
857 // what is the timestamp in the middle of this bin? (0.5 is for middle of bin)
858 UInt_t timeStamp = fStartTime + (UInt_t)((j+0.5)*secondsPerBin);
859 // get the temperature at this time; use average over whole SM for now (TO BE CHECKED LATER - if we can do better with finer grained info)
860 Double_t dSMTemperature = GetTemperatureSM(iSM, timeStamp);
862 Double_t temperatureDiff = referenceTemperature - dSMTemperature; // ref - new
863 if (fVerbosity > 0) {
864 cout << " referenceTemperature " << referenceTemperature
865 << " dSMTemperature " << dSMTemperature
866 << " temperatureDiff " << temperatureDiff
869 // if the new temperature is higher than the old/reference one (diff<0), then the gain has gone down
870 // if the new temperature is lower than the old/reference one (diff>0), then the gain has gone up
871 // dTempCoeff is a (unsigned) factor describing how many % the gain
872 // changes with a degree change.
873 // i.e. the product temperatureDiff * dTempCoeff increase when the gain goes up
874 // The correction we want to keep is what we should multiply our ADC value with as a function
875 // of time, i.e. the inverse of the gain change..
876 if ( (TMath::Abs(temperatureDiff)>fTemperatureResolution)
877 && (TMath::Abs(temperatureDiff)<fMaxTemperatureDiff) ) {
878 // significant enough difference that we need to consider it, and also not unreasonably large
880 // loop over all towers; effect of temperature change will depend on gain for this tower
881 for (iCol = 0; iCol < AliEMCALGeoParams::fgkEMCALCols; iCol++) {
882 for (iRow = 0; iRow < AliEMCALGeoParams::fgkEMCALRows; iRow++) {
884 // the correction should be inverse of modification in gain: (see discussion above)
885 // modification in gain: 1.0 + (temperatureDiff * dTempCoeff[iCol][iRow])*0.01;
886 // 1/(1+x) ~= 1 - x for small x, i.e. we arrive at:
887 correction = 1.0 - (temperatureDiff * dTempCoeff[iCol][iRow]);
888 dataCalibTimeDepCorrection->GetCorrection(iCol,iRow)->AddAt(correction, j);
889 if (fVerbosity > 1) {
890 cout << " iSM " << iSM
894 << " correction " << correction
900 } // if noteworthy temperature change
901 else { // just set correction values to 1.0
903 for (iCol = 0; iCol < AliEMCALGeoParams::fgkEMCALCols; iCol++) {
904 for (iRow = 0; iRow < AliEMCALGeoParams::fgkEMCALRows; iRow++) {
905 dataCalibTimeDepCorrection->GetCorrection(iCol,iRow)->AddAt(correction, j);
911 } // if reference temperature exist
912 else { // could not do the needed check.. signal that in the return code
913 nRemaining += AliEMCALGeoParams::fgkEMCALCols * AliEMCALGeoParams::fgkEMCALRows * nBins;