diff --git a/Reconstruction/eflowRec/eflowRec/PFRecoverSplitShowersTool.h b/Reconstruction/eflowRec/eflowRec/PFRecoverSplitShowersTool.h index 86fdf16746b1bea1fc9fe691bf4b5e741b7af62a..b7e6cbabb59fa81ab32fa9fff2f9f64faf798f34 100644 --- a/Reconstruction/eflowRec/eflowRec/PFRecoverSplitShowersTool.h +++ b/Reconstruction/eflowRec/eflowRec/PFRecoverSplitShowersTool.h @@ -6,6 +6,9 @@ #define PFRECOVERSPLITSHOWERSTOOL_H #include "AthenaBaseComps/AthAlgTool.h" + +#include <unordered_set> + #include "GaudiKernel/ToolHandle.h" #include "xAODCaloEvent/CaloCluster.h" #include "eflowRec/IPFSubtractionTool.h" @@ -40,7 +43,7 @@ class PFRecoverSplitShowersTool : public extends<AthAlgTool, IPFSubtractionTool> struct eflowData { eflowCaloObjectContainer* caloObjects; - std::vector<eflowRecCluster*> clustersToConsider; + std::unordered_set<eflowRecCluster*> clustersToConsider; std::vector<eflowRecTrack*> tracksToRecover; }; @@ -58,9 +61,6 @@ class PFRecoverSplitShowersTool : public extends<AthAlgTool, IPFSubtractionTool> /* Tool for getting e/p values and hadronic shower cell ordering principle parameters */ ToolHandle<IEFlowCellEOverPTool> m_theEOverPTool{this,"eflowCellEOverPTool","eflowCellEOverPTool","Energy Flow E/P Values and Shower Parameters Tool"}; - /** Track-Cluster matching tool */ - ToolHandle<PFTrackClusterMatchingTool> m_matchingTool{this,"PFTrackClusterMatchingTool","PFTrackClusterMatchingTool/RcvrSpltMatchingTool","The track-cluster matching tool"}; - std::unique_ptr<eflowEEtaBinnedParameters> m_binnedParameters; /** Parameter that controls whether to use retain remaining calorimeter energy in track-cluster system, after charged shower subtraction */ diff --git a/Reconstruction/eflowRec/eflowRec/PFTrackClusterMatchingTool.h b/Reconstruction/eflowRec/eflowRec/PFTrackClusterMatchingTool.h index ddf36db9d423ddf4ac9b19c4773758d4bb23e646..7867de6529b77f7641e2e3ae7df5819a16e71e06 100644 --- a/Reconstruction/eflowRec/eflowRec/PFTrackClusterMatchingTool.h +++ b/Reconstruction/eflowRec/eflowRec/PFTrackClusterMatchingTool.h @@ -14,6 +14,7 @@ #ifndef PFMATCHINGTOOL_H_ #define PFMATCHINGTOOL_H_ +#include <utility> #include "eflowRec/PFMatcher.h" class eflowRecCluster; @@ -38,8 +39,8 @@ public: StatusCode finalize(); /** Get n clusters that matches best to a given track */ - std::vector<eflowRecCluster*> doMatches(const eflowRecTrack* track, eflowRecClusterContainer* clusters, int n) const; - std::vector<eflowRecCluster*> doMatches(const eflowRecTrack* track, const std::vector<eflowRecCluster*> clusters, int n) const; + std::vector<std::pair<eflowRecCluster*,float> > doMatches(const eflowRecTrack* track, eflowRecClusterContainer* clusters, int n) const; + std::vector<std::pair<eflowRecCluster*,float> > doMatches(const eflowRecTrack* track, const std::vector<eflowRecCluster*> clusters, int n) const; private: diff --git a/Reconstruction/eflowRec/python/PFHLTSequence.py b/Reconstruction/eflowRec/python/PFHLTSequence.py index 146426e762fe4062e5d2f25262cd2eee250222fc..1b59e4c86fa1c581691f8c1449d12f42cae9b045 100644 --- a/Reconstruction/eflowRec/python/PFHLTSequence.py +++ b/Reconstruction/eflowRec/python/PFHLTSequence.py @@ -95,8 +95,7 @@ def getPFAlg(clustersin,tracktype): # cluster is needed to recover the full track expected energy # Reuse the default E/P subtraction tool PFRecoverSplitShowersTool = eflowRecConf.PFRecoverSplitShowersTool("PFRecoverSplitShowersTool", - eflowCellEOverPTool = CellEOverPTool, - PFTrackClusterMatchingTool = getPFMatchingTool("MatchingTool_RecoverSS",0.2) + eflowCellEOverPTool = CellEOverPTool ) # Configure moment calculation using topocluster moment calculator diff --git a/Reconstruction/eflowRec/share/PFlowMTConfig.py b/Reconstruction/eflowRec/share/PFlowMTConfig.py index 721308e53aa507009103a1db32347db5c997293c..8bf16d1e55e85a97d41f4679de681d6047a2d74e 100644 --- a/Reconstruction/eflowRec/share/PFlowMTConfig.py +++ b/Reconstruction/eflowRec/share/PFlowMTConfig.py @@ -98,13 +98,6 @@ if jobproperties.eflowRecFlags.recoverIsolatedTracks == True: if jobproperties.eflowRecFlags.useUpdated2015ChargedShowerSubtraction == False: PFRecoverSplitShowersTool.useUpdated2015ChargedShowerSubtraction = False -MatchingTool_Recover = PFTrackClusterMatchingTool() -MatchingTool_Recover.TrackPositionType = 'EM2EtaPhi' # str -MatchingTool_Recover.ClusterPositionType = 'PlainEtaPhi' # str -MatchingTool_Recover.DistanceType = 'EtaPhiSquareDistance' # str -MatchingTool_Recover.MatchCut = 0.2*0.2 # float -PFRecoverSplitShowersTool.PFTrackClusterMatchingTool = MatchingTool_Recover - if jobproperties.eflowRecFlags.eflowAlgType != "EOverP": PFAlgorithm.SubtractionToolList += [PFRecoverSplitShowersTool] diff --git a/Reconstruction/eflowRec/src/PFCellLevelSubtractionTool.cxx b/Reconstruction/eflowRec/src/PFCellLevelSubtractionTool.cxx index 07a5fe815ecddd70c63a92279c51ddc656db6ecd..e43b11d0f6cc75b3fb00435c747365a182d9869c 100644 --- a/Reconstruction/eflowRec/src/PFCellLevelSubtractionTool.cxx +++ b/Reconstruction/eflowRec/src/PFCellLevelSubtractionTool.cxx @@ -57,10 +57,6 @@ StatusCode PFCellLevelSubtractionTool::initialize(){ msg(MSG::WARNING) << "Cannot find PFTrackClusterMatchingTool" << endmsg; } - if (m_matchingToolForPull_015.retrieve().isFailure()) { - msg(MSG::WARNING) << "Cannot find PFTrackClusterMatchingTool_2" << endmsg; - } - if (m_matchingToolForPull_02.retrieve().isFailure()) { msg(MSG::WARNING) << "Cannot find PFTrackClusterMatchingTool_2" << endmsg; } @@ -115,29 +111,30 @@ unsigned int PFCellLevelSubtractionTool::matchAndCreateEflowCaloObj(unsigned int eflowRecTrack *thisEfRecTrack = static_cast<eflowRecTrack*>(data.tracks->at(iTrack)); /* Add cluster matches needed for pull calculation*/ - std::vector<eflowRecCluster*> bestClusters_015 = m_matchingToolForPull_015->doMatches(thisEfRecTrack, data.clusters, -1); - std::vector<eflowRecCluster*> bestClusters_02 = m_matchingToolForPull_02->doMatches(thisEfRecTrack, data.clusters, -1); - - for (unsigned int imatch=0; imatch < bestClusters_015.size(); ++imatch) { - eflowTrackClusterLink* trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack, bestClusters_015.at(imatch)); - thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,"cone_015"); - } - - for (unsigned int imatch=0; imatch < bestClusters_02.size(); ++imatch) { - eflowTrackClusterLink* trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack, bestClusters_02.at(imatch)); + std::vector<std::pair<eflowRecCluster*,float> > bestClusters_02 = m_matchingToolForPull_02->doMatches(thisEfRecTrack, data.clusters, -1); + + for (auto& matchpair : bestClusters_02) { + eflowRecCluster* theCluster = matchpair.first; + float distancesq = matchpair.second; + eflowTrackClusterLink* trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack, theCluster); + if(distancesq<0.15*0.15) { + // Narrower cone is a subset of the selected clusters + // Distance returned is deltaR^2 + thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,"cone_015"); + } thisEfRecTrack->addAlternativeClusterMatch(trackClusterLink,"cone_02"); } - std::vector<eflowRecCluster*> bestClusters = m_matchingTool->doMatches(thisEfRecTrack, data.clusters, n); + std::vector<std::pair<eflowRecCluster*,float> > bestClusters = m_matchingTool->doMatches(thisEfRecTrack, data.clusters, n); if (bestClusters.empty()) { continue; } /* Matched cluster: create TrackClusterLink and add it to both the track and the cluster (eflowCaloObject will be created later) */ nMatches++; - for (unsigned int imatch=0; imatch < bestClusters.size(); ++imatch) { - eflowTrackClusterLink* trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack, bestClusters.at(imatch)); - thisEfRecTrack->addClusterMatch(trackClusterLink); - bestClusters.at(imatch)->addTrackMatch(trackClusterLink); - + for (auto& matchpair : bestClusters) { + eflowRecCluster* theCluster = matchpair.first; + eflowTrackClusterLink* trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack, theCluster); + thisEfRecTrack->addClusterMatch(trackClusterLink); + theCluster->addTrackMatch(trackClusterLink); } } diff --git a/Reconstruction/eflowRec/src/PFClusterCollectionTool.cxx b/Reconstruction/eflowRec/src/PFClusterCollectionTool.cxx index 79f658a6c7fc7d3946c2f6880820bbfd7aea1896..6cf144b74eec1b478cf51a74f1fc8cd776bb8898 100644 --- a/Reconstruction/eflowRec/src/PFClusterCollectionTool.cxx +++ b/Reconstruction/eflowRec/src/PFClusterCollectionTool.cxx @@ -61,6 +61,7 @@ std::unique_ptr<xAOD::CaloClusterContainer> PFClusterCollectionTool::execute(con ATH_MSG_DEBUG("Adding cluster with E, eta and phi to moments maker " << thisCluster->e() << ", " << thisCluster->eta() << " and " << thisCluster->phi()); } } + std::sort(result->begin(), result->end(), [](xAOD::CaloCluster* c1, xAOD::CaloCluster* c2) {return c1->e()>c2->e();}); return result; } diff --git a/Reconstruction/eflowRec/src/PFRecoverSplitShowersTool.cxx b/Reconstruction/eflowRec/src/PFRecoverSplitShowersTool.cxx index d0bb314287ac2b2986e7351762829cd7f249bcc8..06b16f46c9774355cd3a667d461bec66565034ec 100644 --- a/Reconstruction/eflowRec/src/PFRecoverSplitShowersTool.cxx +++ b/Reconstruction/eflowRec/src/PFRecoverSplitShowersTool.cxx @@ -36,11 +36,6 @@ PFRecoverSplitShowersTool::~PFRecoverSplitShowersTool() {} StatusCode PFRecoverSplitShowersTool::initialize(){ - if (m_matchingTool.retrieve().isFailure()){ - ATH_MSG_WARNING("Couldn't retrieve PFTrackClusterMatchingTool"); - return StatusCode::SUCCESS; - } - if (m_theEOverPTool.retrieve().isFailure()){ ATH_MSG_WARNING("Cannot find eflowEOverPTool"); return StatusCode::SUCCESS; @@ -54,12 +49,14 @@ StatusCode PFRecoverSplitShowersTool::initialize(){ return StatusCode::SUCCESS; } -void PFRecoverSplitShowersTool::execute(eflowCaloObjectContainer* theEflowCaloObjectContainer, eflowRecTrackContainer*, eflowRecClusterContainer*) const { +void PFRecoverSplitShowersTool::execute(eflowCaloObjectContainer* theEflowCaloObjectContainer, eflowRecTrackContainer* eflowRecTracks, eflowRecClusterContainer* eflowRecClusters) const { ATH_MSG_DEBUG("Executing"); eflowData data; data.caloObjects = theEflowCaloObjectContainer; + data.tracksToRecover.reserve(eflowRecTracks->size()); + data.clustersToConsider.reserve(eflowRecClusters->size()); fillTracksToRecover(data); fillClustersToConsider(data); @@ -91,12 +88,10 @@ void PFRecoverSplitShowersTool::fillClustersToConsider(eflowData& data) const { if (0 == (int)theCellLink->size()){ continue; } thisEflowCaloObject->efRecCluster(i)->clearTrackMatches(); - data.clustersToConsider.push_back(thisEflowCaloObject->efRecCluster(i)); + data.clustersToConsider.insert(thisEflowCaloObject->efRecCluster(i)); thisEflowCaloObject->clearClusters(); } } - - std::sort(data.clustersToConsider.begin(),data.clustersToConsider.end(),eflowRecCluster::SortDescendingPt()); } void PFRecoverSplitShowersTool::fillTracksToRecover(eflowData& data) const { @@ -163,26 +158,35 @@ unsigned int PFRecoverSplitShowersTool::matchAndCreateEflowCaloObj(eflowData& da const xAOD::TrackParticle* track = thisEfRecTrack->getTrack(); ATH_MSG_DEBUG("Recovering charged EFO with e,pt, eta and phi " << track->e() << ", " << track->pt() << ", " << track->eta() << " and " << track->phi()); } - /* Get list of matched clusters */ - std::vector<eflowRecCluster*> matchedClusters = m_matchingTool->doMatches(thisEfRecTrack, data.clustersToConsider, -1); + // Get list of matched clusters in the dR<0.2 cone -- already identified + const std::vector<eflowTrackClusterLink*>* matchedClusters_02 = thisEfRecTrack->getAlternativeClusterMatches("cone_02"); + if (!matchedClusters_02) { continue; } if (msgLvl(MSG::DEBUG)){ - for (auto thisEFRecCluster : matchedClusters) ATH_MSG_DEBUG("Have matched cluster with e, pt, eta, phi of " << thisEFRecCluster->getCluster()->e() << ", " << thisEFRecCluster->getCluster()->eta() << ", " << thisEFRecCluster->getCluster()->eta() << " and " << thisEFRecCluster->getCluster()->phi()); + for (auto trkClusLink : *matchedClusters_02) { + const eflowRecCluster* thisEFRecCluster = trkClusLink->getCluster(); + ATH_MSG_DEBUG("Have matched cluster with e, pt, eta, phi of " << thisEFRecCluster->getCluster()->e() << ", " << thisEFRecCluster->getCluster()->eta() << ", " << thisEFRecCluster->getCluster()->eta() << " and " << thisEFRecCluster->getCluster()->phi()); + } } - if (matchedClusters.empty()) { continue; } + if (matchedClusters_02->empty()) { continue; } /* Matched cluster: create TrackClusterLink and add it to both the track and the cluster (eflowCaloObject will be created later) */ - for (auto efRecCluster : matchedClusters){ - eflowTrackClusterLink* trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack,efRecCluster); + for (auto trkClusLink : *matchedClusters_02){ + eflowRecCluster* thisEFRecCluster = trkClusLink->getCluster(); + // Look up whether this cluster is intended for recovery + if( data.clustersToConsider.find(trkClusLink->getCluster()) == data.clustersToConsider.end() ) {continue;} + eflowTrackClusterLink* trackClusterLink = eflowTrackClusterLink::getInstance(thisEfRecTrack,thisEFRecCluster); thisEfRecTrack->addClusterMatch(trackClusterLink); - efRecCluster->addTrackMatch(trackClusterLink); + thisEFRecCluster->addTrackMatch(trackClusterLink); } } /* Create all eflowCaloObjects that contain eflowRecCluster */ eflowCaloObjectMaker makeCaloObject; - unsigned int nCaloObjects = makeCaloObject.makeTrkCluCaloObjects(data.tracksToRecover, data.clustersToConsider, + std::vector<eflowRecCluster*> v_clustersToConsider(data.clustersToConsider.begin(),data.clustersToConsider.end()); + std::sort(v_clustersToConsider.begin(),v_clustersToConsider.end(),eflowRecCluster::SortDescendingPt()); + unsigned int nCaloObjects = makeCaloObject.makeTrkCluCaloObjects(data.tracksToRecover, v_clustersToConsider, data.caloObjects); ATH_MSG_DEBUG("PFRecoverSplitShowersTool created " << nCaloObjects << " CaloObjects"); @@ -214,9 +218,10 @@ void PFRecoverSplitShowersTool::performSubtraction(eflowCaloObject* thisEflowCal matchedClusters.clear(); std::vector<eflowTrackClusterLink*> links = thisEfRecTrack->getClusterMatches(); for ( auto thisEFlowTrackClusterLink : links) matchedClusters.push_back(thisEFlowTrackClusterLink->getCluster()); + std::sort(matchedClusters.begin(),matchedClusters.end(),eflowRecCluster::SortDescendingPt()); if (msgLvl(MSG::DEBUG)){ - for (auto thisClus : matchedClusters) ATH_MSG_DEBUG("Cluster with e,pt, eta and phi of " << thisClus->getCluster()->e() << ", "<< thisClus->getCluster()->pt() << ", " << thisClus->getCluster()->eta() << " and " << thisClus->getCluster()->phi() << " will be subtracted"); + for (auto thisClus : matchedClusters) ATH_MSG_DEBUG("Cluster " << thisClus->getCluster()->index() << " with e,pt, eta and phi of " << thisClus->getCluster()->e() << ", "<< thisClus->getCluster()->pt() << ", " << thisClus->getCluster()->eta() << " and " << thisClus->getCluster()->phi() << " will be subtracted"); } /* Do subtraction */ std::vector<std::pair<xAOD::CaloCluster*, bool> > clusterSubtractionList; @@ -255,7 +260,7 @@ void PFRecoverSplitShowersTool::performSubtraction(eflowCaloObject* thisEflowCal else clusterSubtractedEnergyRatios.push_back(NAN); } - pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, *thisEflowCaloObject); + pfSubtractionStatusSetter.markSubtractionStatus(clusterSubtractionList, clusterSubtractedEnergyRatios, *thisEflowCaloObject); } diff --git a/Reconstruction/eflowRec/src/PFTrackClusterMatchingTool.cxx b/Reconstruction/eflowRec/src/PFTrackClusterMatchingTool.cxx index 04724057d4fbf1b9b1f7051305b086d525a28b24..e92a5e01c9250b8dd0b618458e659c5a23676d59 100644 --- a/Reconstruction/eflowRec/src/PFTrackClusterMatchingTool.cxx +++ b/Reconstruction/eflowRec/src/PFTrackClusterMatchingTool.cxx @@ -53,23 +53,17 @@ StatusCode PFTrackClusterMatchingTool::finalize() { return StatusCode::SUCCESS; } -std::vector<eflowRecCluster*> PFTrackClusterMatchingTool::doMatches(const eflowRecTrack* track, eflowRecClusterContainer* clusters, int nMatches) const { - std::vector<eflowRecCluster*> vec_clusters; - for (unsigned int iCluster = 0; iCluster < clusters->size(); ++iCluster) { - eflowRecCluster* thisEFRecCluster = clusters->at(iCluster); - vec_clusters.push_back(thisEFRecCluster); - } - const std::vector<eflowRecCluster*> const_clusters = vec_clusters; - return doMatches(track, const_clusters, nMatches); +std::vector<std::pair<eflowRecCluster*,float> > PFTrackClusterMatchingTool::doMatches(const eflowRecTrack* track, eflowRecClusterContainer* clusters, int nMatches) const { + const std::vector<eflowRecCluster*> vec_clusters(clusters->begin(), clusters->end()); + return doMatches(track, vec_clusters, nMatches); } -std::vector<eflowRecCluster*> PFTrackClusterMatchingTool::doMatches(const eflowRecTrack* track, const std::vector<eflowRecCluster*> clusters, int nMatches) const { +std::vector<std::pair<eflowRecCluster*,float> > PFTrackClusterMatchingTool::doMatches(const eflowRecTrack* track, const std::vector<eflowRecCluster*> clusters, int nMatches) const { /* Transform the vector of eflowRecCluster into a vector of eflowMatchClusters */ - unsigned int nClusters = clusters.size(); std::vector<const eflowMatchCluster*> matchClusters; - for (unsigned int iCluster = 0; iCluster < nClusters; ++iCluster) { - matchClusters.push_back(clusters.at(iCluster)->getMatchCluster()); + for (auto& cluster : clusters) { + matchClusters.push_back(cluster->getMatchCluster()); } /* Use the TrackClusterMatcher to retrieve the matches */ @@ -77,12 +71,12 @@ std::vector<eflowRecCluster*> PFTrackClusterMatchingTool::doMatches(const eflowR std::vector<MatchDistance> allMatches = m_matcher->bestMatches(&matchTrack, matchClusters, nMatches, 0.1*track->getTrack()->e()); /* Transform the vector of MatchDistance objects into a vector of eflowRecClusters and return it */ - std::vector<eflowRecCluster*> results; - for (unsigned int imatch = 0; imatch < allMatches.size(); ++imatch) { + std::vector<std::pair<eflowRecCluster*,float> > results; + for (MatchDistance& match : allMatches) { // The matching cannot change the cluster type, this started as eflowMatchCluster // and remains of that type -- no need to test cast from ICluster* - const eflowMatchCluster* thisMatch = static_cast<const eflowMatchCluster*>(allMatches.at(imatch).first); - results.push_back(thisMatch->getEfRecCluster()); + const eflowMatchCluster* thisMatch = static_cast<const eflowMatchCluster*>(match.first); + results.push_back(std::make_pair(thisMatch->getEfRecCluster(),match.second)); } return results; }