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 
0015 int main(int argc, char** argv) {
0016   FWLiteEnabler::enable();
0017 
0018   std::cout << "Test!!!" << std::endl << std::endl;
0019   TFile f("performance_ssvm.root", "READ");
0020 
0021   fwlite::EventSetup es(&f);
0022 
0023   if (es.exists("BTagPerformanceRecord")) {
0024     std::cout << "Got the right tree" << std::endl;
0025   } else {
0026     std::cout << "Can't find tree" << std::endl;
0027   }
0028 
0029   fwlite::RecordID testRecID = es.recordID("BTagPerformanceRecord");
0030 
0031   int index = 1001;
0032   es.syncTo(edm::EventID(index, 0, 0), edm::Timestamp());
0033 
0034   std::cout << "Got record ID " << testRecID << es.get(testRecID).startSyncValue().eventID() << std::endl;
0035 
0036   fwlite::ESHandle<PerformancePayload> plHandle;
0037   es.get(testRecID).get(plHandle, "MCPfTCHEMb");
0038   fwlite::ESHandle<PerformanceWorkingPoint> wpHandle;
0039   es.get(testRecID).get(wpHandle, "MCPfTCHEMb");
0040 
0041   if (plHandle.isValid() && wpHandle.isValid()) {
0042     BtagPerformance perf(*plHandle, *wpHandle);
0043 
0044     std::cout << "Values: " << PerformanceResult::BTAGNBEFF << " " << PerformanceResult::MUERR << " " << std::endl;
0045 
0046     // check beff, berr for eta=.6, et=55;

0047     BinningPointByMap p;
0048 
0049     //     std::cout <<" My Performance Object is indeed a "<<typeid(perf).name()<<std::endl;

0050 
0051     std::cout << " test eta=0.6, et=55" << std::endl;
0052 
0053     p.insert(BinningVariables::JetAbsEta, 0.6);
0054     p.insert(BinningVariables::JetEt, 55);
0055     std::cout << " nbeff/nberr ?" << perf.isResultOk(PerformanceResult::BTAGNBEFF, p) << "/"
0056               << perf.isResultOk(PerformanceResult::BTAGNBERR, p) << std::endl;
0057     std::cout << " beff/berr ?" << perf.isResultOk(PerformanceResult::BTAGBEFF, p) << "/"
0058               << perf.isResultOk(PerformanceResult::BTAGBERR, p) << std::endl;
0059     std::cout << " beff/berr =" << perf.getResult(PerformanceResult::BTAGBEFF, p) << "/"
0060               << perf.getResult(PerformanceResult::BTAGBERR, p) << std::endl;
0061 
0062     std::cout << " test eta=1.9, et=33" << std::endl;
0063     p.insert(BinningVariables::JetAbsEta, 1.9);
0064     p.insert(BinningVariables::JetEt, 33);
0065     std::cout << " beff/berr ?" << perf.isResultOk(PerformanceResult::BTAGBEFF, p) << "/"
0066               << perf.isResultOk(PerformanceResult::BTAGBERR, p) << std::endl;
0067     std::cout << " beff/berr =" << perf.getResult(PerformanceResult::BTAGBEFF, p) << "/"
0068               << perf.getResult(PerformanceResult::BTAGBERR, p) << std::endl;
0069 
0070     std::cout << " The WP is defined by a cut at " << perf.workingPoint().cut() << std::endl;
0071     std::cout << " Discriminant is " << perf.workingPoint().discriminantName() << std::endl;
0072 
0073     std::cout << " now I ask for a calibration but I do not set eta in the binning point ---> should return all not "
0074                  "available "
0075               << std::endl;
0076     p.reset();
0077     p.insert(BinningVariables::JetNTracks, 3);
0078     p.insert(BinningVariables::JetEt, 55);
0079     std::cout << " beff/berr ?" << perf.isResultOk(PerformanceResult::BTAGBEFF, p) << "/"
0080               << perf.isResultOk(PerformanceResult::BTAGBERR, p) << std::endl;
0081     std::cout << " beff/berr =" << perf.getResult(PerformanceResult::BTAGBEFF, p) << "/"
0082               << perf.getResult(PerformanceResult::BTAGBERR, p) << std::endl;
0083 
0084     //  std::cout <<" now I ask for a calibration which is not present ---> should throw an exception "<<std::endl;

0085 
0086     //  edm::ESHandle<BtagPerformance> perfH2;

0087     //  iSetup.get<BTagPerformanceRecord>().get("TrackCountingHighEff_tight",perfH2);

0088 
0089   } else {
0090     std::cout << "invalid handle: workingPoint " << wpHandle.isValid() << " payload " << plHandle.isValid()
0091               << std::endl;
0092     try {
0093       *wpHandle;
0094       *plHandle;
0095     } catch (std::exception& iE) {
0096       std::cout << iE.what() << std::endl;
0097     }
0098   }
0099 }