From 07b3f9e4820f330bba0d9292d2ca188fe19a40d2 Mon Sep 17 00:00:00 2001
From: Nils Erik Krumnack <nils.erik.krumnack@cern.ch>
Date: Mon, 18 May 2020 13:13:07 +0000
Subject: [PATCH] Merge branch 'AddSupportForDFCommonJetDr' into '21.2'

Providing support for MuonsAuxDyn.DFCommonJetDr in MuonEfficiencyCorrections (for "2D" muon isolation scale factors)

See merge request atlas/athena!32777

(cherry picked from commit 3786008c2b2d33e55c97da84bbd6d8c824d2827f)

ea1c77ad Providing support for MuonsAuxDyn.DFCommonJetDr
ed142077 Updating default calibration release, and isolation WPs in tester
---
 .../MuonEfficiencyCorrections/HistHandler.h   | 32 +++++++++++++------
 .../Root/MuonEfficiencyScaleFactors.cxx       |  2 +-
 .../util/MuonEfficiencyScaleFactorsTest.cxx   |  7 ++--
 3 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/HistHandler.h b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/HistHandler.h
index 6dc6b68e0c2..c560816f436 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/HistHandler.h
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/MuonEfficiencyCorrections/HistHandler.h
@@ -245,18 +245,30 @@ namespace CP {
         public:
             CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) const override {
                 static const SG::AuxElement::ConstAccessor<float> dRJet("dRJet");
-                value = dRJet.isAvailable(mu) ? dRJet(mu) : -2;
-		// We want these warnings to be printed few times per job, so that they're visible, then stop before log file's size blows up 
-                static std::atomic<unsigned int> warned = {0};
-                if (warned<5 && !dRJet.isAvailable(mu)){
-                    using namespace msgMuonEfficiency;
-                    ANA_MSG_WARNING("The dRJet decoration has not been found for the Muon. Isolation scale-factors are now also binned in #Delta R(jet,#mu)");
-                    ANA_MSG_WARNING("using the closest calibrated AntiKt4EMTopo jet with p_{T}>20~GeV and surving the standard OR criteria.");
-                    ANA_MSG_WARNING("You should decorate your muon appropiately before passing to the tool, and use dRJet = -1 in case there is no jet in an event.");
-                    ANA_MSG_WARNING("For the time being the inclusive scale-factor is going to be returned.");
+		static const SG::AuxElement::ConstAccessor<float> dRJet_DxAOD("DFCommonJetDr");
+		using namespace msgMuonEfficiency;
+		if( dRJet_DxAOD.isAvailable(mu) ) {
+		  // decoration available in DxAOD
+		  value = dRJet_DxAOD(mu);
+		  ANA_MSG_VERBOSE("Taking #Delta R(jet,#mu) decoration from MuonsAuxDyn.DFCommonJetDr for retrieving the muon isolation scale factors.");
+		} else if( dRJet.isAvailable(mu) ) {
+		  // decoration manually provided by analyzers
+		  value = dRJet.isAvailable(mu);
+		  ANA_MSG_INFO("MuonsAuxDyn.DFCommonJetDr is not available in this DxAOD, but you've decorated the muon with dRJet. Using it for retrieving the isolation scale factors.");
+		} else {
+		  // decoration not available 
+		  value = -2.; 
+		  // We want these warnings to be printed few times per job, so that they're visible, then stop before log file's size blows up 
+		  static std::atomic<unsigned int> warned = {0};
+		  if (warned<5){
+		    ANA_MSG_WARNING("The dRJet decoration has not been found for the Muon. Isolation scale-factors are now also binned in #Delta R(jet,#mu)");
+		    ANA_MSG_WARNING("using the closest calibrated AntiKt4EMTopo jet with p_{T}>20~GeV and surving the standard OR criteria.");
+		    ANA_MSG_WARNING("You should decorate your muon appropiately before passing to the tool, and use dRJet = -1 in case there is no jet in an event.");
+		    ANA_MSG_WARNING("For the time being the inclusive scale-factor is going to be returned.");
 		    ANA_MSG_WARNING("In future derivations, muons will also be decorated centrally with dRJet, for your benefit.");
 		    warned++;
-                }
+		  }
+		}
                 return CorrectionCode::Ok;
             }
             virtual ~dRJetAxisHandler() = default;
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonEfficiencyScaleFactors.cxx b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonEfficiencyScaleFactors.cxx
index 64a9af1bdd8..a0734953d39 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonEfficiencyScaleFactors.cxx
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/Root/MuonEfficiencyScaleFactors.cxx
@@ -31,7 +31,7 @@ namespace CP {
                 m_efficiency_decoration_name_data(),
                 m_efficiency_decoration_name_mc(),
                 m_sf_decoration_name(),
-                m_calibration_version("200202_Precision_r21"),
+                m_calibration_version("200513_Precision_r21"),
                 m_lowpt_threshold(15.e3),
                 m_affectingSys(),
                 m_filtered_sys_sets(),
diff --git a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/util/MuonEfficiencyScaleFactorsTest.cxx b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/util/MuonEfficiencyScaleFactorsTest.cxx
index c15814b8c14..104a54d9019 100644
--- a/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/util/MuonEfficiencyScaleFactorsTest.cxx
+++ b/PhysicsAnalysis/MuonID/MuonIDAnalysis/MuonEfficiencyCorrections/util/MuonEfficiencyScaleFactorsTest.cxx
@@ -148,14 +148,15 @@ int main(int argc, char* argv[]) {
 
      const std::vector<std::string> WPs {
          // reconstruction WPs
-         "Loose", "Medium", "Tight", "HighPt",
+         "Loose", "Medium", "Tight", "HighPt", "LowPt", "LowPtMVA",
          // track-to-vertex-association WPs
          "TTVA",
          // BadMuon veto SFs
          "BadMuonVeto_HighPt",
          // isolation WPs
-         "FixedCutLooseIso", "LooseTrackOnlyIso", "LooseIso", "GradientIso", "GradientLooseIso",
-         "FixedCutTightTrackOnlyIso", "FixedCutHighPtTrackOnlyIso", "FixedCutTightIso"
+	 "PLVLooseIso", "PLVTightIso", "HighPtTrackOnlyIso",
+	 "Loose_FixedRadIso", "Tight_FixedRadIso", "PflowLoose_FixedRadIso", "PflowTight_FixedRadIso", "TightTrackOnly_FixedRadIso",
+	 "Loose_VarRadIso", "Tight_VarRadIso", "PflowLoose_VarRadIso", "PflowTight_VarRadIso", "TightTrackOnly_VarRadIso"
     };
    
     std::vector<EffiToolInstance> EffiTools;
-- 
GitLab