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 () 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 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 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: 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 46 of file SiStripApvGainRescaler.cc.

Constructor & Destructor Documentation

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

Definition at line 66 of file SiStripApvGainRescaler.cc.

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

Definition at line 71 of file SiStripApvGainRescaler.cc.

71  {
72  // do anything here that needs to be done at desctruction time
73  // (e.g. close files, deallocate resources etc.)
74 }

Member Function Documentation

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

Definition at line 81 of file SiStripApvGainRescaler.cc.

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

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

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 138 of file SiStripApvGainRescaler.cc.

138 {}
void SiStripApvGainRescaler::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 141 of file SiStripApvGainRescaler.cc.

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

Definition at line 177 of file SiStripApvGainRescaler.cc.

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

177  {
179 
180  desc.setComment(
181  " Utility class to rescale the values of SiStrip G2 by the ratio of G1_old/G1_new: this is useful in the case in "
182  "which a Gain2 payload needs to recycled after a G1 update to keep the G1*G2 product constant."
183  "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
184 
185  desc.add<std::string>("Record", "SiStripApvGainRcd");
186  descriptions.add("rescaleGain2byGain1", desc);
187 }
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 144 of file SiStripApvGainRescaler.cc.

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

Referenced by analyze().

145  {
146  std::unique_ptr<SiStripApvGain> obj = std::unique_ptr<SiStripApvGain>(new SiStripApvGain());
147 
148  std::vector<float> theSiStripVector;
149  uint32_t PreviousDetId = 0;
150  for (const auto& element : theMap) {
151  uint32_t DetId = element.first.first;
152  if (DetId != PreviousDetId) {
153  if (!theSiStripVector.empty()) {
154  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
155  if (!obj->put(PreviousDetId, range))
156  printf("Bug to put detId = %i\n", PreviousDetId);
157  }
158  theSiStripVector.clear();
159  PreviousDetId = DetId;
160  }
161  theSiStripVector.push_back(element.second);
162 
163  edm::LogInfo("SiStripApvGainRescaler")
164  << " DetId: " << DetId << " APV: " << element.first.second << " Gain: " << element.second << std::endl;
165  }
166 
167  if (!theSiStripVector.empty()) {
168  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
169  if (!obj->put(PreviousDetId, range))
170  printf("Bug to put detId = %i\n", PreviousDetId);
171  }
172 
173  return obj;
174 }
std::pair< ContainerIterator, ContainerIterator > Range
Definition: DetId.h:17

Member Data Documentation

const std::string SiStripApvGainRescaler::m_Record
private

Definition at line 60 of file SiStripApvGainRescaler.cc.

Referenced by analyze().