72 void init(
double conversionFactor,
double conversionFactorL1,
double offset,
double offsetL1) {
105 template <
class tokenType,
class PayloadType>
130 : recordName_(iConfig.getParameter<std::
string>(
"record")),
131 isForHLT_(iConfig.getParameter<bool>(
"isForHLT")),
132 verbose_(iConfig.getUntrackedParameter<bool>(
"verbose",
false)),
140 const unsigned int phase(thePSet.getParameter<
unsigned int>(
"phase"));
144 thePSet.getParameter<
double>(
"conversionFactorL1"),
145 thePSet.getParameter<
double>(
"offset"),
146 thePSet.getParameter<
double>(
"offsetL1"));
151 thePSet.getParameter<
double>(
"conversionFactorL1"),
152 thePSet.getParameter<
double>(
"offset"),
153 thePSet.getParameter<
double>(
"offsetL1"));
157 throw cms::Exception(
"LogicError") <<
"Unrecongnized phase: " << phase <<
". Exiting!";
177 edm::LogPrint(
"SiPixelGainCalibScaler") <<
" Pixel Gains have a new IOV for run: " <<
run << std::endl;
180 computeAndStorePalyoads<edm::ESGetToken<SiPixelGainCalibrationForHLT, SiPixelGainCalibrationForHLTRcd>,
183 computeAndStorePalyoads<edm::ESGetToken<SiPixelGainCalibrationOffline, SiPixelGainCalibrationOfflineRcd>,
190 template <
class tokenType,
class PayloadType>
198 edm::LogInfo(
"SiPixelGainCalibScaler") <<
"There are: " << pDD->
dets().size() <<
" detectors";
203 edm::LogInfo(
"SiPixelGainCalibScaler") <<
" ==> This is a phase1 IOV";
206 edm::LogInfo(
"SiPixelGainCalibScaler") <<
" ==> This is a phase0 IOV";
213 std::vector<uint32_t> detids;
216 float mingain =
payload->getGainLow();
218 float minped =
payload->getPedLow();
219 float maxped =
payload->getPedHigh() * 1.10;
221 PayloadType SiPixelGainCalibration_(minped, maxped, mingain, maxgain);
230 for (
const auto&
d : detids) {
231 bool isLayer1 =
false;
240 std::vector<char> theSiPixelGainCalibration;
243 int numberOfRowsToAverageOver =
payload->getNumberOfRowsToAverageOver();
245 int nRocsInRow = (
range.second -
range.first) / ncols / numberOfRowsToAverageOver;
246 unsigned int nRowsForHLT = 1;
247 int nrows =
std::max((
payload->getNumberOfRowsToAverageOver() * nRocsInRow),
250 auto rangeAndCol =
payload->getRangeAndNCols(
d);
256 <<
"NCOLS: " <<
payload->getNCols(
d) <<
" " << rangeAndCol.second <<
" NROWS:" << nrows
257 <<
", RANGES: " << rangeAndCol.first.second - rangeAndCol.first.first
258 <<
", Ratio: " << float(rangeAndCol.first.second - rangeAndCol.first.first) / rangeAndCol.second << std::endl;
262 for (
int row = 0; row < nrows; row++) {
263 float gain =
payload->getGain(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
264 float ped =
payload->getPed(
col, row, rangeAndCol.first, rangeAndCol.second, isDeadColumn, isNoisyColumn);
267 edm::LogInfo(
"SiPixelGainCalibScaler") <<
"pre-change gain: " << gain <<
" pede:" << ped << std::endl;
295 ped = ped - myVCalInfo.
getOffset() / gain;
299 edm::LogInfo(
"SiPixelGainCalibScaler") <<
"post-change gain: " << gain <<
" pede:" << ped << std::endl;
301 if constexpr (std::is_same_v<PayloadType, SiPixelGainCalibrationForHLT>) {
302 SiPixelGainCalibration_.setData(ped, gain, theSiPixelGainCalibration,
false,
false);
304 SiPixelGainCalibration_.setDataPedestal(ped, theSiPixelGainCalibration);
305 if ((row + 1) % numberOfRowsToAverageOver == 0) {
306 SiPixelGainCalibration_.setDataGain(gain, numberOfRowsToAverageOver, theSiPixelGainCalibration);
312 typename PayloadType::Range outrange(theSiPixelGainCalibration.begin(), theSiPixelGainCalibration.end());
313 if (!SiPixelGainCalibration_.put(
d, outrange, ncols))
314 edm::LogError(
"SiPixelGainCalibScaler") <<
"[SiPixelGainCalibScaler::analyze] detid already exists" << std::endl;
337 edm::LogError(
"SiPixelGainCalibScaler") <<
"caught std::exception " << er.what() << std::endl;
339 edm::LogError(
"SiPixelGainCalibScaler") <<
"Funny error" << std::endl;
352 desc.
add<
std::string>(
"record",
"SiPixelGainCalibrationForHLTRcd");
353 desc.
add<
bool>(
"isForHLT",
true);
356 vcalInfos.
add<
unsigned int>(
"phase");
357 vcalInfos.add<
double>(
"conversionFactor");
358 vcalInfos.add<
double>(
"conversionFactorL1");
359 vcalInfos.add<
double>(
"offset");
360 vcalInfos.add<
double>(
"offsetL1");
362 std::vector<edm::ParameterSet>
tmp;
367 phase0VCal.
addParameter<
double>(
"conversionFactor", 65.);
368 phase0VCal.
addParameter<
double>(
"conversionFactorL1", 65.);
371 tmp.push_back(phase0VCal);
376 phase1VCal.
addParameter<
double>(
"conversionFactor", 47.);
377 phase1VCal.
addParameter<
double>(
"conversionFactorL1", 50.);
380 tmp.push_back(phase1VCal);
382 desc.
addVPSet(
"parameters", vcalInfos, tmp);
386 descriptions.
add(
"siPixelGainCalibScaler", desc);
Log< level::Info, true > LogVerbatim
~SiPixelGainCalibScaler() override
Base exception class for the object to relational access.
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
const std::string recordName_
void analyze(const edm::Event &, const edm::EventSetup &) override
PixelRecoRange< float > Range
#define DEFINE_FWK_MODULE(type)
double m_conversionFactor
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
void computeAndStorePalyoads(const edm::EventSetup &iSetup, const tokenType &token)
const std::vector< edm::ParameterSet > m_parameters
Log< level::Error, false > LogError
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
constexpr std::array< uint8_t, layerIndexSize > layer
const uint16_t range(const Frame &aFrame)
edm::ESWatcher< SiPixelGainCalibrationOfflineRcd > pixelOfflineGainWatcher_
bool isThere(GeomDetEnumerators::SubDetector subdet) const
bool getData(T &iHolder) const
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
double getConversionFactor()
double getConversionFactorL1()
bool isNewTagRequest(const std::string &recordName)
cond::Time_t beginOfTime() const
void addParameter(std::string const &name, T const &value)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
char const * what() const noexceptoverride
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Warning, true > LogPrint
unsigned int pxbLayer(const DetId &id) const
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
Log< level::Info, false > LogInfo
gainScale::VCalInfo phase0VCal
edm::ESGetToken< SiPixelGainCalibrationOffline, SiPixelGainCalibrationOfflineRcd > gainOfflineCalibToken_
gainScale::VCalInfo phase1VCal
edm::ESWatcher< SiPixelGainCalibrationForHLTRcd > pixelHLTGainWatcher_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tkTopoToken_
edm::ESGetToken< SiPixelGainCalibrationForHLT, SiPixelGainCalibrationForHLTRcd > gainHLTCalibToken_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool check(const edm::EventSetup &iSetup)
void init(double conversionFactor, double conversionFactorL1, double offset, double offsetL1)
cond::Time_t currentTime() const
SiPixelGainCalibScaler(const edm::ParameterSet &)
double m_conversionFactorL1
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)