26 #include "CLHEP/Random/RandGauss.h"
62 const float theDefault);
96 scale_map = std::make_unique<TrackerMap>(
"scale");
97 scale_map->setTitle(
"Tracker Map of Scale factor averaged by module");
100 smear_map = std::make_unique<TrackerMap>(
"smear");
101 smear_map->setTitle(
"Tracker Map of Smear factor averaged by module");
105 old_payload_map->setTitle(
"Tracker Map of Starting Noise Payload averaged by module");
109 new_payload_map->setTitle(
"Tracker Map of Modified Noise Payload averaged by module");
112 ratio_map = std::make_unique<TrackerMap>(
"ratio");
113 ratio_map->setTitle(
"Tracker Map of Average by module of the payload ratio (new/old)");
117 missing_map = std::make_unique<TrackerMap>(
"uncabled");
118 missing_map->setTitle(
"Tracker Map of uncabled modules");
144 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
146 for (
auto& thePSet : m_parameters) {
150 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
151 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
152 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
153 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
156 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;
165 stripNoises.getDetIds(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);
184 params = mapOfSmearings[
regions[
j]];
193 for (
int it = 0; it < (range.second - range.first) * 8 / 9; ++it) {
194 auto noise = stripNoises.getNoise(it, range);
195 std::pair<uint32_t, int>
index = std::make_pair(
d, nStrips);
199 if (params.m_doScale) {
200 noise *= params.m_scaleFactor;
203 if (params.m_doSmear) {
204 float smearedNoise = CLHEP::RandGauss::shoot(
noise, params.m_smearFactor);
205 noise = smearedNoise;
223 uint32_t cachedId(0);
227 unsigned int countDetIds(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) {
236 ratio_map->fill(cachedId, noise_ratio.mean());
251 <<
"SiStripNoisesFromDBMiscalibrator"
252 <<
"::" << __FUNCTION__ <<
" detid " << DetId <<
" \t"
253 <<
" strip " << nstrip <<
" \t new noise: " << std::setw(5) << std::setprecision(2) << new_noise
254 <<
" \t old noise: " << old_noise <<
" \t" << std::endl;
258 noise_ratio.add(new_noise / old_noise);
259 o_noise.add(old_noise);
260 n_noise.add(new_noise);
266 if (poolDbService.isAvailable()) {
267 if (poolDbService->isNewTagRequest(
"SiStripNoisesRcd")) {
268 poolDbService->
createOneIOV(theSiStripNoises, poolDbService->currentTime(),
"SiStripNoisesRcd");
270 poolDbService->appendOneIOV(theSiStripNoises, poolDbService->currentTime(),
"SiStripNoisesRcd");
273 throw std::runtime_error(
"PoolDBService required.");
280 scale_map->save(
true, 0, 0,
"noise_scale_map.pdf");
281 scale_map->save(
true, 0, 0,
"noise_scale_map.png");
283 smear_map->save(
true, 0, 0,
"noise_smear_map.pdf");
284 smear_map->save(
true, 0, 0,
"noise_smear_map.png");
286 ratio_map->save(
true, 0, 0,
"noise_ratio_map.pdf");
287 ratio_map->save(
true, 0, 0,
"noise_ratio_map.png");
308 const std::map<std::pair<uint32_t, int>,
float>& theMap,
const float theDefault) {
311 std::vector<uint32_t> missingDetIds;
314 const auto& DetInfos =
reader.getAllData();
316 for (
const auto& it : DetInfos) {
317 const auto& nAPVs = it.second.nApvs;
319 bool isMissing(
false);
321 for (
int t_strip = 0; t_strip < 128 * nAPVs; ++t_strip) {
322 std::pair<uint32_t, int>
index = std::make_pair(it.first, t_strip);
324 if (theMap.find(index) == theMap.end()) {
325 LogDebug(
"SiStripNoisesFromDBMiscalibrator") <<
"detid " << it.first <<
" \t"
326 <<
" strip " << t_strip <<
" \t"
327 <<
" not found" << std::endl;
330 obj.setData(theDefault, theSiStripVector);
333 float noise = theMap.at(index);
334 obj.setData(noise, theSiStripVector);
339 missingDetIds.push_back(it.first);
341 if (!
obj.put(it.first, theSiStripVector)) {
343 <<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists" << std::endl;
347 if (!missingDetIds.empty()) {
349 std::stringstream
name;
350 name <<
"missing_modules.txt";
352 if (!ofile->is_open())
353 throw "cannot open output file!";
354 for (
const auto&
missing : missingDetIds) {
356 (*ofile) <<
missing <<
" " << 1 << std::endl;
371 uint32_t PreviousDetId = 0;
373 for (
const auto& element : theMap) {
374 uint32_t
DetId = element.first.first;
375 float noise = element.second;
377 if (DetId != PreviousDetId) {
378 if (!theSiStripVector.empty()) {
379 if (!
obj.put(PreviousDetId, theSiStripVector)) {
381 <<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists" << std::endl;
385 theSiStripVector.clear();
386 PreviousDetId = DetId;
388 obj.setData(noise, theSiStripVector);
398 "Creates rescaled / smeared SiStrip Noise payload."
399 "PoolDBOutputService must be set up for 'SiSiStripNoisesRcd'.");
403 "ParameterSet specifying the Strip tracker partition to be scaled / smeared "
404 "by a given factor.");
407 descScaler.
add<
bool>(
"doScale",
true);
408 descScaler.
add<
bool>(
"doSmear",
true);
409 descScaler.
add<
double>(
"scaleFactor", 1.0);
410 descScaler.
add<
double>(
"smearFactor", 1.0);
411 desc.
addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
417 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
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