CMS 3D CMS Logo

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

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

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

Public Member Functions

 SiStripApvGainRescaler (const edm::ParameterSet &)
 
 ~SiStripApvGainRescaler ()
 
- 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)
 

Private Attributes

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: Utility class to rescale the values of SiStrip G2 by the ratio of G1_old/G1_new: this is useful in the case in which a Gain2 payload needs to recycled after a G1 update to keep the G1*G2 product constant

Implementation: [Notes on implementation]

Definition at line 47 of file SiStripApvGainRescaler.cc.

Constructor & Destructor Documentation

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

Definition at line 68 of file SiStripApvGainRescaler.cc.

68  :
69  m_Record(iConfig.getParameter<std::string> ("Record"))
70 {
71  //now do what ever initialization is needed
72 }
T getParameter(std::string const &) const
SiStripApvGainRescaler::~SiStripApvGainRescaler ( )

Definition at line 74 of file SiStripApvGainRescaler.cc.

75 {
76 
77  // do anything here that needs to be done at desctruction time
78  // (e.g. close files, deallocate resources etc.)
79 }

Member Function Documentation

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

Definition at line 88 of file SiStripApvGainRescaler.cc.

References cond::service::PoolDBOutputService::currentTime(), edmIntegrityCheck::d, edm::EventSetup::get(), SiStripGain::getApvGain(), SiStripApvGain::getApvGain(), SiStripGain::getDetIds(), getNewObject(), SiStripGain::getRange(), SiStripApvGain::getRange(), edm::Service< T >::isAvailable(), m_Record, and cond::service::PoolDBOutputService::writeOne().

89 {
90  using namespace edm;
91 
92  // take G2_old and G1_old from the regular gain handle
93  edm::ESHandle<SiStripGain> g1g2Handle_;
94  iSetup.get<SiStripGainRcd>().get(g1g2Handle_);
95 
96  // take the additional G1_new from the Gain3Rcd (dirty trick)
98  iSetup.get<SiStripApvGain3Rcd>().get(g3Handle_);
99 
100  std::map<std::pair<uint32_t,int>,float> theMap;
101 
102  std::vector<uint32_t> detid;
103  g1g2Handle_->getDetIds(detid);
104  for (const auto & d : detid) {
105 
106  SiStripApvGain::Range rangeG1_old = g1g2Handle_->getRange(d,0);
107  SiStripApvGain::Range rangeG2_old = g1g2Handle_->getRange(d,1);
108  SiStripApvGain::Range rangeG1_new = g3Handle_->getRange(d);
109 
110  int nAPV=0;
111  for(int it=0;it<rangeG1_old.second-rangeG1_old.first;it++){
112  nAPV++;
113 
114  std::pair<uint32_t,int> index = std::make_pair(d,nAPV);
115 
116  float G1_old = g1g2Handle_->getApvGain(it,rangeG1_old);
117  float G2_old = g1g2Handle_->getApvGain(it,rangeG2_old);
118  float G1G2_old = G1_old*G2_old;
119  float G1_new = g3Handle_->getApvGain(it,rangeG1_new);
120 
121  // this is based on G1_old*G2_old = G1_new * G2_new ==> G2_new = (G1_old*G2_old)/G1_new
122 
123  float NewGain = G1G2_old/G1_new;
124 
125  // DO NOT RESCALE APVs set to the default value
126  if(G2_old!=1.){
127  theMap[index]=NewGain;
128  } else {
129  theMap[index]=1.;
130  }
131 
132  } // loop over APVs
133  } // loop over DetIds
134 
135  std::unique_ptr<SiStripApvGain> theAPVGains = this->getNewObject(theMap);
136 
137  // write out the APVGains record
139 
140  if( poolDbService.isAvailable() )
141  poolDbService->writeOne(theAPVGains.get(),poolDbService->currentTime(),m_Record);
142  else
143  throw std::runtime_error("PoolDBService required.");
144 
145 }
std::unique_ptr< SiStripApvGain > getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
static float getApvGain(uint16_t apv, const Range &range)
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:73
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
HLT enums.
T get() const
Definition: EventSetup.h:63
const Range getRange(const uint32_t detID) const
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:70
void SiStripApvGainRescaler::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 150 of file SiStripApvGainRescaler.cc.

151 {
152 }
void SiStripApvGainRescaler::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 156 of file SiStripApvGainRescaler.cc.

157 {
158 }
void SiStripApvGainRescaler::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 197 of file SiStripApvGainRescaler.cc.

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

197  {
199 
200  desc.setComment(" Utility class to rescale the values of SiStrip G2 by the ratio of G1_old/G1_new: this is useful in the case in which a Gain2 payload needs to recycled after a G1 update to keep the G1*G2 product constant."
201  "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
202 
203  desc.add<std::string>("Record","SiStripApvGainRcd");
204  descriptions.add("rescaleGain2byGain1", desc);
205 }
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 > SiStripApvGainRescaler::getNewObject ( const std::map< std::pair< uint32_t, int >, float > &  theMap)
private

Definition at line 162 of file SiStripApvGainRescaler.cc.

References GetRecoTauVFromDQM_MC_cff::obj.

Referenced by analyze().

163 {
164  std::unique_ptr<SiStripApvGain> obj = std::unique_ptr<SiStripApvGain>(new SiStripApvGain());
165 
166  std::vector<float> theSiStripVector;
167  uint32_t PreviousDetId = 0;
168  for(const auto &element : theMap){
169  uint32_t DetId = element.first.first;
170  if(DetId != PreviousDetId){
171  if(!theSiStripVector.empty()){
172  SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
173  if ( !obj->put(PreviousDetId,range) ) printf("Bug to put detId = %i\n",PreviousDetId);
174  }
175  theSiStripVector.clear();
176  PreviousDetId = DetId;
177  }
178  theSiStripVector.push_back(element.second);
179 
180  edm::LogInfo("SiStripApvGainRescaler")<<" DetId: "<<DetId
181  <<" APV: "<<element.first.second
182  <<" Gain: "<<element.second
183  <<std::endl;
184  }
185 
186  if(!theSiStripVector.empty()){
187  SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
188  if ( !obj->put(PreviousDetId,range) ) printf("Bug to put detId = %i\n",PreviousDetId);
189  }
190 
191  return obj;
192 }
std::pair< ContainerIterator, ContainerIterator > Range
Definition: DetId.h:18

Member Data Documentation

const std::string SiStripApvGainRescaler::m_Record
private

Definition at line 61 of file SiStripApvGainRescaler.cc.

Referenced by analyze().