Project
Loading...
Searching...
No Matches
EMCALTempCalibExtractor.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include "EMCALCalib/CalibDB.h"
14#include "CCDB/CcdbApi.h"
16#include <numeric>
17
18namespace o2
19{
20namespace emcal
21{
22
23void EMCALTempCalibExtractor::InitializeFromCCDB(std::string path, uint64_t timestamp)
24{
25
27 uint64_t maxRunNr = 1000000;
28 if (timestamp < maxRunNr) {
29 LOG(info) << "assuming input is run " << timestamp << " will convert it to timstamp";
30 auto [sor, eor] = ccdbMgr.getRunDuration(timestamp);
31 uint64_t sixtySec = 60000;
32 timestamp = eor - sixtySec; // safety margin of 1min at EOR
33 LOG(info) << "set timestamp to " << timestamp;
34 }
35
36 o2::emcal::CalibDB calibdb("http://alice-ccdb.cern.ch");
37 std::map<std::string, std::string> metadata;
38 auto tempSensorData = calibdb.readTemperatureSensorData(timestamp, metadata);
39
40 // also obtain cell dependent correction factors
41 TempCalibrationParams* params = ccdbMgr.getForTimeStamp<o2::emcal::TempCalibrationParams>(path, timestamp);
42
43 std::map<unsigned short, float> mapSMTemperature;
44 for (unsigned short i = 0; i < mNCells; ++i) {
45 const unsigned short iSM = mGeometry->GetSuperModuleNumber(i);
46 if (mapSMTemperature.count(iSM) == 0) {
47 mapSMTemperature[iSM] = getTemperatureForSM(iSM, tempSensorData);
48 }
49 float corrFac = params->getTempCalibParamA0(i) + params->getTempCalibParamSlope(i) * mapSMTemperature[iSM];
50 mGainCalibFactors[i] = corrFac;
51 }
52}
53
55{
56 if (iSM < 0 || iSM > 20) {
57 LOG(error) << "SM " << iSM << "does not exist!"; // could be replaced with a proper exception
58 return 0.;
59 }
60 std::vector<unsigned short> vecSensorID = getSensorsForSM(iSM);
61
62 // Obtain temperature for these sensors
63 std::vector<float> vecTemperature;
64 for (const auto& iSensor : vecSensorID) {
65 float temp = ElmbData->getMean(iSensor);
66 if (temp < mAcceptedTempRange[0] || temp > mAcceptedTempRange[1]) {
67 continue;
68 }
69 vecTemperature.push_back(temp);
70 }
71
72 const unsigned int nEntries = vecTemperature.size();
73 if (nEntries == 0) {
74 LOG(warning) << "No sensor data between " << mAcceptedTempRange[0] << " and " << mAcceptedTempRange[1] << "degree found... for SM " << iSM << " Setting to default 20 degree";
75 return 20.; //
76 }
77
78 // get median energy
79 float tempSM = 0.;
80 if (mUseMedian) {
81 std::sort(vecTemperature.begin(), vecTemperature.end());
82 if (nEntries % 2 == 0) {
83 // even number of elements: average the two middle ones
84 tempSM = (vecTemperature[nEntries / 2 - 1] + vecTemperature[nEntries / 2]) / 2.0;
85 } else {
86 // odd number of elements: return the middle one
87 tempSM = vecTemperature[nEntries / 2];
88 }
89 } else { // use Mean temperature
90 float sum = std::accumulate(vecTemperature.begin(), vecTemperature.end(), 0.0);
91 tempSM = sum / vecTemperature.size();
92 }
93 return tempSM;
94}
95
96float EMCALTempCalibExtractor::getGainCalibFactor(const unsigned short cellID) const
97{
98 if (cellID >= mNCells) {
99 LOG(error) << "cell ID" << cellID << " does not exist";
100 return 1.;
101 }
102 return mGainCalibFactors[cellID];
103}
104
105std::vector<unsigned short> EMCALTempCalibExtractor::getSensorsForSM(const unsigned short iSM) const
106{
107 unsigned short nSensors = 8;
108 if (iSM == 10 || iSM == 11 || iSM == 18 || iSM == 19) { // 1/3 SM of EMCal only have 4 sensors
109 nSensors = 4;
110 }
111
112 std::vector<unsigned short> vecSensorID;
113 for (unsigned short iELMBSensor = iSM * 8; iELMBSensor < iSM * 8 + nSensors; iELMBSensor++) {
114 vecSensorID.push_back(iELMBSensor);
115 }
116 return vecSensorID;
117}
118
120{
121 mAcceptedTempRange[0] = low;
122 mAcceptedTempRange[1] = high;
123}
124
125} // namespace emcal
126
127} // namespace o2
int32_t i
static BasicCCDBManager & instance()
Interface to calibration data from CCDB for EMCAL.
Definition CalibDB.h:68
ElmbData * readTemperatureSensorData(ULong_t timestamp, const std::map< std::string, std::string > &metadata)
Find Temperature Sensor data in the CCDB for given timestamp.
Definition CalibDB.cxx:215
float getTemperatureForSM(const unsigned short iSM, o2::emcal::ElmbData *ElmbData) const
get average temperature in a supermodule
std::vector< unsigned short > getSensorsForSM(const unsigned short iSM) const
get sensor IDs for a specific supermodule
void setAcceptedEnergyRange(float low, float high)
set temperature range in which sensor ddata is assumed to be good
float getGainCalibFactor(const unsigned short cellID) const
get gain calibration factor depending on the temperature and the slope of the cell
void InitializeFromCCDB(std::string path, uint64_t timestamp)
Initialize temperature data and slope for each cell from the ccdb.
float getMean(short iSensor)
Definition ElmbData.h:44
Int_t GetSuperModuleNumber(Int_t absId) const
Get cell SM, from absolute ID number.
float sum(float s, o2::dcs::DataPointValue v)
Definition dcs-ccdb.cxx:39
GLenum const GLfloat * params
Definition glcorearb.h:272
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"