From 9816fbd085a88e81ea8ef7538503ce2077e64d0f Mon Sep 17 00:00:00 2001 From: Dan Guest <dguest@cern.ch> Date: Fri, 24 Apr 2020 12:24:03 +0200 Subject: [PATCH] make customSeqGetter avaliable outside this package --- .../FlavorTagDiscriminants/customGetter.h | 6 ++ .../Root/customGetter.cxx | 77 +++++++++++-------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/customGetter.h b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/customGetter.h index 820f8255606..937f5dcd15f 100644 --- a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/customGetter.h +++ b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/FlavorTagDiscriminants/customGetter.h @@ -18,6 +18,12 @@ #define CUSTOM_GETTER_H namespace FlavorTagDiscriminants { + + std::function<std::vector<double>( + const xAOD::Jet&, + const std::vector<const xAOD::TrackParticle*>&)> customSeqGetter( + const std::string& name); + 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 e8753e238d4..b37110af878 100644 --- a/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/customGetter.cxx +++ b/PhysicsAnalysis/JetTagging/FlavorTagDiscriminants/Root/customGetter.cxx @@ -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 = customSeqGetter(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 // @@ -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); } + } -- GitLab