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

Constructor & Destructor Documentation

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

Definition at line 81 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.

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

115 {
116 }

Member Function Documentation

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

Definition at line 125 of file SiStripChannelGainFromDBMiscalibrator.cc.

References SiStripMiscalibrate::Entry::add(), cond::service::PoolDBOutputService::currentTime(), edmIntegrityCheck::d, spr::find(), g4SimHits_cfi::Gain, edm::EventSetup::get(), SiStripGain::getApvGain(), SiStripGain::getDetIds(), getNewObject(), SiStripGain::getRange(), SiStripMiscalibrate::getRegionFromString(), SiStripMiscalibrate::getRegionsFromDetId(), edm::Service< T >::isAvailable(), m_gainType, m_parameters, m_Record, SiStripMiscalibrate::Entry::mean(), new_payload_map, old_payload_map, edm::ESHandle< T >::product(), ratio_map, SiStripMiscalibrate::Entry::reset(), scale_map, SiStripMiscalibrate::Smearings::setSmearing(), smear_map, jetUpdater_cfi::sort, AlCaHLTBitMon_QueryRunRegistry::string, and cond::service::PoolDBOutputService::writeOne().

126 {
127  using namespace edm;
128 
129  edm::ESHandle<TrackerTopology> tTopoHandle;
130  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
131  const auto* const tTopo = tTopoHandle.product();
132 
133  std::vector<std::string> partitions;
134 
135  // fill the list of partitions
136  for(auto& thePSet : m_parameters){
137  const std::string partition(thePSet.getParameter<std::string>("partition"));
138  // only if it is not yet in the list
139  if(std::find(partitions.begin(), partitions.end(), partition) == partitions.end()) {
140  partitions.push_back(partition);
141  }
142  }
143 
144  std::map<sistripsummary::TrackerRegion,SiStripMiscalibrate::Smearings> mapOfSmearings;
145 
146  for(auto& thePSet : m_parameters){
147 
148  const std::string partition(thePSet.getParameter<std::string>("partition"));
150 
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"));
155 
157  params.setSmearing(m_doScale,m_doSmear,m_scaleFactor,m_smearFactor);
158  mapOfSmearings[region]=params;
159  }
160 
161 
162  edm::ESHandle<SiStripGain> SiStripApvGain_;
163  iSetup.get<SiStripGainRcd>().get(SiStripApvGain_);
164 
165  std::map<std::pair<uint32_t,int>,float> theMap,oldPayloadMap;
166 
167  std::vector<uint32_t> detid;
168  SiStripApvGain_->getDetIds(detid);
169  for (const auto & d : detid) {
170  SiStripApvGain::Range range=SiStripApvGain_->getRange(d,m_gainType);
171  float nAPV=0;
172 
174 
175  // sort by largest to smallest
176  std::sort(regions.rbegin(), regions.rend());
177 
179 
180  for (unsigned int j=0; j<regions.size();j++){
181  bool checkRegion = (mapOfSmearings.count(regions[j]) != 0);
182 
183  if(!checkRegion) {
184  // if the subdetector is not in the list and there's no indication for the whole tracker, just use the default
185  // i.e. no change
186  continue;
187  } else {
188  params = mapOfSmearings[regions[j]];
189  break;
190  }
191  }
192 
193  scale_map->fill(d,params.m_scaleFactor);
194  smear_map->fill(d,params.m_smearFactor);
195 
196  for(int it=0;it<range.second-range.first;it++){
197  nAPV+=1;
198  float Gain=SiStripApvGain_->getApvGain(it,range);
199  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
200 
201  oldPayloadMap[index]=Gain;
202 
203  if(params.m_doScale){
204  Gain*=params.m_scaleFactor;
205  }
206 
207  if(params.m_doSmear){
208  float smearedGain = CLHEP::RandGauss::shoot(Gain,params.m_smearFactor);
209  Gain=smearedGain;
210  }
211 
212  theMap[index]=Gain;
213 
214  } // loop over APVs
215  } // loop over DetIds
216 
217  std::unique_ptr<SiStripApvGain> theAPVGains = this->getNewObject(theMap);
218 
219  // make the payload ratio map
220  uint32_t cachedId(0);
221  SiStripMiscalibrate::Entry gain_ratio;
224  for(const auto &element : theMap){
225 
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)];
230 
231  // flush the counters
232  if(cachedId!=0 && DetId!=cachedId){
233  ratio_map->fill(cachedId,gain_ratio.mean());
234  old_payload_map->fill(cachedId,o_gain.mean());
235  new_payload_map->fill(cachedId,n_gain.mean());
236 
237  //auto test = new_payload_map.get()->smoduleMap;
238 
239  gain_ratio.reset();
240  o_gain.reset();
241  n_gain.reset();
242  }
243 
244  cachedId=DetId;
245  gain_ratio.add(new_gain/old_gain);
246  o_gain.add(old_gain);
247  n_gain.add(new_gain);
248  }
249 
250  // write out the APVGains record
252 
253  if( poolDbService.isAvailable() )
254  poolDbService->writeOne(theAPVGains.get(),poolDbService->currentTime(),m_Record);
255  else
256  throw std::runtime_error("PoolDBService required.");
257 
258 }
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:20
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
Definition: DetId.h:18
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:71
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 262 of file SiStripChannelGainFromDBMiscalibrator.cc.

263 {
264 }
void SiStripChannelGainFromDBMiscalibrator::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 268 of file SiStripChannelGainFromDBMiscalibrator.cc.

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

269 {
270  if(m_saveMaps){
271 
272  std::string ss_gain = (m_gainType > 0) ? "G2" : "G1";
273 
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");
276 
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");
279 
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");
282 
284 
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");
287 
289 
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");
292  }
293 }
std::pair< float, float > getTruncatedRange(const TrackerMap *theMap)
void SiStripChannelGainFromDBMiscalibrator::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 332 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.

332  {
334 
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'.");
337 
338  edm::ParameterSetDescription descScaler;
339  descScaler.setComment("ParameterSet specifying the Strip tracker partition to be scaled / smeared "
340  "by a given factor.");
341 
342  descScaler.add<std::string>("partition", "Tracker");
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));
348 
349  desc.addUntracked<std::string>("record","SiStripApvGainRcd");
350  desc.addUntracked<unsigned int>("gainType",1);
351  desc.addUntracked<bool>("saveMaps",true);
352 
353  descriptions.add("scaleAndSmearSiStripGains", desc);
354 
355 }
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 297 of file SiStripChannelGainFromDBMiscalibrator.cc.

References hgcalPlots::obj.

Referenced by analyze().

298 {
299  std::unique_ptr<SiStripApvGain> obj = std::unique_ptr<SiStripApvGain>(new SiStripApvGain());
300 
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()){
307  SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
308  if ( !obj->put(PreviousDetId,range) ) printf("Bug to put detId = %i\n",PreviousDetId);
309  }
310  theSiStripVector.clear();
311  PreviousDetId = DetId;
312  }
313  theSiStripVector.push_back(element.second);
314 
315  edm::LogInfo("SiStripChannelGainFromDBMiscalibrator")<<" DetId: "<<DetId
316  <<" APV: "<<element.first.second
317  <<" Gain: "<<element.second
318  <<std::endl;
319  }
320 
321  if(!theSiStripVector.empty()){
322  SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
323  if ( !obj->put(PreviousDetId,range) ) printf("Bug to put detId = %i\n",PreviousDetId);
324  }
325 
326  return obj;
327 }
std::pair< ContainerIterator, ContainerIterator > Range
Definition: DetId.h:18

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 65 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