25 #include "CLHEP/Random/RandGauss.h" 60 std::unique_ptr<SiStripApvGain>
getNewObject(
const std::map<std::pair<uint32_t, int>,
float>& theMap);
81 m_gainType{iConfig.getUntrackedParameter<uint32_t>(
"gainType", 1)},
82 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
83 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")} {
89 scale_map->setTitle(
"Scale factor averaged by module");
93 smear_map->setTitle(
"Smear factor averaged by module");
97 ratio_map->setTitle(
"Average by module of the " + ss_gain +
" Gain payload ratio (new/old)");
101 new_payload_map->setTitle(
"Tracker Map of Modified " + ss_gain +
" Gain payload averaged by module");
105 old_payload_map->setTitle(
"Tracker Map of Starting " + ss_gain +
" Gain Payload averaged by module");
121 const auto*
const tTopo = tTopoHandle.
product();
129 if (
std::find(partitions.begin(), partitions.end(), partition) == partitions.end()) {
130 partitions.push_back(partition);
134 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
136 for (
auto& thePSet : m_parameters) {
140 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
141 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
142 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
143 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
146 params.
setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
153 std::map<std::pair<uint32_t, int>,
float> theMap, oldPayloadMap;
155 std::vector<uint32_t> detid;
157 for (
const auto&
d : detid) {
168 for (
unsigned int j = 0;
j <
regions.size();
j++) {
169 bool checkRegion = (mapOfSmearings.count(
regions[
j]) != 0);
176 params = mapOfSmearings[
regions[
j]];
184 for (
int it = 0; it < range.second - range.first; it++) {
187 std::pair<uint32_t, int>
index = std::make_pair(
d, nAPV);
191 if (params.m_doScale) {
192 Gain *= params.m_scaleFactor;
195 if (params.m_doSmear) {
196 float smearedGain = CLHEP::RandGauss::shoot(Gain, params.m_smearFactor);
205 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(theMap);
208 uint32_t cachedId(0);
212 for (
const auto& element : theMap) {
213 uint32_t
DetId = element.first.first;
214 int nAPV = element.first.second;
215 float new_gain = element.second;
216 float old_gain = oldPayloadMap[std::make_pair(DetId, nAPV)];
219 if (cachedId != 0 && DetId != cachedId) {
232 gain_ratio.
add(new_gain / old_gain);
233 o_gain.
add(old_gain);
234 n_gain.
add(new_gain);
243 throw std::runtime_error(
"PoolDBService required.");
254 scale_map->save(
true, 0, 0, ss_gain +
"_gain_scale_map.pdf");
255 scale_map->save(
true, 0, 0, ss_gain +
"_gain_scale_map.png");
257 smear_map->save(
true, 0, 0, ss_gain +
"_gain_smear_map.pdf");
258 smear_map->save(
true, 0, 0, ss_gain +
"_gain_smear_map.png");
260 ratio_map->save(
true, 0, 0, ss_gain +
"_gain_ratio_map.pdf");
261 ratio_map->save(
true, 0, 0, ss_gain +
"_gain_ratio_map.png");
277 const std::map<std::pair<uint32_t, int>,
float>& theMap) {
278 std::unique_ptr<SiStripApvGain>
obj = std::unique_ptr<SiStripApvGain>(
new SiStripApvGain());
280 std::vector<float> theSiStripVector;
281 uint32_t PreviousDetId = 0;
282 for (
const auto& element : theMap) {
283 uint32_t
DetId = element.first.first;
284 if (DetId != PreviousDetId) {
285 if (!theSiStripVector.empty()) {
287 if (!obj->put(PreviousDetId,
range))
288 printf(
"Bug to put detId = %i\n", PreviousDetId);
290 theSiStripVector.clear();
291 PreviousDetId = DetId;
293 theSiStripVector.push_back(element.second);
296 <<
" DetId: " << DetId <<
" APV: " << element.first.second <<
" Gain: " << element.second << std::endl;
299 if (!theSiStripVector.empty()) {
301 if (!obj->put(PreviousDetId,
range))
302 printf(
"Bug to put detId = %i\n", PreviousDetId);
313 "Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2." 314 "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
318 "ParameterSet specifying the Strip tracker partition to be scaled / smeared " 319 "by a given factor.");
322 descScaler.
add<
bool>(
"doScale",
true);
323 descScaler.
add<
bool>(
"doSmear",
true);
324 descScaler.
add<
double>(
"scaleFactor", 1.0);
325 descScaler.
add<
double>(
"smearFactor", 1.0);
326 desc.
addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
332 descriptions.
add(
"scaleAndSmearSiStripGains", desc);
T getUntrackedParameter(std::string const &, T const &) const
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
~SiStripChannelGainFromDBMiscalibrator() override
std::vector< sistripsummary::TrackerRegion > getRegionsFromDetId(const TrackerTopology *m_trackerTopo, DetId detid)
sistripsummary::TrackerRegion getRegionFromString(std::string region)
std::unique_ptr< TrackerMap > smear_map
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::unique_ptr< TrackerMap > old_payload_map
SiStripChannelGainFromDBMiscalibrator(const edm::ParameterSet &)
const uint32_t m_gainType
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
std::unique_ptr< TrackerMap > new_payload_map
void setComment(std::string const &value)
#define DEFINE_FWK_MODULE(type)
std::unique_ptr< TrackerMap > ratio_map
std::pair< ContainerIterator, ContainerIterator > Range
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void getDetIds(std::vector< uint32_t > &DetIds_) const
ATTENTION: we assume the detIds are the same as those from the first gain.
void analyze(const edm::Event &, const edm::EventSetup &) override
std::unique_ptr< SiStripApvGain > getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
void setSmearing(bool doScale, bool doSmear, double the_scaleFactor, double the_smearFactor)
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
std::unique_ptr< TrackerMap > scale_map
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
const std::string m_Record
const SiStripApvGain::Range getRange(uint32_t detID) const