CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
getbtagPerformance.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <iostream>
3 
4 #include "TFile.h"
5 #include "TTree.h"
7 
8 
16 
17 using namespace std;
19 
20 int main(int argc, char ** argv)
21 {
22  // load fwlite libraries
24  // command line options
25  optutl::CommandLineParser parser ("get performance");
26 
27  parser.addOption ("rootFile", CommandLineParser::kString,
28  "root filename");
29  parser.addOption ("payload", CommandLineParser::kString,
30  "for example MISTAGSSVHEM, MCPfTCHEMb", "MISTAGSSVHEM");
31  parser.addOption ("flavor", CommandLineParser::kString,
32  "for example b, c, or l", "b");
33  parser.addOption ("type", CommandLineParser::kString,
34  "for example eff or SF", "eff");
35  parser.addOption ("pt", CommandLineParser::kDouble,
36  "jet pt");
37  parser.addOption ("eta", CommandLineParser::kDouble,
38  "jet eta");
39 
40  // Parse the command line arguments
41  parser.parseArguments (argc, argv);
42 
43  if (argc<3) {
44  parser.help();
45  }
46 
47  string inputFile = parser.stringValue("rootFile");
48  string payload = parser.stringValue("payload");
49  string flavor = parser.stringValue("flavor");
50  string type = parser.stringValue("type");
51  double ajetpt = parser.doubleValue("pt");
52  double ajeteta = parser.doubleValue("eta");
53 
54  TFile f(inputFile.c_str(),"READ");
55 
56  fwlite::EventSetup es(&f);
57 
58  if ( ! es.exists("BTagPerformanceRecord") ) {
59  cout << "Can't find tree" << endl;
60  parser.help();
61  }
62 
63  fwlite::RecordID testRecID = es.recordID("BTagPerformanceRecord");
64 
65  int index = 1001;
66 
67  es.syncTo(edm::EventID(index,0,0),edm::Timestamp());
68 
70  es.get(testRecID).get(plHandle, payload.c_str() ); // MCPfTCHEMb
72  es.get(testRecID).get(wpHandle, payload.c_str() );
73 
74  if ( plHandle.isValid() && wpHandle.isValid() ) {
75  BtagPerformance perf(*plHandle, *wpHandle);
76 
77  //std::cout << "Values: "<<
78  // PerformanceResult::BTAGNBEFF<<" " <<
79  // PerformanceResult::MUERR<<" " <<
80  // std::endl;
81 
82  // check beff, berr for eta=.6, et=55;
84 
85 
87  p.insert(BinningVariables::JetEt, ajetpt );
88 
89  //std::cout <<" nbeff/nberr ?"<<perf.isResultOk(PerformanceResult::BTAGNBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGNBERR,p)<<std::endl;
90  //std::cout <<" beff/berr ?"<<perf.isResultOk(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGBERR,p)<<std::endl;
91  if ( type == "eff") {
92  if ( flavor == "b" ) cout <<"eff/err = "<<perf.getResult(PerformanceResult::BTAGBEFF,p)<<" / "<<perf.getResult(PerformanceResult::BTAGBERR,p) << endl;
93  if ( flavor == "c" ) cout <<"eff/err = "<<perf.getResult(PerformanceResult::BTAGCEFF,p)<<" / "<<perf.getResult(PerformanceResult::BTAGCERR,p) << endl;
94  if ( flavor == "l" ) cout <<"eff/err = "<<perf.getResult(PerformanceResult::BTAGLEFF,p)<<" / "<<perf.getResult(PerformanceResult::BTAGLERR,p) << endl;
95  } else if ( type == "SF") {
96  if ( flavor == "b" ) cout <<"SF/err = "<<perf.getResult(PerformanceResult::BTAGBEFFCORR,p)<<" / "<<perf.getResult(PerformanceResult::BTAGBERRCORR,p) << endl;
97  if ( flavor == "c" ) cout <<"SF/err = "<<perf.getResult(PerformanceResult::BTAGCEFFCORR,p)<<" / "<<perf.getResult(PerformanceResult::BTAGCERRCORR,p) << endl;
98  if ( flavor == "l" ) cout <<"SF/err = "<<perf.getResult(PerformanceResult::BTAGLEFFCORR,p)<<" / "<<perf.getResult(PerformanceResult::BTAGLERRCORR,p) << endl;
99  }
100 
101 
102  } else {
103  std::cout << "invalid handle: workingPoint " <<wpHandle.isValid()<<" payload "<<plHandle.isValid()<< std::endl;
104  try {
105  *wpHandle;
106  *plHandle;
107  }catch(std::exception& iE) {
108  std::cout <<iE.what()<<std::endl;
109  }
110  }
111 
112 }
type
Definition: HCALResponse.h:21
std::string & stringValue(std::string key)
void parseArguments(int argc, char **argv, bool allowArgs=false)
unsigned int RecordID
Definition: EventSetup.h:63
double & doubleValue(std::string key)
bool isValid() const
Definition: ESHandle.h:44
static void enable()
enable automatic library loading
double f[11][100]
bool insert(BinningVariables::BinningVariablesType, float)
tuple argc
Definition: dir2webdir.py:38
void addOption(std::string key, OptionType type, const std::string &description="")
virtual float getResult(PerformanceResult::ResultType, const BinningPointByMap &) const
tuple cout
Definition: gather_cfg.py:121