26 #include "CLHEP/Random/RandGauss.h" 61 std::unique_ptr<SiStripApvGain>
getNewObject(
const std::map<std::pair<uint32_t,int>,
float>& theMap);
83 m_gainType{iConfig.getUntrackedParameter<uint32_t>(
"gainType",1)},
84 m_saveMaps{iConfig.getUntrackedParameter<
bool>(
"saveMaps",
true)},
85 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")}
92 scale_map->setTitle(
"Scale factor averaged by module");
96 smear_map->setTitle(
"Smear factor averaged by module");
100 ratio_map->setTitle(
"Average by module of the "+ss_gain+
" Gain payload ratio (new/old)");
104 new_payload_map->setTitle(
"Tracker Map of Modified "+ss_gain+
" Gain payload averaged by module");
108 old_payload_map->setTitle(
"Tracker Map of Starting "+ss_gain+
" Gain Payload averaged by module");
131 const auto*
const tTopo = tTopoHandle.
product();
139 if(
std::find(partitions.begin(), partitions.end(), partition) == partitions.end()) {
140 partitions.push_back(partition);
144 std::map<sistripsummary::TrackerRegion,SiStripMiscalibrate::Smearings> mapOfSmearings;
146 for(
auto& thePSet : m_parameters){
151 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
152 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
153 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
154 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
157 params.
setSmearing(m_doScale,m_doSmear,m_scaleFactor,m_smearFactor);
158 mapOfSmearings[region]=params;
165 std::map<std::pair<uint32_t,int>,
float> theMap,oldPayloadMap;
167 std::vector<uint32_t> detid;
169 for (
const auto &
d : detid) {
180 for (
unsigned int j=0; j<
regions.size();j++){
181 bool checkRegion = (mapOfSmearings.count(
regions[j]) != 0);
188 params = mapOfSmearings[
regions[j]];
196 for(
int it=0;it<range.second-range.first;it++){
199 std::pair<uint32_t,int>
index = std::make_pair(
d,nAPV);
203 if(params.m_doScale){
204 Gain*=params.m_scaleFactor;
207 if(params.m_doSmear){
208 float smearedGain = CLHEP::RandGauss::shoot(Gain,params.m_smearFactor);
217 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(theMap);
220 uint32_t cachedId(0);
224 for(
const auto &element : theMap){
226 uint32_t
DetId = element.first.first;
227 int nAPV = element.first.second;
228 float new_gain = element.second;
229 float old_gain = oldPayloadMap[std::make_pair(DetId,nAPV)];
232 if(cachedId!=0 && DetId!=cachedId){
245 gain_ratio.
add(new_gain/old_gain);
246 o_gain.
add(old_gain);
247 n_gain.
add(new_gain);
256 throw std::runtime_error(
"PoolDBService required.");
274 scale_map->save(
true,0,0,ss_gain+
"_gain_scale_map.pdf");
275 scale_map->save(
true,0,0,ss_gain+
"_gain_scale_map.png");
277 smear_map->save(
true,0,0,ss_gain+
"_gain_smear_map.pdf");
278 smear_map->save(
true,0,0,ss_gain+
"_gain_smear_map.png");
280 ratio_map->save(
true,0,0,ss_gain+
"_gain_ratio_map.pdf");
281 ratio_map->save(
true,0,0,ss_gain+
"_gain_ratio_map.png");
285 old_payload_map->save(
true,range.first,range.second,
"starting_"+ss_gain+
"_gain_payload_map.pdf");
286 old_payload_map->save(
true,range.first,range.second,
"starting_"+ss_gain+
"_gain_payload_map.png");
290 new_payload_map->save(
true,range.first,range.second,
"new_"+ss_gain+
"_gain_payload_map.pdf");
291 new_payload_map->save(
true,range.first,range.second,
"new_"+ss_gain+
"_gain_payload_map.png");
296 std::unique_ptr<SiStripApvGain>
299 std::unique_ptr<SiStripApvGain>
obj = std::unique_ptr<SiStripApvGain>(
new SiStripApvGain());
301 std::vector<float> theSiStripVector;
302 uint32_t PreviousDetId = 0;
303 for(
const auto &element : theMap){
304 uint32_t
DetId = element.first.first;
305 if(DetId != PreviousDetId){
306 if(!theSiStripVector.empty()){
308 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
310 theSiStripVector.clear();
311 PreviousDetId = DetId;
313 theSiStripVector.push_back(element.second);
315 edm::LogInfo(
"SiStripChannelGainFromDBMiscalibrator")<<
" DetId: "<<DetId
316 <<
" APV: "<<element.first.second
317 <<
" Gain: "<<element.second
321 if(!theSiStripVector.empty()){
323 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
335 desc.
setComment(
"Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2." 336 "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
339 descScaler.
setComment(
"ParameterSet specifying the Strip tracker partition to be scaled / smeared " 340 "by a given factor.");
343 descScaler.
add<
bool>(
"doScale",
true);
344 descScaler.
add<
bool>(
"doSmear",
true);
345 descScaler.
add<
double>(
"scaleFactor", 1.0);
346 descScaler.
add<
double>(
"smearFactor", 1.0);
347 desc.
addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
353 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