26 #include "CLHEP/Random/RandGauss.h" 61 std::unique_ptr<SiStripNoises>
getNewObject(
const std::map<std::pair<uint32_t,int>,
float>& theMap);
84 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
85 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")},
91 scale_map->setTitle(
"Tracker Map of Scale factor averaged by module");
95 smear_map->setTitle(
"Tracker Map of Smear factor averaged by module");
99 old_payload_map->setTitle(
"Tracker Map of Starting Noise Payload averaged by module");
103 new_payload_map->setTitle(
"Tracker Map of Modified Noise Payload averaged by module");
107 ratio_map->setTitle(
"Tracker Map of Average by module of the payload ratio (new/old)");
112 missing_map->setTitle(
"Tracker Map of uncabled modules");
136 const auto*
const tTopo = tTopoHandle.
product();
144 if(
std::find(partitions.begin(), partitions.end(), partition) == partitions.end()) {
145 partitions.push_back(partition);
149 std::map<sistripsummary::TrackerRegion,SiStripMiscalibrate::Smearings> mapOfSmearings;
151 for(
auto& thePSet : m_parameters){
156 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
157 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
158 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
159 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
162 params.
setSmearing(m_doScale,m_doSmear,m_scaleFactor,m_smearFactor);
163 mapOfSmearings[region]=params;
169 std::map<std::pair<uint32_t,int>,
float> theMap, oldPayloadMap;
171 std::vector<uint32_t> detid;
173 for (
const auto &
d : detid) {
183 for (
unsigned int j=0; j<
regions.size();j++){
184 bool checkRegion = (mapOfSmearings.count(
regions[j]) != 0);
191 params = mapOfSmearings[
regions[j]];
200 for(
int it=0; it < (range.second-range.first)*8/9; ++it ){
201 auto noise=SiStripNoise_->
getNoise(it,range);
202 std::pair<uint32_t,int>
index = std::make_pair(
d,nStrips);
204 oldPayloadMap[
index]=noise;
206 if(params.m_doScale){
207 noise*=params.m_scaleFactor;
210 if(params.m_doSmear){
211 float smearedNoise = CLHEP::RandGauss::shoot(noise,params.m_smearFactor);
222 std::unique_ptr<SiStripNoises> theSiStripNoises;
230 uint32_t cachedId(0);
234 for(
const auto &element : theMap){
236 uint32_t
DetId = element.first.first;
237 int nstrip = element.first.second;
238 float new_noise = element.second;
239 float old_noise = oldPayloadMap[std::make_pair(DetId,nstrip)];
242 if(cachedId!=0 && DetId!=cachedId){
255 noise_ratio.
add(new_noise/old_noise);
256 o_noise.
add(old_noise);
257 n_noise.
add(new_noise);
264 poolDbService->
writeOne(theSiStripNoises.get(),poolDbService->
currentTime(),
"SiStripNoisesRcd");
266 throw std::runtime_error(
"PoolDBService required.");
282 scale_map->save(
true,0,0,
"noise_scale_map.pdf");
283 scale_map->save(
true,0,0,
"noise_scale_map.png");
285 smear_map->save(
true,0,0,
"noise_smear_map.pdf");
286 smear_map->save(
true,0,0,
"noise_smear_map.png");
288 ratio_map->save(
true,0,0,
"noise_ratio_map.pdf");
289 ratio_map->save(
true,0,0,
"noise_ratio_map.png");
293 old_payload_map->save(
true,range.first,range.second,
"starting_noise_payload_map.pdf");
294 old_payload_map->save(
true,range.first,range.second,
"starting_noise_payload_map.png");
298 new_payload_map->save(
true,range.first,range.second,
"new_noise_payload_map.pdf");
299 new_payload_map->save(
true,range.first,range.second,
"new_noise_payload_map.png");
309 std::unique_ptr<SiStripNoises>
312 std::unique_ptr<SiStripNoises>
obj = std::unique_ptr<SiStripNoises>(
new SiStripNoises());
315 const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >& DetInfos =
reader.getAllData();
317 std::vector<uint32_t> missingDetIds;
319 for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){
321 bool isMissing(
false);
323 for(
int t_strip=0;t_strip<128*it->second.nApvs; ++t_strip){
325 std::pair<uint32_t,int>
index = std::make_pair(it->first, t_strip) ;
327 if ( theMap.find(index) == theMap.end() ) {
329 LogDebug(
"SiStripNoisesFromDBMiscalibrator") <<
"detid " << it->first <<
" \t" 330 <<
" strip " << t_strip <<
" \t" 331 <<
" not found" << std::endl;
334 obj->setData(theDefault,theSiStripVector);
338 float noise = theMap.at(index);
339 obj->setData(noise,theSiStripVector);
344 if(isMissing) missingDetIds.push_back(it->first);
346 if ( ! obj->put(it->first,theSiStripVector) ) {
347 edm::LogError(
"SiStripNoisesFromDBMiscalibrator")<<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists"<<std::endl;
351 if(!missingDetIds.empty()){
353 std::stringstream
name;
354 name <<
"missing_modules.txt";
356 if ( !ofile->is_open() )
throw "cannot open output file!";
357 for(
const auto &missing : missingDetIds){
358 edm::LogVerbatim(
"SiStripNoisesFromDBMiscalibrator") << missing <<
" " << 1 << std::endl;
359 (*ofile) << missing <<
" " << 1 << std::endl;
373 std::unique_ptr<SiStripNoises>
376 std::unique_ptr<SiStripNoises>
obj = std::unique_ptr<SiStripNoises>(
new SiStripNoises());
378 uint32_t PreviousDetId = 0;
380 for(
const auto &element : theMap){
382 uint32_t
DetId = element.first.first;
383 float noise = element.second;
385 if(DetId != PreviousDetId){
386 if(!theSiStripVector.empty()){
388 if ( ! obj->put(PreviousDetId,theSiStripVector) ) {
389 edm::LogError(
"SiStripNoisesFromDBMiscalibrator")<<
"[SiStripNoisesFromDBMiscalibrator::analyze] detid already exists"<<std::endl;
393 theSiStripVector.clear();
394 PreviousDetId = DetId;
396 obj->setData(noise,theSiStripVector);
407 desc.
setComment(
"Creates rescaled / smeared SiStrip Noise payload." 408 "PoolDBOutputService must be set up for 'SiSiStripNoisesRcd'.");
411 descScaler.
setComment(
"ParameterSet specifying the Strip tracker partition to be scaled / smeared " 412 "by a given factor.");
415 descScaler.
add<
bool>(
"doScale",
true);
416 descScaler.
add<
bool>(
"doSmear",
true);
417 descScaler.
add<
double>(
"scaleFactor", 1.0);
418 descScaler.
add<
double>(
"smearFactor", 1.0);
419 desc.
addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
424 descriptions.
add(
"scaleAndSmearSiStripNoises", desc);
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)
std::unique_ptr< TrackerMap > smear_map
std::vector< uint16_t > InputVector
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::unique_ptr< TrackerMap > missing_map
void setComment(std::string const &value)
static float getNoise(uint16_t strip, const Range &range)
#define DEFINE_FWK_MODULE(type)
std::unique_ptr< TrackerMap > new_payload_map
std::unique_ptr< TrackerMap > scale_map
std::unique_ptr< SiStripNoises > getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const bool m_fillDefaults
void analyze(const edm::Event &, const edm::EventSetup &) override
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< SiStripNoises > getNewObject_withDefaults(const std::map< std::pair< uint32_t, int >, float > &theMap, const float theDefault)
void setSmearing(bool doScale, bool doSmear, double the_scaleFactor, double the_smearFactor)
void getDetIds(std::vector< uint32_t > &DetIds_) 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
cond::Time_t currentTime() const
const Range getRange(const uint32_t detID) const
SiStripNoisesFromDBMiscalibrator(const edm::ParameterSet &)
std::string fullPath() const
~SiStripNoisesFromDBMiscalibrator() override
std::pair< ContainerIterator, ContainerIterator > Range
T const * product() const