26 #include "CLHEP/Random/RandGauss.h" 62 const float theDefault);
88 m_perDetIDdebug{iConfig.getUntrackedParameter<
bool>(
"perDetIDdebug",
false)},
89 m_fillDefaults{iConfig.getUntrackedParameter<
bool>(
"fillDefaults",
false)},
90 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
91 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")},
98 scale_map = std::make_unique<TrackerMap>(
"scale");
99 scale_map->setTitle(
"Tracker Map of Scale factor averaged by module");
100 scale_map->setPalette(1);
102 smear_map = std::make_unique<TrackerMap>(
"smear");
103 smear_map->setTitle(
"Tracker Map of Smear factor averaged by module");
104 smear_map->setPalette(1);
106 old_payload_map = std::make_unique<TrackerMap>(
"old_payload");
107 old_payload_map->setTitle(
"Tracker Map of Starting Noise Payload averaged by module");
108 old_payload_map->setPalette(1);
110 new_payload_map = std::make_unique<TrackerMap>(
"new_payload");
111 new_payload_map->setTitle(
"Tracker Map of Modified Noise Payload averaged by module");
112 new_payload_map->setPalette(1);
114 ratio_map = std::make_unique<TrackerMap>(
"ratio");
115 ratio_map->setTitle(
"Tracker Map of Average by module of the payload ratio (new/old)");
116 ratio_map->setPalette(1);
118 if (m_fillDefaults) {
119 missing_map = std::make_unique<TrackerMap>(
"uncabled");
120 missing_map->setTitle(
"Tracker Map of uncabled modules");
121 missing_map->setPalette(1);
146 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
152 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
153 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
154 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
155 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
158 params.setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
164 std::map<std::pair<uint32_t, int>,
float> theMap, oldPayloadMap;
166 std::vector<uint32_t> detid;
167 stripNoises.getDetIds(detid);
168 for (
const auto&
d : detid) {
178 for (
unsigned int j = 0;
j <
regions.size();
j++) {
179 bool checkRegion = (mapOfSmearings.count(
regions[
j]) != 0);
206 float smearedNoise = CLHEP::RandGauss::shoot(
noise,
params.m_smearFactor);
207 noise = smearedNoise;
225 uint32_t cachedId(0);
231 for (
const auto& element : theMap) {
233 uint32_t
DetId = element.first.first;
234 int nstrip = element.first.second;
235 float new_noise = element.second;
236 float old_noise = oldPayloadMap[std::make_pair(
DetId, nstrip)];
239 if (cachedId != 0 &&
DetId != cachedId) {
253 <<
"SiStripNoisesFromDBMiscalibrator" 254 <<
"::" << __FUNCTION__ <<
" detid " <<
DetId <<
" \t" 255 <<
" strip " << nstrip <<
" \t new <noise>: " << std::setw(5) << std::setprecision(2) << n_noise.
mean()
256 <<
" \t old <noise>: " << o_noise.
mean() <<
" \t" << std::endl;
263 <<
"SiStripNoisesFromDBMiscalibrator" 264 <<
"::" << __FUNCTION__ <<
" detid " <<
DetId <<
" \t" 265 <<
" strip " << nstrip <<
" \t new noise: " << std::setw(5) << std::setprecision(2) << new_noise
266 <<
" \t old noise: " << old_noise <<
" \t" << std::endl;
270 noise_ratio.
add(new_noise / old_noise);
271 o_noise.
add(old_noise);
272 n_noise.
add(new_noise);
285 throw std::runtime_error(
"PoolDBService required.");
292 scale_map->save(
true, 0, 0,
"noise_scale_map.pdf");
293 scale_map->save(
true, 0, 0,
"noise_scale_map.png");
295 smear_map->save(
true, 0, 0,
"noise_smear_map.pdf");
296 smear_map->save(
true, 0, 0,
"noise_smear_map.png");
298 ratio_map->save(
true, 0, 0,
"noise_ratio_map.pdf");
299 ratio_map->save(
true, 0, 0,
"noise_ratio_map.png");
320 const std::map<std::pair<uint32_t, int>,
float>& theMap,
const float theDefault) {
323 std::vector<uint32_t> missingDetIds;
326 const auto& DetInfos =
reader.getAllData();
328 for (
const auto&
it : DetInfos) {
329 const auto& nAPVs =
it.second.nApvs;
331 bool isMissing(
false);
333 for (
int t_strip = 0; t_strip < 128 * nAPVs; ++t_strip) {
334 std::pair<uint32_t, int>
index = std::make_pair(
it.first, t_strip);
336 if (theMap.find(
index) == theMap.end()) {
337 LogDebug(
"SiStripNoisesFromDBMiscalibrator") <<
"detid " <<
it.first <<
" \t" 338 <<
" strip " << t_strip <<
" \t" 339 <<
" not found" << std::endl;
342 obj.setData(theDefault, theSiStripVector);
346 obj.setData(
noise, theSiStripVector);
351 missingDetIds.push_back(
it.first);
353 if (!
obj.put(
it.first, theSiStripVector)) {
355 <<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists" << std::endl;
359 if (!missingDetIds.empty()) {
361 std::stringstream
name;
362 name <<
"missing_modules.txt";
364 if (!ofile->is_open())
365 throw "cannot open output file!";
366 for (
const auto&
missing : missingDetIds) {
368 (*ofile) <<
missing <<
" " << 1 << std::endl;
383 uint32_t PreviousDetId = 0;
385 for (
const auto& element : theMap) {
386 uint32_t
DetId = element.first.first;
387 float noise = element.second;
389 if (
DetId != PreviousDetId) {
390 if (!theSiStripVector.empty()) {
391 if (!
obj.put(PreviousDetId, theSiStripVector)) {
393 <<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists" << std::endl;
397 theSiStripVector.clear();
398 PreviousDetId =
DetId;
400 obj.setData(
noise, theSiStripVector);
410 "Creates rescaled / smeared SiStrip Noise payload." 411 "PoolDBOutputService must be set up for 'SiSiStripNoisesRcd'.");
415 "ParameterSet specifying the Strip tracker partition to be scaled / smeared " 416 "by a given factor.");
419 descScaler.
add<
bool>(
"doScale",
true);
420 descScaler.
add<
bool>(
"doSmear",
true);
421 descScaler.
add<
double>(
"scaleFactor", 1.0);
422 descScaler.
add<
double>(
"smearFactor", 1.0);
423 desc.addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
425 desc.addUntracked<
unsigned int>(
"printDebug", 10);
426 desc.addUntracked<
bool>(
"perDetIDdebug",
false);
427 desc.addUntracked<
bool>(
"fillDefaults",
false);
428 desc.addUntracked<
bool>(
"saveMaps",
true);
430 descriptions.
add(
"scaleAndSmearSiStripNoises",
desc);
Log< level::Info, true > LogVerbatim
std::unique_ptr< TrackerMap > old_payload_map
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
std::string fullPath() const
std::vector< sistripsummary::TrackerRegion > getRegionsFromDetId(const TrackerTopology *m_trackerTopo, DetId detid)
sistripsummary::TrackerRegion getRegionFromString(std::string region)
std::unique_ptr< TrackerMap > smear_map
const edm::FileInPath fp_
std::vector< uint16_t > InputVector
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
SiStripNoises getNewObject_withDefaults(const std::map< std::pair< uint32_t, int >, float > &theMap, const float theDefault)
std::unique_ptr< TrackerMap > missing_map
T getUntrackedParameter(std::string const &, T const &) const
const bool m_perDetIDdebug
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
void setComment(std::string const &value)
bool isNewTagRequest(const std::string &recordName)
cond::Time_t currentTime() const
std::unique_ptr< TrackerMap > new_payload_map
std::unique_ptr< TrackerMap > scale_map
~SiStripNoisesFromDBMiscalibrator() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const bool m_fillDefaults
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
SiStripDetInfo read(std::string filePath)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Warning, true > LogPrint
const uint32_t m_printdebug
std::unique_ptr< TrackerMap > ratio_map
std::pair< float, float > getTruncatedRange(const TrackerMap *theMap)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::vector< edm::ParameterSet > m_parameters
SiStripNoises getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
SiStripNoisesFromDBMiscalibrator(const edm::ParameterSet &)
static constexpr char const *const kDefaultFile
const edm::ESGetToken< SiStripNoises, SiStripNoisesRcd > m_noiseToken
std::pair< ContainerIterator, ContainerIterator > Range
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > m_tTopoToken