CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () 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
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex >
const & 
esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
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 endJob () override
 
SiStripApvGain getNewObject (const std::map< std::pair< uint32_t, int >, float > &theMap)
 

Private Attributes

const edm::ESGetToken
< SiStripGain, SiStripGainRcd
gainToken_
 
const uint32_t m_gainType
 
const std::vector
< edm::ParameterSet
m_parameters
 
const uint32_t m_printdebug
 
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
 
const edm::ESGetToken
< TrackerTopology,
TrackerTopologyRcd
tTopoToken_
 

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)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

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 81 of file SiStripChannelGainFromDBMiscalibrator.cc.

References edm::EDConsumerBase::esConsumes(), gainToken_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), m_gainType, m_parameters, m_Record, m_saveMaps, new_payload_map, old_payload_map, ratio_map, scale_map, smear_map, AlCaHLTBitMon_QueryRunRegistry::string, tTopoToken_, and ~SiStripChannelGainFromDBMiscalibrator().

82  : m_printdebug{iConfig.getUntrackedParameter<uint32_t>("printDebug", 1)},
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")},
89  //now do what ever initialization is needed
90 
91  std::string ss_gain = (m_gainType > 0) ? "G2" : "G1";
92 
93  scale_map = std::make_unique<TrackerMap>("scale");
94  scale_map->setTitle("Scale factor averaged by module");
95  scale_map->setPalette(1);
96 
97  smear_map = std::make_unique<TrackerMap>("smear");
98  smear_map->setTitle("Smear factor averaged by module");
99  smear_map->setPalette(1);
100 
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);
104 
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);
108 
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);
112 }
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
T getUntrackedParameter(std::string const &, T const &) const
const edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const std::vector< edm::ParameterSet > m_parameters
SiStripChannelGainFromDBMiscalibrator::~SiStripChannelGainFromDBMiscalibrator ( )
overridedefault

Member Function Documentation

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

Implements edm::one::EDAnalyzerBase.

Definition at line 121 of file SiStripChannelGainFromDBMiscalibrator.cc.

References cond::service::PoolDBOutputService::createOneIOV(), ztail::d, spr::find(), gainToken_, edm::EventSetup::getData(), getNewObject(), SiStripMiscalibrate::getRegionFromString(), SiStripMiscalibrate::getRegionsFromDetId(), dqmiolumiharvest::j, m_gainType, m_parameters, m_printdebug, m_Record, new_payload_map, old_payload_map, submitPVValidationJobs::params, sistrip::SpyUtilities::range(), ratio_map, HLT_FULL_cff::region, scale_map, SiStripMiscalibrate::Smearings::setSmearing(), smear_map, AlCaHLTBitMon_QueryRunRegistry::string, and tTopoToken_.

121  {
122  using namespace edm;
123 
124  const auto* const tTopo = &iSetup.getData(tTopoToken_);
125 
126  std::vector<std::string> partitions;
127 
128  // fill the list of partitions
129  for (auto& thePSet : m_parameters) {
130  const std::string partition(thePSet.getParameter<std::string>("partition"));
131  // only if it is not yet in the list
132  if (std::find(partitions.begin(), partitions.end(), partition) == partitions.end()) {
133  partitions.push_back(partition);
134  }
135  }
136 
137  std::map<sistripsummary::TrackerRegion, SiStripMiscalibrate::Smearings> mapOfSmearings;
138 
139  for (auto& thePSet : m_parameters) {
140  const std::string partition(thePSet.getParameter<std::string>("partition"));
142 
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"));
147 
149  params.setSmearing(m_doScale, m_doSmear, m_scaleFactor, m_smearFactor);
150  mapOfSmearings[region] = params;
151  }
152 
153  const auto& apvGain = iSetup.getData(gainToken_);
154 
155  std::map<std::pair<uint32_t, int>, float> theMap, oldPayloadMap;
156 
157  std::vector<uint32_t> detid;
158  apvGain.getDetIds(detid);
159  for (const auto& d : detid) {
160  SiStripApvGain::Range range = apvGain.getRange(d, m_gainType);
161  float nAPV = 0;
162 
164 
165  // sort by largest to smallest
166  std::sort(regions.rbegin(), regions.rend());
167 
169 
170  for (unsigned int j = 0; j < regions.size(); j++) {
171  bool checkRegion = (mapOfSmearings.count(regions[j]) != 0);
172 
173  if (!checkRegion) {
174  // if the subdetector is not in the list and there's no indication for the whole tracker, just use the default
175  // i.e. no change
176  continue;
177  } else {
178  params = mapOfSmearings[regions[j]];
179  break;
180  }
181  }
182 
183  scale_map->fill(d, params.m_scaleFactor);
184  smear_map->fill(d, params.m_smearFactor);
185 
186  for (int it = 0; it < range.second - range.first; it++) {
187  nAPV += 1;
188  float Gain = apvGain.getApvGain(it, range);
189  std::pair<uint32_t, int> index = std::make_pair(d, nAPV);
190 
191  oldPayloadMap[index] = Gain;
192 
193  if (params.m_doScale) {
194  Gain *= params.m_scaleFactor;
195  }
196 
197  if (params.m_doSmear) {
198  float smearedGain = CLHEP::RandGauss::shoot(Gain, params.m_smearFactor);
199  Gain = smearedGain;
200  }
201 
202  theMap[index] = Gain;
203 
204  } // loop over APVs
205  } // loop over DetIds
206 
207  SiStripApvGain theAPVGains = this->getNewObject(theMap);
208 
209  // make the payload ratio map
210  uint32_t cachedId(0);
211  SiStripMiscalibrate::Entry gain_ratio;
214  unsigned int countDetIds(0); // count DetIds to print
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)];
220 
221  // flush the counters
222  if (cachedId != 0 && DetId != cachedId) {
223  ratio_map->fill(cachedId, gain_ratio.mean());
224  old_payload_map->fill(cachedId, o_gain.mean());
225  new_payload_map->fill(cachedId, n_gain.mean());
226 
227  //auto test = new_payload_map.get()->smoduleMap;
228 
229  gain_ratio.reset();
230  o_gain.reset();
231  n_gain.reset();
232  countDetIds++;
233  }
234 
235  // printout for debug
236  if (countDetIds < m_printdebug) {
237  edm::LogPrint("SiStripChannelGainFromDBMiscalibrator")
238  << "SiStripChannelGainFromDBMiscalibrator"
239  << "::" << __FUNCTION__ << " detid " << DetId << " \t"
240  << " APV " << nAPV << " \t new gain: " << new_gain << " \t old gain: " << old_gain << " \t" << std::endl;
241  }
242 
243  cachedId = DetId;
244  gain_ratio.add(new_gain / old_gain);
245  o_gain.add(old_gain);
246  n_gain.add(new_gain);
247  }
248 
249  // write out the APVGains record
251 
252  if (poolDbService.isAvailable()) {
253  if (poolDbService->isNewTagRequest(m_Record)) {
254  poolDbService->createOneIOV(theAPVGains, poolDbService->currentTime(), m_Record);
255  } else {
256  poolDbService->appendOneIOV(theAPVGains, poolDbService->currentTime(), m_Record);
257  }
258  } else {
259  throw std::runtime_error("PoolDBService required.");
260  }
261 }
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
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
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
const uint16_t range(const Frame &aFrame)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
tuple d
Definition: ztail.py:151
const edm::ESGetToken< SiStripGain, SiStripGainRcd > gainToken_
std::pair< ContainerIterator, ContainerIterator > Range
SiStripApvGain getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
Log< level::Warning, true > LogPrint
Definition: DetId.h:17
void setSmearing(bool doScale, bool doSmear, double the_scaleFactor, double the_smearFactor)
const std::vector< edm::ParameterSet > m_parameters
void SiStripChannelGainFromDBMiscalibrator::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 264 of file SiStripChannelGainFromDBMiscalibrator.cc.

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

264  {
265  if (m_saveMaps) {
266  std::string ss_gain = (m_gainType > 0) ? "G2" : "G1";
267 
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");
270 
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");
273 
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");
276 
278 
279  old_payload_map->save(true, range.first, range.second, "starting_" + ss_gain + "_gain_payload_map.pdf");
280  old_payload_map->save(true, range.first, range.second, "starting_" + ss_gain + "_gain_payload_map.png");
281 
283 
284  new_payload_map->save(true, range.first, range.second, "new_" + ss_gain + "_gain_payload_map.pdf");
285  new_payload_map->save(true, range.first, range.second, "new_" + ss_gain + "_gain_payload_map.png");
286  }
287 }
const uint16_t range(const Frame &aFrame)
std::pair< float, float > getTruncatedRange(const TrackerMap *theMap)
void SiStripChannelGainFromDBMiscalibrator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 323 of file SiStripChannelGainFromDBMiscalibrator.cc.

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

323  {
325 
326  desc.setComment(
327  "Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2."
328  "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
329 
330  edm::ParameterSetDescription descScaler;
331  descScaler.setComment(
332  "ParameterSet specifying the Strip tracker partition to be scaled / smeared "
333  "by a given factor.");
334 
335  descScaler.add<std::string>("partition", "Tracker");
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));
341 
342  desc.addUntracked<unsigned int>("printDebug", 1);
343  desc.addUntracked<std::string>("record", "SiStripApvGainRcd");
344  desc.addUntracked<unsigned int>("gainType", 1);
345  desc.addUntracked<bool>("saveMaps", true);
346 
347  descriptions.add("scaleAndSmearSiStripGains", desc);
348 }
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)
SiStripApvGain SiStripChannelGainFromDBMiscalibrator::getNewObject ( const std::map< std::pair< uint32_t, int >, float > &  theMap)
private

Definition at line 290 of file SiStripChannelGainFromDBMiscalibrator.cc.

References getGTfromDQMFile::obj, gpuVertexFinder::printf(), and sistrip::SpyUtilities::range().

Referenced by analyze().

291  {
293 
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()) {
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  theSiStripVector.clear();
305  PreviousDetId = DetId;
306  }
307  theSiStripVector.push_back(element.second);
308 
309  edm::LogInfo("SiStripChannelGainFromDBMiscalibrator")
310  << " DetId: " << DetId << " APV: " << element.first.second << " Gain: " << element.second << std::endl;
311  }
312 
313  if (!theSiStripVector.empty()) {
314  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
315  if (!obj.put(PreviousDetId, range))
316  printf("Bug to put detId = %i\n", PreviousDetId);
317  }
318 
319  return obj;
320 }
const uint16_t range(const Frame &aFrame)
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
std::pair< ContainerIterator, ContainerIterator > Range
Log< level::Info, false > LogInfo
Definition: DetId.h:17

Member Data Documentation

const edm::ESGetToken<SiStripGain, SiStripGainRcd> SiStripChannelGainFromDBMiscalibrator::gainToken_
private
const uint32_t SiStripChannelGainFromDBMiscalibrator::m_gainType
private
const std::vector<edm::ParameterSet> SiStripChannelGainFromDBMiscalibrator::m_parameters
private
const uint32_t SiStripChannelGainFromDBMiscalibrator::m_printdebug
private

Definition at line 63 of file SiStripChannelGainFromDBMiscalibrator.cc.

Referenced by analyze().

const std::string SiStripChannelGainFromDBMiscalibrator::m_Record
private
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
const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> SiStripChannelGainFromDBMiscalibrator::tTopoToken_
private