CMS 3D CMS Logo

SiStripApvGainRescaler.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondTools/SiStrip
4 // Class: SiStripApvGainRescaler
5 //
13 //
14 // Original Author: Marco Musich
15 // Created: Tue, 03 Oct 2017 12:57:34 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <iostream>
22 
23 // user include files
26 
29 
32 
37 
41 
42 //
43 // class declaration
44 //
45 
47 public:
49  ~SiStripApvGainRescaler() override;
50 
51  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
52 
53 private:
54  void beginJob() override;
55  void analyze(const edm::Event&, const edm::EventSetup&) override;
56  std::unique_ptr<SiStripApvGain> getNewObject(const std::map<std::pair<uint32_t, int>, float>& theMap);
57  void endJob() override;
58 
59  // ----------member data ---------------------------
61 };
62 
63 //
64 // constructors and destructor
65 //
67  : m_Record(iConfig.getParameter<std::string>("Record")) {
68  //now do what ever initialization is needed
69 }
70 
72  // do anything here that needs to be done at desctruction time
73  // (e.g. close files, deallocate resources etc.)
74 }
75 
76 //
77 // member functions
78 //
79 
80 // ------------ method called for each event ------------
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 }
136 
137 // ------------ method called once each job just before starting event loop ------------
139 
140 // ------------ method called once each job just after ending the event loop ------------
142 
143 //********************************************************************************//
144 std::unique_ptr<SiStripApvGain> SiStripApvGainRescaler::getNewObject(
145  const std::map<std::pair<uint32_t, int>, float>& theMap) {
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 }
175 
176 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
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 }
188 
189 //define this as a plug-in
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
SiStripGainRcd
Definition: SiStripDependentRecords.h:29
EDAnalyzer.h
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
SiStripApvGainRescaler::~SiStripApvGainRescaler
~SiStripApvGainRescaler() override
Definition: SiStripApvGainRescaler.cc:71
ESHandle.h
SiStripGain.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::LogInfo
Definition: MessageLogger.h:254
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
SiStripGainRcd.h
SiStripApvGainRcd.h
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
SiStripApvGain::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripApvGain.cc:30
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
DetId
Definition: DetId.h:17
MakerMacros.h
PoolDBOutputService.h
SiStripApvGainRescaler::endJob
void endJob() override
Definition: SiStripApvGainRescaler.cc:141
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
Service.h
SiStripGain::getRange
const SiStripApvGain::Range getRange(uint32_t detID) const
Definition: SiStripGain.h:71
SiStripApvGainRescaler::getNewObject
std::unique_ptr< SiStripApvGain > getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
Definition: SiStripApvGainRescaler.cc:144
edm::ESHandle< SiStripGain >
SiStripApvGain3Rcd
Definition: SiStripCondDataRecords.h:10
SiStripGain::getDetIds
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
SiStripApvGain.h
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripGain::getApvGain
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
Definition: SiStripGain.h:76
edm::ParameterSet
Definition: ParameterSet.h:36
edm::ParameterSetDescription::setComment
void setComment(std::string const &value)
Definition: ParameterSetDescription.cc:33
Event.h
edm::Service< cond::service::PoolDBOutputService >
iEvent
int iEvent
Definition: GenABIO.cc:224
SiStripApvGainRescaler::m_Record
const std::string m_Record
Definition: SiStripApvGainRescaler.cc:60
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
SiStripApvGainRescaler::beginJob
void beginJob() override
Definition: SiStripApvGainRescaler.cc:138
SiStripApvGainRescaler::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SiStripApvGainRescaler.cc:177
SiStripApvGainRescaler::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: SiStripApvGainRescaler.cc:81
std
Definition: JetResolutionObject.h:76
SiStripApvGainRescaler::SiStripApvGainRescaler
SiStripApvGainRescaler(const edm::ParameterSet &)
Definition: SiStripApvGainRescaler.cc:66
Frameworkfwd.h
SiStripApvGain::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripApvGain.h:28
cond::service::PoolDBOutputService::writeOne
Hash writeOne(const T *payload, Time_t time, const std::string &recordName)
Definition: PoolDBOutputService.h:57
EventSetup.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ztail.d
d
Definition: ztail.py:151
SiStripApvGainRescaler
Definition: SiStripApvGainRescaler.cc:46
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
edm::Event
Definition: Event.h:73
SiStripApvGain
Definition: SiStripApvGain.h:25
SiStripApvGain::getApvGain
static float getApvGain(uint16_t apv, const Range &range)
Definition: SiStripApvGain.h:82
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:189