CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/RecoBTag/PerformanceDB/bin/TestPerformanceFWLite_ES.cc

Go to the documentation of this file.
00001 #include <vector>
00002 #include <iostream>
00003 
00004 #include "Cintex/Cintex.h"
00005 #include "TFile.h"
00006 #include "TTree.h"
00007 #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
00008 
00009 
00010 #include "PhysicsTools/CondLiteIO/interface/RecordWriter.h"
00011 #include "DataFormats/FWLite/interface/Record.h"
00012 #include "DataFormats/FWLite/interface/EventSetup.h"
00013 #include "DataFormats/FWLite/interface/ESHandle.h"
00014 #include "CondFormats/PhysicsToolsObjects/interface/BinningPointByMap.h"
00015 #include "RecoBTag/PerformanceDB/interface/BtagPerformance.h"
00016 
00017 int main(int argc, char ** argv)
00018 {
00019   AutoLibraryLoader::enable();
00020   
00021   std::cout << "Test!!!" << std::endl << std::endl;
00022   TFile f("performance_ssvm.root","READ");
00023       
00024   fwlite::EventSetup es(&f);
00025 
00026   if ( es.exists("BTagPerformanceRecord") ) {
00027     std::cout << "Got the right tree" << std::endl;
00028   } else {
00029     std::cout << "Can't find tree" << std::endl;
00030   }
00031 
00032   fwlite::RecordID testRecID = es.recordID("BTagPerformanceRecord");
00033 
00034   int index = 1001;
00035   es.syncTo(edm::EventID(index,0,0),edm::Timestamp());
00036 
00037       
00038   std::cout << "Got record ID " << testRecID << es.get(testRecID).startSyncValue().eventID()<<std::endl;
00039 
00040   fwlite::ESHandle< PerformancePayload > plHandle;
00041   es.get(testRecID).get(plHandle,"MCPfTCHEMb");
00042   fwlite::ESHandle< PerformanceWorkingPoint > wpHandle;
00043   es.get(testRecID).get(wpHandle,"MCPfTCHEMb");
00044 
00045   if ( plHandle.isValid() && wpHandle.isValid() ) {
00046     BtagPerformance perf(*plHandle, *wpHandle);
00047 
00048     std::cout << "Values: "<<
00049       PerformanceResult::BTAGNBEFF<<" " <<
00050       PerformanceResult::MUERR<<" " <<
00051       std::endl;
00052 
00053     // check beff, berr for eta=.6, et=55;
00054     BinningPointByMap p;
00055 
00056 //     std::cout <<" My Performance Object is indeed a "<<typeid(perf).name()<<std::endl;
00057 
00058     std::cout <<" test eta=0.6, et=55"<<std::endl;
00059 
00060 
00061     p.insert(BinningVariables::JetAbsEta,0.6);
00062     p.insert(BinningVariables::JetEt,55);
00063     std::cout <<" nbeff/nberr ?"<<perf.isResultOk(PerformanceResult::BTAGNBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGNBERR,p)<<std::endl;
00064     std::cout <<" beff/berr ?"<<perf.isResultOk(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGBERR,p)<<std::endl;
00065     std::cout <<" beff/berr ="<<perf.getResult(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.getResult(PerformanceResult::BTAGBERR,p)<<std::endl;
00066         
00067     std::cout <<" test eta=1.9, et=33"<<std::endl;
00068     p.insert(BinningVariables::JetAbsEta,1.9);
00069     p.insert(BinningVariables::JetEt,33);
00070     std::cout <<" beff/berr ?"<<perf.isResultOk(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGBERR,p)<<std::endl;
00071     std::cout <<" beff/berr ="<<perf.getResult(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.getResult(PerformanceResult::BTAGBERR,p)<<std::endl;
00072         
00073     std::cout <<" The WP is defined by a cut at "<<perf.workingPoint().cut()<<std::endl;
00074     std::cout <<" Discriminant is "<<perf.workingPoint().discriminantName()<<std::endl;
00075         
00076     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;
00077     p.reset();
00078     p.insert(BinningVariables::JetNTracks,3);
00079     p.insert(BinningVariables::JetEt,55);
00080     std::cout <<" beff/berr ?"<<perf.isResultOk(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.isResultOk(PerformanceResult::BTAGBERR,p)<<std::endl;
00081     std::cout <<" beff/berr ="<<perf.getResult(PerformanceResult::BTAGBEFF,p)<<"/"<<perf.getResult(PerformanceResult::BTAGBERR,p)<<std::endl;
00082         
00083     //  std::cout <<" now I ask for a calibration which is not present ---> should throw an exception "<<std::endl;
00084         
00085     //  edm::ESHandle<BtagPerformance> perfH2;
00086     //  iSetup.get<BTagPerformanceRecord>().get("TrackCountingHighEff_tight",perfH2);
00087         
00088         
00089   } else {
00090     std::cout << "invalid handle: workingPoint " <<wpHandle.isValid()<<" payload "<<plHandle.isValid()<< std::endl;
00091     try {
00092       *wpHandle;
00093       *plHandle;
00094     }catch(std::exception& iE) {
00095       std::cout <<iE.what()<<std::endl;
00096     }
00097   }
00098       
00099 }