From 80e2aa8156dd64b3d8c8a8fe4a7095ba3f14dad2 Mon Sep 17 00:00:00 2001 From: Will Leight <wleight@cern.ch> Date: Sun, 7 Jan 2018 17:55:30 +0100 Subject: [PATCH] Migrate MuidCaloEnergyMeas and MuidTrackIsolation to use DataHandles. Both tools now retrieve the collection they need using a ReadHandle. No other changes are made to the code. Former-commit-id: ef6e5784b8b428fc73a09cc9a59128cbfcd82ceb --- .../MuidCaloEnergyTools/MuidCaloEnergyMeas.h | 4 +- .../src/MuidCaloEnergyMeas.cxx | 40 ++++++++----------- .../MuidTrackIsolation.h | 3 +- .../src/MuidTrackIsolation.cxx | 18 ++++----- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/Reconstruction/MuonIdentification/MuidCaloEnergyTools/MuidCaloEnergyTools/MuidCaloEnergyMeas.h b/Reconstruction/MuonIdentification/MuidCaloEnergyTools/MuidCaloEnergyTools/MuidCaloEnergyMeas.h index 81af9af2555..e9058f2b937 100755 --- a/Reconstruction/MuonIdentification/MuidCaloEnergyTools/MuidCaloEnergyTools/MuidCaloEnergyMeas.h +++ b/Reconstruction/MuonIdentification/MuidCaloEnergyTools/MuidCaloEnergyTools/MuidCaloEnergyMeas.h @@ -21,6 +21,8 @@ #include "AthenaBaseComps/AthAlgTool.h" #include "GaudiKernel/ToolHandle.h" #include "MuidInterfaces/IMuidCaloEnergyMeas.h" +#include "StoreGate/ReadHandleKey.h" +#include "CaloEvent/CaloCellContainer.h" //<<<<<< CLASS DECLARATIONS >>>>>> @@ -95,7 +97,7 @@ private: const TileID* m_tileID; const LArEM_ID* m_emID; const LArHEC_ID* m_hecID; - std::string m_cellContainerLocation; // Cell container's name + SG::ReadHandleKey<CaloCellContainer> m_cellContainerLocation{this,"CellContainerLocation","AllCalo","calo cell container location"}; double m_measurementConeTile; double m_measurementConeLArHEC; diff --git a/Reconstruction/MuonIdentification/MuidCaloEnergyTools/src/MuidCaloEnergyMeas.cxx b/Reconstruction/MuonIdentification/MuidCaloEnergyTools/src/MuidCaloEnergyMeas.cxx index fc00bcf92db..5999e74c047 100755 --- a/Reconstruction/MuonIdentification/MuidCaloEnergyTools/src/MuidCaloEnergyMeas.cxx +++ b/Reconstruction/MuonIdentification/MuidCaloEnergyTools/src/MuidCaloEnergyMeas.cxx @@ -14,7 +14,6 @@ //<<<<<< INCLUDES >>>>>> #include "CLHEP/Geometry/Vector3D.h" -#include "CaloEvent/CaloCellContainer.h" #include "CaloEvent/CaloCell.h" #include "CaloIdentifier/CaloCell_ID.h" #include "CaloIdentifier/TileID.h" @@ -44,7 +43,6 @@ MuidCaloEnergyMeas::MuidCaloEnergyMeas (const std::string& type, m_tileID (0), m_emID (0), m_hecID (0), - m_cellContainerLocation (""), m_sigmasAboveNoise (4.), m_sigmasAboveNoiseCore (1.5), m_useCaloNoiseTool (true), @@ -58,7 +56,6 @@ MuidCaloEnergyMeas::MuidCaloEnergyMeas (const std::string& type, declareInterface<IMuidCaloEnergyMeas>(this); declareProperty ("CaloNoiseTool", m_caloNoiseTool); declareProperty ("CaloParamTool", m_caloParamTool); - declareProperty ("CellContainerLocation", m_cellContainerLocation); declareProperty ("NoiseThresInSigmas", m_sigmasAboveNoise); declareProperty ("NoiseThresInSigmasCore", m_sigmasAboveNoiseCore); declareProperty ("UseCaloNoiseTool", m_useCaloNoiseTool); @@ -136,6 +133,8 @@ MuidCaloEnergyMeas::initialize() ATH_MSG_INFO( "Retrieved tool " << m_caloParamTool ); } + ATH_CHECK(m_cellContainerLocation.initialize()); + return StatusCode::SUCCESS; } @@ -160,33 +159,28 @@ MuidCaloEnergyMeas::energyMeasurement (double etaEM, double etaHad, double phiHad) const { - const CaloCellContainer* cellContainer = 0; - if (evtStore()->contains<CaloCellContainer>(m_cellContainerLocation)) - { - if (StatusCode::FAILURE == evtStore()->retrieve(cellContainer,m_cellContainerLocation)) - { - ATH_MSG_WARNING( "failed to retrieve CaloCellContainer: " << m_cellContainerLocation ); - return 0; - } - } - else - { - ATH_MSG_WARNING( "failed to retrieve CaloCellContainer: " << m_cellContainerLocation ); - return 0; - } + SG::ReadHandle<CaloCellContainer> cellContainer(m_cellContainerLocation); + if(!cellContainer.isPresent()){ + ATH_MSG_DEBUG("No calo cell container "<<m_cellContainerLocation.key()<<", energy measurement is 0"); + return 0; + } + if(!cellContainer.isValid()){ + ATH_MSG_WARNING("Calo cell container "<<m_cellContainerLocation.key()<<" not valid!"); + return 0; + } // set measured tile energy, measured sampling fraction and isolation energy into CaloMeas CaloMeas* caloMeas = new CaloMeas(); - energyInCalo(*caloMeas,cellContainer,etaHad,phiHad,0); - isolationEnergy(*caloMeas,cellContainer,etaHad,phiHad,0); + energyInCalo(*caloMeas,cellContainer.cptr(),etaHad,phiHad,0); + isolationEnergy(*caloMeas,cellContainer.cptr(),etaHad,phiHad,0); // similar for LArHEC - energyInCalo(*caloMeas,cellContainer,etaHad,phiHad,1); - isolationEnergy(*caloMeas,cellContainer,etaHad,phiHad,1); + energyInCalo(*caloMeas,cellContainer.cptr(),etaHad,phiHad,1); + isolationEnergy(*caloMeas,cellContainer.cptr(),etaHad,phiHad,1); // and for the em calo - energyInCalo(*caloMeas,cellContainer,etaEM,phiEM,2); - isolationEnergy(*caloMeas,cellContainer,etaEM,phiEM,2); + energyInCalo(*caloMeas,cellContainer.cptr(),etaEM,phiEM,2); + isolationEnergy(*caloMeas,cellContainer.cptr(),etaEM,phiEM,2); if (msgLvl(MSG::DEBUG)) { diff --git a/Reconstruction/MuonIdentification/MuidCaloIsolationTools/MuidCaloIsolationTools/MuidTrackIsolation.h b/Reconstruction/MuonIdentification/MuidCaloIsolationTools/MuidCaloIsolationTools/MuidTrackIsolation.h index 2adcca59e31..bd7d0e7b4a9 100755 --- a/Reconstruction/MuonIdentification/MuidCaloIsolationTools/MuidCaloIsolationTools/MuidTrackIsolation.h +++ b/Reconstruction/MuonIdentification/MuidCaloIsolationTools/MuidCaloIsolationTools/MuidTrackIsolation.h @@ -21,6 +21,7 @@ #include "GaudiKernel/ToolHandle.h" #include "MuidInterfaces/IMuidTrackIsolation.h" #include "TrkTrack/TrackCollection.h" +#include "StoreGate/ReadHandleKey.h" //<<<<<< CLASS DECLARATIONS >>>>>> @@ -71,7 +72,7 @@ private: const Trk::Surface* m_caloCylinder; const Trk::Surface* m_caloForwardDisc; double m_etaSafetyFactor; - std::string m_inDetTracksLocation; + SG::ReadHandleKey<TrackCollection> m_inDetTracksLocation{this,"InDetTracksLocation","Tracks","ID tracks"}; // FIXME: mutable mutable ToolHandle<Trk::IIntersector> m_intersector; mutable double m_maxP; diff --git a/Reconstruction/MuonIdentification/MuidCaloIsolationTools/src/MuidTrackIsolation.cxx b/Reconstruction/MuonIdentification/MuidCaloIsolationTools/src/MuidTrackIsolation.cxx index 7c4d85ea4a9..e6268b62b78 100755 --- a/Reconstruction/MuonIdentification/MuidCaloIsolationTools/src/MuidTrackIsolation.cxx +++ b/Reconstruction/MuonIdentification/MuidCaloIsolationTools/src/MuidTrackIsolation.cxx @@ -35,7 +35,6 @@ MuidTrackIsolation::MuidTrackIsolation (const std::string&type, const IInterface*parent) : AthAlgTool (type, name, parent), m_etaSafetyFactor (0.1), - m_inDetTracksLocation ("Tracks"), m_intersector ("Trk::RungeKuttaIntersector/RungeKuttaIntersector"), m_minPt (1.0*Gaudi::Units::GeV), m_trackCone (0.2), @@ -44,7 +43,6 @@ MuidTrackIsolation::MuidTrackIsolation (const std::string&type, declareInterface<IMuidTrackIsolation>(this); declareProperty("MinPt", m_minPt); declareProperty("RungeKuttaIntersector", m_intersector); - declareProperty("InDetTracksLocation", m_inDetTracksLocation); declareProperty("TrackCone", m_trackCone); declareProperty("TrackExtrapolation", m_trackExtrapolation); } @@ -90,6 +88,8 @@ MuidTrackIsolation::initialize() *transform *= Amg::Translation3D(backwardDiscPosition); m_caloBackwardDisc = new Trk::DiscSurface(transform, 0., radius); + ATH_CHECK(m_inDetTracksLocation.initialize()); + return StatusCode::SUCCESS; } @@ -131,27 +131,27 @@ MuidTrackIsolation::trackIsolation(double eta, double phi) const std::pair<int,double> isolation = std::make_pair(0,0.); // retrieve track collection - const TrackCollection* inDetTracks = 0; - if (! evtStore()->contains<TrackCollection>(m_inDetTracksLocation)) + SG::ReadHandle<TrackCollection> inDetTracks(m_inDetTracksLocation); + if (! inDetTracks.isPresent()) { - ATH_MSG_DEBUG( " no ID Track container at location " << m_inDetTracksLocation ); + ATH_MSG_DEBUG( " no ID Track container at location " << m_inDetTracksLocation.key() ); return isolation; } - if (StatusCode::SUCCESS != evtStore()->retrieve(inDetTracks,m_inDetTracksLocation)) + if (!inDetTracks.isValid()) { - ATH_MSG_WARNING( " Could not retrieve ID Track container from " << m_inDetTracksLocation ); + ATH_MSG_WARNING( " ID Track container " << m_inDetTracksLocation.key()<<" not valid!" ); return isolation; } // evaluate isolation according to configuration if (m_trackExtrapolation) { - isolation = trackExtrapolated(inDetTracks,eta,phi); + isolation = trackExtrapolated(inDetTracks.cptr(),eta,phi); } else { - isolation = trackVertex(inDetTracks,eta,phi); + isolation = trackVertex(inDetTracks.cptr(),eta,phi); } // debug result -- GitLab