]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALCalibTimeDep.cxx
change default max distance R to 0.1
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibTimeDep.cxx
index 385323cfe5ecec2b5484c0009dfc47253f6bd51c..1249653413681a7e8e29bc3c28a969db2275f2cb 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <iostream>
 #include <TGraphSmooth.h>
+#include <TMath.h>
 #include "AliLog.h"
 #include "AliCDBEntry.h"
 #include "AliCDBManager.h"
@@ -52,6 +53,8 @@ const double kTempCoeffP0Factor = -1.381e7; //
 const double kTempCoeffP1Const = -0.023; // 
 const double kTempCoeffP1Factor = -4.966e5; //
  
+const double kTempMaxDiffMedian = 2; // Temperature values should not be further away from median value within SM when considered in the average calc.
+
 const double kErrorCode = -999; // to indicate that something went wrong
 
 using namespace std;
@@ -67,6 +70,8 @@ AliEMCALCalibTimeDep::AliEMCALCalibTimeDep() :
   fMaxTemp(0),
   fMinTempVariation(0),
   fMaxTempVariation(0),
+  fMinTempValid(15),
+  fMaxTempValid(35),
   fMinTime(0),
   fMaxTime(0),
   fTemperatureResolution(0.1), // 0.1 deg C is default
@@ -93,6 +98,8 @@ AliEMCALCalibTimeDep::AliEMCALCalibTimeDep(const AliEMCALCalibTimeDep& calibt) :
   fMaxTemp(calibt.GetMaxTemp()),
   fMinTempVariation(calibt.GetMinTempVariation()),
   fMaxTempVariation(calibt.GetMaxTempVariation()),
+  fMinTempValid(calibt.GetMinTempValid()),
+  fMaxTempValid(calibt.GetMaxTempValid()),
   fMinTime(calibt.GetMinTime()),
   fMaxTime(calibt.GetMaxTime()),
   fTemperatureResolution(calibt.GetTemperatureResolution()),
@@ -137,6 +144,8 @@ void  AliEMCALCalibTimeDep::Reset()
   fMaxTemp = 0;
   fMinTempVariation = 0;
   fMaxTempVariation = 0;
+  fMinTempValid = 15; 
+  fMaxTempValid = 35;
   fMinTime = 0;
   fMaxTime = 0;
   fTemperatureResolution = 0.1; // 0.1 deg C is default
@@ -165,7 +174,8 @@ void  AliEMCALCalibTimeDep::PrintInfo() const
        << " GetMinTemp() " << GetMinTemp() << endl
        << " GetMaxTemp() " << GetMaxTemp() << endl
        << " GetMinTempVariation() " << GetMinTempVariation() << endl
-       << " GetMaxTempVariation() " << GetMaxTempVariation() << endl;
+       << " GetMaxTempVariation() " << GetMaxTempVariation() << endl
+       << " GetTemperatureResolution() " << GetTemperatureResolution() << endl;
   // run ranges
   cout << " RUN INFO: " << endl
        << " runnumber " << GetRunNumber() << endl
@@ -226,8 +236,8 @@ Double_t AliEMCALCalibTimeDep::GetTemperatureSM(int imod, UInt_t timeStamp) cons
   // first convert from seconds to hours..
   Double_t timeHour = (timeStamp - fStartTime) * kSecToHour;
 
-  Double_t average = 0;
   int n = 0;
+  Double_t valArr[8]={0}; // 8 sensors per SM
 
   for (int i=0; i<fTempArray->NumSensors(); i++) {
     
@@ -243,8 +253,10 @@ Double_t AliEMCALCalibTimeDep::GetTemperatureSM(int imod, UInt_t timeStamp) cons
          if ( fVerbosity > 0 ) {
            cout << " sensor i " << i << " val " << val << endl;
          }
-         average += val;
-         n++;
+         if (val>fMinTempValid && val<fMaxTempValid && n<8) { 
+           valArr[n] = val;
+           n++;
+         }
        }
       } // time
     }
@@ -252,8 +264,24 @@ Double_t AliEMCALCalibTimeDep::GetTemperatureSM(int imod, UInt_t timeStamp) cons
   } // loop over fTempArray
   
   if (n>0) { // some valid data was found
-    average /= n;
-    return average;
+    Double_t median = TMath::Median(n, valArr);
+    Double_t average = 0;
+    Int_t nval = 0;
+    for (int is=0; is<n; is++) {
+      if (TMath::Abs(valArr[is] - median) < kTempMaxDiffMedian) {
+       average += valArr[is];
+       nval++;
+      }
+    }
+    //cout << " n " << n << " nval " << nval << " median " << median << endl;
+    if (nval >  0) {
+      average /= nval;
+      //cout << " average " << average << endl; 
+      return average;
+    }
+    else { // this case should not happen, but kept for completeness (coverity etc)
+      return median;
+    }
   }
   else { // no good data
     return kErrorCode;
@@ -282,8 +310,13 @@ Int_t AliEMCALCalibTimeDep::CalcCorrection()
   // the run (compare max-min for each sensor separately)
   if (fMaxTempVariation < fTemperatureResolution) {
     nBins = 1; // just one bin needed..
+  }
+  if (nBins == 1) {    
     binSize = fEndTime - fStartTime;
   }
+  if (fVerbosity > 0) {
+    cout << " nBins " << nBins << " binSize " << binSize << endl;
+  }
 
   // set up a reasonable default (correction = 1.0)
   fCalibTimeDepCorrection = new AliEMCALCalibTimeDepCorrection(nSM);
@@ -311,7 +344,7 @@ Double_t AliEMCALCalibTimeDep::GetTempCoeff(Double_t IDark, Double_t M) const
   // from % numbers to regular ones..:
   dTC *= 0.01;
 
-  return fabs(dTC); // return the absolute value, to avoid any sign confusion
+  return TMath::Abs(dTC); // return the absolute value, to avoid any sign confusion
 }
 
 /* Next come the methods that do the work in picking up all the needed info..*/
@@ -369,17 +402,23 @@ Int_t AliEMCALCalibTimeDep::ScanTemperatureInfo()
       // min and max values within the single sensor
       Double_t min = 999;
       Double_t max = 0;
+      int nval = 0;
       for (int ip=0; ip<np; ip++) { 
-       if (min > y0[ip]) { min = y0[ip]; }
-       if (max < y0[ip]) { max = y0[ip]; }
+       if (y0[ip]>fMinTempValid && y0[ip]<fMaxTempValid) {
+         if (min > y0[ip]) { min = y0[ip]; }
+         if (max < y0[ip]) { max = y0[ip]; }
+         nval++;
+       }
+      }
+      if (nval>0) {
+       if (fMinTemp > min) { fMinTemp = min; }
+       if (fMaxTemp < max) { fMaxTemp = max; }
+       Double_t variation = max - min;
+       if (fMinTempVariation > variation) { fMinTempVariation = variation; }
+       if (fMaxTempVariation < variation) { fMaxTempVariation = variation; }
+       
+       n++;
       }
-      if (fMinTemp > min) { fMinTemp = min; }
-      if (fMaxTemp < max) { fMaxTemp = max; }
-      Double_t variation = max - min;
-      if (fMinTempVariation > variation) { fMinTempVariation = variation; }
-      if (fMaxTempVariation < variation) { fMaxTempVariation = variation; }
-
-      n++;
     }
   } // loop over fTempArray
   
@@ -816,12 +855,18 @@ Int_t AliEMCALCalibTimeDep::CalcTemperatureCorrection(Int_t nSM, Int_t nBins, In
     if (nVal>0) {
       referenceTemperature /= nVal; // valid values exist, we can look into corrections
       
+      Double_t dSMTemperature = 0;
       for (int j = 0; j < nBins; j++) {
        // what is the timestamp in the middle of this bin? (0.5 is for middle of bin)
        UInt_t timeStamp = fStartTime + (UInt_t)((j+0.5)*secondsPerBin);
       // 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)
-       Double_t dSMTemperature = GetTemperatureSM(iSM, timeStamp); 
-
+       Double_t oldSMTemperature = dSMTemperature;
+       dSMTemperature = GetTemperatureSM(iSM, timeStamp); 
+       if (j>0 && (dSMTemperature==kErrorCode)) { 
+         // if we have previous values, and retrieval of values failed - use that instead (hopefully good)
+         dSMTemperature = oldSMTemperature; 
+       }
        Double_t temperatureDiff = referenceTemperature - dSMTemperature; // ref - new
        if (fVerbosity > 0) {
          cout << " referenceTemperature " << referenceTemperature
@@ -836,8 +881,8 @@ Int_t AliEMCALCalibTimeDep::CalcTemperatureCorrection(Int_t nSM, Int_t nBins, In
        // i.e. the product temperatureDiff * dTempCoeff increase when the gain goes up
        // The correction we want to keep is what we should multiply our ADC value with as a function
        // of time, i.e. the inverse of the gain change..
-       if ( (fabs(temperatureDiff)>fTemperatureResolution)
-            && (fabs(temperatureDiff)<fMaxTemperatureDiff) ) {
+       if ( (TMath::Abs(temperatureDiff)>fTemperatureResolution)
+            && (TMath::Abs(temperatureDiff)<fMaxTemperatureDiff) ) {
          // significant enough difference that we need to consider it, and also not unreasonably large
 
          // loop over all towers; effect of temperature change will depend on gain for this tower