From 9b62c3c778b7b9195efface7939e708da9651d15 Mon Sep 17 00:00:00 2001
From: Walter Lampl <Walter.Lampl@cern.ch>
Date: Fri, 19 Mar 2021 16:45:52 +0100
Subject: [PATCH] DRAW_ZMUMU_SkimmingTool: ReadHandle, atomic counters,
 range-based for loop

---
 .../PrimaryDPDMaker/DRAW_ZMUMUSkimmingTool.h  | 10 +++++----
 .../src/DRAW_ZMUMU_SkimmingTool.cxx           | 22 +++++--------------
 2 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/PhysicsAnalysis/PrimaryDPDMaker/PrimaryDPDMaker/DRAW_ZMUMUSkimmingTool.h b/PhysicsAnalysis/PrimaryDPDMaker/PrimaryDPDMaker/DRAW_ZMUMUSkimmingTool.h
index d326797cee14..2f55e860b1e8 100644
--- a/PhysicsAnalysis/PrimaryDPDMaker/PrimaryDPDMaker/DRAW_ZMUMUSkimmingTool.h
+++ b/PhysicsAnalysis/PrimaryDPDMaker/PrimaryDPDMaker/DRAW_ZMUMUSkimmingTool.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -17,6 +17,7 @@
 // DerivationFramework includes
 #include "DerivationFrameworkInterfaces/ISkimmingTool.h"
 #include "MuonAnalysisInterfaces/IMuonSelectionTool.h"
+#include "xAODMuon/MuonContainer.h"
 
 namespace DerivationFramework {
 
@@ -44,9 +45,10 @@ namespace DerivationFramework {
     virtual bool eventPassesFilter() const;
     
   private:
-    mutable unsigned int m_ntot;
-    mutable unsigned int m_npass;
-    std::string m_muonSGKey;
+    mutable std::atomic<unsigned int> m_ntot{0};
+    mutable std::atomic<unsigned int> m_npass{0};
+
+    SG::ReadHandleKey<xAOD::MuonContainer> m_muonSGKey{this,"MuonContainerKey","Muons"};
     ToolHandle<CP::IMuonSelectionTool> m_muonSelectionTool;
     unsigned int m_nMuons;
     double m_muonPtCut;
diff --git a/PhysicsAnalysis/PrimaryDPDMaker/src/DRAW_ZMUMU_SkimmingTool.cxx b/PhysicsAnalysis/PrimaryDPDMaker/src/DRAW_ZMUMU_SkimmingTool.cxx
index f70549e5dcbd..644b0b6f664f 100644
--- a/PhysicsAnalysis/PrimaryDPDMaker/src/DRAW_ZMUMU_SkimmingTool.cxx
+++ b/PhysicsAnalysis/PrimaryDPDMaker/src/DRAW_ZMUMU_SkimmingTool.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
 */
 
 /////////////////////////////////////////////////////////////////
@@ -11,7 +11,6 @@
 // muons. Inherits from derivation framework components.
 
 #include "PrimaryDPDMaker/DRAW_ZMUMUSkimmingTool.h"
-#include "xAODMuon/MuonContainer.h"
 #include <vector>
 #include <string>
 
@@ -20,15 +19,11 @@ DerivationFramework::DRAW_ZMUMUSkimmingTool::DRAW_ZMUMUSkimmingTool( const std::
                                                  const std::string& n,
                                                  const IInterface* p ) : 
   AthAlgTool(t,n,p),
-  m_ntot(0),
-  m_npass(0),
-  m_muonSGKey("Muons"),
   m_muonSelectionTool("CP::MuonSelectionTool/MuonSelectionTool"),
   m_nMuons(1),
   m_muonPtCut(20.0)
   {
     declareInterface<DerivationFramework::ISkimmingTool>(this);
-    declareProperty("MuonContainerKey", m_muonSGKey);
     declareProperty("MuonSelectorTool", m_muonSelectionTool); 
     declareProperty("MinimumNumberOfMuons", m_nMuons);
     declareProperty("MuonPtCut", m_muonPtCut);	
@@ -42,6 +37,7 @@ DerivationFramework::DRAW_ZMUMUSkimmingTool::~DRAW_ZMUMUSkimmingTool() {
 StatusCode DerivationFramework::DRAW_ZMUMUSkimmingTool::initialize()
 {
      ATH_MSG_VERBOSE("initialize() ...");
+     ATH_CHECK(m_muonSGKey.initialize());
      return StatusCode::SUCCESS;
 }
 StatusCode DerivationFramework::DRAW_ZMUMUSkimmingTool::finalize()
@@ -56,19 +52,11 @@ bool DerivationFramework::DRAW_ZMUMUSkimmingTool::eventPassesFilter() const
 {
      ++m_ntot;
 
-     // Retrieve muon container	
-     const xAOD::MuonContainer* muons(0);
-     StatusCode sc = evtStore()->retrieve(muons,m_muonSGKey);	
-     if (sc.isFailure()) {
-	ATH_MSG_ERROR("No muon collection with name " << m_muonSGKey << " found in StoreGate!");
-	return(false);
-     } 
-     
+     SG::ReadHandle<xAOD::MuonContainer> muons{m_muonSGKey};
      // Loop over muons, count up and set decision
-     xAOD::MuonContainer::const_iterator muItr;
      unsigned int nGoodMu(0);
-     for (muItr=muons->begin(); muItr!=muons->end(); ++muItr) {  
-	if ( m_muonSelectionTool->accept(**muItr) && (*muItr)->pt() > m_muonPtCut ) ++nGoodMu;
+     for (const xAOD::Muon* muItr : *muons) {
+	if ( m_muonSelectionTool->accept(*muItr) && muItr->pt() > m_muonPtCut ) ++nGoodMu;
      }
      bool acceptEvent(false);
      if (nGoodMu >= m_nMuons) { 
-- 
GitLab