Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    TestPerformanceFW_ES
0004 // Class:      TestPerformanceFW_ES
0005 //
0006 /**\class TestPerformanceFW_ES TestPerformanceFW_ES.cc RecoBTag/TestPerformanceFW_ES/src/TestPerformanceFW_ES.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 <iostream>
0021 #include <memory>
0022 #include <map>
0023 #include <vector>
0024 #include <string>
0025 
0026 // user include files
0027 #include "FWCore/Framework/interface/Frameworkfwd.h"
0028 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0029 
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 #include "FWCore/Framework/interface/EventSetup.h"
0033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0034 #include "FWCore/Framework/interface/ESHandle.h"
0035 //
0036 // class decleration
0037 //
0038 
0039 #include "RecoBTag/Records/interface/BTagPerformanceRecord.h"
0040 #include "CondFormats/PhysicsToolsObjects/interface/BinningPointByMap.h"
0041 #include "RecoBTag/PerformanceDB/interface/BtagPerformance.h"
0042 
0043 class TestPerformanceFW_ES : public edm::one::EDAnalyzer<> {
0044 public:
0045   explicit TestPerformanceFW_ES(const edm::ParameterSet&);
0046   ~TestPerformanceFW_ES();
0047 
0048 private:
0049   std::string name;
0050   std::vector<std::string> measureName;
0051   std::vector<std::string> measureType;
0052   std::vector<edm::ESGetToken<BtagPerformance, BTagPerformanceRecord>> measureToken;
0053   virtual void beginJob();
0054   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0055   virtual void endJob();
0056 
0057   // ----------member data ---------------------------
0058 };
0059 
0060 TestPerformanceFW_ES::TestPerformanceFW_ES(const edm::ParameterSet& iConfig)
0061 
0062 {
0063   measureName = iConfig.getParameter<std::vector<std::string>>("measureName");
0064   measureType = iConfig.getParameter<std::vector<std::string>>("measureType");
0065   measureToken.reserve(measureName.size());
0066 
0067   for (auto const& n : measureName) {
0068     measureToken.push_back(esConsumes<BtagPerformance, BTagPerformanceRecord>(edm::ESInputTag("", n)));
0069   }
0070 }
0071 
0072 TestPerformanceFW_ES::~TestPerformanceFW_ES() {
0073   // do anything here that needs to be done at desctruction time
0074   // (e.g. close files, deallocate resources etc.)
0075 }
0076 
0077 //
0078 // member functions
0079 //
0080 
0081 // ------------ method called to for each event  ------------
0082 void TestPerformanceFW_ES::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0083   std::map<std::string, PerformanceResult::ResultType> measureMap;
0084   measureMap["BTAGBEFF"] = PerformanceResult::BTAGBEFF;
0085   measureMap["BTAGBERR"] = PerformanceResult::BTAGBERR;
0086   measureMap["BTAGCEFF"] = PerformanceResult::BTAGCEFF;
0087   measureMap["BTAGCERR"] = PerformanceResult::BTAGCERR;
0088   measureMap["BTAGLEFF"] = PerformanceResult::BTAGLEFF;
0089   measureMap["BTAGLERR"] = PerformanceResult::BTAGLERR;
0090   measureMap["BTAGNBEFF"] = PerformanceResult::BTAGNBEFF;
0091   measureMap["BTAGNBERR"] = PerformanceResult::BTAGNBERR;
0092   measureMap["BTAGBEFFCORR"] = PerformanceResult::BTAGBEFFCORR;
0093   measureMap["BTAGBERRCORR"] = PerformanceResult::BTAGBERRCORR;
0094   measureMap["BTAGCEFFCORR"] = PerformanceResult::BTAGCEFFCORR;
0095   measureMap["BTAGCERRCORR"] = PerformanceResult::BTAGCERRCORR;
0096   measureMap["BTAGLEFFCORR"] = PerformanceResult::BTAGLEFFCORR;
0097   measureMap["BTAGLERRCORR"] = PerformanceResult::BTAGLERRCORR;
0098   measureMap["BTAGNBEFFCORR"] = PerformanceResult::BTAGNBEFFCORR;
0099   measureMap["BTAGNBERRCORR"] = PerformanceResult::BTAGNBERRCORR;
0100   measureMap["BTAGNBERRCORR"] = PerformanceResult::BTAGNBERRCORR;
0101   measureMap["MUEFF"] = PerformanceResult::MUEFF;
0102   measureMap["MUERR"] = PerformanceResult::MUERR;
0103   measureMap["MUFAKE"] = PerformanceResult::MUFAKE;
0104   measureMap["MUEFAKE"] = PerformanceResult::MUEFAKE;
0105 
0106   if (measureName.size() != measureType.size()) {
0107     std::cout << "measureName, measureType size mismatch!" << std::endl;
0108     exit(-1);
0109   }
0110 
0111   for (size_t iMeasure = 0; iMeasure < measureName.size(); iMeasure++) {
0112     std::cout << "Testing: " << measureName[iMeasure] << " of type " << measureType[iMeasure] << std::endl;
0113 
0114     //Setup our measurement
0115     const BtagPerformance& perf = iSetup.getData(measureToken[iMeasure]);
0116 
0117     //Working point
0118     std::cout << "Working point: " << perf.workingPoint().cut() << std::endl;
0119     //Setup the point we wish to test!
0120     BinningPointByMap measurePoint;
0121     measurePoint.insert(BinningVariables::JetEt, 50);
0122     measurePoint.insert(BinningVariables::JetAbsEta, 0.6);
0123 
0124     std::cout << "Is it OK? " << perf.isResultOk(measureMap[measureType[iMeasure]], measurePoint)
0125               << " result at 50 GeV, 0,6 |eta| " << perf.getResult(measureMap[measureType[iMeasure]], measurePoint)
0126               << std::endl;
0127 
0128     std::cout << "Error checking!" << std::endl;
0129     measurePoint.reset();
0130     measurePoint.insert(BinningVariables::JetEt, 0);
0131     measurePoint.insert(BinningVariables::JetAbsEta, 10);
0132 
0133     std::cout << "Is it OK? " << perf.isResultOk(measureMap[measureType[iMeasure]], measurePoint)
0134               << " result at 0 GeV, 10 |eta| " << perf.getResult(measureMap[measureType[iMeasure]], measurePoint)
0135               << std::endl;
0136     std::cout << std::endl;
0137   }
0138 
0139   // std::cout << "Values: "<<
0140   //   PerformanceResult::BTAGNBEFF<<" " <<
0141   //   PerformanceResult::MUERR<<" " <<
0142   //   std::endl;
0143 
0144   // // check beff, berr for eta=.6, et=55;
0145   // BinningPointByMap p;
0146 
0147   // std::cout <<" My Performance Object is indeed a "<<typeid(perfH.product()).name()<<std::endl;
0148 
0149   // std::cout <<" test eta=0.6, et=55"<<std::endl;
0150 
0151   // p.insert(BinningVariables::JetEta,0.6);
0152   // p.insert(BinningVariables::JetEt,55);
0153   // std::cout <<" nbeff/nberr ?"<<perf.isResultOk(PerformanceResult::BTAGNBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGNBERR,p)<<std::endl;
0154   // std::cout <<" beff/berr ?"<<perf.isResultOk(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGBERR,p)<<std::endl;
0155   // std::cout <<" beff/berr ="<<perf.getResult(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.getResult(PerformanceResult::BTAGBERR,p)<<std::endl;
0156 
0157   // std::cout <<" test eta=1.9, et=33"<<std::endl;
0158   //  p.insert(BinningVariables::JetEta,1.9);
0159   // p.insert(BinningVariables::JetEt,33);
0160   // std::cout <<" beff/berr ?"<<perf.isResultOk(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGBERR,p)<<std::endl;
0161   // std::cout <<" beff/berr ="<<perf.getResult(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.getResult(PerformanceResult::BTAGBERR,p)<<std::endl;
0162 
0163   // std::cout <<" The WP is defined by a cut at "<<perf.workingPoint().cut()<<std::endl;
0164   // std::cout <<" Discriminant is "<<perf.workingPoint().discriminantName()<<std::endl;
0165 
0166   // std::cout <<" now I ask for a calibration but I do not set eta in the binning point ---> should return all not available "<<std::endl;
0167   // p.reset();
0168   // p.insert(BinningVariables::JetNTracks,3);
0169   // p.insert(BinningVariables::JetEt,55);
0170   // std::cout <<" beff/berr ?"<<perf.isResultOk(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGBERR,p)<<std::endl;
0171   // std::cout <<" beff/berr ="<<perf.getResult(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.getResult(PerformanceResult::BTAGBERR,p)<<std::endl;
0172 
0173   // //  std::cout <<" now I ask for a calibration which is not present ---> should throw an exception "<<std::endl;
0174 
0175   // //  edm::ESHandle<BtagPerformance> perfH2;
0176   // //  iSetup.get<BTagPerformanceRecord>().get("TrackCountingHighEff_tight",perfH2);
0177 }
0178 
0179 // ------------ method called once each job just before starting event loop  ------------
0180 void TestPerformanceFW_ES::beginJob() {}
0181 
0182 // ------------ method called once each job just after ending the event loop  ------------
0183 void TestPerformanceFW_ES::endJob() {}
0184 
0185 //define this as a plug-in
0186 DEFINE_FWK_MODULE(TestPerformanceFW_ES);