Project
Loading...
Searching...
No Matches
CellRecalibrator.h
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#ifndef ALCEO2_EMCAL_CELLRECALIBRATOR_H
12#define ALCEO2_EMCAL_CELLRECALIBRATOR_H
13
14#include <exception>
15#include <iosfwd>
16#include <optional>
17#include <vector>
18#include <tuple>
19#include <gsl/span>
20
21#include "Rtypes.h"
22
27
28namespace o2
29{
30
31namespace emcal
32{
33
61{
62 public:
65 class CellTypeException : public std::exception
66 {
67 public:
69 CellTypeException() = default;
70
72 ~CellTypeException() noexcept final = default;
73
76 const char* what() const noexcept final
77 {
78 return "Only possible to calibrate cells of type high gain or low gain";
79 }
80 };
81
83 CellRecalibrator() = default;
84
86 ~CellRecalibrator() = default;
87
90 void setBadChannelMap(const BadChannelMap* bcm) { mBadChannelMap = bcm; }
91
94 void setTimeCalibration(const TimeCalibrationParams* tcp) { mTimeCalibration = tcp; }
95
98 void setGainCalibration(const GainCalibrationFactors* gcf) { mGainCalibration = gcf; }
99
102 bool hasBadChannelMap() const { return mBadChannelMap != nullptr; }
103
106 bool hasTimeCalibration() const { return mTimeCalibration != nullptr; }
107
110 bool hasGainCalibration() const { return mGainCalibration != nullptr; }
111
114 const BadChannelMap* getBadChannelMap() const { return mBadChannelMap; }
115
118 const TimeCalibrationParams* getTimeCalibration() const { return mTimeCalibration; }
119
122 const GainCalibrationFactors* getGainCalibration() const { return mGainCalibration; }
123
134 template <typename T>
135 std::optional<T> getCalibratedCell(const T& inputcell) const
136 {
137 if (!(inputcell.getHighGain() || inputcell.getLowGain())) {
138 throw CellTypeException();
139 }
140 if (hasBadChannelMap()) {
141 if (mBadChannelMap->getChannelStatus(inputcell.getTower()) != BadChannelMap::MaskType_t::GOOD_CELL) {
142 return std::optional<T>();
143 }
144 }
145
146 float calibratedEnergy = inputcell.getEnergy();
147 float calibratedTime = inputcell.getTimeStamp();
148
149 if (hasTimeCalibration()) {
150 calibratedTime -= mTimeCalibration->getTimeCalibParam(inputcell.getTower(), inputcell.getLowGain());
151 }
152
153 if (hasGainCalibration()) {
154 calibratedEnergy *= mGainCalibration->getGainCalibFactors(inputcell.getTower());
155 }
156 return std::make_optional<T>(inputcell.getTower(), calibratedEnergy, calibratedTime, inputcell.getHighGain() ? ChannelType_t::HIGH_GAIN : ChannelType_t::LOW_GAIN);
157 }
158
168 template <typename T>
169 std::tuple<std::vector<T>, std::vector<int>> getCalibratedCells(const gsl::span<const T> inputcells)
170 {
171 std::vector<T> result;
172 std::vector<int> indices;
173 int currentindex = 0;
174 for (const auto& cellToCalibrate : inputcells) {
175 if (!(cellToCalibrate.getHighGain() || cellToCalibrate.getLowGain())) {
176 currentindex++;
177 continue;
178 }
179 auto calibrated = getCalibratedCell(cellToCalibrate);
180 if (calibrated) {
181 result.push_back(calibrated.value());
182 indices.emplace_back(currentindex);
183 }
184 currentindex++;
185 }
186 return std::make_tuple(result, indices);
187 }
188
191 void printStream(std::ostream& stream) const;
192
193 private:
194 const BadChannelMap* mBadChannelMap = nullptr;
195 const TimeCalibrationParams* mTimeCalibration = nullptr;
196 const GainCalibrationFactors* mGainCalibration = nullptr;
197
198 ClassDefNV(CellRecalibrator, 1);
199};
200
205std::ostream& operator<<(std::ostream& in, const CellRecalibrator& calib);
206
207} // namespace emcal
208
209} // namespace o2
210
211#endif // !ALCEO2_EMCAL_CELLRECALIBRATOR_H
CCDB container for masked cells in EMCAL.
MaskType_t getChannelStatus(unsigned short channelID) const
Get the status of a certain cell.
@ GOOD_CELL
GOOD cell, can be used without problems.
Handling of invalid cell types in calibration.
~CellTypeException() noexcept final=default
Destructor.
const char * what() const noexcept final
Get error message of the exception.
Tool for recalibration at cell level.
bool hasBadChannelMap() const
Check if the bad channel calibration is enabled.
std::tuple< std::vector< T >, std::vector< int > > getCalibratedCells(const gsl::span< const T > inputcells)
Get list of calibrated cells based on a cell input collection.
const TimeCalibrationParams * getTimeCalibration() const
Get time calibration parameters currently used in the calibrator.
const BadChannelMap * getBadChannelMap() const
Get bad channel map currently used in the calibrator.
void setGainCalibration(const GainCalibrationFactors *gcf)
Set the gain calibration params.
void setTimeCalibration(const TimeCalibrationParams *tcp)
Set the time calibration params.
void printStream(std::ostream &stream) const
Print settings to the stream.
~CellRecalibrator()=default
Destructor.
void setBadChannelMap(const BadChannelMap *bcm)
Set the bad channel map.
std::optional< T > getCalibratedCell(const T &inputcell) const
Calibrate single cell.
const GainCalibrationFactors * getGainCalibration() const
Get gain calibration factors currently used in the calibrator.
bool hasGainCalibration() const
Check if the energy calibration is enabled.
CellRecalibrator()=default
Constructor.
bool hasTimeCalibration() const
Check if the time calibration is enabled.
CCDB container for the gain calibration factors.
float getGainCalibFactors(unsigned short iCell) const
Get the gain calibration factor for a certain cell.
short getTimeCalibParam(unsigned short cellID, bool isLowGain) const
Get the time calibration coefficient for a certain cell.
GLuint64EXT * result
Definition glcorearb.h:5662
GLsizei GLenum const void * indices
Definition glcorearb.h:400
GLuint GLuint stream
Definition glcorearb.h:1806
std::ostream & operator<<(std::ostream &stream, const Cell &cell)
Stream operator for EMCAL cell.
Definition Cell.cxx:355
@ HIGH_GAIN
High gain channel.
Definition Constants.h:35
@ LOW_GAIN
Low gain channel.
Definition Constants.h:34
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...