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
68
69
70
71
72
73
74
75
76
|
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
#include "CondFormats/HcalObjects/interface/HcalGains.h"
#include "CondFormats/HcalObjects/interface/HcalRespCorrs.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 corrGains : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
explicit corrGains(const edm::ParameterSet&);
~corrGains() 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, fileCorr;
edm::ESGetToken<HcalTopology, HcalRecNumberingRecord> tok_htopo_;
};
corrGains::corrGains(const edm::ParameterSet& iConfig) {
fileIn = iConfig.getUntrackedParameter<std::string>("FileIn");
fileOut = iConfig.getUntrackedParameter<std::string>("FileOut");
fileCorr = iConfig.getUntrackedParameter<std::string>("FileCorr");
tok_htopo_ = esConsumes<HcalTopology, HcalRecNumberingRecord>();
}
corrGains::~corrGains() {}
void corrGains::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();
HcalRespCorrs corrsIn(&topo);
;
std::ifstream inCorr(fileCorr.c_str());
HcalDbASCIIIO::getObject(inCorr, &corrsIn);
inCorr.close();
HcalGains gainsOut(&topo);
;
std::vector<DetId> channels = gainsIn.getAllChannels();
for (unsigned int i = 0; i < channels.size(); i++) {
DetId id = channels[i];
float scale = 1.;
if (corrsIn.exists(id))
scale = corrsIn.getValues(id)->getValue();
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(corrGains);
|