File indexing completed on 2024-04-06 12:24:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <iostream>
0022 #include <fstream>
0023 #include <utility>
0024 #include <map>
0025 #include <string>
0026
0027
0028 #include "FWCore/Framework/interface/Frameworkfwd.h"
0029 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0030
0031 #include "FWCore/Framework/interface/Event.h"
0032 #include "FWCore/Framework/interface/MakerMacros.h"
0033 #include "FWCore/Framework/interface/EventSetup.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0035 #include "FWCore/Framework/interface/ESHandle.h"
0036
0037
0038
0039
0040 #include "RecoBTag/Records/interface/BTagPerformanceRecord.h"
0041
0042 #include "CondFormats/PhysicsToolsObjects/interface/BinningPointByMap.h"
0043 #include "RecoBTag/PerformanceDB/interface/BtagPerformance.h"
0044
0045
0046
0047 class validateBTagDB : public edm::one::EDAnalyzer<> {
0048 public:
0049 explicit validateBTagDB(const edm::ParameterSet&);
0050
0051 private:
0052 std::string beff, mistag, ceff;
0053 std::vector<std::string> algoNames;
0054 std::vector<std::string> fileList;
0055 std::vector<edm::ESGetToken<BtagPerformance, BTagPerformanceRecord>> algoTokens;
0056 void analyze(const edm::Event&, const edm::EventSetup&) final;
0057
0058
0059 };
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 validateBTagDB::validateBTagDB(const edm::ParameterSet& iConfig)
0073
0074 {
0075
0076 std::cout << " In the constructor" << std::endl;
0077
0078 beff = iConfig.getParameter<std::string>("CalibrationForBEfficiency");
0079 ceff = iConfig.getParameter<std::string>("CalibrationForCEfficiency");
0080 mistag = iConfig.getParameter<std::string>("CalibrationForMistag");
0081 algoNames = iConfig.getParameter<std::vector<std::string>>("algoNames");
0082 fileList = iConfig.getParameter<std::vector<std::string>>("fileList");
0083 for (auto const& n : algoNames) {
0084 algoTokens.push_back(esConsumes<BtagPerformance, BTagPerformanceRecord>(edm::ESInputTag("", n)));
0085 }
0086 }
0087
0088
0089
0090
0091
0092
0093 void validateBTagDB::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0094 if (fileList.size() < algoNames.size()) {
0095 std::cout << "File list short!" << std::endl;
0096 exit(1);
0097 }
0098 std::cout << "Cut checks" << std::endl;
0099 for (size_t i = 0; i < algoNames.size(); i++) {
0100 BtagPerformance const& perfTest = iSetup.getData(algoTokens[i]);
0101 std::cout << algoNames[i] << " " << perfTest.workingPoint().cut() << std::endl;
0102 std::cout << "Checking against: " << fileList[i] << std::endl;
0103 std::ifstream inFile(fileList[i].c_str());
0104 std::ofstream outFile(("text/" + algoNames[i] + ".txt").c_str());
0105 std::ostringstream output;
0106
0107 int nMeasures;
0108 int nVars;
0109 std::string name;
0110 float workingPoint;
0111 std::string type;
0112 std::cout << "1" << std::endl;
0113
0114 inFile >> name;
0115 output << name << std::endl;
0116 std::cout << "2" << std::endl;
0117
0118 inFile >> workingPoint;
0119 output << workingPoint << std::endl;
0120 std::cout << "3" << std::endl;
0121
0122 inFile >> type;
0123 output << type << std::endl;
0124 std::cout << "4" << std::endl;
0125
0126 inFile >> nMeasures;
0127 output << nMeasures << std::endl;
0128 std::cout << "5" << std::endl;
0129
0130 inFile >> nVars;
0131 output << nVars << std::endl;
0132 std::cout << "6" << std::endl;
0133
0134 std::vector<int> measureList;
0135 for (int iM = 1; iM <= nMeasures; iM++) {
0136 int temp;
0137 inFile >> temp;
0138 measureList.push_back(temp);
0139 output << measureList[iM - 1] << " ";
0140 }
0141 output << std::endl;
0142 std::cout << "7" << std::endl;
0143
0144 std::vector<int> varList;
0145 for (int iV = 1; iV <= nVars; iV++) {
0146 int temp;
0147 inFile >> temp;
0148 varList.push_back(temp);
0149 output << varList[iV - 1] << " ";
0150 }
0151 output << std::endl;
0152 std::cout << "8" << std::endl;
0153 while (!inFile.eof()) {
0154
0155 BinningPointByMap tempMeasure;
0156 bool done = false;
0157
0158 for (int iV = 1; iV <= nVars; iV++) {
0159 float val1, val2;
0160 inFile >> val1;
0161 inFile >> val2;
0162
0163 output << val1 << " " << val2 << " ";
0164 tempMeasure.insert((BinningVariables::BinningVariablesType)varList[iV - 1], (val1 + val2) / 2.0);
0165 }
0166
0167
0168 for (int iM = 1; iM <= nMeasures; iM++) {
0169 if (inFile.peek() == EOF) {
0170 done = true;
0171 }
0172 }
0173 if (done) {
0174 continue;
0175 }
0176 for (int iM = 1; iM <= nMeasures; iM++) {
0177 float res1, measured;
0178 measured = perfTest.getResult((PerformanceResult::ResultType)measureList[iM - 1], tempMeasure);
0179 inFile >> res1;
0180 output << measured << " ";
0181 std::cout << measured << std::endl;
0182 if (res1 != measured) {
0183 std::cout << "Measure/result mismatch with" << measured << " " << res1 << std::endl;
0184
0185 }
0186 }
0187 output << std::endl;
0188 }
0189
0190 outFile << output.str();
0191 outFile.close();
0192 inFile.close();
0193
0194
0195 }
0196 }
0197
0198
0199 DEFINE_FWK_MODULE(validateBTagDB);