CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
SiStripChannelGainFromDBMiscalibrator Class Reference

#include <CondTools/SiStrip/plugins/SiStripChannelGainFromDBMiscalibrator.cc>

Inheritance diagram for SiStripChannelGainFromDBMiscalibrator:
edm::one::EDAnalyzer<> edm::one::EDAnalyzerBase edm::EDConsumerBase

Public Member Functions

 SiStripChannelGainFromDBMiscalibrator (const edm::ParameterSet &)
 
 ~SiStripChannelGainFromDBMiscalibrator () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer<>
 EDAnalyzer ()=default
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 
std::unique_ptr< SiStripApvGaingetNewObject (const std::map< std::pair< uint32_t, int >, float > &theMap)
 

Private Attributes

const uint32_t m_gainType
 
const std::vector< edm::ParameterSetm_parameters
 
const std::string m_Record
 
const bool m_saveMaps
 
std::unique_ptr< TrackerMapnew_payload_map
 
std::unique_ptr< TrackerMapold_payload_map
 
std::unique_ptr< TrackerMapratio_map
 
std::unique_ptr< TrackerMapscale_map
 
std::unique_ptr< TrackerMapsmear_map
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: Class to miscalibrate a SiStrip Channel Gain payload from Database

Implementation: Read a SiStrip Channel Gain payload from DB (either central DB or sqlite file) and apply a miscalibration (either an offset / gaussian smearing or both) returns a local sqlite file with the same since of the original payload

Definition at line 50 of file SiStripChannelGainFromDBMiscalibrator.cc.

Constructor & Destructor Documentation

SiStripChannelGainFromDBMiscalibrator::SiStripChannelGainFromDBMiscalibrator ( const edm::ParameterSet iConfig)
explicit

Definition at line 79 of file SiStripChannelGainFromDBMiscalibrator.cc.

References edm::ParameterSet::getUntrackedParameter(), m_gainType, m_parameters, m_saveMaps, new_payload_map, old_payload_map, ratio_map, scale_map, smear_map, and AlCaHLTBitMon_QueryRunRegistry::string.

80  : m_Record{iConfig.getUntrackedParameter<std::string>("record", "SiStripApvGainRcd")},
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")} {
84  //now do what ever initialization is needed
85 
86  std::string ss_gain = (m_gainType > 0) ? "G2" : "G1";
87 
88  scale_map = std::unique_ptr<TrackerMap>(new TrackerMap("scale"));
89  scale_map->setTitle("Scale factor averaged by module");
90  scale_map->setPalette(1);
91 
92  smear_map = std::unique_ptr<TrackerMap>(new TrackerMap("smear"));
93  smear_map->setTitle("Smear factor averaged by module");
94  smear_map->setPalette(1);
95 
96  ratio_map = std::unique_ptr<TrackerMap>(new TrackerMap("ratio"));
97  ratio_map->setTitle("Average by module of the " + ss_gain + " Gain payload ratio (new/old)");
98  ratio_map->setPalette(1);
99 
100  new_payload_map = std::unique_ptr<TrackerMap>(new TrackerMap("new_payload"));
101  new_payload_map->setTitle("Tracker Map of Modified " + ss_gain + " Gain payload averaged by module");
102  new_payload_map->setPalette(1);
103 
104  old_payload_map = std::unique_ptr<TrackerMap>(new TrackerMap("old_payload"));
105  old_payload_map->setTitle("Tracker Map of Starting " + ss_gain + " Gain Payload averaged by module");
106  old_payload_map->setPalette(1);
107 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< edm::ParameterSet > m_parameters
SiStripChannelGainFromDBMiscalibrator::~SiStripChannelGainFromDBMiscalibrator ( )
override

Definition at line 109 of file SiStripChannelGainFromDBMiscalibrator.cc.

109 {}

Member Function Documentation

void SiStripChannelGainFromDBMiscalibrator::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 116 of file SiStripChannelGainFromDBMiscalibrator.cc.

References SiStripMiscalibrate::Entry::add(), cond::service::PoolDBOutputService::currentTime(), ztail::d, spr::find(), IntegrityClient_cfi::Gain, edm::EventSetup::get(), SiStripGain::getApvGain(), SiStripGain::getDetIds(), getNewObject(), SiStripGain::getRange(), SiStripMiscalibrate::getRegionFromString(), SiStripMiscalibrate::getRegionsFromDetId(), edm::Service< T >::isAvailable(), dqmiolumiharvest::j, m_gainType, m_parameters, m_Record, SiStripMiscalibrate::Entry::mean(), new_payload_map, old_payload_map, CalibrationSummaryClient_cfi::params, edm::ESHandle< T >::product(), FastTimerService_cff::range, ratio_map, HLT_2018_cff::region, SiStripMiscalibrate::Entry::reset(), scale_map, SiStripMiscalibrate::Smearings::setSmearing(), smear_map, AlCaHLTBitMon_QueryRunRegistry::string, and cond::service::PoolDBOutputService::writeOne().

116  {
117  using namespace edm;
118 
119  edm::ESHandle<TrackerTopology> tTopoHandle;
120  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
121  const auto* const tTopo = tTopoHandle.product();
122 
123  std::vector<std::string> partitions;
124 
125  // fill the list of partitions
126  for (auto& thePSet : m_parameters) {
127  const std::string partition(thePSet.getParameter<std::string>("partition"));
128  // only if it is not yet in the list
129  if (std::find(partitions.begin(), partitions.end(), partition) == partitions.end()) {
130  partitions.push_back(partition);
131  }
132  }
133 
134  std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
135 
136  for (auto& thePSet : m_parameters) {
137  const std::string partition(thePSet.getParameter<std::string>("partition"));
139 
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"));
144 
146  params.setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
147  mapOfSmearings[region] = params;
148  }
149 
150  edm::ESHandle<SiStripGain> SiStripApvGain_;
151  iSetup.get<SiStripGainRcd>().get(SiStripApvGain_);
152 
153  std::map<std::pair<uint32_t, int>, float> theMap, oldPayloadMap;
154 
155  std::vector<uint32_t> detid;
156  SiStripApvGain_->getDetIds(detid);
157  for (const auto& d : detid) {
158  SiStripApvGain::Range range = SiStripApvGain_->getRange(d, m_gainType);
159  float nAPV = 0;
160 
162 
163  // sort by largest to smallest
164  std::sort(regions.rbegin(), regions.rend());
165 
167 
168  for (unsigned int j = 0; j < regions.size(); j++) {
169  bool checkRegion = (mapOfSmearings.count(regions[j]) != 0);
170 
171  if (!checkRegion) {
172  // if the subdetector is not in the list and there's no indication for the whole tracker, just use the default
173  // i.e. no change
174  continue;
175  } else {
176  params = mapOfSmearings[regions[j]];
177  break;
178  }
179  }
180 
181  scale_map->fill(d, params.m_scaleFactor);
182  smear_map->fill(d, params.m_smearFactor);
183 
184  for (int it = 0; it < range.second - range.first; it++) {
185  nAPV += 1;
186  float Gain = SiStripApvGain_->getApvGain(it, range);
187  std::pair<uint32_t, int> index = std::make_pair(d, nAPV);
188 
189  oldPayloadMap[index] = Gain;
190 
191  if (params.m_doScale) {
192  Gain *= params.m_scaleFactor;
193  }
194 
195  if (params.m_doSmear) {
196  float smearedGain = CLHEP::RandGauss::shoot(Gain, params.m_smearFactor);
197  Gain = smearedGain;
198  }
199 
200  theMap[index] = Gain;
201 
202  } // loop over APVs
203  } // loop over DetIds
204 
205  std::unique_ptr<SiStripApvGain> theAPVGains = this->getNewObject(theMap);
206 
207  // make the payload ratio map
208  uint32_t cachedId(0);
209  SiStripMiscalibrate::Entry gain_ratio;
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)];
217 
218  // flush the counters
219  if (cachedId != 0 && DetId != cachedId) {
220  ratio_map->fill(cachedId, gain_ratio.mean());
221  old_payload_map->fill(cachedId, o_gain.mean());
222  new_payload_map->fill(cachedId, n_gain.mean());
223 
224  //auto test = new_payload_map.get()->smoduleMap;
225 
226  gain_ratio.reset();
227  o_gain.reset();
228  n_gain.reset();
229  }
230 
231  cachedId = DetId;
232  gain_ratio.add(new_gain / old_gain);
233  o_gain.add(old_gain);
234  n_gain.add(new_gain);
235  }
236 
237  // write out the APVGains record
239 
240  if (poolDbService.isAvailable())
241  poolDbService->writeOne(theAPVGains.get(), poolDbService->currentTime(), m_Record);
242  else
243  throw std::runtime_error("PoolDBService required.");
244 }
std::vector< sistripsummary::TrackerRegion > getRegionsFromDetId(const TrackerTopology *m_trackerTopo, DetId detid)
sistripsummary::TrackerRegion getRegionFromString(std::string region)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:76
bool isAvailable() const
Definition: Service.h:40
std::pair< ContainerIterator, ContainerIterator > Range
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void getDetIds(std::vector< uint32_t > &DetIds_) const
ATTENTION: we assume the detIds are the same as those from the first gain.
Definition: SiStripGain.cc:102
d
Definition: ztail.py:151
Definition: DetId.h:17
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)
const std::vector< edm::ParameterSet > m_parameters
HLT enums.
T get() const
Definition: EventSetup.h:73
T const * product() const
Definition: ESHandle.h:86
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71
void SiStripChannelGainFromDBMiscalibrator::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 247 of file SiStripChannelGainFromDBMiscalibrator.cc.

247 {}
void SiStripChannelGainFromDBMiscalibrator::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 250 of file SiStripChannelGainFromDBMiscalibrator.cc.

References SiStripMiscalibrate::getTruncatedRange(), m_gainType, m_saveMaps, new_payload_map, old_payload_map, FastTimerService_cff::range, ratio_map, scale_map, smear_map, and AlCaHLTBitMon_QueryRunRegistry::string.

250  {
251  if (m_saveMaps) {
252  std::string ss_gain = (m_gainType > 0) ? "G2" : "G1";
253 
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");
256 
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");
259 
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");
262 
264 
265  old_payload_map->save(true, range.first, range.second, "starting_" + ss_gain + "_gain_payload_map.pdf");
266  old_payload_map->save(true, range.first, range.second, "starting_" + ss_gain + "_gain_payload_map.png");
267 
269 
270  new_payload_map->save(true, range.first, range.second, "new_" + ss_gain + "_gain_payload_map.pdf");
271  new_payload_map->save(true, range.first, range.second, "new_" + ss_gain + "_gain_payload_map.png");
272  }
273 }
std::pair< float, float > getTruncatedRange(const TrackerMap *theMap)
void SiStripChannelGainFromDBMiscalibrator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 309 of file SiStripChannelGainFromDBMiscalibrator.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addUntracked(), edm::ParameterSetDescription::addVPSet(), DEFINE_FWK_MODULE, edm::ParameterSetDescription::setComment(), and AlCaHLTBitMon_QueryRunRegistry::string.

309  {
311 
312  desc.setComment(
313  "Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2."
314  "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
315 
316  edm::ParameterSetDescription descScaler;
317  descScaler.setComment(
318  "ParameterSet specifying the Strip tracker partition to be scaled / smeared "
319  "by a given factor.");
320 
321  descScaler.add<std::string>("partition", "Tracker");
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));
327 
328  desc.addUntracked<std::string>("record", "SiStripApvGainRcd");
329  desc.addUntracked<unsigned int>("gainType", 1);
330  desc.addUntracked<bool>("saveMaps", true);
331 
332  descriptions.add("scaleAndSmearSiStripGains", desc);
333 }
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void setComment(std::string const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr< SiStripApvGain > SiStripChannelGainFromDBMiscalibrator::getNewObject ( const std::map< std::pair< uint32_t, int >, float > &  theMap)
private

Definition at line 276 of file SiStripChannelGainFromDBMiscalibrator.cc.

References getGTfromDQMFile::obj, and FastTimerService_cff::range.

Referenced by analyze().

277  {
278  std::unique_ptr<SiStripApvGain> obj = std::unique_ptr<SiStripApvGain>(new SiStripApvGain());
279 
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()) {
286  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
287  if (!obj->put(PreviousDetId, range))
288  printf("Bug to put detId = %i\n", PreviousDetId);
289  }
290  theSiStripVector.clear();
291  PreviousDetId = DetId;
292  }
293  theSiStripVector.push_back(element.second);
294 
295  edm::LogInfo("SiStripChannelGainFromDBMiscalibrator")
296  << " DetId: " << DetId << " APV: " << element.first.second << " Gain: " << element.second << std::endl;
297  }
298 
299  if (!theSiStripVector.empty()) {
300  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
301  if (!obj->put(PreviousDetId, range))
302  printf("Bug to put detId = %i\n", PreviousDetId);
303  }
304 
305  return obj;
306 }
std::pair< ContainerIterator, ContainerIterator > Range
Definition: DetId.h:17

Member Data Documentation

const uint32_t SiStripChannelGainFromDBMiscalibrator::m_gainType
private
const std::vector<edm::ParameterSet> SiStripChannelGainFromDBMiscalibrator::m_parameters
private
const std::string SiStripChannelGainFromDBMiscalibrator::m_Record
private

Definition at line 64 of file SiStripChannelGainFromDBMiscalibrator.cc.

Referenced by analyze().

const bool SiStripChannelGainFromDBMiscalibrator::m_saveMaps
private
std::unique_ptr<TrackerMap> SiStripChannelGainFromDBMiscalibrator::new_payload_map
private
std::unique_ptr<TrackerMap> SiStripChannelGainFromDBMiscalibrator::old_payload_map
private
std::unique_ptr<TrackerMap> SiStripChannelGainFromDBMiscalibrator::ratio_map
private
std::unique_ptr<TrackerMap> SiStripChannelGainFromDBMiscalibrator::scale_map
private
std::unique_ptr<TrackerMap> SiStripChannelGainFromDBMiscalibrator::smear_map
private