diff --git a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/customGetter.h b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/customGetter.h index 820f82556063429726b36889e773e934bf95d360..16d4d7b77f522f246f73d02b8755746babdd9c7d 100644 --- a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/customGetter.h +++ b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/customGetter.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // The customGetter file is a catch-all for various getter functinos @@ -18,6 +18,32 @@ #define CUSTOM_GETTER_H namespace FlavorTagDiscriminants { + + /// Factory function to produce TrackParticle -> vector<double> functions + /// + /// DL2 configures the its inputs when the algorithm is initalized, + /// meaning that the list of track and jet properties that are used + /// as inputs won't be known at compile time. Instead we build an + /// array of "getter" functions, each of which returns one input for + /// the tagger. The function here returns those getter functions. + /// + /// Many of the getter functions are trivial: they will, for example, + /// read one double of auxdata off of the BTagging object. The + /// sequence input getters tend to be more complicated. Since we'd + /// like to avoid reimplementing the logic in these functions in + /// multiple places, they are exposed here. + /// + /// This function will return a getter based on a string key. See the + /// implementation for the definitions. + /// + /// NOTE: This function is for experts only, don't expect support. + /// + std::function<std::vector<double>( + const xAOD::Jet&, + const std::vector<const xAOD::TrackParticle*>&)> + customSequenceGetter(const std::string& name); + + // internal functions namespace internal { std::function<std::pair<std::string, double>(const xAOD::Jet&)> customGetterAndName(const std::string&); diff --git a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/customGetter.cxx b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/customGetter.cxx index e8753e238d45bf8ba01a05cd56cec9229677d0c9..800a1d54da7ed607b1e0a62cfd1568f59137062d 100644 --- a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/customGetter.cxx +++ b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/customGetter.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "FlavorTagDiscriminants/customGetter.h" #include "FlavorTagDiscriminants/BTagTrackAugmenter.h" @@ -68,6 +68,40 @@ namespace { }; +} + +namespace FlavorTagDiscriminants { + namespace internal { + + // ________________________________________________________________ + // Interface functions + // + // As long as we're giving lwtnn pair<name, double> objects, we + // can't use the raw getter functions above (which only return a + // double). Instead we'll wrap those functions in another function, + // which returns the pair we wanted. + // + // Case for jet variables + std::function<std::pair<std::string, double>(const xAOD::Jet&)> + customGetterAndName(const std::string& name) { + auto getter = customGetter(name); + return [name, getter](const xAOD::Jet& j) { + return std::make_pair(name, getter(j)); + }; + } + + // Case for track variables + std::function<std::pair<std::string, std::vector<double>>( + const xAOD::Jet&, + const std::vector<const xAOD::TrackParticle*>&)> + customNamedSeqGetter(const std::string& name) { + auto getter = customSequenceGetter(name); + return [name, getter](const xAOD::Jet& j, + const std::vector<const xAOD::TrackParticle*>& t) { + return std::make_pair(name, getter(j, t)); + }; + } + } // ________________________________________________________________________ // Master track getter list // @@ -76,8 +110,8 @@ namespace { // std::function<std::vector<double>( const xAOD::Jet&, - const std::vector<const xAOD::TrackParticle*>&)> customSeqGetter( - const std::string& name) { + const std::vector<const xAOD::TrackParticle*>&)> + customSequenceGetter(const std::string& name) { typedef std::vector<const xAOD::TrackParticle*> Tracks; if (name == "IP3D_signed_d0_significance") { return SignedD0SequenceGetter(); @@ -116,40 +150,21 @@ namespace { return log_dr; }; } - throw std::logic_error("no match for custom getter " + name); - } -} - -namespace FlavorTagDiscriminants { - namespace internal { - - // ________________________________________________________________ - // Interface functions - // - // As long as we're giving lwtnn pair<name, double> objects, we - // can't use the raw getter functions above (which only return a - // double). Instead we'll wrap those functions in another function, - // which returns the pair we wanted. - // - // Case for jet variables - std::function<std::pair<std::string, double>(const xAOD::Jet&)> - customGetterAndName(const std::string& name) { - auto getter = customGetter(name); - return [name, getter](const xAOD::Jet& j) { - return std::make_pair(name, getter(j)); + if (name == "pt") { + return [](const xAOD::Jet&, const Tracks& t) { + std::vector<double> tracks; + for (auto* trk: t) tracks.push_back(trk->pt()); + return tracks; }; } - - // Case for track variables - std::function<std::pair<std::string, std::vector<double>>( - const xAOD::Jet&, - const std::vector<const xAOD::TrackParticle*>&)> - customNamedSeqGetter(const std::string& name) { - auto getter = customSeqGetter(name); - return [name, getter](const xAOD::Jet& j, - const std::vector<const xAOD::TrackParticle*>& t) { - return std::make_pair(name, getter(j, t)); + if (name == "eta") { + return [](const xAOD::Jet&, const Tracks& t) { + std::vector<double> tracks; + for (auto* trk: t) tracks.push_back(trk->eta()); + return tracks; }; } + throw std::logic_error("no match for custom getter " + name); } + }