ATLAS Offline Software
BTaggingTruthTaggingTester.cxx
Go to the documentation of this file.
1 #include "AsgTools/AsgTool.h"
8 
9 #include <string>
10 #include <iomanip>
11 #include <vector>
12 
13 int main() {
14 
15  asg::StandaloneToolHandle<IBTaggingTruthTaggingTool> tool("BTaggingTruthTaggingTool/BtagTT_Tool");
16 
17 
18  //choose working point and CDI file
19  StatusCode code = tool.setProperty("TaggerName", "MV2c10");
20  StatusCode code2 = tool.setProperty("OperatingPoint", "FixedCutBEff_77");
21  StatusCode code3 = tool.setProperty("JetAuthor", "AntiKt4EMTopoJets");
22  StatusCode code4 = tool.setProperty("ScaleFactorFileName", "xAODBTaggingEfficiency/13TeV/2017-21-13TeV-MC16-CDI-2018-02-09_v1.root");
23 
24 
25  //truth tagging settings
26  StatusCode code5 = tool.setProperty("IgnoreScaleFactors", false); //use the data/MC and MC/MC scale factors when computing event weights
27  StatusCode code6 = tool.setProperty("UseSystematics", true); // store event weights for all systematic variations in the results object
28  StatusCode code7 = tool.setProperty("MaxNtagged", 3);
29  StatusCode code8 = tool.setProperty("UsePermutations", true);
30  StatusCode code9 = tool.setProperty("UseQuantile", true);
31 
32  StatusCode code10 = tool.initialize();
33 
34  if (code != StatusCode::SUCCESS || code2 != StatusCode::SUCCESS || code3 != StatusCode::SUCCESS || code4 != StatusCode::SUCCESS || code5 != StatusCode::SUCCESS ||
35  code6 != StatusCode::SUCCESS || code7 != StatusCode::SUCCESS || code8 != StatusCode::SUCCESS || code9 != StatusCode::SUCCESS || code10 != StatusCode::SUCCESS ) {
36  std::cout << "Initialization of tool " << tool->name() << " failed! " << std::endl;
37  return -1;
38  }
39  else {
40  std::cout << "Initialization of tool " << tool->name() << " finished." << std::endl;
41  }
42 
43  //Set the jets to be used in the tool.
44  std::vector<float> pt = {44000., 66000., 77000.};
45  std::vector<float> eta = {2.2, 1.6, 1.7};
46  std::vector<int> flav = {0,4,5};
47  std::vector<float> tagw = {0.3, 0.55, 0.99};
48 
50 
51  if(StatusCode::SUCCESS!=tool->CalculateResults( pt,eta,flav,tagw, results) ){
52  std::cout << "failed to compute truth tagging results! " << std::endl;
53  return -1;
54  };
55 
56  //direct tagged results:
57  std::cout << "Direct tagged results: "<< std::endl;
58  for(unsigned int i=0; i< results.is_tagged.size();i++)
59  {
60  std::cout << "jet "<< i << " is direct tagged: " << results.is_tagged.at(i) << std::endl;
61  }
62  //print the results for each of the systematic variations
63 
64  for(unsigned int systindex=0; systindex< results.syst_names.size(); systindex++){
65  std::string syst_name = results.syst_names.at(systindex);
66 
67  std::cout << "direct tag Event SF ( "<< syst_name <<" ) = " <<results.getEvtDirectTagSF(syst_name) << std::endl;
68 
69  }
70 
71 
72  //truth tagging results:
73  for(int ntags=1; ntags<=3;ntags++){
74 
75  std::cout << " for " << ntags << " tagged jets: " << std::endl;
76  std::cout << " --------------------------------- " << std::endl;
77  //print chosen premutation, tagweight bin assinment and event weight
78 
79  std::vector<bool> exclusive_permuation = results.getEventPermutation(ntags,true);
80  std::vector<int> exclusive_tagweightBin = results.getEventQuantiles(ntags,true);
81 
82  std::vector<bool> inclusive_permuation = results.getEventPermutation(ntags,false);
83  std::vector<int> inclusive_tagweightBin = results.getEventQuantiles(ntags,false);
84 
85  std::cout << " exclusive || inclusive" << std::endl;
86  std::cout << " tagged | bin || tagged | bin" << std::endl;
87  for(unsigned int i=0; i< exclusive_permuation.size();i++)
88  {
89  std::cout << "jet "<< i << " " << exclusive_permuation.at(i) << " " << exclusive_tagweightBin.at(i)
90  << " || " << inclusive_permuation.at(i) << " " << inclusive_tagweightBin.at(i) << std::endl;
91  }
92 
93  std::cout << " Nominal event weight exclusive: " << results.getEventWeight(ntags,true,"Nominal") << std::endl;
94  std::cout << " Nominal event weight inclusive: " << results.getEventWeight(ntags,false,"Nominal") << std::endl;
95  std::cout << " ---------------------------------\n\n " << std::endl;
96 
97  }
98 
99  return 0;
100 }
TruthTagResults.h
IBTaggingTruthTaggingTool.h
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
test_pyathena.pt
pt
Definition: test_pyathena.py:11
main
int main()
Definition: BTaggingTruthTaggingTester.cxx:13
lumiFormat.i
int i
Definition: lumiFormat.py:92
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MessageCheck.h
macros for messaging and checking status codes
Analysis::TruthTagResults
Definition: TruthTagResults.h:14
pmontree.code
code
Definition: pmontree.py:443
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
python.ami.results
def results
Definition: ami.py:386
StandaloneToolHandle.h
AsgTool.h
MsgStream.h