25 #include "CLHEP/Random/RandGauss.h"
60 std::unique_ptr<SiStripApvGain>
getNewObject(
const std::map<std::pair<uint32_t, int>,
float>& theMap);
83 m_gainType{iConfig.getUntrackedParameter<uint32_t>(
"gainType", 1)},
84 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
85 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")},
90 std::string ss_gain = (m_gainType > 0) ?
"G2" :
"G1";
92 scale_map = std::make_unique<TrackerMap>(
"scale");
93 scale_map->setTitle(
"Scale factor averaged by module");
94 scale_map->setPalette(1);
96 smear_map = std::make_unique<TrackerMap>(
"smear");
97 smear_map->setTitle(
"Smear factor averaged by module");
98 smear_map->setPalette(1);
100 ratio_map = std::make_unique<TrackerMap>(
"ratio");
101 ratio_map->setTitle(
"Average by module of the " + ss_gain +
" Gain payload ratio (new/old)");
102 ratio_map->setPalette(1);
104 new_payload_map = std::make_unique<TrackerMap>(
"new_payload");
105 new_payload_map->setTitle(
"Tracker Map of Modified " + ss_gain +
" Gain payload averaged by module");
106 new_payload_map->setPalette(1);
108 old_payload_map = std::make_unique<TrackerMap>(
"old_payload");
109 old_payload_map->setTitle(
"Tracker Map of Starting " + ss_gain +
" Gain Payload averaged by module");
110 old_payload_map->setPalette(1);
136 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
142 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
143 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
144 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
145 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
148 params.setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
154 std::map<std::pair<uint32_t, int>,
float> theMap, oldPayloadMap;
156 std::vector<uint32_t> detid;
157 apvGain.getDetIds(detid);
158 for (
const auto&
d : detid) {
169 for (
unsigned int j = 0;
j <
regions.size();
j++) {
170 bool checkRegion = (mapOfSmearings.count(
regions[
j]) != 0);
185 for (
int it = 0; it <
range.second -
range.first; it++) {
187 float Gain = apvGain.getApvGain(it,
range);
188 std::pair<uint32_t, int>
index = std::make_pair(
d, nAPV);
197 float smearedGain = CLHEP::RandGauss::shoot(
Gain,
params.m_smearFactor);
206 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(theMap);
209 uint32_t cachedId(0);
213 for (
const auto& element : theMap) {
214 uint32_t
DetId = element.first.first;
215 int nAPV = element.first.second;
216 float new_gain = element.second;
217 float old_gain = oldPayloadMap[std::make_pair(
DetId, nAPV)];
220 if (cachedId != 0 &&
DetId != cachedId) {
233 gain_ratio.
add(new_gain / old_gain);
234 o_gain.
add(old_gain);
235 n_gain.
add(new_gain);
244 throw std::runtime_error(
"PoolDBService required.");
255 scale_map->save(
true, 0, 0, ss_gain +
"_gain_scale_map.pdf");
256 scale_map->save(
true, 0, 0, ss_gain +
"_gain_scale_map.png");
258 smear_map->save(
true, 0, 0, ss_gain +
"_gain_smear_map.pdf");
259 smear_map->save(
true, 0, 0, ss_gain +
"_gain_smear_map.png");
261 ratio_map->save(
true, 0, 0, ss_gain +
"_gain_ratio_map.pdf");
262 ratio_map->save(
true, 0, 0, ss_gain +
"_gain_ratio_map.png");
278 const std::map<std::pair<uint32_t, int>,
float>& theMap) {
279 std::unique_ptr<SiStripApvGain>
obj = std::make_unique<SiStripApvGain>();
281 std::vector<float> theSiStripVector;
282 uint32_t PreviousDetId = 0;
283 for (
const auto& element : theMap) {
284 uint32_t
DetId = element.first.first;
285 if (
DetId != PreviousDetId) {
286 if (!theSiStripVector.empty()) {
288 if (!
obj->put(PreviousDetId,
range))
289 printf(
"Bug to put detId = %i\n", PreviousDetId);
291 theSiStripVector.clear();
292 PreviousDetId =
DetId;
294 theSiStripVector.push_back(element.second);
297 <<
" DetId: " <<
DetId <<
" APV: " << element.first.second <<
" Gain: " << element.second << std::endl;
300 if (!theSiStripVector.empty()) {
302 if (!
obj->put(PreviousDetId,
range))
303 printf(
"Bug to put detId = %i\n", PreviousDetId);
314 "Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2."
315 "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
319 "ParameterSet specifying the Strip tracker partition to be scaled / smeared "
320 "by a given factor.");
323 descScaler.
add<
bool>(
"doScale",
true);
324 descScaler.
add<
bool>(
"doSmear",
true);
325 descScaler.
add<
double>(
"scaleFactor", 1.0);
326 descScaler.
add<
double>(
"smearFactor", 1.0);
327 desc.addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
330 desc.addUntracked<
unsigned int>(
"gainType", 1);
331 desc.addUntracked<
bool>(
"saveMaps",
true);
333 descriptions.
add(
"scaleAndSmearSiStripGains",
desc);