ATLAS Offline Software
Macros | Functions
BTaggingSelectionToolTester.cxx File Reference
#include <AsgTools/StandaloneToolHandle.h>
#include "FTagAnalysisInterfaces/IBTaggingSelectionTool.h"
#include "xAODJet/JetContainer.h"
#include "xAODBTagging/BTagging.h"
#include "xAODBTagging/BTaggingUtilities.h"
#include "POOLRootAccess/TEvent.h"
#include <string>
#include <iomanip>
#include "TFile.h"
Include dependency graph for BTaggingSelectionToolTester.cxx:

Go to the source code of this file.

Macros

#define TEVENT   POOL::TEvent
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ TEVENT

#define TEVENT   POOL::TEvent

Definition at line 17 of file BTaggingSelectionToolTester.cxx.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 28 of file BTaggingSelectionToolTester.cxx.

28  {
29 
30  const char* TEST_NAME = argv[0];
31 
32  if (argc < 4) {
33  ANA_MSG_ERROR ( "No right inputs received!" );
34  ANA_MSG_ERROR ( "Usage: " << TEST_NAME << "[DAOD file name] [CDI path] [b-tagger name] [WP name]" );
35  return 1;
36  }
37 
38  std::string inputDAOD = argv[1];
39  std::string CDIPath = argv[2];
40  std::string taggerName = argv[3];
41  std::string workingPointName = argv[4];
42  std::string JetCollectionName = "AntiKt4EMPFlowJets";
43 
44  std::string EDMTaggerName;
45  if (taggerName.find("GN2v00") != std::string::npos) {
46  EDMTaggerName = "GN2v00";
47  } else {
48  EDMTaggerName = taggerName;
49  }
50 
51  asg::StandaloneToolHandle<IBTaggingSelectionTool> tool("BTaggingSelectionTool/BTagSelecTest");
52  StatusCode code1 = tool.setProperty( "FlvTagCutDefinitionsFileName", CDIPath);
53  StatusCode code2 = tool.setProperty( "TaggerName", taggerName);
54  StatusCode code3 = tool.setProperty( "OperatingPoint", workingPointName);
55  StatusCode code4 = tool.setProperty( "JetAuthor", JetCollectionName);
56  StatusCode code5 = tool.setProperty( "MinPt", 20000);
57  StatusCode code6 = tool.initialize();
58  std::vector<StatusCode> codes = {code1, code2, code3, code4, code5, code6};
59  for (const auto& code : codes) {
60  if (code != StatusCode::SUCCESS) {
61  ANA_MSG_ERROR ( "Initialization of tool " << tool->name() << " failed! " );
62  return 1;
63  }
64  }
65 
66  //load some jets to show how to use the tool
68  TEVENT event(TEVENT::kClassAccess);
69 
70  TFile* m_file = TFile::Open(inputDAOD.c_str(),"read");
71  if(!event.readFrom(m_file).isSuccess()) {
72  ANA_MSG_ERROR ( "failed to load file! " );
73  return 1;
74  }
75 
76  event.getEntry(0);
77 
78  const xAOD::JetContainer* jets = nullptr;
79  if (!event.retrieve( jets, JetCollectionName ).isSuccess() ) {
80  ANA_MSG_ERROR ( " Failed to retrieve jet container! " );
81  return 1;
82  }
83 
84  int jet_index = 0;
85  for (const xAOD::Jet* jet : *jets) {
86 
87  //getting a tagging decision, is the jet tagged or not
88  bool tagged = static_cast<bool>(tool->accept(*jet));
89 
90  //you can get the tagger weight,
91  double tagweight;
92  if( tool->getTaggerWeight( *jet ,tagweight)!=CorrectionCode::Ok) {
93  ANA_MSG_ERROR (" error retrieving tagger weight! " );
94  return 1;
95  }
96 
97  if (workingPointName.find("Continuous") == std::string::npos) {
98  ANA_MSG_INFO ( "jet " << jet_index << " " << taggerName << " " << workingPointName << " is tagged " << tagged << " tag weight " << tagweight );
99 
100  //if you have tagger weights, you can get the tagger weight this way
102 
103  float jet_pb = btag->auxdata<float>(EDMTaggerName + "_pb");
104  float jet_pc = btag->auxdata<float>(EDMTaggerName + "_pc");
105  float jet_pu = btag->auxdata<float>(EDMTaggerName + "_pu");
106  float jet_ptau = 0.;
107  if (taggerName == "GN2v01") jet_ptau = btag->auxdata<float>(EDMTaggerName + "_ptau");
108 
109  if( tool->getTaggerWeight(jet_pb,jet_pc,jet_pu, tagweight, jet_ptau) != CorrectionCode::Ok ){
110  ANA_MSG_ERROR (" error retrieving tagger weight! " );
111  return 1;
112  }
113 
114  ANA_MSG_INFO (" tagweight " << tagweight );
115 
116  double pT = jet->pt();
117  double eta = jet->eta();
118 
119  // you can see if the jet is tagged using its pt/eta and tagweight
120 
121  tagged = static_cast<bool>(tool->accept(pT,eta,tagweight));
122  //you can also extract the cut value (which may or may not depend on the jet pt)
123  double cutval;
124  //provide the pt in MeV
125  if( tool->getCutValue( jet->pt() , cutval)!=CorrectionCode::Ok ) {
126  ANA_MSG_ERROR ( " error retrieving cut value " );
127  return 1;
128  }
129  ANA_MSG_INFO ( " tagged " << tagged << " cut value " << cutval );
130  } else{
131  int quantile = tool->getQuantile(*jet);
132  ANA_MSG_INFO ("jet " << jet_index << " " << taggerName << " " << workingPointName << " tag weight " << tagweight << " quantile " << quantile );
133  }
134 
135  jet_index++;
136  }
137 
138  return 0;
139 }
CalculateHighPtTerm.pT
pT
Definition: ICHEP2016/CalculateHighPtTerm.py:57
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:294
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
m_file
std::unique_ptr< TFile > m_file
description: this is a custom writer for the old-school drivers that don't use an actual writer
Definition: OutputStreamData.cxx:52
python.ExitCodes.codes
dictionary codes
helper to get a human-readable string
Definition: ExitCodes.py:49
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition: StandaloneToolHandle.h:44
Analysis::kError
@ kError
Definition: CalibrationDataVariables.h:60
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:290
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::AuxElement::auxdata
Accessor< T, ALLOC >::reference_type auxdata(const std::string &name)
Fetch an aux data variable, as a non-const reference.
pmontree.code
code
Definition: pmontree.py:443
TEVENT
#define TEVENT
Definition: BTaggingSelectionToolTester.cxx:16
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
gErrorIgnoreLevel
int gErrorIgnoreLevel
xAOD::BTaggingUtilities::getBTagging
const BTagging * getBTagging(const SG::AuxElement &part)
Access the default xAOD::BTagging object associated to an object.
Definition: BTaggingUtilities.cxx:37
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24