Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:06

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