26 #include "CLHEP/Random/RandGauss.h"
61 std::unique_ptr<SiStripNoises>
getNewObject(
const std::map<std::pair<uint32_t, int>,
float>& theMap);
63 const float theDefault);
87 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
88 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")},
95 scale_map = std::make_unique<TrackerMap>(
"scale");
96 scale_map->setTitle(
"Tracker Map of Scale factor averaged by module");
97 scale_map->setPalette(1);
99 smear_map = std::make_unique<TrackerMap>(
"smear");
100 smear_map->setTitle(
"Tracker Map of Smear factor averaged by module");
101 smear_map->setPalette(1);
103 old_payload_map = std::make_unique<TrackerMap>(
"old_payload");
104 old_payload_map->setTitle(
"Tracker Map of Starting Noise Payload averaged by module");
105 old_payload_map->setPalette(1);
107 new_payload_map = std::make_unique<TrackerMap>(
"new_payload");
108 new_payload_map->setTitle(
"Tracker Map of Modified Noise Payload averaged by module");
109 new_payload_map->setPalette(1);
111 ratio_map = std::make_unique<TrackerMap>(
"ratio");
112 ratio_map->setTitle(
"Tracker Map of Average by module of the payload ratio (new/old)");
113 ratio_map->setPalette(1);
115 if (m_fillDefaults) {
116 missing_map = std::make_unique<TrackerMap>(
"uncabled");
117 missing_map->setTitle(
"Tracker Map of uncabled modules");
118 missing_map->setPalette(1);
145 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
151 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
152 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
153 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
154 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
157 params.setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
163 std::map<std::pair<uint32_t, int>,
float> theMap, oldPayloadMap;
165 std::vector<uint32_t> detid;
166 stripNoises.getDetIds(detid);
167 for (
const auto&
d : detid) {
177 for (
unsigned int j = 0;
j <
regions.size();
j++) {
178 bool checkRegion = (mapOfSmearings.count(
regions[
j]) != 0);
194 for (
int it = 0; it < (
range.second -
range.first) * 8 / 9; ++it) {
205 float smearedNoise = CLHEP::RandGauss::shoot(
noise,
params.m_smearFactor);
206 noise = smearedNoise;
216 std::unique_ptr<SiStripNoises> theSiStripNoises;
224 uint32_t cachedId(0);
228 for (
const auto& element : theMap) {
229 uint32_t
DetId = element.first.first;
230 int nstrip = element.first.second;
231 float new_noise = element.second;
232 float old_noise = oldPayloadMap[std::make_pair(
DetId, nstrip)];
235 if (cachedId != 0 &&
DetId != cachedId) {
248 noise_ratio.
add(new_noise / old_noise);
249 o_noise.
add(old_noise);
250 n_noise.
add(new_noise);
257 poolDbService->
writeOne(theSiStripNoises.get(), poolDbService->
currentTime(),
"SiStripNoisesRcd");
259 throw std::runtime_error(
"PoolDBService required.");
268 scale_map->save(
true, 0, 0,
"noise_scale_map.pdf");
269 scale_map->save(
true, 0, 0,
"noise_scale_map.png");
271 smear_map->save(
true, 0, 0,
"noise_smear_map.pdf");
272 smear_map->save(
true, 0, 0,
"noise_smear_map.png");
274 ratio_map->save(
true, 0, 0,
"noise_ratio_map.pdf");
275 ratio_map->save(
true, 0, 0,
"noise_ratio_map.png");
296 const std::map<std::pair<uint32_t, int>,
float>& theMap,
const float theDefault) {
297 std::unique_ptr<SiStripNoises>
obj = std::make_unique<SiStripNoises>();
299 std::vector<uint32_t> missingDetIds;
303 bool isMissing(
false);
305 for (
int t_strip = 0; t_strip < 128 * it.second.nApvs; ++t_strip) {
306 std::pair<uint32_t, int>
index = std::make_pair(it.first, t_strip);
308 if (theMap.find(
index) == theMap.end()) {
309 LogDebug(
"SiStripNoisesFromDBMiscalibrator") <<
"detid " << it.first <<
" \t"
310 <<
" strip " << t_strip <<
" \t"
311 <<
" not found" << std::endl;
314 obj->setData(theDefault, theSiStripVector);
318 obj->setData(
noise, theSiStripVector);
323 missingDetIds.push_back(it.first);
325 if (!
obj->put(it.first, theSiStripVector)) {
327 <<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists" << std::endl;
331 if (!missingDetIds.empty()) {
333 std::stringstream
name;
334 name <<
"missing_modules.txt";
336 if (!ofile->is_open())
337 throw "cannot open output file!";
338 for (
const auto&
missing : missingDetIds) {
340 (*ofile) <<
missing <<
" " << 1 << std::endl;
353 const std::map<std::pair<uint32_t, int>,
float>& theMap) {
354 std::unique_ptr<SiStripNoises>
obj = std::make_unique<SiStripNoises>();
356 uint32_t PreviousDetId = 0;
358 for (
const auto& element : theMap) {
359 uint32_t
DetId = element.first.first;
360 float noise = element.second;
362 if (
DetId != PreviousDetId) {
363 if (!theSiStripVector.empty()) {
364 if (!
obj->put(PreviousDetId, theSiStripVector)) {
366 <<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists" << std::endl;
370 theSiStripVector.clear();
371 PreviousDetId =
DetId;
373 obj->setData(
noise, theSiStripVector);
383 "Creates rescaled / smeared SiStrip Noise payload."
384 "PoolDBOutputService must be set up for 'SiSiStripNoisesRcd'.");
388 "ParameterSet specifying the Strip tracker partition to be scaled / smeared "
389 "by a given factor.");
392 descScaler.
add<
bool>(
"doScale",
true);
393 descScaler.
add<
bool>(
"doSmear",
true);
394 descScaler.
add<
double>(
"scaleFactor", 1.0);
395 descScaler.
add<
double>(
"smearFactor", 1.0);
396 desc.addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
398 desc.addUntracked<
bool>(
"fillDefaults",
false);
399 desc.addUntracked<
bool>(
"saveMaps",
true);
401 descriptions.
add(
"scaleAndSmearSiStripNoises",
desc);