Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:31

0001 // -*- C++ -*-
0002 //
0003 // Package:    validateBTagDB
0004 // Class:      validateBTagDB
0005 //
0006 /**\class TestOctoberExe TestOctoberExe.cc RecoBTag/TestOctoberExe/src/TestOctoberExe.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Tommaso Boccali
0015 //         Created:  Tue Nov 25 15:50:50 CET 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <iostream>
0022 #include <fstream>
0023 #include <utility>
0024 #include <map>
0025 #include <string>
0026 
0027 // user include files
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 // class decleration
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 //#include "CondFormats/BTagPerformance/interface/BtagPerformancePayloadFromTableEtaJetEt.h"
0045 //#include "CondFormats/BTagPerformance/interface/BtagPerformancePayloadFromTableEtaJetEtPhi.h"
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   // ----------member data ---------------------------
0059 };
0060 
0061 //
0062 // constants, enums and typedefs
0063 //
0064 
0065 //
0066 // static data member definitions
0067 //
0068 
0069 //
0070 // constructors and destructor
0071 //
0072 validateBTagDB::validateBTagDB(const edm::ParameterSet& iConfig)
0073 
0074 {
0075   //now do what ever initialization is needed
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 // member functions
0090 //
0091 
0092 // ------------ method called to for each event  ------------
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     //Name
0114     inFile >> name;
0115     output << name << std::endl;
0116     std::cout << "2" << std::endl;
0117     //WP
0118     inFile >> workingPoint;
0119     output << workingPoint << std::endl;
0120     std::cout << "3" << std::endl;
0121     //Payload type
0122     inFile >> type;
0123     output << type << std::endl;
0124     std::cout << "4" << std::endl;
0125     //N measurements
0126     inFile >> nMeasures;
0127     output << nMeasures << std::endl;
0128     std::cout << "5" << std::endl;
0129     //N Vars
0130     inFile >> nVars;
0131     output << nVars << std::endl;
0132     std::cout << "6" << std::endl;
0133     //Measure enums
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     //Vars enums
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       //    std::vector< std::pair<float,float> > varBins;
0155       BinningPointByMap tempMeasure;
0156       bool done = false;
0157       //std::cout <<"nvars = "<< nVars << std::endl;
0158       for (int iV = 1; iV <= nVars; iV++) {
0159         float val1, val2;
0160         inFile >> val1;
0161         inFile >> val2;
0162         //      varBins.push_back( std::make_pair( val1, val2 ) );
0163         output << val1 << " " << val2 << " ";
0164         tempMeasure.insert((BinningVariables::BinningVariablesType)varList[iV - 1], (val1 + val2) / 2.0);
0165       }
0166       //std::cout << "9" << std::endl;
0167       //Measurement goes here!
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           //        output << " check! ";
0185         }
0186       }
0187       output << std::endl;
0188     }
0189     //  std::cout << output.str();
0190     outFile << output.str();
0191     outFile.close();
0192     inFile.close();
0193 
0194     //    std::cout << output.str() << std::endl;
0195   }
0196 }
0197 
0198 //define this as a plug-in
0199 DEFINE_FWK_MODULE(validateBTagDB);