From b864622219e52267811c4764bfef3588b2c0cf80 Mon Sep 17 00:00:00 2001 From: Jovan Mitrevski <Jovan.Mitrevski@cern.ch> Date: Tue, 19 Mar 2019 14:02:59 +0100 Subject: [PATCH] migrate ConvVxSorter and TrackMatchSorter to C++17 compatible style (and simplify) --- .../egamma/egammaTools/src/ConvVxSorter.h | 52 ------------------- .../egammaTools/src/EMConversionBuilder.cxx | 46 ++++++++++++++-- .../egammaTools/src/EMTrackMatchBuilder.cxx | 27 +++++++++- .../egammaTools/src/EMTrackMatchBuilder.h | 22 +++++++- .../egamma/egammaTools/src/TrackMatchSorter.h | 52 ------------------- 5 files changed, 88 insertions(+), 111 deletions(-) delete mode 100644 Reconstruction/egamma/egammaTools/src/ConvVxSorter.h delete mode 100644 Reconstruction/egamma/egammaTools/src/TrackMatchSorter.h diff --git a/Reconstruction/egamma/egammaTools/src/ConvVxSorter.h b/Reconstruction/egamma/egammaTools/src/ConvVxSorter.h deleted file mode 100644 index 5ebdd018edc..00000000000 --- a/Reconstruction/egamma/egammaTools/src/ConvVxSorter.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef EGAMMATOOLS_CONVVXSORTER_H -#define EGAMMATOOLS_CONVVXSORTER_H - -#include "xAODTracking/Vertex.h" -#include "xAODEgamma/EgammaxAODHelpers.h" - -/** Sort conversion vertices according to the following criteria: - - Vertices with more Si tracks have priority - - Vertices with more tracks have priority - - Vertices with smaller radii have priority - - OLD SCHEME: - - Vertices with 2 tracks have priority over the ones with 1 track - - Vertices with Si + Si tracks have priority (if m_preferSi > 0) - - Vertices with Si + TRT or TRT + TRT depending on m_preferSi - - Vertices with smaller radii have priority - **/ -class ConvVxSorter -: public std::binary_function<xAOD::Vertex&, xAOD::Vertex&, bool> { - public: - bool operator()(const xAOD::Vertex& vx1, const xAOD::Vertex& vx2) const - { - xAOD::EgammaParameters::ConversionType convType1, convType2; - convType1 = xAOD::EgammaHelpers::conversionType(&vx1); - convType2 = xAOD::EgammaHelpers::conversionType(&vx2); - - if (convType1 != convType2) - { - // Different conversion type, preference to vertices with Si tracks - int nSi1 = xAOD::EgammaHelpers::numberOfSiTracks(convType1); - int nSi2 = xAOD::EgammaHelpers::numberOfSiTracks(convType2); - if (nSi1 != nSi2) return nSi1 > nSi2; - - // Same number of Si tracks: either 0 or 1 (Si+TRT vs. Si single) - // For 1 Si track, preference to Si+TRT - if (nSi1 != 0) return convType1 == xAOD::EgammaParameters::doubleSiTRT; - - // No Si track, preference to doubleTRT over single TRT - return convType1 == xAOD::EgammaParameters::doubleTRT; - } - - // Same conversion type, preference to lower radius - return (vx1.position().perp() < vx2.position().perp()); - } - -}; - -#endif diff --git a/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.cxx b/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.cxx index 6c5b126f056..1351946c501 100644 --- a/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.cxx +++ b/Reconstruction/egamma/egammaTools/src/EMConversionBuilder.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /******************************************************************** @@ -18,17 +18,57 @@ PURPOSE: subAlgorithm which creates an EMConversion object. // INCLUDE HEADER FILES: #include "EMConversionBuilder.h" -#include "ConvVxSorter.h" #include "xAODTracking/VertexContainer.h" #include "egammaRecEvent/egammaRecContainer.h" #include "egammaRecEvent/egammaRec.h" #include "FourMomUtils/P4Helpers.h" #include "StoreGate/ReadHandle.h" #include "GaudiKernel/EventContext.h" +#include "xAODTracking/Vertex.h" +#include "xAODEgamma/EgammaxAODHelpers.h" + // END OF HEADER FILES INCLUDE ///////////////////////////////////////////////////////////////// +namespace { + /** Sort conversion vertices according to the following criteria: + - Vertices with more Si tracks have priority + - Vertices with more tracks have priority + - Vertices with smaller radii have priority + + OLD SCHEME: + - Vertices with 2 tracks have priority over the ones with 1 track + - Vertices with Si + Si tracks have priority (if m_preferSi > 0) + - Vertices with Si + TRT or TRT + TRT depending on m_preferSi + - Vertices with smaller radii have priority + **/ + bool ConvVxSorter (const xAOD::Vertex& vx1, const xAOD::Vertex& vx2) + { + xAOD::EgammaParameters::ConversionType convType1, convType2; + convType1 = xAOD::EgammaHelpers::conversionType(&vx1); + convType2 = xAOD::EgammaHelpers::conversionType(&vx2); + + if (convType1 != convType2) + { + // Different conversion type, preference to vertices with Si tracks + int nSi1 = xAOD::EgammaHelpers::numberOfSiTracks(convType1); + int nSi2 = xAOD::EgammaHelpers::numberOfSiTracks(convType2); + if (nSi1 != nSi2) return nSi1 > nSi2; + + // Same number of Si tracks: either 0 or 1 (Si+TRT vs. Si single) + // For 1 Si track, preference to Si+TRT + if (nSi1 != 0) return convType1 == xAOD::EgammaParameters::doubleSiTRT; + + // No Si track, preference to doubleTRT over single TRT + return convType1 == xAOD::EgammaParameters::doubleTRT; + } + + // Same conversion type, preference to lower radius + return (vx1.position().perp() < vx2.position().perp()); + } +} // end of namespace + using namespace xAOD::EgammaParameters; EMConversionBuilder::EMConversionBuilder(const std::string& type, @@ -125,7 +165,7 @@ StatusCode EMConversionBuilder::vertexExecute(egammaRec* egRec, const xAOD::Vert const ElementLink< xAOD::VertexContainer > vertexLink( *conversions, iVtx ); // If this is the best (or the first) vertex, push front and keep deltaEta, deltaPhi - if (!egRec->getNumberOfVertices() || ConvVxSorter()(*vertex, *egRec->vertex())){ + if (!egRec->getNumberOfVertices() || ConvVxSorter(*vertex, *egRec->vertex())){ egRec->pushFrontVertex( vertexLink ); egRec->setDeltaEtaVtx( cluster->etaBE(2) - etaAtCalo ); egRec->setDeltaPhiVtx( P4Helpers::deltaPhi(cluster->phiBE(2), phiAtCalo) ); diff --git a/Reconstruction/egamma/egammaTools/src/EMTrackMatchBuilder.cxx b/Reconstruction/egamma/egammaTools/src/EMTrackMatchBuilder.cxx index 0a6ed6213fc..105114f834b 100644 --- a/Reconstruction/egamma/egammaTools/src/EMTrackMatchBuilder.cxx +++ b/Reconstruction/egamma/egammaTools/src/EMTrackMatchBuilder.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ // INCLUDE HEADER FILES: @@ -151,7 +151,7 @@ StatusCode EMTrackMatchBuilder::trackExecute(const EventContext& ctx, egammaRec* if(trkMatches.size()>0) { //sort the track matches - std::sort(trkMatches.begin(), trkMatches.end(), TrackMatchSorter()); + std::sort(trkMatches.begin(), trkMatches.end(), TrackMatchSorter); //set the matching values @@ -502,5 +502,28 @@ EMTrackMatchBuilder::isCandidateMatch(const xAOD::CaloCluster* cluster, return true; } +bool EMTrackMatchBuilder::TrackMatchSorter(const EMTrackMatchBuilder::TrackMatch& match1, + const EMTrackMatchBuilder::TrackMatch& match2) +{ + + if(match1.score!= match2.score) {//Higher score + return match1.score>match2.score; + } + //sqrt(0.025**2)*sqrt(2)/sqrt(12) ~ 0.01 + if(fabs(match1.dR-match2.dR)<1e-02) { + + if(fabs(match1.seconddR-match2.seconddR)>1e-02 ){ //Can the second distance separate them? + return match1.seconddR < match2.seconddR ; + } + + if((match1.hitsScore!= match2.hitsScore)){ //use the one with more pixel + return match1.hitsScore>match2.hitsScore; + } + + } + + //closest DR + return match1.dR < match2.dR ; +} diff --git a/Reconstruction/egamma/egammaTools/src/EMTrackMatchBuilder.h b/Reconstruction/egamma/egammaTools/src/EMTrackMatchBuilder.h index 46fcd9c570f..aeddafe3bcf 100644 --- a/Reconstruction/egamma/egammaTools/src/EMTrackMatchBuilder.h +++ b/Reconstruction/egamma/egammaTools/src/EMTrackMatchBuilder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef EGAMMATOOLS_EMTRACKMATCHBUILDER_H @@ -19,7 +19,6 @@ The matching of a track to a cluster is driven by the EMTrackMatchBuilder tool l #include "AthenaBaseComps/AthAlgTool.h" #include "egammaInterfaces/IEMTrackMatchBuilder.h" #include "egammaInterfaces/IEMExtrapolationTools.h" -#include "TrackMatchSorter.h" #include "GaudiKernel/ToolHandle.h" #include "GaudiKernel/EventContext.h" @@ -54,6 +53,25 @@ class EMTrackMatchBuilder : public AthAlgTool, virtual public IEMTrackMatchBuild private: + /** @brief A structure for keeping track match information */ + struct TrackMatch + { + public: + int trackNumber; + double dR; + double seconddR; + bool isTRT; + int score; + int hitsScore; + double deltaPhiLast; + double deltaEta[4]; + double deltaPhi[4]; + double deltaPhiRescaled[4]; + }; + + /** @brief function to sort track matches based on quality */ + static bool TrackMatchSorter(const TrackMatch& match1, const TrackMatch& match2); + /** @brief Compute for tracks passing the loose matching the distance between track extrapolated to 2nd sampling and cluster */ bool inBroadWindow(const EventContext& ctx, diff --git a/Reconstruction/egamma/egammaTools/src/TrackMatchSorter.h b/Reconstruction/egamma/egammaTools/src/TrackMatchSorter.h deleted file mode 100644 index b4da016a9b0..00000000000 --- a/Reconstruction/egamma/egammaTools/src/TrackMatchSorter.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -#ifndef EGAMMATOOLS_TRACKMATCHSORTER_H -#define EGAMMATOOLS_TRACKMATCHSORTER_H -class egammaRec; - -struct TrackMatch -{ - public: - int trackNumber; - double dR; - double seconddR; - bool isTRT; - int score; - int hitsScore; - double deltaPhiLast; - double deltaEta[4]; - double deltaPhi[4]; - double deltaPhiRescaled[4]; - -}; - -class TrackMatchSorter -: public std::binary_function<TrackMatch, TrackMatch, bool> { - public: - bool operator()(const TrackMatch& match1, const TrackMatch& match2) const - { - - if(match1.score!= match2.score) {//Higher score - return match1.score>match2.score; - } - //sqrt(0.025**2)*sqrt(2)/sqrt(12) ~ 0.01 - if(fabs(match1.dR-match2.dR)<1e-02) { - - if(fabs(match1.seconddR-match2.seconddR)>1e-02 ){ //Can the second distance separate them? - return match1.seconddR < match2.seconddR ; - } - - if((match1.hitsScore!= match2.hitsScore)){ //use the one with more pixel - return match1.hitsScore>match2.hitsScore; - } - - } - - //closest DR - return match1.dR < match2.dR ; - } -}; - -#endif -- GitLab