Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:09

0001 #include <cstdlib>
0002 #include <iostream>
0003 #include <fstream>
0004 #include <vector>
0005 
0006 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
0007 #include "CondFormats/HcalObjects/interface/HcalRespCorrs.h"
0008 #include "Geometry/CaloTopology/interface/HcalTopology.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "Geometry/Records/interface/HcalRecNumberingRecord.h"
0015 
0016 class corrResps : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0017 public:
0018   explicit corrResps(const edm::ParameterSet&);
0019   ~corrResps() override;
0020 
0021 private:
0022   void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
0023   void analyze(edm::Event const&, edm::EventSetup const&) override;
0024   void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
0025   std::string fileIn, fileOut, fileCorr;
0026   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0027 };
0028 
0029 corrResps::corrResps(const edm::ParameterSet& iConfig) {
0030   fileIn = iConfig.getUntrackedParameter<std::string>("FileIn");
0031   fileOut = iConfig.getUntrackedParameter<std::string>("FileOut");
0032   fileCorr = iConfig.getUntrackedParameter<std::string>("FileCorr");
0033   tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0034 }
0035 
0036 corrResps::~corrResps() {}
0037 
0038 void corrResps::analyze(edm::Event const&, edm::EventSetup const& iSetup) {
0039   HcalTopology topo = iSetup.getData(tok_htopo_);
0040 
0041   HcalRespCorrs respIn(&topo);
0042   std::ifstream inStream(fileIn.c_str());
0043   HcalDbASCIIIO::getObject(inStream, &respIn);
0044   inStream.close();
0045 
0046   HcalRespCorrs corrsIn(&topo);
0047   std::ifstream inCorr(fileCorr.c_str());
0048   HcalDbASCIIIO::getObject(inCorr, &corrsIn);
0049   inCorr.close();
0050 
0051   HcalRespCorrs respOut(&topo);
0052   std::vector<DetId> channels = respIn.getAllChannels();
0053   for (unsigned int i = 0; i < channels.size(); i++) {
0054     DetId id = channels[i];
0055     float scale = 1.0;
0056     if (corrsIn.exists(id))
0057       scale = corrsIn.getValues(id)->getValue();
0058     HcalRespCorr item(id, respIn.getValues(id)->getValue() * scale);
0059     respOut.addValues(item);
0060   }
0061 
0062   std::ofstream outStream(fileOut.c_str());
0063   HcalDbASCIIIO::dumpObject(outStream, respOut);
0064   outStream.close();
0065 }
0066 
0067 //define this as a plug-in
0068 DEFINE_FWK_MODULE(corrResps);