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 ()
 
- 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
 
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)
 
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

virtual void analyze (const edm::Event &, const edm::EventSetup &) override
 
virtual void beginJob () override
 
virtual void endJob () override
 
std::unique_ptr< SiStripApvGaingetNewObject (const std::map< std::pair< uint32_t, int >, float > &theMap)
 
sistripsummary::TrackerRegion getRegionFromString (std::string region)
 
std::vector< sistripsummary::TrackerRegiongetRegionsFromDetId (const TrackerTopology *tTopo, DetId detid)
 

Private Attributes

const uint32_t m_gainType
 
const std::vector< edm::ParameterSetm_parameters
 
const std::string m_Record
 

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 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: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 79 of file SiStripChannelGainFromDBMiscalibrator.cc.

Constructor & Destructor Documentation

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

Definition at line 103 of file SiStripChannelGainFromDBMiscalibrator.cc.

References edm::ParameterSet::getUntrackedParameter(), m_gainType, m_parameters, and AlCaHLTBitMon_QueryRunRegistry::string.

103  :
104  m_Record{iConfig.getUntrackedParameter<std::string> ("record" , "SiStripApvGainRcd")},
105  m_gainType{iConfig.getUntrackedParameter<uint32_t>("gainType",1)},
106  m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >("params")}
107 {
108  //now do what ever initialization is needed
109 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< edm::ParameterSet > m_parameters
SiStripChannelGainFromDBMiscalibrator::~SiStripChannelGainFromDBMiscalibrator ( )

Definition at line 112 of file SiStripChannelGainFromDBMiscalibrator.cc.

113 {
114 }

Member Function Documentation

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

Definition at line 123 of file SiStripChannelGainFromDBMiscalibrator.cc.

References cond::service::PoolDBOutputService::currentTime(), edmIntegrityCheck::d, spr::find(), g4SimHits_cfi::Gain, edm::EventSetup::get(), SiStripGain::getApvGain(), SiStripGain::getDetIds(), getNewObject(), SiStripGain::getRange(), getRegionFromString(), getRegionsFromDetId(), edm::Service< T >::isAvailable(), m_gainType, m_parameters, m_Record, edm::ESHandle< T >::product(), random, ApvGain::GainSmearings::setSmearing(), AlCaHLTBitMon_QueryRunRegistry::string, and cond::service::PoolDBOutputService::writeOne().

124 {
125  using namespace edm;
126 
127  edm::ESHandle<TrackerTopology> tTopoHandle;
128  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
129  const auto* const tTopo = tTopoHandle.product();
130 
131  std::vector<std::string> partitions;
132 
133  // fill the list of partitions
134  for(auto& thePSet : m_parameters){
135  const std::string partition(thePSet.getParameter<std::string>("partition"));
136  // only if it is not yet in the list
137  if(std::find(partitions.begin(), partitions.end(), partition) == partitions.end()) {
138  partitions.push_back(partition);
139  }
140  }
141 
142  std::map<sistripsummary::TrackerRegion,ApvGain::GainSmearings> mapOfSmearings;
143 
144  for(auto& thePSet : m_parameters){
145 
146  const std::string partition(thePSet.getParameter<std::string>("partition"));
147  sistripsummary::TrackerRegion region = this->getRegionFromString(partition);
148 
149  bool m_doScale(thePSet.getParameter<bool>("doScale"));
150  bool m_doSmear(thePSet.getParameter<bool>("doSmear"));
151  double m_scaleFactor(thePSet.getParameter<double>("scaleFactor"));
152  double m_smearFactor(thePSet.getParameter<double>("smearFactor"));
153 
155  params.setSmearing(m_doScale,m_doSmear,m_scaleFactor,m_smearFactor);
156  mapOfSmearings[region]=params;
157  }
158 
159 
160  edm::ESHandle<SiStripGain> SiStripApvGain_;
161  iSetup.get<SiStripGainRcd>().get(SiStripApvGain_);
162 
163  std::map<std::pair<uint32_t,int>,float> theMap;
164  std::shared_ptr<TRandom3> random(new TRandom3(1));
165 
166  std::vector<uint32_t> detid;
167  SiStripApvGain_->getDetIds(detid);
168  for (const auto & d : detid) {
169  SiStripApvGain::Range range=SiStripApvGain_->getRange(d,m_gainType);
170  float nAPV=0;
171 
172  auto regions = getRegionsFromDetId(tTopo,d);
173 
174  // sort by largest to smallest
175  std::sort(regions.rbegin(), regions.rend());
176 
178 
179  for (unsigned int j=0; j<regions.size();j++){
180  bool checkRegion = (mapOfSmearings.count(regions[j]) != 0);
181 
182  if(!checkRegion) {
183  // if the subdetector is not in the list and there's no indication for the whole tracker, just use the default
184  // i.e. no change
185  continue;
186  } else {
187  params = mapOfSmearings[regions[j]];
188  break;
189  }
190  }
191 
192  for(int it=0;it<range.second-range.first;it++){
193  nAPV+=1;
194  float Gain=SiStripApvGain_->getApvGain(it,range);
195  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
196 
197  if(params.m_doScale){
198  Gain*=params.m_scaleFactor;
199  }
200 
201  if(params.m_doSmear){
202  float smearedGain = random->Gaus(Gain,params.m_smearFactor);
203  Gain=smearedGain;
204  }
205 
206  theMap[index]=Gain;
207 
208  } // loop over APVs
209  } // loop over DetIds
210 
211  std::unique_ptr<SiStripApvGain> theAPVGains = this->getNewObject(theMap);
212 
213  // write out the APVGains record
215 
216  if( poolDbService.isAvailable() )
217  poolDbService->writeOne(theAPVGains.get(),poolDbService->currentTime(),m_Record);
218  else
219  throw std::runtime_error("PoolDBService required.");
220 
221 }
TRandom random
Definition: MVATrainer.cc:138
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:73
void setSmearing(bool doScale, bool doSmear, double the_scaleFactor, double the_smearFactor)
std::vector< sistripsummary::TrackerRegion > getRegionsFromDetId(const TrackerTopology *tTopo, DetId detid)
bool isAvailable() const
Definition: Service.h:46
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:108
std::unique_ptr< SiStripApvGain > getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
const T & get() const
Definition: EventSetup.h:59
const std::vector< edm::ParameterSet > m_parameters
HLT enums.
sistripsummary::TrackerRegion getRegionFromString(std::string region)
T const * product() const
Definition: ESHandle.h:86
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:70
void SiStripChannelGainFromDBMiscalibrator::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 226 of file SiStripChannelGainFromDBMiscalibrator.cc.

227 {
228 }
void SiStripChannelGainFromDBMiscalibrator::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 232 of file SiStripChannelGainFromDBMiscalibrator.cc.

233 {
234 }
void SiStripChannelGainFromDBMiscalibrator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 273 of file SiStripChannelGainFromDBMiscalibrator.cc.

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

273  {
275 
276  desc.setComment("Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2."
277  "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
278 
279  edm::ParameterSetDescription descScaler;
280  descScaler.setComment("ParameterSet specifying the Strip tracker partition to be scaled / smeared "
281  "by a given factor.");
282 
283  descScaler.add<std::string>("partition", "Tracker");
284  descScaler.add<bool>("doScale",true);
285  descScaler.add<bool>("doSmear",true);
286  descScaler.add<double>("scaleFactor", 1.0);
287  descScaler.add<double>("smearFactor", 1.0);
288  desc.addVPSet("params", descScaler, std::vector<edm::ParameterSet>(1));
289 
290  desc.addUntracked<std::string>("record","SiStripApvGainRcd");
291  desc.addUntracked<unsigned int>("gainType",1);
292 
293  descriptions.add("scaleAndSmearSiStripGains", desc);
294 
295 }
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 238 of file SiStripChannelGainFromDBMiscalibrator.cc.

References GetRecoTauVFromDQM_MC_cff::obj.

Referenced by analyze().

239 {
240  std::unique_ptr<SiStripApvGain> obj = std::unique_ptr<SiStripApvGain>(new SiStripApvGain());
241 
242  std::vector<float> theSiStripVector;
243  uint32_t PreviousDetId = 0;
244  for(const auto &element : theMap){
245  uint32_t DetId = element.first.first;
246  if(DetId != PreviousDetId){
247  if(!theSiStripVector.empty()){
248  SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
249  if ( !obj->put(PreviousDetId,range) ) printf("Bug to put detId = %i\n",PreviousDetId);
250  }
251  theSiStripVector.clear();
252  PreviousDetId = DetId;
253  }
254  theSiStripVector.push_back(element.second);
255 
256  edm::LogInfo("SiStripChannelGainFromDBMiscalibrator")<<" DetId: "<<DetId
257  <<" APV: "<<element.first.second
258  <<" Gain: "<<element.second
259  <<std::endl;
260  }
261 
262  if(!theSiStripVector.empty()){
263  SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
264  if ( !obj->put(PreviousDetId,range) ) printf("Bug to put detId = %i\n",PreviousDetId);
265  }
266 
267  return obj;
268 }
std::pair< ContainerIterator, ContainerIterator > Range
Definition: DetId.h:18
sistripsummary::TrackerRegion SiStripChannelGainFromDBMiscalibrator::getRegionFromString ( std::string  region)
private

Definition at line 298 of file SiStripChannelGainFromDBMiscalibrator.cc.

References Exception, sistripsummary::TEC, sistripsummary::TECM, sistripsummary::TECM_1, sistripsummary::TECM_2, sistripsummary::TECM_3, sistripsummary::TECM_4, sistripsummary::TECM_5, sistripsummary::TECM_6, sistripsummary::TECM_7, sistripsummary::TECM_8, sistripsummary::TECM_9, sistripsummary::TECP, sistripsummary::TECP_1, sistripsummary::TECP_2, sistripsummary::TECP_3, sistripsummary::TECP_4, sistripsummary::TECP_5, sistripsummary::TECP_6, sistripsummary::TECP_7, sistripsummary::TECP_8, sistripsummary::TECP_9, sistripsummary::TIB, sistripsummary::TIB_1, sistripsummary::TIB_2, sistripsummary::TIB_3, sistripsummary::TIB_4, sistripsummary::TID, sistripsummary::TIDM, sistripsummary::TIDM_1, sistripsummary::TIDM_2, sistripsummary::TIDM_3, sistripsummary::TIDP, sistripsummary::TIDP_1, sistripsummary::TIDP_2, sistripsummary::TIDP_3, sistripsummary::TOB, sistripsummary::TOB_1, sistripsummary::TOB_2, sistripsummary::TOB_3, sistripsummary::TOB_4, sistripsummary::TOB_5, sistripsummary::TOB_6, and sistripsummary::TRACKER.

Referenced by analyze().

300 {
301  if(region.find("Tracker")!=std::string::npos){
302  return sistripsummary::TRACKER ;
303  } else if(region.find("TIB")!=std::string::npos){
304  if (region=="TIB_1") return sistripsummary::TIB_1;
305  else if (region=="TIB_2") return sistripsummary::TIB_2;
306  else if (region=="TIB_3") return sistripsummary::TIB_3;
307  else if (region=="TIB_4") return sistripsummary::TIB_4;
308  else return sistripsummary::TIB ;
309  } else if(region.find("TOB")!=std::string::npos){
310  if (region=="TOB_1") return sistripsummary::TOB_1;
311  else if (region=="TOB_2") return sistripsummary::TOB_2;
312  else if (region=="TOB_3") return sistripsummary::TOB_3;
313  else if (region=="TOB_4") return sistripsummary::TOB_4;
314  else if (region=="TOB_5") return sistripsummary::TOB_5;
315  else if (region=="TOB_6") return sistripsummary::TOB_6;
316  else return sistripsummary::TOB ;
317  } else if(region.find("TID")!=std::string::npos){
318  if(region.find("TIDM")!=std::string::npos){
319  if (region=="TIDM_1") return sistripsummary::TIDM_1;
320  else if (region=="TIDM_2") return sistripsummary::TIDM_2;
321  else if (region=="TIDM_3") return sistripsummary::TIDM_3;
322  else return sistripsummary::TIDM;
323  } else if(region.find("TIDP")!=std::string::npos){
324  if (region=="TIDP_1") return sistripsummary::TIDP_1;
325  else if (region=="TIDP_2") return sistripsummary::TIDP_2;
326  else if (region=="TIDP_3") return sistripsummary::TIDP_3;
327  else return sistripsummary::TIDP;
328  } else return sistripsummary::TID ;
329  } else if(region.find("TEC")!=std::string::npos) {
330  if(region.find("TECM")!=std::string::npos){
331  if (region=="TECM_1") return sistripsummary::TECM_1;
332  else if (region=="TECM_2") return sistripsummary::TECM_2;
333  else if (region=="TECM_3") return sistripsummary::TECM_3;
334  else if (region=="TECM_4") return sistripsummary::TECM_4;
335  else if (region=="TECM_5") return sistripsummary::TECM_5;
336  else if (region=="TECM_6") return sistripsummary::TECM_6;
337  else if (region=="TECM_7") return sistripsummary::TECM_7;
338  else if (region=="TECM_8") return sistripsummary::TECM_8;
339  else if (region=="TECM_9") return sistripsummary::TECM_9;
340  else return sistripsummary::TECM;
341  } else if(region.find("TECP")!=std::string::npos){
342  if (region=="TECP_1") return sistripsummary::TECP_1;
343  else if (region=="TECP_2") return sistripsummary::TECP_2;
344  else if (region=="TECP_3") return sistripsummary::TECP_3;
345  else if (region=="TECP_4") return sistripsummary::TECP_4;
346  else if (region=="TECP_5") return sistripsummary::TECP_5;
347  else if (region=="TECP_6") return sistripsummary::TECP_6;
348  else if (region=="TECP_7") return sistripsummary::TECP_7;
349  else if (region=="TECP_8") return sistripsummary::TECP_8;
350  else if (region=="TECP_9") return sistripsummary::TECP_9;
351  else return sistripsummary::TECP;
352  } else return sistripsummary::TEC ;
353  } else {
354  edm::LogError("LogicError") << "Unknown partition: " << region;
355  throw cms::Exception("Invalid Partition passed");
356  }
357 }
std::vector< sistripsummary::TrackerRegion > SiStripChannelGainFromDBMiscalibrator::getRegionsFromDetId ( const TrackerTopology tTopo,
DetId  detid 
)
private

Definition at line 360 of file SiStripChannelGainFromDBMiscalibrator.cc.

References DEFINE_FWK_MODULE, DetId::subdetId(), StripSubdetector::TEC, TrackerTopology::tecSide(), TrackerTopology::tecWheel(), StripSubdetector::TIB, TrackerTopology::tibLayer(), StripSubdetector::TID, TrackerTopology::tidSide(), TrackerTopology::tidWheel(), StripSubdetector::TOB, TrackerTopology::tobLayer(), and sistripsummary::TRACKER.

Referenced by analyze().

362 {
363  int layer = 0;
364  int side = 0;
365  int subdet = 0;
366  int detCode = 0;
367 
368  std::vector<sistripsummary::TrackerRegion> ret;
369 
370  switch (detid.subdetId()) {
372  layer = m_trackerTopo->tibLayer(detid);
373  subdet = 1;
374  break;
376  layer = m_trackerTopo->tobLayer(detid);
377  subdet = 2;
378  break;
380  // is this module in TID+ or TID-?
381  layer = m_trackerTopo->tidWheel(detid);
382  side = m_trackerTopo->tidSide(detid);
383  subdet = 3*10+side;
384  break;
386  // is this module in TEC+ or TEC-?
387  layer = m_trackerTopo->tecWheel(detid);
388  side = m_trackerTopo->tecSide(detid);
389  subdet = 4*10+side;
390  break;
391  }
392 
393  detCode = (subdet*10)+layer;
394 
395  ret.push_back(static_cast<sistripsummary::TrackerRegion>(detCode));
396 
397  if(subdet/10 > 0) {
398  ret.push_back(static_cast<sistripsummary::TrackerRegion>(subdet/10));
399  }
400 
401  ret.push_back(static_cast<sistripsummary::TrackerRegion>(subdet));
402  ret.push_back(sistripsummary::TRACKER);
403 
404  return ret;
405 }
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38

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

Referenced by analyze().