25 #include "CLHEP/Random/RandGauss.h" 83 m_Record{iConfig.getUntrackedParameter<
std::string>(
"record",
"SiStripApvGainRcd")},
84 m_gainType{iConfig.getUntrackedParameter<uint32_t>(
"gainType", 1)},
85 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
86 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")},
91 std::string ss_gain = (m_gainType > 0) ?
"G2" :
"G1";
93 scale_map = std::make_unique<TrackerMap>(
"scale");
94 scale_map->setTitle(
"Scale factor averaged by module");
95 scale_map->setPalette(1);
97 smear_map = std::make_unique<TrackerMap>(
"smear");
98 smear_map->setTitle(
"Smear factor averaged by module");
99 smear_map->setPalette(1);
101 ratio_map = std::make_unique<TrackerMap>(
"ratio");
102 ratio_map->setTitle(
"Average by module of the " + ss_gain +
" Gain payload ratio (new/old)");
103 ratio_map->setPalette(1);
105 new_payload_map = std::make_unique<TrackerMap>(
"new_payload");
106 new_payload_map->setTitle(
"Tracker Map of Modified " + ss_gain +
" Gain payload averaged by module");
107 new_payload_map->setPalette(1);
109 old_payload_map = std::make_unique<TrackerMap>(
"old_payload");
110 old_payload_map->setTitle(
"Tracker Map of Starting " + ss_gain +
" Gain Payload averaged by module");
111 old_payload_map->setPalette(1);
137 std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
143 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
144 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
145 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
146 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
149 params.setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
155 std::map<std::pair<uint32_t, int>,
float> theMap, oldPayloadMap;
157 std::vector<uint32_t> detid;
158 apvGain.getDetIds(detid);
159 for (
const auto&
d : detid) {
170 for (
unsigned int j = 0;
j <
regions.size();
j++) {
171 bool checkRegion = (mapOfSmearings.count(
regions[
j]) != 0);
186 for (
int it = 0; it <
range.second -
range.first; it++) {
188 float Gain = apvGain.getApvGain(it,
range);
189 std::pair<uint32_t, int>
index = std::make_pair(
d, nAPV);
198 float smearedGain = CLHEP::RandGauss::shoot(
Gain,
params.m_smearFactor);
210 uint32_t cachedId(0);
214 unsigned int countDetIds(0);
215 for (
const auto& element : theMap) {
216 uint32_t
DetId = element.first.first;
217 int nAPV = element.first.second;
218 float new_gain = element.second;
219 float old_gain = oldPayloadMap[std::make_pair(
DetId, nAPV)];
222 if (cachedId != 0 &&
DetId != cachedId) {
238 <<
"SiStripChannelGainFromDBMiscalibrator" 239 <<
"::" << __FUNCTION__ <<
" detid " <<
DetId <<
" \t" 240 <<
" APV " << nAPV <<
" \t new gain: " << new_gain <<
" \t old gain: " << old_gain <<
" \t" << std::endl;
244 gain_ratio.
add(new_gain / old_gain);
245 o_gain.
add(old_gain);
246 n_gain.
add(new_gain);
259 throw std::runtime_error(
"PoolDBService required.");
268 scale_map->save(
true, 0, 0, ss_gain +
"_gain_scale_map.pdf");
269 scale_map->save(
true, 0, 0, ss_gain +
"_gain_scale_map.png");
271 smear_map->save(
true, 0, 0, ss_gain +
"_gain_smear_map.pdf");
272 smear_map->save(
true, 0, 0, ss_gain +
"_gain_smear_map.png");
274 ratio_map->save(
true, 0, 0, ss_gain +
"_gain_ratio_map.pdf");
275 ratio_map->save(
true, 0, 0, ss_gain +
"_gain_ratio_map.png");
291 const std::map<std::pair<uint32_t, int>,
float>& theMap) {
294 std::vector<float> theSiStripVector;
295 uint32_t PreviousDetId = 0;
296 for (
const auto& element : theMap) {
297 uint32_t
DetId = element.first.first;
298 if (
DetId != PreviousDetId) {
299 if (!theSiStripVector.empty()) {
302 printf(
"Bug to put detId = %i\n", PreviousDetId);
304 theSiStripVector.clear();
305 PreviousDetId =
DetId;
307 theSiStripVector.push_back(element.second);
310 <<
" DetId: " <<
DetId <<
" APV: " << element.first.second <<
" Gain: " << element.second << std::endl;
313 if (!theSiStripVector.empty()) {
316 printf(
"Bug to put detId = %i\n", PreviousDetId);
327 "Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2." 328 "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
332 "ParameterSet specifying the Strip tracker partition to be scaled / smeared " 333 "by a given factor.");
336 descScaler.
add<
bool>(
"doScale",
true);
337 descScaler.
add<
bool>(
"doSmear",
true);
338 descScaler.
add<
double>(
"scaleFactor", 1.0);
339 descScaler.
add<
double>(
"smearFactor", 1.0);
340 desc.addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
342 desc.addUntracked<
unsigned int>(
"printDebug", 1);
344 desc.addUntracked<
unsigned int>(
"gainType", 1);
345 desc.addUntracked<
bool>(
"saveMaps",
true);
347 descriptions.
add(
"scaleAndSmearSiStripGains",
desc);
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
~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
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
T getUntrackedParameter(std::string const &, T const &) const
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
std::unique_ptr< TrackerMap > new_payload_map
void setComment(std::string const &value)
std::unique_ptr< TrackerMap > ratio_map
bool isNewTagRequest(const std::string &recordName)
cond::Time_t currentTime() const
const edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
std::pair< ContainerIterator, ContainerIterator > Range
#define DEFINE_FWK_MODULE(type)
SiStripApvGain getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Log< level::Warning, true > LogPrint
void analyze(const edm::Event &, const edm::EventSetup &) override
Log< level::Info, false > LogInfo
const uint32_t m_printdebug
std::pair< float, float > getTruncatedRange(const TrackerMap *theMap)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::vector< edm::ParameterSet > m_parameters
std::unique_ptr< TrackerMap > scale_map
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string m_Record