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);
85 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
86 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")},
88 "file",
edm::FileInPath(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"))} {
91 scale_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"scale"));
92 scale_map->setTitle(
"Tracker Map of Scale factor averaged by module");
93 scale_map->setPalette(1);
95 smear_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"smear"));
96 smear_map->setTitle(
"Tracker Map of Smear factor averaged by module");
97 smear_map->setPalette(1);
99 old_payload_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"old_payload"));
100 old_payload_map->setTitle(
"Tracker Map of Starting Noise Payload averaged by module");
101 old_payload_map->setPalette(1);
103 new_payload_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"new_payload"));
104 new_payload_map->setTitle(
"Tracker Map of Modified Noise Payload averaged by module");
105 new_payload_map->setPalette(1);
107 ratio_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"ratio"));
108 ratio_map->setTitle(
"Tracker Map of Average by module of the payload ratio (new/old)");
109 ratio_map->setPalette(1);
111 if (m_fillDefaults) {
112 missing_map = std::unique_ptr<TrackerMap>(
new TrackerMap(
"uncabled"));
113 missing_map->setTitle(
"Tracker Map of uncabled modules");
114 missing_map->setPalette(1);
130 const auto*
const tTopo = tTopoHandle.
product();
143 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
149 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
150 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
151 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
152 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
155 params.setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
162 std::map<std::pair<uint32_t, int>,
float> theMap, oldPayloadMap;
164 std::vector<uint32_t> detid;
166 for (
const auto&
d : detid) {
176 for (
unsigned int j = 0;
j <
regions.size();
j++) {
177 bool checkRegion = (mapOfSmearings.count(
regions[
j]) != 0);
193 for (
int it = 0; it < (
range.second -
range.first) * 8 / 9; ++it) {
204 float smearedNoise = CLHEP::RandGauss::shoot(
noise,
params.m_smearFactor);
205 noise = smearedNoise;
215 std::unique_ptr<SiStripNoises> theSiStripNoises;
223 uint32_t cachedId(0);
227 for (
const auto& element : theMap) {
228 uint32_t
DetId = element.first.first;
229 int nstrip = element.first.second;
230 float new_noise = element.second;
231 float old_noise = oldPayloadMap[std::make_pair(
DetId, nstrip)];
234 if (cachedId != 0 &&
DetId != cachedId) {
247 noise_ratio.
add(new_noise / old_noise);
248 o_noise.
add(old_noise);
249 n_noise.
add(new_noise);
256 poolDbService->
writeOne(theSiStripNoises.get(), poolDbService->
currentTime(),
"SiStripNoisesRcd");
258 throw std::runtime_error(
"PoolDBService required.");
267 scale_map->save(
true, 0, 0,
"noise_scale_map.pdf");
268 scale_map->save(
true, 0, 0,
"noise_scale_map.png");
270 smear_map->save(
true, 0, 0,
"noise_smear_map.pdf");
271 smear_map->save(
true, 0, 0,
"noise_smear_map.png");
273 ratio_map->save(
true, 0, 0,
"noise_ratio_map.pdf");
274 ratio_map->save(
true, 0, 0,
"noise_ratio_map.png");
295 const std::map<std::pair<uint32_t, int>,
float>& theMap,
const float theDefault) {
296 std::unique_ptr<SiStripNoises>
obj = std::unique_ptr<SiStripNoises>(
new SiStripNoises());
299 const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>& DetInfos =
reader.getAllData();
301 std::vector<uint32_t> missingDetIds;
303 for (std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator it = DetInfos.begin();
304 it != DetInfos.end();
307 bool isMissing(
false);
309 for (
int t_strip = 0; t_strip < 128 * it->second.nApvs; ++t_strip) {
310 std::pair<uint32_t, int>
index = std::make_pair(it->first, t_strip);
312 if (theMap.find(
index) == theMap.end()) {
313 LogDebug(
"SiStripNoisesFromDBMiscalibrator") <<
"detid " << it->first <<
" \t"
314 <<
" strip " << t_strip <<
" \t"
315 <<
" not found" << std::endl;
318 obj->setData(theDefault, theSiStripVector);
322 obj->setData(
noise, theSiStripVector);
327 missingDetIds.push_back(it->first);
329 if (!
obj->put(it->first, theSiStripVector)) {
331 <<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists" << std::endl;
335 if (!missingDetIds.empty()) {
337 std::stringstream
name;
338 name <<
"missing_modules.txt";
340 if (!
ofile->is_open())
341 throw "cannot open output file!";
342 for (
const auto&
missing : missingDetIds) {
344 (*ofile) <<
missing <<
" " << 1 << std::endl;
357 const std::map<std::pair<uint32_t, int>,
float>& theMap) {
358 std::unique_ptr<SiStripNoises>
obj = std::unique_ptr<SiStripNoises>(
new SiStripNoises());
360 uint32_t PreviousDetId = 0;
362 for (
const auto& element : theMap) {
363 uint32_t
DetId = element.first.first;
364 float noise = element.second;
366 if (
DetId != PreviousDetId) {
367 if (!theSiStripVector.empty()) {
368 if (!
obj->put(PreviousDetId, theSiStripVector)) {
370 <<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists" << std::endl;
374 theSiStripVector.clear();
375 PreviousDetId =
DetId;
377 obj->setData(
noise, theSiStripVector);
387 "Creates rescaled / smeared SiStrip Noise payload."
388 "PoolDBOutputService must be set up for 'SiSiStripNoisesRcd'.");
392 "ParameterSet specifying the Strip tracker partition to be scaled / smeared "
393 "by a given factor.");
396 descScaler.
add<
bool>(
"doScale",
true);
397 descScaler.
add<
bool>(
"doSmear",
true);
398 descScaler.
add<
double>(
"scaleFactor", 1.0);
399 descScaler.
add<
double>(
"smearFactor", 1.0);
400 desc.
addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
405 descriptions.
add(
"scaleAndSmearSiStripNoises", desc);