ATLAS Offline Software
Loading...
Searching...
No Matches
DL2.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "lwtnn/LightweightGraph.hh"
9#include "lwtnn/NanReplacer.hh"
10
11// #include "xAODBTagging/BTaggingUtilities.h"
12
13
14
15namespace FlavorTagDiscriminants {
16
17 // DL2
18 //
19 // TODO: make this work with more input nodes
20 DL2::DL2(const lwt::GraphConfig& graph_config,
21 const std::vector<FTagInputConfig>& inputs,
22 const std::vector<ConstituentsInputConfig>& tracks_configs,
23 const FTagOptions& options):
25 m_graph(new lwt::LightweightGraph(graph_config,graph_config.outputs.begin()->first)),
26 m_variable_cleaner(nullptr),
27 m_defaultValue(options.default_output_value)
28 {
29 // set up inputs
30 if (graph_config.inputs.size() > 1) {
31 throw std::logic_error("We don't currently support graphs with "
32 "more than one input");
33 } else if (graph_config.inputs.size() == 1){
34 m_input_node_name = graph_config.inputs.at(0).name;
35 m_variable_cleaner.reset(new lwt::NanReplacer(
36 graph_config.inputs.at(0).defaults,
37 lwt::rep::all));
38 }
39
40 auto [vj, ds] = dataprep::createBvarGetters(inputs);
41 m_varsFromJet = vj;
43
44 for (auto config : tracks_configs){
45 m_tracksLoaders.push_back(std::make_shared<TracksLoader>(config, options));
46 }
47
48 auto [decorators, dd, rd] = dataprep::createDecorators(
49 graph_config, options);
51 m_decorators = decorators;
52
53 auto [track_validity, is_defaults, ipdd, rc] = dataprep::createIpChecker(
54 graph_config, options);
55 m_invalid_track_checker = track_validity;
56 m_is_defaults = is_defaults;
58
59 // Update dependencies and used remap from the tracks loaders.
60 for (const auto& loader : m_tracksLoaders){
61 m_dataDependencyNames += loader->getDependencies();
62 std::set<std::string> used_remap = loader->getUsedRemap();
63 rd.merge(used_remap);
64 }
65 // check that all remapping was used
66 rd.merge(rc);
67 dataprep::checkForUnusedRemaps(options.remap_scalar, rd);
68 }
69
70 void DL2::decorate(const xAOD::IParticle& i_jet) const {
71 auto jet = dynamic_cast<const xAOD::Jet*>(&i_jet);
72 decorate(*jet);
73 }
75 // save out things
76 for (const auto& dec: m_decorators) {
77 for (const auto& node: dec.second) {
78 // save something that is clearly wrong
79 node.second(jet) = m_defaultValue;
80 }
81 }
82 }
83
84 void DL2::decorate(const xAOD::Jet& jet) const {
85 using namespace internal;
86 std::vector<NamedVar> vvec;
87 for (const auto& getter: m_varsFromJet) {
88 vvec.push_back(getter.second(jet));
89 }
90 std::map<std::string, std::map<std::string, double> > nodes;
92 std::map<std::string, double> variables(vvec.begin(), vvec.end());
93 auto cleaned = m_variable_cleaner->replace(variables);
94
95 // Note, you can hack in more variables to `cleaned` here.
96
97 // put the cleaned inputs into the node structure
98 nodes[m_input_node_name] = cleaned;
99 }
100
101 // add track sequences, check if any are invalid
102 char invalid = 0;
103 std::map<std::string, std::map<std::string, std::vector<double>>> seqs;
104
105 for (const auto& loader : m_tracksLoaders){
106 std::map<std::string, std::vector<double>> feats;
107 std::tie(invalid, feats) = loader->getDL2Data(jet, m_invalid_track_checker);
108 seqs[loader->getName()] = feats;
109 }
110
111 for (const auto& def: m_is_defaults) {
112 def(jet) = invalid;
113 }
114 if (invalid) {
116 return;
117 }
118
119 // save out things
120 for (const auto& dec: m_decorators) {
121 // the second argument to compute(...) is for sequences
122 auto out_vals = m_graph->compute(nodes, seqs, dec.first);
123 for (const auto& node: dec.second) {
124 node.second(jet) = out_vals.at(node.first);
125 }
126 }
127 }
128
132}
static Double_t rc
if(febId1==febId2)
DL2(const lwt::GraphConfig &, const std::vector< FTagInputConfig > &, const std::vector< ConstituentsInputConfig > &={}, const FTagOptions &=FTagOptions())
Definition DL2.cxx:20
std::function< char(const internal::Tracks &)> m_invalid_track_checker
Definition DL2.h:44
void decorate(const xAOD::IParticle &i_jet) const
Definition DL2.cxx:70
std::unique_ptr< lwt::LightweightGraph > m_graph
Definition DL2.h:38
std::string m_input_node_name
Definition DL2.h:37
const FTagDataDependencyNames & getDataDependencyNames() const
Definition DL2.cxx:129
std::vector< SG::AuxElement::Decorator< char > > m_is_defaults
Definition DL2.h:45
std::vector< std::shared_ptr< TracksLoader > > m_tracksLoaders
Definition DL2.h:41
std::unique_ptr< lwt::NanReplacer > m_variable_cleaner
Definition DL2.h:39
std::map< std::string, internal::OutNodeFloat > m_decorators
Definition DL2.h:42
FTagDataDependencyNames m_dataDependencyNames
Definition DL2.h:47
std::vector< std::pair< std::string, internal::VarFromJet > > m_varsFromJet
Definition DL2.h:40
void decorateWithDefaults(const SG::AuxElement &) const
Definition DL2.cxx:74
Base class for elements of a container that can have aux data.
Definition AuxElement.h:483
Definition node.h:24
Class providing the definition of the 4-vector interface.
std::tuple< std::map< std::string, internal::OutNodeFloat >, FTagDataDependencyNames, std::set< std::string > > createDecorators(const GraphConfig &config, const FTagOptions &options)
std::tuple< std::vector< std::pair< std::string, internal::VarFromJet > >, FTagDataDependencyNames > createBvarGetters(const std::vector< FTagInputConfig > &inputs)
std::tuple< std::function< char(const internal::Tracks &)>, std::vector< SG::AuxElement::Decorator< char > >, FTagDataDependencyNames, std::set< std::string > > createIpChecker(const GraphConfig &, const FTagOptions &)
void checkForUnusedRemaps(const std::map< std::string, std::string > &requested, const std::set< std::string > &used)
Jet_v1 Jet
Definition of the current "jet version".