29 mToleratedGapWidth = toleratedGapWidth;
30 mZSnSigmas = nSigmasZS;
31 mSuspiciousPedestalRMS = suspiciousPedestalRMS;
37 mNEntries += rhs.mNEntries;
38 for (
auto iAmpl = rhs.mSpectrumContainer.begin(); iAmpl != rhs.mSpectrumContainer.end(); iAmpl++) {
39 mSpectrumContainer[iAmpl->first] += iAmpl->second;
46 mSpectrumContainer[amplitude]++;
53void PedestalSpectrum::analyze()
81 std::vector<uint16_t> peakLowEdge, peakHighEdge;
82 peakLowEdge.push_back(mSpectrumContainer.begin()->first);
83 peakHighEdge.push_back((--mSpectrumContainer.end())->first);
84 uint32_t peakCounts(0), totalCounts(0);
85 float peakSumA(0.), peakSumA2(0.), totalSumA(0.), totalSumA2(0.);
88 auto iNextAmpl = mSpectrumContainer.begin();
90 for (
auto iAmpl = mSpectrumContainer.begin(); iAmpl != mSpectrumContainer.end(); iAmpl++, iNextAmpl++) {
91 peakCounts += iAmpl->second;
92 totalCounts += iAmpl->second;
93 peakSumA += iAmpl->first * iAmpl->second;
94 peakSumA2 += (iAmpl->first * iAmpl->first) * iAmpl->second;
95 totalSumA += iAmpl->first * iAmpl->second;
96 totalSumA2 += (iAmpl->first * iAmpl->first) * iAmpl->second;
98 if (iNextAmpl != mSpectrumContainer.end()) {
99 if ((iNextAmpl->first - iAmpl->first) > mToleratedGapWidth) {
101 peakHighEdge.push_back(iAmpl->first);
102 peakLowEdge.push_back(iNextAmpl->first);
104 mMeanOfPeaks.push_back(peakSumA / peakCounts);
105 mRMSOfPeaks.push_back(sqrt(peakSumA2 / peakCounts - mMeanOfPeaks.back() * mMeanOfPeaks.back()));
106 mPeakCounts.push_back(peakCounts);
112 peakHighEdge.push_back(iAmpl->first);
113 mMeanOfPeaks.push_back(peakSumA / peakCounts);
114 mRMSOfPeaks.push_back(sqrt(peakSumA2 / peakCounts - mMeanOfPeaks.back() * mMeanOfPeaks.back()));
115 mPeakCounts.push_back(peakCounts);
120 mMeanOfPeaks.push_back(totalSumA / totalCounts);
121 mRMSOfPeaks.push_back(sqrt(totalSumA2 / totalCounts - mMeanOfPeaks.back() * mMeanOfPeaks.back()));
122 mPeakCounts.push_back(totalCounts);
126 mPedestalValue = mMeanOfPeaks.back();
127 mPedestalRMS = mRMSOfPeaks.back();
128 }
else if (mNPeaks > 1) {
129 uint16_t iPeakWithMaxStat = 0;
130 for (
auto i = 0;
i < mNPeaks;
i++) {
131 if (mPeakCounts[iPeakWithMaxStat] < mPeakCounts[
i]) {
132 iPeakWithMaxStat =
i;
135 mPedestalValue = mMeanOfPeaks[iPeakWithMaxStat];
136 mPedestalRMS = mRMSOfPeaks[iPeakWithMaxStat];
154 if (iPeak > mNPeaks) {
155 return mMeanOfPeaks.back();
157 return mMeanOfPeaks.at(iPeak);
166 if (iPeak > mNPeaks) {
167 return mRMSOfPeaks.back();
169 return mRMSOfPeaks.at(iPeak);
178 return mPedestalValue;
196 mPedestalSpectra.emplace_back(toleratedGapWidth, nSigmasZS, suspiciousPedestalRMS);
202 for (
auto& dig :
digits) {
214 LOG(info) <<
"Merged TimeSlot with previous one. Now we have " <<
mNEvents <<
" events.";
219 LOG(info) <<
"PedestalCalibData::mNEvents = " <<
mNEvents;
226 LOG(info) <<
"PedestalCalibrator::PedestalCalibrator() : pedestal calibrator created!";
232 mMinEvents = cpvParams.pedMinEvents;
233 mZSnSigmas = cpvParams.pedZSnSigmas;
234 mToleratedGapWidth = cpvParams.pedToleratedGapWidth;
235 mZSnSigmas = cpvParams.pedZSnSigmas;
236 mSuspiciousPedestalRMS = cpvParams.pedSuspiciousPedestalRMS;
237 LOG(info) <<
"PedestalCalibrator::configParameters() : following parameters configured:";
238 LOG(info) <<
"mMinEvents = " << mMinEvents;
239 LOG(info) <<
"mZSnSigmas = " << mZSnSigmas;
240 LOG(info) <<
"mToleratedGapWidth = " << mToleratedGapWidth;
241 LOG(info) <<
"mZSnSigmas = " << mZSnSigmas;
242 LOG(info) <<
"mSuspiciousPedestalRMS = " << mSuspiciousPedestalRMS;
247 mCcdbInfoPedestalsVec.clear();
248 mPedestalsVec.clear();
249 mCcdbInfoDeadChannelsVec.clear();
250 mDeadChannelsVec.clear();
251 mCcdbInfoHighPedChannelsVec.clear();
252 mHighPedChannelsVec.clear();
253 mCcdbInfoThresholdsFEEVec.clear();
254 mThresholdsFEEVec.clear();
255 mCcdbInfoPedEfficienciesVec.clear();
256 mPedEfficienciesVec.clear();
262 LOG(info) <<
"PedestalCalibrator::finalizeSlot() : finalizing slot "
273 std::vector<float> efficiencies;
274 std::vector<int> deadChannels;
275 std::vector<int> thresholdsFEE;
276 std::vector<int> highPedChannels;
278 short ccId, dil, gas, pad, ped, threshold;
280 float sigma, efficiency;
291 efficiencies.push_back(efficiency);
294 if (efficiency == 0.0) {
295 deadChannels.push_back(
i);
299 threshold = ped + std::floor(sigma * mZSnSigmas) + 1;
300 if (threshold > 511) {
302 highPedChannels.push_back(
i);
305 addr = ccId * 4 * 5 * 64 + dil * 5 * 64 + gas * 64 + pad;
306 adrThr = (addr << 16) + threshold;
308 thresholdsFEE.push_back(adrThr);
311 mPedestalsVec.push_back(*peds);
312 mPedEfficienciesVec.push_back(efficiencies);
313 mDeadChannelsVec.push_back(deadChannels);
314 mThresholdsFEEVec.push_back(thresholdsFEE);
315 mThresholdsFEEVec.push_back(thresholdsFEE);
316 mHighPedChannelsVec.push_back(highPedChannels);
319 std::map<std::string, std::string> metaData;
323 mCcdbInfoPedestalsVec.emplace_back(
"CPV/Calib/Pedestals", className, fileName, metaData, timeStamp, timeStamp + 31536000000);
328 mCcdbInfoPedEfficienciesVec.emplace_back(
"CPV/PedestalRun/ChannelEfficiencies", className, fileName, metaData, timeStamp, timeStamp + 31536000000);
333 mCcdbInfoDeadChannelsVec.emplace_back(
"CPV/PedestalRun/DeadChannels", className, fileName, metaData, timeStamp, timeStamp + 31536000000);
338 mCcdbInfoThresholdsFEEVec.emplace_back(
"CPV/PedestalRun/FEEThresholds", className, fileName, metaData, timeStamp, timeStamp + 31536000000);
340 mCcdbInfoThresholdsFEEVec.emplace_back(
"CPV/PedestalRun/FEEThresholds", className, fileName, metaData, timeStamp, timeStamp + 31536000000);
345 mCcdbInfoHighPedChannelsVec.emplace_back(
"CPV/PedestalRun/HighPedChannels", className, fileName, metaData, timeStamp, timeStamp + 31536000000);
351 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
352 slot.setContainer(std::make_unique<PedestalCalibData>());
Utils and constants for calibration and related workflows.
o2::calibration::TFType TFType
const Container * getContainer() const
TFType getTFStart() const
static std::string generateFileName(const std::string &inp)
static const CPVCalibParams & Instance()
static constexpr short kNCHANNELS
static bool absIdToHWaddress(unsigned short absId, short &ccId, short &dil, short &gas, short &pad)
PedestalTimeSlot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
void finalizeSlot(PedestalTimeSlot &slot) final
void fill(uint16_t amplitude)
PedestalSpectrum & operator+=(const PedestalSpectrum &rhs)
float getPeakMean(uint16_t iPeak)
float getPeakRMS(uint16_t iPeak)
PedestalSpectrum(uint16_t toleratedGapWidth=5, float nSigmasZS=3., float suspiciousPedestalRMS=20.)
void setPedestal(short cellID, short c)
Set pedestal.
void setPedSigma(short cellID, float c)
long getCurrentTimestamp()
returns the timestamp in long corresponding to "now"
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void fill(const gsl::span< const o2::cpv::Digit > data)
std::vector< PedestalSpectrum > mPedestalSpectra
PedestalCalibData(uint16_t toleratedGapWidth=5, float nSigmasZS=3., float suspiciousPedestalRMS=20.)
void merge(const PedestalCalibData *prev)
static std::string getClassName(const T &obj)
get the class name of the object
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::vector< Digit > digits