CMS 3D CMS Logo

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