Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/HcalGains.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 scaleGains : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0017 public:
0018   explicit scaleGains(const edm::ParameterSet&);
0019   ~scaleGains() 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;
0026   double scale;
0027   edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
0028 };
0029 
0030 scaleGains::scaleGains(const edm::ParameterSet& iConfig) {
0031   fileIn = iConfig.getUntrackedParameter<std::string>("FileIn");
0032   fileOut = iConfig.getUntrackedParameter<std::string>("FileOut");
0033   scale = iConfig.getUntrackedParameter<double>("Scale");
0034   tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
0035 }
0036 
0037 scaleGains::~scaleGains() {}
0038 
0039 void scaleGains::analyze(edm::Event const&, edm::EventSetup const& iSetup) {
0040   HcalTopology topo = iSetup.getData(tok_htopo_);
0041 
0042   HcalGains gainsIn(&topo);
0043   ;
0044   std::ifstream inStream(fileIn.c_str());
0045   HcalDbASCIIIO::getObject(inStream, &gainsIn);
0046   inStream.close();
0047 
0048   HcalGains gainsOut(&topo);
0049   ;
0050   std::vector<DetId> channels = gainsIn.getAllChannels();
0051   for (unsigned i = 0; i < channels.size(); i++) {
0052     DetId id = channels[i];
0053     HcalGain item(id,
0054                   gainsIn.getValues(id)->getValue(0) * scale,
0055                   gainsIn.getValues(id)->getValue(1) * scale,
0056                   gainsIn.getValues(id)->getValue(2) * scale,
0057                   gainsIn.getValues(id)->getValue(3) * scale);
0058     gainsOut.addValues(item);
0059   }
0060 
0061   std::ofstream outStream(fileOut.c_str());
0062   HcalDbASCIIIO::dumpObject(outStream, gainsOut);
0063   outStream.close();
0064 }
0065 
0066 //define this as a plug-in
0067 DEFINE_FWK_MODULE(scaleGains);