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 
31 
36 
40 
41 //
42 // class declaration
43 //
44 
46 public:
48  ~SiStripApvGainRescaler() override;
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52 private:
53  void beginJob() override;
54  void analyze(const edm::Event&, const edm::EventSetup&) override;
55  std::unique_ptr<SiStripApvGain> getNewObject(const std::map<std::pair<uint32_t, int>, float>& theMap);
56  void endJob() override;
57 
58  // ----------member data ---------------------------
60 
61  // take G2_old and G1_old from the regular gain handle
63  // take the additional G1_new from the Gain3Rcd (dirty trick)
65 };
66 
67 //
68 // constructors and destructor
69 //
71  : m_Record(iConfig.getParameter<std::string>("Record")), g1g2Token_(esConsumes()), g3Token_(esConsumes()) {
72  //now do what ever initialization is needed
73 }
74 
76  // do anything here that needs to be done at desctruction time
77  // (e.g. close files, deallocate resources etc.)
78 }
79 
80 //
81 // member functions
82 //
83 
84 // ------------ method called for each event ------------
86  using namespace edm;
87 
88  const auto& g1g2 = iSetup.getData(g1g2Token_);
89  const auto& g3 = iSetup.getData(g3Token_);
90 
91  std::map<std::pair<uint32_t, int>, float> theMap;
92 
93  std::vector<uint32_t> detid;
94  g1g2.getDetIds(detid);
95  for (const auto& d : detid) {
96  SiStripApvGain::Range rangeG1_old = g1g2.getRange(d, 0);
97  SiStripApvGain::Range rangeG2_old = g1g2.getRange(d, 1);
98  SiStripApvGain::Range rangeG1_new = g3.getRange(d);
99 
100  int nAPV = 0;
101  for (int it = 0; it < rangeG1_old.second - rangeG1_old.first; it++) {
102  nAPV++;
103 
104  std::pair<uint32_t, int> index = std::make_pair(d, nAPV);
105 
106  float G1_old = g1g2.getApvGain(it, rangeG1_old);
107  float G2_old = g1g2.getApvGain(it, rangeG2_old);
108  float G1G2_old = G1_old * G2_old;
109  float G1_new = g3.getApvGain(it, rangeG1_new);
110 
111  // this is based on G1_old*G2_old = G1_new * G2_new ==> G2_new = (G1_old*G2_old)/G1_new
112 
113  float NewGain = G1G2_old / G1_new;
114 
115  // DO NOT RESCALE APVs set to the default value
116  if (G2_old != 1.) {
117  theMap[index] = NewGain;
118  } else {
119  theMap[index] = 1.;
120  }
121 
122  } // loop over APVs
123  } // loop over DetIds
124 
125  std::unique_ptr<SiStripApvGain> theAPVGains = this->getNewObject(theMap);
126 
127  // write out the APVGains record
129 
130  if (poolDbService.isAvailable())
131  poolDbService->writeOne(theAPVGains.get(), poolDbService->currentTime(), m_Record);
132  else
133  throw std::runtime_error("PoolDBService required.");
134 }
135 
136 // ------------ method called once each job just before starting event loop ------------
138 
139 // ------------ method called once each job just after ending the event loop ------------
141 
142 //********************************************************************************//
143 std::unique_ptr<SiStripApvGain> SiStripApvGainRescaler::getNewObject(
144  const std::map<std::pair<uint32_t, int>, float>& theMap) {
145  std::unique_ptr<SiStripApvGain> obj = std::make_unique<SiStripApvGain>();
146 
147  std::vector<float> theSiStripVector;
148  uint32_t PreviousDetId = 0;
149  for (const auto& element : theMap) {
150  uint32_t DetId = element.first.first;
151  if (DetId != PreviousDetId) {
152  if (!theSiStripVector.empty()) {
153  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
154  if (!obj->put(PreviousDetId, range))
155  printf("Bug to put detId = %i\n", PreviousDetId);
156  }
157  theSiStripVector.clear();
158  PreviousDetId = DetId;
159  }
160  theSiStripVector.push_back(element.second);
161 
162  edm::LogInfo("SiStripApvGainRescaler")
163  << " DetId: " << DetId << " APV: " << element.first.second << " Gain: " << element.second << std::endl;
164  }
165 
166  if (!theSiStripVector.empty()) {
167  SiStripApvGain::Range range(theSiStripVector.begin(), theSiStripVector.end());
168  if (!obj->put(PreviousDetId, range))
169  printf("Bug to put detId = %i\n", PreviousDetId);
170  }
171 
172  return obj;
173 }
174 
175 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
178 
179  desc.setComment(
180  " Utility class to rescale the values of SiStrip G2 by the ratio of G1_old/G1_new: this is useful in the case in "
181  "which a Gain2 payload needs to recycled after a G1 update to keep the G1*G2 product constant."
182  "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
183 
184  desc.add<std::string>("Record", "SiStripApvGainRcd");
185  descriptions.add("rescaleGain2byGain1", desc);
186 }
187 
188 //define this as a plug-in
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
EDAnalyzer.h
SiStripApvGainRescaler::~SiStripApvGainRescaler
~SiStripApvGainRescaler() override
Definition: SiStripApvGainRescaler.cc:75
SiStripGain.h
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
SiStripGainRcd.h
SiStripApvGainRcd.h
SiStripApvGainRescaler::g1g2Token_
edm::ESGetToken< SiStripGain, SiStripGainRcd > g1g2Token_
Definition: SiStripApvGainRescaler.cc:62
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::one::EDAnalyzer
Definition: EDAnalyzer.h: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:140
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
SiStripApvGainRescaler::getNewObject
std::unique_ptr< SiStripApvGain > getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
Definition: SiStripApvGainRescaler.cc:143
SiStripApvGain.h
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ParameterSet
Definition: ParameterSet.h:47
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:59
edm::EventSetup
Definition: EventSetup.h:58
edm::ESGetToken< SiStripGain, SiStripGainRcd >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripApvGainRescaler::beginJob
void beginJob() override
Definition: SiStripApvGainRescaler.cc:137
edm::EventSetup::getData
bool getData(T &iHolder) const
Definition: EventSetup.h:127
SiStripApvGainRescaler::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: SiStripApvGainRescaler.cc:176
SiStripApvGainRescaler::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: SiStripApvGainRescaler.cc:85
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
std
Definition: JetResolutionObject.h:76
SiStripApvGainRescaler::SiStripApvGainRescaler
SiStripApvGainRescaler(const edm::ParameterSet &)
Definition: SiStripApvGainRescaler.cc:70
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:63
EventSetup.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
ztail.d
d
Definition: ztail.py:151
SiStripApvGainRescaler
Definition: SiStripApvGainRescaler.cc:45
genParticles_cff.map
map
Definition: genParticles_cff.py:11
ParameterSet.h
SiStripApvGainRescaler::g3Token_
edm::ESGetToken< SiStripApvGain, SiStripApvGain3Rcd > g3Token_
Definition: SiStripApvGainRescaler.cc:64
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:217