25 #include "CLHEP/Random/RandGauss.h"
60 std::unique_ptr<SiStripApvGain>
getNewObject(
const std::map<std::pair<uint32_t, int>,
float>& theMap);
81 m_gainType{iConfig.getUntrackedParameter<uint32_t>(
"gainType", 1)},
82 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
83 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")} {
86 std::string ss_gain = (m_gainType > 0) ?
"G2" :
"G1";
88 scale_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"scale"));
89 scale_map->setTitle(
"Scale factor averaged by module");
90 scale_map->setPalette(1);
92 smear_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"smear"));
93 smear_map->setTitle(
"Smear factor averaged by module");
94 smear_map->setPalette(1);
96 ratio_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"ratio"));
97 ratio_map->setTitle(
"Average by module of the " + ss_gain +
" Gain payload ratio (new/old)");
98 ratio_map->setPalette(1);
100 new_payload_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"new_payload"));
101 new_payload_map->setTitle(
"Tracker Map of Modified " + ss_gain +
" Gain payload averaged by module");
102 new_payload_map->setPalette(1);
104 old_payload_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"old_payload"));
105 old_payload_map->setTitle(
"Tracker Map of Starting " + ss_gain +
" Gain Payload averaged by module");
106 old_payload_map->setPalette(1);
121 const auto*
const tTopo = tTopoHandle.
product();
134 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
140 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
141 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
142 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
143 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
146 params.setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
153 std::map<std::pair<uint32_t, int>,
float> theMap, oldPayloadMap;
155 std::vector<uint32_t> detid;
157 for (
const auto&
d : detid) {
168 for (
unsigned int j = 0;
j <
regions.size();
j++) {
169 bool checkRegion = (mapOfSmearings.count(
regions[
j]) != 0);
184 for (
int it = 0; it <
range.second -
range.first; it++) {
187 std::pair<uint32_t, int>
index = std::make_pair(
d, nAPV);
196 float smearedGain = CLHEP::RandGauss::shoot(
Gain,
params.m_smearFactor);
205 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(theMap);
208 uint32_t cachedId(0);
212 for (
const auto& element : theMap) {
213 uint32_t
DetId = element.first.first;
214 int nAPV = element.first.second;
215 float new_gain = element.second;
216 float old_gain = oldPayloadMap[std::make_pair(
DetId, nAPV)];
219 if (cachedId != 0 &&
DetId != cachedId) {
232 gain_ratio.
add(new_gain / old_gain);
233 o_gain.
add(old_gain);
234 n_gain.
add(new_gain);
243 throw std::runtime_error(
"PoolDBService required.");
254 scale_map->save(
true, 0, 0, ss_gain +
"_gain_scale_map.pdf");
255 scale_map->save(
true, 0, 0, ss_gain +
"_gain_scale_map.png");
257 smear_map->save(
true, 0, 0, ss_gain +
"_gain_smear_map.pdf");
258 smear_map->save(
true, 0, 0, ss_gain +
"_gain_smear_map.png");
260 ratio_map->save(
true, 0, 0, ss_gain +
"_gain_ratio_map.pdf");
261 ratio_map->save(
true, 0, 0, ss_gain +
"_gain_ratio_map.png");
277 const std::map<std::pair<uint32_t, int>,
float>& theMap) {
278 std::unique_ptr<SiStripApvGain>
obj = std::unique_ptr<SiStripApvGain>(
new SiStripApvGain());
280 std::vector<float> theSiStripVector;
281 uint32_t PreviousDetId = 0;
282 for (
const auto& element : theMap) {
283 uint32_t
DetId = element.first.first;
284 if (
DetId != PreviousDetId) {
285 if (!theSiStripVector.empty()) {
287 if (!
obj->put(PreviousDetId,
range))
288 printf(
"Bug to put detId = %i\n", PreviousDetId);
290 theSiStripVector.clear();
291 PreviousDetId =
DetId;
293 theSiStripVector.push_back(element.second);
296 <<
" DetId: " <<
DetId <<
" APV: " << element.first.second <<
" Gain: " << element.second << std::endl;
299 if (!theSiStripVector.empty()) {
301 if (!
obj->put(PreviousDetId,
range))
302 printf(
"Bug to put detId = %i\n", PreviousDetId);
313 "Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2."
314 "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
318 "ParameterSet specifying the Strip tracker partition to be scaled / smeared "
319 "by a given factor.");
322 descScaler.
add<
bool>(
"doScale",
true);
323 descScaler.
add<
bool>(
"doSmear",
true);
324 descScaler.
add<
double>(
"scaleFactor", 1.0);
325 descScaler.
add<
double>(
"smearFactor", 1.0);
326 desc.
addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
332 descriptions.
add(
"scaleAndSmearSiStripGains", desc);