CMS 3D CMS Logo

corrGains.cc
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <iostream>
3 #include <fstream>
4 #include <string>
5 #include <vector>
6 
18 
19 class corrGains : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
20 
21 public:
22  explicit corrGains(const edm::ParameterSet&);
23  ~corrGains() override;
24 
25 private:
26  void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
27  void analyze(edm::Event const&, edm::EventSetup const&) override;
28  void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
30 };
31 
33  fileIn = iConfig.getUntrackedParameter<std::string>("FileIn");
34  fileOut = iConfig.getUntrackedParameter<std::string>("FileOut");
35  fileCorr = iConfig.getUntrackedParameter<std::string>("FileCorr");
36 }
37 
39 
40 void corrGains::analyze(edm::Event const&, edm::EventSetup const& iSetup) {
41 
43  iSetup.get<HcalRecNumberingRecord>().get(htopo);
44  HcalTopology topo = (*htopo);
45 
46  HcalGains gainsIn(&topo);;
47  std::ifstream inStream (fileIn.c_str());
48  HcalDbASCIIIO::getObject (inStream, &gainsIn);
49  inStream.close();
50 
51  HcalRespCorrs corrsIn(&topo);;
52  std::ifstream inCorr (fileCorr.c_str());
53  HcalDbASCIIIO::getObject (inCorr, &corrsIn);
54  inCorr.close();
55 
56  HcalGains gainsOut(&topo);;
57  std::vector<DetId> channels = gainsIn.getAllChannels ();
58  for (unsigned int i = 0; i < channels.size(); i++) {
59  DetId id = channels[i];
60  float scale = 1.;
61  if (corrsIn.exists(id)) scale = corrsIn.getValues(id)->getValue();
62  HcalGain item(id, gainsIn.getValues(id)->getValue(0) * scale, gainsIn.getValues(id)->getValue(1) * scale,
63  gainsIn.getValues(id)->getValue(2) * scale, gainsIn.getValues(id)->getValue(3) * scale);
64  gainsOut.addValues(item);
65  }
66  std::ofstream outStream (fileOut.c_str());
67  HcalDbASCIIIO::dumpObject (outStream, gainsOut);
68  outStream.close();
69 }
70 
71 //define this as a plug-in
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: corrGains.cc:26
std::string fileIn
Definition: corrGains.cc:29
T getUntrackedParameter(std::string const &, T const &) const
std::string fileCorr
Definition: corrGains.cc:29
corrGains(const edm::ParameterSet &)
Definition: corrGains.cc:32
void analyze(edm::Event const &, edm::EventSetup const &) override
Definition: corrGains.cc:40
const Item * getValues(DetId fId, bool throwOnFail=true) const
float getValue(int fCapId) const
get value for capId = 0..3
Definition: HcalGain.h:22
int iEvent
Definition: GenABIO.cc:224
std::string fileOut
Definition: corrGains.cc:29
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const bool exists(DetId fId) const
std::vector< DetId > getAllChannels() const
~corrGains() override
Definition: corrGains.cc:38
Definition: DetId.h:18
bool getObject(std::istream &fInput, HcalPedestals *fObject)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
float getValue() const
Definition: HcalRespCorr.h:20
T get() const
Definition: EventSetup.h:71
bool addValues(const Item &myItem)
Definition: Run.h:45
void endRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: corrGains.cc:28