ATLAS Offline Software
ConstituentsLoader.cxx
Go to the documentation of this file.
1 /*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <regex>
7 
8 namespace {
9  using namespace FlavorTagDiscriminants;
10 
11  // define a regex literal operator
12  std::regex operator "" _r(const char* c, size_t /* length */) {
13  return std::regex(c);
14  }
15 
16  // ____________________________________________________________________
17  //
18  // We define a few structures to map variable names to type, default
19  // value, etc.
20  //
21  typedef std::vector<std::pair<std::regex, ConstituentsEDMType>> TypeRegexes;
22  typedef std::vector<std::pair<std::regex, std::string>> StringRegexes;
23  typedef std::vector<std::pair<std::regex, ConstituentsSortOrder>> SortRegexes;
24  typedef std::vector<std::pair<std::regex, ConstituentsSelection>> SelRegexes;
25 
26  ConstituentsInputConfig get_iparticle_input_config(
27  const std::string& name,
28  const std::vector<std::string>& input_variables,
29  const TypeRegexes& type_regexes) {
31  config.name = name;
33  for (const auto& varname: input_variables) {
35  size_t pos = varname.find("flow_");
36  if (pos != std::string::npos){
37  input.name = varname.substr(pos+5);
38  }
39  else{
40  input.name = varname;
41  }
42  input.flip_sign = false;
43  input.type = str::match_first(type_regexes, input.name,
44  "iparticle type matching");
45  config.inputs.push_back(input);
46  }
47  return config;
48  }
49 
50  ConstituentsInputConfig get_track_input_config(
51  const std::string& name,
52  const std::vector<std::string>& input_variables,
53  const TypeRegexes& type_regexes,
54  const SortRegexes& sort_regexes,
55  const SelRegexes& select_regexes,
56  const std::regex& re,
57  const FlipTagConfig& flip_config) {
59  config.name = name;
60  config.order = str::match_first(sort_regexes, name,
61  "track order matching");
62  config.selection = str::match_first(select_regexes, name,
63  "track selection matching");
64  for (const auto& varname: input_variables) {
66  input.name = varname;
67  input.type = str::match_first(type_regexes, varname,
68  "track type matching");
69 
70  input.flip_sign=false;
71  if ((flip_config != FlipTagConfig::STANDARD) && std::regex_match(varname, re)){
72  input.flip_sign=true;
73  }
74  config.inputs.push_back(input);
75  }
76  return config;
77  }
78 }
79 
80 namespace FlavorTagDiscriminants {
81  //
82  // Create a configuration for the constituents loaders
83  //
85  const std::string & name,
86  const std::vector<std::string> & input_variables,
87  FlipTagConfig flip_config
88  ){
90 
91  TypeRegexes iparticle_type_regexes {
92  // iparticle variables
93  // ConstituentsEDMType picked correspond to the first matching regex
94  {"(pt|deta|dphi|energy)"_r, ConstituentsEDMType::CUSTOM_GETTER}
95  };
96  TypeRegexes trk_type_regexes {
97  // Some innermost / next-to-innermost hit variables had a different
98  // definition in 21p9, recomputed here with customGetter to reuse
99  // existing training
100  // ConstituentsEDMType picked correspond to the first matching regex
101  {"numberOf.*21p9"_r, ConstituentsEDMType::CUSTOM_GETTER},
102  {"numberOf.*"_r, ConstituentsEDMType::UCHAR},
103  {"btagIp_(d0|z0SinTheta)Uncertainty"_r, ConstituentsEDMType::FLOAT},
104  {"(numberDoF|chiSquared|qOverP|theta)"_r, ConstituentsEDMType::FLOAT},
105  {"(^.*[_])?(d|z)0.*"_r, ConstituentsEDMType::CUSTOM_GETTER},
106  {"(log_)?(ptfrac|dr|pt).*"_r, ConstituentsEDMType::CUSTOM_GETTER},
107  {"(deta|dphi)"_r, ConstituentsEDMType::CUSTOM_GETTER},
108  {"phi|theta|qOverP"_r, ConstituentsEDMType::FLOAT},
109  {"(phi|theta|qOverP)Uncertainty"_r, ConstituentsEDMType::CUSTOM_GETTER},
110  {"leptonID"_r, ConstituentsEDMType::CHAR}
111  };
112  // We have a number of special naming conventions to sort and
113  // filter tracks. The track nodes should be named according to
114  //
115  // tracks_<selection>_<sort-order>
116  //
117  SortRegexes trk_sort_regexes {
120  {".*ptsort"_r, ConstituentsSortOrder::PT_DESCENDING},
121  {".*absD0DescendingSort"_r, ConstituentsSortOrder::ABS_D0_DESCENDING},
122  };
123  SelRegexes trk_select_regexes {
124  {".*_ip3d_.*"_r, ConstituentsSelection::IP3D_2018},
125  {".*_dipsTightUpgrade_.*"_r, ConstituentsSelection::DIPS_TIGHT_UPGRADE},
126  {".*_dipsLooseUpgrade_.*"_r, ConstituentsSelection::DIPS_LOOSE_UPGRADE},
127  {".*_all_.*"_r, ConstituentsSelection::ALL},
128  {".*_dipsLoose202102_.*"_r, ConstituentsSelection::DIPS_LOOSE_202102},
129  {".*_loose202102NoIpCuts_.*"_r, ConstituentsSelection::LOOSE_202102_NOIP},
130  {".*_r22default_.*"_r, ConstituentsSelection::R22_DEFAULT},
131  {".*_r22loose_.*"_r, ConstituentsSelection::R22_LOOSE},
132  };
133 
134  if (name.find("tracks") != std::string::npos){
135  std::regex flip_sequences;
136  if (flip_config == FlipTagConfig::FLIP_SIGN || flip_config == FlipTagConfig::NEGATIVE_IP_ONLY){
137  flip_sequences=std::regex(".*signed_[dz]0.*");
138  }
139  if (flip_config == FlipTagConfig::SIMPLE_FLIP){
140  flip_sequences=std::regex("(.*signed_[dz]0.*)|d0|z0SinTheta");
141  }
142  config = get_track_input_config(
143  name, input_variables,
144  trk_type_regexes, trk_sort_regexes, trk_select_regexes,
145  flip_sequences, flip_config);
147  config.output_name = "tracks";
148  }
149  else if (name.find("flows") != std::string::npos){
150  config = get_iparticle_input_config(
151  name, input_variables,
152  iparticle_type_regexes);
154  config.output_name = "flows";
155  }
156  else{
157  throw std::runtime_error(
158  "Unknown constituent type: " + name + ". Only tracks and flows are supported."
159  );
160  }
161  return config;
162  }
163 }
FlavorTagDiscriminants::FlipTagConfig::SIMPLE_FLIP
@ SIMPLE_FLIP
FlavorTagDiscriminants::ConstituentsSelection::IP3D_2018
@ IP3D_2018
FlavorTagDiscriminants::ConstituentsInputConfig
Definition: ConstituentsLoader.h:59
FlavorTagDiscriminants::FlipTagConfig::STANDARD
@ STANDARD
FlavorTagDiscriminants
This file contains "getter" functions used for accessing tagger inputs from the EDM.
Definition: AssociationEnums.h:11
FlavorTagDiscriminants::dataprep::StringRegexes
std::vector< std::pair< std::regex, std::string > > StringRegexes
Definition: DataPrepUtilities.h:148
FlavorTagDiscriminants::FlipTagConfig::NEGATIVE_IP_ONLY
@ NEGATIVE_IP_ONLY
FlavorTagDiscriminants::ConstituentsType::TRACK
@ TRACK
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
FlavorTagDiscriminants::createConstituentsLoaderConfig
ConstituentsInputConfig createConstituentsLoaderConfig(const std::string &name, const std::vector< std::string > &input_variables, FlipTagConfig flip_config)
Definition: ConstituentsLoader.cxx:84
FlavorTagDiscriminants::ConstituentsSortOrder::ABS_D0_SIGNIFICANCE_DESCENDING
@ ABS_D0_SIGNIFICANCE_DESCENDING
FlavorTagDiscriminants::ConstituentsEDMType::CUSTOM_GETTER
@ CUSTOM_GETTER
FlavorTagDiscriminants::ConstituentsSelection::DIPS_TIGHT_UPGRADE
@ DIPS_TIGHT_UPGRADE
FlavorTagDiscriminants::FlipTagConfig::FLIP_SIGN
@ FLIP_SIGN
ConstituentsLoader.h
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
FlavorTagDiscriminants::ConstituentsSortOrder::ABS_D0_DESCENDING
@ ABS_D0_DESCENDING
FlavorTagDiscriminants::ConstituentsSelection::DIPS_LOOSE_UPGRADE
@ DIPS_LOOSE_UPGRADE
FlavorTagDiscriminants::ConstituentsSelection::ALL
@ ALL
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
FlavorTagDiscriminants::ConstituentsSortOrder::PT_DESCENDING
@ PT_DESCENDING
FlavorTagDiscriminants::ConstituentsSelection::R22_DEFAULT
@ R22_DEFAULT
FlavorTagDiscriminants::ConstituentsEDMType::UCHAR
@ UCHAR
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
FlavorTagDiscriminants::ConstituentsSelection::R22_LOOSE
@ R22_LOOSE
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
FlavorTagDiscriminants::ConstituentsEDMType::CHAR
@ CHAR
FlavorTagDiscriminants::ConstituentsSelection::DIPS_LOOSE_202102
@ DIPS_LOOSE_202102
FlavorTagDiscriminants::str::match_first
T match_first(const std::vector< std::pair< std::regex, T > > &regexes, const std::string &var_name, const std::string &context)
Definition: PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/StringUtils.h:27
re
const boost::regex re(r_e)
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:72
FlavorTagDiscriminants::ConstituentsEDMType::FLOAT
@ FLOAT
FlavorTagDiscriminants::FlipTagConfig
FlipTagConfig
Definition: FlipTagEnums.h:14
FlavorTagDiscriminants::ConstituentsType::IPARTICLE
@ IPARTICLE
FlavorTagDiscriminants::ConstituentsSelection::LOOSE_202102_NOIP
@ LOOSE_202102_NOIP
python.compressB64.c
def c
Definition: compressB64.py:93
FlavorTagDiscriminants::InputVariableConfig
Definition: ConstituentsLoader.h:53
FlavorTagDiscriminants::ConstituentsSortOrder::D0_SIGNIFICANCE_DESCENDING
@ D0_SIGNIFICANCE_DESCENDING