From ca655633e4fc3f22b2f9720fe9e41437ad8ca875 Mon Sep 17 00:00:00 2001 From: Andrey Popov Date: Tue, 11 Mar 2014 14:35:31 +0100 Subject: [PATCH] Add an accessor to b-tagging efficiencies and scale factors that requires jet flavour explicitly This feature is useful when b-tagging efficiencies or scale factors are used in a data-driven method, in which case Jet::GetParentID() does not make sense. --- core/include/BTagEffInterface.hpp | 29 ++++++++++++++++++++++--- core/include/BTagSFInterface.hpp | 28 ++++++++++++++++++++---- core/src/BTagEffInterface.cpp | 14 +++++++++++- core/src/BTagSFInterface.cpp | 16 +++++++++++++- extensions/include/BTagEfficiencies.hpp | 5 +++-- extensions/include/BTagScaleFactors.hpp | 5 +++-- extensions/src/BTagEfficiencies.cpp | 7 +++--- extensions/src/BTagScaleFactors.cpp | 4 ++-- 8 files changed, 90 insertions(+), 18 deletions(-) diff --git a/core/include/BTagEffInterface.hpp b/core/include/BTagEffInterface.hpp index 9a8860e..93fc3e7 100644 --- a/core/include/BTagEffInterface.hpp +++ b/core/include/BTagEffInterface.hpp @@ -71,13 +71,36 @@ class BTagEffInterface */ virtual void LoadPayload(Dataset const &dataset); - /// Returns b-tagging efficiency for a given working point and a given jet - virtual double GetEfficiency(BTagger::WorkingPoint wp, Jet const &jet) const = 0; + /** + * \brief Returns b-tagging efficiency for a given working point and a given jet momentum and + * flavour + * + * Jet flavour might be negative. + */ + virtual double GetEfficiency(BTagger::WorkingPoint wp, Candidate const &jet, int flavour) + const = 0; + + /** + * \brief Returns b-tagging efficiency for a given working point and a given jet + * + * Internally calls the pure virtual method with the same name. + */ + double GetEfficiency(BTagger::WorkingPoint wp, Jet const &jet) const; + + /** + * \brief Returns b-tagging efficiency for a given jet momentum and flavour using the default + * working point + * + * The method is useful for prescriptions that support only one working point. Internally calls + * the pure virtual method with the same name. + */ + double GetEfficiency(Candidate const &jet, int flavour) const; /** * \brief Returns b-tagging efficiency for a given jet using the default working point * - * The method is useful for prescriptions that support only one working point. + * The method is useful for prescriptions that support only one working point. Internally calls + * the pure virtual method with the same name. */ double GetEfficiency(Jet const &jet) const; diff --git a/core/include/BTagSFInterface.hpp b/core/include/BTagSFInterface.hpp index ebaa408..ebe0f54 100644 --- a/core/include/BTagSFInterface.hpp +++ b/core/include/BTagSFInterface.hpp @@ -68,19 +68,39 @@ class BTagSFInterface virtual BTagSFInterface *Clone() const = 0; /** - * \brief Returns b-tagging scale factor for a given jet + * \brief Returns b-tagging scale factor for a given working point and given jet momentum and + * flavour. * * User is not expected to calculate scale factors for jets that fail the pseudorapidity * coverage defined by the method GetMaxPseudorapidity. Behaviour of the method is undefined - * otherwise. + * otherwise. The flavour might be negative. */ - virtual double GetScaleFactor(BTagger::WorkingPoint wp, Jet const &jet, + virtual double GetScaleFactor(BTagger::WorkingPoint wp, Candidate const &jet, int flavour, Variation var = Variation::Nominal) const = 0; + /** + * \brief Returns b-tagging scale factor for a given jet + * + * Internally calls the pure virtual method with the same name. + */ + double GetScaleFactor(BTagger::WorkingPoint wp, Jet const &jet, + Variation var = Variation::Nominal) const; + + /** + * \brief Returns b-tagging scale factor for given jet momentum and flavour using the default + * working point + * + * The method is useful for prescriptions that support only one working point. Internally calls + * the pure virtual method with the same name. + */ + double GetScaleFactor(Candidate const &jet, int flavour, Variation var = Variation::Nominal) + const; + /** * \brief Returns b-tagging scale factor for a given jet using the default working point * - * The method is useful for prescriptions that support only one working point. + * The method is useful for prescriptions that support only one working point. Internally calls + * the pure virtual method with the same name. */ double GetScaleFactor(Jet const &jet, Variation var = Variation::Nominal) const; diff --git a/core/src/BTagEffInterface.cpp b/core/src/BTagEffInterface.cpp index 9cb5acb..c27e9f3 100644 --- a/core/src/BTagEffInterface.cpp +++ b/core/src/BTagEffInterface.cpp @@ -14,9 +14,21 @@ void BTagEffInterface::LoadPayload(Dataset const &) {} +double BTagEffInterface::GetEfficiency(BTagger::WorkingPoint wp, Jet const &jet) const +{ + return GetEfficiency(wp, jet, jet.GetParentID()); +} + + +double BTagEffInterface::GetEfficiency(Candidate const &jet, int flavour) const +{ + return GetEfficiency(defaultWP, jet, flavour); +} + + double BTagEffInterface::GetEfficiency(Jet const &jet) const { - return GetEfficiency(defaultWP, jet); + return GetEfficiency(defaultWP, jet, jet.GetParentID()); } diff --git a/core/src/BTagSFInterface.cpp b/core/src/BTagSFInterface.cpp index d7cdd42..cc0f8b4 100644 --- a/core/src/BTagSFInterface.cpp +++ b/core/src/BTagSFInterface.cpp @@ -17,9 +17,23 @@ BTagSFInterface::~BTagSFInterface() noexcept {} +double BTagSFInterface::GetScaleFactor(BTagger::WorkingPoint wp, Jet const &jet, + Variation var /*= Variation::Nominal*/) const +{ + return GetScaleFactor(wp, jet, jet.GetParentID(), var); +} + + +double BTagSFInterface::GetScaleFactor(Candidate const &jet, int flavour, + Variation var /*= Variation::Nominal*/) const +{ + return GetScaleFactor(defaultWP, jet, flavour, var); +} + + double BTagSFInterface::GetScaleFactor(Jet const &jet, Variation var /*= Variation::Nominal*/) const { - return GetScaleFactor(defaultWP, jet, var); + return GetScaleFactor(defaultWP, jet, jet.GetParentID(), var); } diff --git a/extensions/include/BTagEfficiencies.hpp b/extensions/include/BTagEfficiencies.hpp index 07186b4..2ddaf9e 100644 --- a/extensions/include/BTagEfficiencies.hpp +++ b/extensions/include/BTagEfficiencies.hpp @@ -140,14 +140,15 @@ class BTagEfficiencies: public BTagEffInterface virtual void LoadPayload(Dataset const &dataset); /** - * \brief Returns b-tagging efficiency for a given working point and a given jet + * \brief Returns b-tagging efficiency for a given working point and given jet momentum and + * flavour * * The efficiency is read from a histogram selected according to jet flavour and requested * working point. Appropriate bin of the histogram is identified by jet transverse momentum and * (signed) pseudorapidity; overflow bins are expected to be filled in a meaningful way. If * required histogram is not found, an exception is thrown. */ - virtual double GetEfficiency(BTagger::WorkingPoint wp, Jet const &jet) const; + virtual double GetEfficiency(BTagger::WorkingPoint wp, Candidate const &jet, int flavour) const; /** * \brief Returns a text label for a b-tagging working point diff --git a/extensions/include/BTagScaleFactors.hpp b/extensions/include/BTagScaleFactors.hpp index 6c8503e..22899d8 100644 --- a/extensions/include/BTagScaleFactors.hpp +++ b/extensions/include/BTagScaleFactors.hpp @@ -66,7 +66,8 @@ class BTagScaleFactors: public BTagSFInterface virtual BTagSFInterface *Clone() const; /** - * \brief Returns b-tagging scale factor for a given working point and a given jet + * \brief Returns b-tagging scale factor for a given working point and given jet momentum and + * flavour * * The method constrains jet transverse momentum to the appropriate range described in [1] and * calls specific automatically generated methods to obtain the scale factor. If the scale @@ -75,7 +76,7 @@ class BTagScaleFactors: public BTagSFInterface * an exception is thrown as well. * [1] https://twiki.cern.ch/twiki/bin/viewauth/CMS/BtagPOG */ - virtual double GetScaleFactor(BTagger::WorkingPoint wp, Jet const &jet, + virtual double GetScaleFactor(BTagger::WorkingPoint wp, Candidate const &jet, int flavour, Variation var = Variation::Nominal) const; private: diff --git a/extensions/src/BTagEfficiencies.cpp b/extensions/src/BTagEfficiencies.cpp index ce93f8e..fbc035f 100644 --- a/extensions/src/BTagEfficiencies.cpp +++ b/extensions/src/BTagEfficiencies.cpp @@ -211,16 +211,17 @@ void BTagEfficiencies::LoadPayload(Dataset const &dataset) } -double BTagEfficiencies::GetEfficiency(BTagger::WorkingPoint wp, Jet const &jet) const +double BTagEfficiencies::GetEfficiency(BTagger::WorkingPoint wp, Candidate const &jet, int flavour) + const { // Find the appropriate efficiency histogram - auto histIt = effHists.find(make_pair(wp, abs(jet.GetParentID()))); + auto histIt = effHists.find(make_pair(wp, abs(flavour))); if (histIt == effHists.end()) { ostringstream ost; ost << "BTagEfficiencies::GetEfficiency: Failed to find an efficiency histogram for " << - "working point " << int(wp) << " and jet flavour " << jet.GetParentID() << "."; + "working point " << int(wp) << " and jet flavour " << flavour << "."; throw runtime_error(ost.str()); } diff --git a/extensions/src/BTagScaleFactors.cpp b/extensions/src/BTagScaleFactors.cpp index b665900..4139e5e 100644 --- a/extensions/src/BTagScaleFactors.cpp +++ b/extensions/src/BTagScaleFactors.cpp @@ -148,7 +148,7 @@ BTagSFInterface *BTagScaleFactors::Clone() const } -double BTagScaleFactors::GetScaleFactor(BTagger::WorkingPoint wp, Jet const &jet, +double BTagScaleFactors::GetScaleFactor(BTagger::WorkingPoint wp, Candidate const &jet, int flavour, Variation var /*= Variation::Nominal*/) const { // Get pointers to the scale factor methods for the given working point @@ -171,7 +171,7 @@ double BTagScaleFactors::GetScaleFactor(BTagger::WorkingPoint wp, Jet const &jet // Switch between heavy-flavour and light-flavour jets - unsigned const absFlavour = abs(jet.GetParentID()); + unsigned const absFlavour = abs(flavour); if (absFlavour == 4 or absFlavour == 5) // b- or c-quark jets {