26 #include "CLHEP/Random/RandGauss.h"
62 const float theDefault);
98 scale_map = std::make_unique<TrackerMap>(
"scale");
99 scale_map->setTitle(
"Tracker Map of Scale factor averaged by module");
102 smear_map = std::make_unique<TrackerMap>(
"smear");
103 smear_map->setTitle(
"Tracker Map of Smear factor averaged by module");
107 old_payload_map->setTitle(
"Tracker Map of Starting Noise Payload averaged by module");
111 new_payload_map->setTitle(
"Tracker Map of Modified Noise Payload averaged by module");
114 ratio_map = std::make_unique<TrackerMap>(
"ratio");
115 ratio_map->setTitle(
"Tracker Map of Average by module of the payload ratio (new/old)");
119 missing_map = std::make_unique<TrackerMap>(
"uncabled");
120 missing_map->setTitle(
"Tracker Map of uncabled modules");
146 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
148 for (
auto& thePSet : m_parameters) {
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);
186 params = mapOfSmearings[
regions[
j]];
195 for (
int it = 0; it < (range.second - range.first) * 8 / 9; ++it) {
196 auto noise = stripNoises.getNoise(it, range);
197 std::pair<uint32_t, int>
index = std::make_pair(
d, nStrips);
201 if (params.m_doScale) {
202 noise *= params.m_scaleFactor;
205 if (params.m_doSmear) {
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) {
240 ratio_map->fill(cachedId, noise_ratio.mean());
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);
278 if (poolDbService.isAvailable()) {
279 if (poolDbService->isNewTagRequest(
"SiStripNoisesRcd")) {
280 poolDbService->
createOneIOV(theSiStripNoises, poolDbService->currentTime(),
"SiStripNoisesRcd");
282 poolDbService->appendOneIOV(theSiStripNoises, poolDbService->currentTime(),
"SiStripNoisesRcd");
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);
345 float noise = theMap.at(index);
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));
430 descriptions.
add(
"scaleAndSmearSiStripNoises", desc);
Log< level::Info, true > LogVerbatim
T getUntrackedParameter(std::string const &, T const &) const
std::unique_ptr< TrackerMap > old_payload_map
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::vector< sistripsummary::TrackerRegion > getRegionsFromDetId(const TrackerTopology *m_trackerTopo, DetId detid)
sistripsummary::TrackerRegion getRegionFromString(std::string region)
#define DEFINE_FWK_MODULE(type)
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)
tuple 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)
const uint16_t range(const Frame &aFrame)
SiStripNoises getNewObject_withDefaults(const std::map< std::pair< uint32_t, int >, float > &theMap, const float theDefault)
std::unique_ptr< TrackerMap > missing_map
bool getData(T &iHolder) const
const bool m_perDetIDdebug
void setComment(std::string const &value)
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
SiStripDetInfo read(std::string filePath)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Warning, true > LogPrint
void setSmearing(bool doScale, bool doSmear, double the_scaleFactor, double the_smearFactor)
const uint32_t m_printdebug
T getParameter(std::string const &) const
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 &)
std::string fullPath() const
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