scaleGains

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>

#include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
#include "CondFormats/HcalObjects/interface/HcalGains.h"
#include "Geometry/CaloTopology/interface/HcalTopology.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "Geometry/Records/interface/HcalRecNumberingRecord.h"

class scaleGains : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
  explicit scaleGains(const edm::ParameterSet&);
  ~scaleGains() override;

private:
  void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
  void analyze(edm::Event const&, edm::EventSetup const&) override;
  void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
  std::string fileIn, fileOut;
  double scale;
  edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
};

scaleGains::scaleGains(const edm::ParameterSet& iConfig) {
  fileIn = iConfig.getUntrackedParameter<std::string>("FileIn");
  fileOut = iConfig.getUntrackedParameter<std::string>("FileOut");
  scale = iConfig.getUntrackedParameter<double>("Scale");
  tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
}

scaleGains::~scaleGains() {}

void scaleGains::analyze(edm::Event const&, edm::EventSetup const& iSetup) {
  HcalTopology topo = iSetup.getData(tok_htopo_);

  HcalGains gainsIn(&topo);
  ;
  std::ifstream inStream(fileIn.c_str());
  HcalDbASCIIIO::getObject(inStream, &gainsIn);
  inStream.close();

  HcalGains gainsOut(&topo);
  ;
  std::vector<DetId> channels = gainsIn.getAllChannels();
  for (unsigned i = 0; i < channels.size(); i++) {
    DetId id = channels[i];
    HcalGain item(id,
                  gainsIn.getValues(id)->getValue(0) * scale,
                  gainsIn.getValues(id)->getValue(1) * scale,
                  gainsIn.getValues(id)->getValue(2) * scale,
                  gainsIn.getValues(id)->getValue(3) * scale);
    gainsOut.addValues(item);
  }

  std::ofstream outStream(fileOut.c_str());
  HcalDbASCIIIO::dumpObject(outStream, gainsOut);
  outStream.close();
}

//define this as a plug-in
DEFINE_FWK_MODULE(scaleGains);