ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FTagScaleFactorTools
util
ScaleFactorToolTester.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
FTagAnalysisInterfaces/IFTagScaleFactorTool.h
"
5
#include <
AsgTools/StandaloneToolHandle.h
>
6
#include "
xAODBase/IParticleContainer.h
"
7
8
#ifdef XAOD_STANDALONE
9
#include "
xAODRootAccess/Init.h
"
10
#include "
xAODRootAccess/TEvent.h
"
11
using
TEVENT
=
xAOD::TEvent
;
12
#else
13
#include "
POOLRootAccess/TEvent.h
"
14
using
TEVENT
=
POOL::TEvent
;
15
#endif
16
17
#include "TFile.h"
18
19
ANA_MSG_HEADER
(testSFTool)
20
ANA_MSG_SOURCE
(testSFTool,
"ScaleFactorToolTester"
)
21
using namespace testSFTool;
22
23
int
main
ATLAS_NOT_THREAD_SAFE
(
int
argc,
char
* argv[]) {
24
25
if
(argc < 5) {
26
ANA_MSG_ERROR
(
"Usage: <exe> <DAOD> <JsonConfig> <TaggerName> <PCTName> <WP1,WP2,...>"
);
27
return
1;
28
}
29
30
std::string inputDAOD = argv[1];
31
std::string JsonConfigFile = argv[2];
32
std::string taggerName = argv[3];
33
std::string PCTName = argv[4];
34
std::string objContainer =
"AntiKt4EMPFlowJets"
;
35
36
// Parse comma-separated WP list into a vector, e.g. "WP60,WP70,WP77" -> {"WP60","WP70","WP77"}
37
std::vector<std::string> wpList;
38
if
(argc > 5) {
39
std::string taggingWPs = argv[5];
40
std::istringstream
ss
(taggingWPs);
41
std::string token;
42
while
(std::getline(
ss
, token,
','
)) {
43
if
(!token.empty()) wpList.push_back(token);
44
}
45
}
46
47
asg::StandaloneToolHandle<ftag::IFTagScaleFactorTool>
sf_tool(
"ftag::FTagScaleFactorTool/SFToolTest"
);
48
StatusCode sf_code1 = sf_tool.
setProperty
(
"TaggerName"
, taggerName);
49
StatusCode sf_code2 = sf_tool.
setProperty
(
"JsonConfigFile"
, JsonConfigFile);
50
StatusCode sf_code3 = sf_tool.
setProperty
(
"ObjContainer"
, objContainer);
51
StatusCode sf_code4 = sf_tool.
setProperty
(
"PCTName"
, PCTName);
52
StatusCode sf_code5 = sf_tool.
setProperty
(
"WorkingPoints"
,wpList);
53
StatusCode sf_code6 = sf_tool.
initialize
();
54
std::vector<StatusCode> sf_codes = { sf_code1, sf_code2, sf_code3, sf_code4, sf_code5, sf_code6};
55
56
for
(
const
auto
& code : sf_codes) {
57
if
(code.isFailure()) {
58
ANA_MSG_ERROR
(
"Failed to set property or initialize tool"
);
59
return
1;
60
}
61
}
62
63
CP::SystematicSet
sysSet;
64
sysSet = sf_tool->recommendedSystematics();
65
66
TEVENT
event(
TEVENT::kClassAccess
);
67
gErrorIgnoreLevel = kError;
68
std::unique_ptr<TFile> root_file {TFile::Open(inputDAOD.c_str(),
"READ"
)};
69
if
(!event.readFrom(root_file.get()).isSuccess()) {
70
ANA_MSG_ERROR
(
"Accessing events in input file "
<< inputDAOD <<
"failed! "
);
71
return
1;
72
}
73
74
for
(
auto
entry=0; entry < 20; ++entry) {
75
event
.getEntry(entry);
76
77
const
xAOD::IParticleContainer
* particles =
nullptr
;
78
if
(!event.retrieve(particles, objContainer).isSuccess()) {
79
ANA_MSG_ERROR
(
"Failed to retrieve jets"
);
80
return
1;
81
}
82
83
for
(
const
auto
particle : *particles) {
84
ANA_MSG_INFO
(
"===================================="
);
85
ANA_MSG_INFO
(
"Jet pt: "
<< particle->pt() <<
"eta: "
<< particle->eta() );
86
float
pb =
SG::ConstAccessor<float>
(taggerName+
"_pb"
)(*particle);
87
float
pc =
SG::ConstAccessor<float>
(taggerName+
"_pc"
)(*particle);
88
float
pu =
SG::ConstAccessor<float>
(taggerName+
"_pu"
)(*particle);
89
float
ptau =
SG::ConstAccessor<float>
(taggerName+
"_ptau"
)(*particle);
90
ANA_MSG_INFO
(
"pb : pc : pl : ptau = "
<< pb <<
", "
<< pc <<
", "
<< pu <<
", "
<< ptau);
91
std::vector<int> wp_decision = sf_tool->inferWPs(particle);
92
for
(
size_t
i = 0; i < wpList.size(); ++i) {
93
ANA_MSG_INFO
(
"decision_"
<< wpList[i] <<
": "
<< wp_decision[i]);
94
}
95
96
float
sf = 1.0f;
97
for
(
const
auto
& var : sysSet) {
98
CP::SystematicSet
set
;
99
set
.insert(var);
100
CP::CorrectionCode
code = sf_tool->getScaleFactor(*particle, sf,
set
);
101
if
(code ==
CP::CorrectionCode::Ok
|| code ==
CP::CorrectionCode::OutOfValidityRange
) {
102
ANA_MSG_INFO
(
"Applied systematic: "
<< var.name());
103
ANA_MSG_INFO
(
" SF: "
<< sf);
104
}
else
{
105
ANA_MSG_ERROR
(
"Failed to get scale factor for jet"
);
106
}
107
}
108
}
109
}
110
111
root_file->Close();
112
root_file.reset();
113
return
0;
114
}
115
116
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:295
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:291
ANA_MSG_HEADER
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:111
ANA_MSG_SOURCE
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:131
TEvent.h
main
int main(int, char **)
Main class for all the CppUnit test classes.
Definition
CppUnit_testdriver.cxx:21
IFTagScaleFactorTool.h
Init.h
ss
static Double_t ss
Definition
LArPhysWaveHECTool.cxx:37
TEvent.h
TEVENT
POOL::TEvent TEVENT
Definition
ScaleFactorToolTester.cxx:14
StandaloneToolHandle.h
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition
checker_macros.h:212
CP::CorrectionCode
Return value from object correction CP tools.
Definition
CorrectionCode.h:31
CP::CorrectionCode::OutOfValidityRange
@ OutOfValidityRange
Input object is out of validity range.
Definition
CorrectionCode.h:37
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition
CorrectionCode.h:38
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition
SystematicSet.h:31
POOL::TEvent
Definition
PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:40
POOL::TEvent::kClassAccess
@ kClassAccess
Definition
PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:46
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition
ConstAccessor.h:55
asg::StandaloneToolHandle
an "initializing" ToolHandle for stand-alone applications
Definition
StandaloneToolHandle.h:44
asg::StandaloneToolHandle::setProperty
StatusCode setProperty(const std::string &name, T2 &&value)
Definition
StandaloneToolHandle.h:105
asg::StandaloneToolHandle::initialize
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
Definition
StandaloneToolHandle.h:158
set
STL class.
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:59
xAOD::IParticleContainer
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
Definition
xAOD/xAODBase/xAODBase/IParticleContainer.h:32
IParticleContainer.h
Generated on
for ATLAS Offline Software by
1.17.0