Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <vector>
0002 #include <iostream>
0003 
0004 #include "TFile.h"
0005 #include "TTree.h"
0006 #include "FWCore/FWLite/interface/FWLiteEnabler.h"
0007 
0008 #include "PhysicsTools/CondLiteIO/interface/RecordWriter.h"
0009 #include "DataFormats/FWLite/interface/Record.h"
0010 #include "DataFormats/FWLite/interface/EventSetup.h"
0011 #include "DataFormats/FWLite/interface/ESHandle.h"
0012 #include "CondFormats/PhysicsToolsObjects/interface/BinningPointByMap.h"
0013 #include "RecoBTag/PerformanceDB/interface/BtagPerformance.h"
0014 #include "PhysicsTools/FWLite/interface/CommandLineParser.h"
0015 
0016 using namespace std;
0017 using optutl::CommandLineParser;
0018 
0019 int main(int argc, char** argv) {
0020   // load fwlite libraries

0021   FWLiteEnabler::enable();
0022   // command line options

0023   optutl::CommandLineParser parser("get performance");
0024 
0025   parser.addOption("rootFile", CommandLineParser::kString, "root filename");
0026   parser.addOption("payload", CommandLineParser::kString, "for example MISTAGSSVHEM, MCPfTCHEMb", "MISTAGSSVHEM");
0027   parser.addOption("flavor", CommandLineParser::kString, "for example b, c, or l", "b");
0028   parser.addOption("type", CommandLineParser::kString, "for example eff or SF", "eff");
0029   parser.addOption("pt", CommandLineParser::kDouble, "jet pt");
0030   parser.addOption("eta", CommandLineParser::kDouble, "jet eta");
0031 
0032   // Parse the command line arguments

0033   parser.parseArguments(argc, argv);
0034 
0035   if (argc < 3) {
0036     parser.help();
0037   }
0038 
0039   string inputFile = parser.stringValue("rootFile");
0040   string payload = parser.stringValue("payload");
0041   string flavor = parser.stringValue("flavor");
0042   string type = parser.stringValue("type");
0043   double ajetpt = parser.doubleValue("pt");
0044   double ajeteta = parser.doubleValue("eta");
0045 
0046   TFile f(inputFile.c_str(), "READ");
0047 
0048   fwlite::EventSetup es(&f);
0049 
0050   if (!es.exists("BTagPerformanceRecord")) {
0051     cout << "Can't find tree" << endl;
0052     parser.help();
0053   }
0054 
0055   fwlite::RecordID testRecID = es.recordID("BTagPerformanceRecord");
0056 
0057   int index = 1001;
0058 
0059   es.syncTo(edm::EventID(index, 0, 0), edm::Timestamp());
0060 
0061   fwlite::ESHandle<PerformancePayload> plHandle;
0062   es.get(testRecID).get(plHandle, payload.c_str());  // MCPfTCHEMb

0063   fwlite::ESHandle<PerformanceWorkingPoint> wpHandle;
0064   es.get(testRecID).get(wpHandle, payload.c_str());
0065 
0066   if (plHandle.isValid() && wpHandle.isValid()) {
0067     BtagPerformance perf(*plHandle, *wpHandle);
0068 
0069     //std::cout << "Values: "<<

0070     //  PerformanceResult::BTAGNBEFF<<" " <<

0071     // PerformanceResult::MUERR<<" " <<

0072     //  std::endl;

0073 
0074     // check beff, berr for eta=.6, et=55;

0075     BinningPointByMap p;
0076 
0077     p.insert(BinningVariables::JetAbsEta, ajeteta);
0078     p.insert(BinningVariables::JetEt, ajetpt);
0079 
0080     //std::cout <<" nbeff/nberr ?"<<perf.isResultOk(PerformanceResult::BTAGNBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGNBERR,p)<<std::endl;

0081     //std::cout <<" beff/berr ?"<<perf.isResultOk(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGBERR,p)<<std::endl;

0082     if (type == "eff") {
0083       if (flavor == "b")
0084         cout << "eff/err = " << perf.getResult(PerformanceResult::BTAGBEFF, p) << " / "
0085              << perf.getResult(PerformanceResult::BTAGBERR, p) << endl;
0086       if (flavor == "c")
0087         cout << "eff/err = " << perf.getResult(PerformanceResult::BTAGCEFF, p) << " / "
0088              << perf.getResult(PerformanceResult::BTAGCERR, p) << endl;
0089       if (flavor == "l")
0090         cout << "eff/err = " << perf.getResult(PerformanceResult::BTAGLEFF, p) << " / "
0091              << perf.getResult(PerformanceResult::BTAGLERR, p) << endl;
0092     } else if (type == "SF") {
0093       if (flavor == "b")
0094         cout << "SF/err = " << perf.getResult(PerformanceResult::BTAGBEFFCORR, p) << " / "
0095              << perf.getResult(PerformanceResult::BTAGBERRCORR, p) << endl;
0096       if (flavor == "c")
0097         cout << "SF/err = " << perf.getResult(PerformanceResult::BTAGCEFFCORR, p) << " / "
0098              << perf.getResult(PerformanceResult::BTAGCERRCORR, p) << endl;
0099       if (flavor == "l")
0100         cout << "SF/err = " << perf.getResult(PerformanceResult::BTAGLEFFCORR, p) << " / "
0101              << perf.getResult(PerformanceResult::BTAGLERRCORR, p) << endl;
0102     }
0103 
0104   } else {
0105     std::cout << "invalid handle: workingPoint " << wpHandle.isValid() << " payload " << plHandle.isValid()
0106               << std::endl;
0107     try {
0108       *wpHandle;
0109       *plHandle;
0110     } catch (std::exception& iE) {
0111       std::cout << iE.what() << std::endl;
0112     }
0113   }
0114 }