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