ATLAS Offline Software
Loading...
Searching...
No Matches
ScaleFactorToolTester.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
7
8#ifdef XAOD_STANDALONE
11using TEVENT = xAOD::TEvent;
12#else
15#endif
16
17#include "TFile.h"
18
19ANA_MSG_HEADER(testSFTool)
20ANA_MSG_SOURCE(testSFTool, "ScaleFactorToolTester")
21using namespace testSFTool;
22
23int 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
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) {
99 set.insert(var);
100 CP::CorrectionCode code = sf_tool->getScaleFactor(*particle, sf, set);
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
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
#define ANA_MSG_SOURCE(NAME, TITLE)
the source code part of ANA_MSG_SOURCE
int main(int, char **)
Main class for all the CppUnit test classes.
static Double_t ss
POOL::TEvent TEVENT
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Return value from object correction CP tools.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
Class to wrap a set of SystematicVariations.
Helper class to provide constant type-safe access to aux data.
an "initializing" ToolHandle for stand-alone applications
StatusCode setProperty(const std::string &name, T2 &&value)
StatusCode initialize()
initialize the tool, will fail if the tool was already initialized
STL class.
Tool for accessing xAOD files outside of Athena.
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.