diff --git a/InnerDetector/InDetConfig/python/VertexFindingConfig.py b/InnerDetector/InDetConfig/python/VertexFindingConfig.py index 03e08cf039c89556fef8dc2f1f5e6a6f98bb1e78..0eb46abe3f7804e1e74f0e025aac541802712cf8 100644 --- a/InnerDetector/InDetConfig/python/VertexFindingConfig.py +++ b/InnerDetector/InDetConfig/python/VertexFindingConfig.py @@ -12,17 +12,20 @@ def primaryVertexFindingCfg(flags, **kwargs): else: vtxFlags = flags.InDet.PriVertex - vertexWeightTool = None if vtxFlags.sortingSetup == 'SumPt2Sorting': vertexWeightTool = CompFactory.Trk.SumPtVertexWeightCalculator( DoSumPt2Selection=True ) + decorName = "sumPt2" elif vtxFlags.sortingSetup == "SumPtSorting": vertexWeightTool = CompFactory.Trk.SumPtVertexWeightCalculator( DoSumPt2Selection=False ) + decorName = "sumPt" + vertexSorter = CompFactory.Trk.VertexCollectionSortingTool( VertexWeightCalculator=vertexWeightTool, + decorationName=decorName, ) # finder tool finderTool = None diff --git a/InnerDetector/InDetExample/InDetRecExample/share/InDetRecLoadTools.py b/InnerDetector/InDetExample/InDetRecExample/share/InDetRecLoadTools.py index 05eca94888f73c8c305f13bea46c8d33212fea50..62fb67878122be47e3b700a3a5a7b496d5a32a75 100755 --- a/InnerDetector/InDetExample/InDetRecExample/share/InDetRecLoadTools.py +++ b/InnerDetector/InDetExample/InDetRecExample/share/InDetRecLoadTools.py @@ -931,18 +931,7 @@ if (InDetFlags.doVertexFinding() or InDetFlags.doVertexFindingForMonitoring()) o from TrkVertexWeightCalculators.TrkVertexWeightCalculatorsConf import Trk__SumPtVertexWeightCalculator VertexWeightCalculator = Trk__SumPtVertexWeightCalculator(name = "InDetSumPtVertexWeightCalculator", DoSumPt2Selection = True) - - elif InDetFlags.primaryVertexSortingSetup() == 'VxProbSorting': - - from TrkVertexWeightCalculators.TrkVertexWeightCalculatorsConf import Trk__VxProbVertexWeightCalculator - VertexWeightCalculator = Trk__VxProbVertexWeightCalculator(name = "InDetVxProbVertexWeightCalculator", - HistogramPath = "/VxProbHisto/h_sTrkPdfminBias") - - elif InDetFlags.primaryVertexSortingSetup() == 'NNSorting': - - from TrkVertexWeightCalculators.TrkVertexWeightCalculatorsConf import Trk__NNVertexWeightCalculator - VertexWeightCalculator = Trk__NNVertexWeightCalculator(name = "InDetNNVertexWeightCalculator", - HistoFilePath ="/NNHisto/") + decorName = "sumPt2" # ToolSvc += VertexWeightCalculator if InDetFlags.doPrintConfigurables(): @@ -953,7 +942,8 @@ if (InDetFlags.doVertexFinding() or InDetFlags.doVertexFindingForMonitoring()) o # from TrkVertexTools.TrkVertexToolsConf import Trk__VertexCollectionSortingTool VertexCollectionSortingTool = Trk__VertexCollectionSortingTool(name = "InDetVertexCollectionSortingTool", - VertexWeightCalculator = VertexWeightCalculator) + VertexWeightCalculator = VertexWeightCalculator, + decorationName=decorName) ToolSvc += VertexCollectionSortingTool if InDetFlags.doPrintConfigurables(): printfunc (VertexCollectionSortingTool) diff --git a/Tracking/TrkVertexFitter/TrkVertexTools/TrkVertexTools/VertexCollectionSortingTool.h b/Tracking/TrkVertexFitter/TrkVertexTools/TrkVertexTools/VertexCollectionSortingTool.h index 7be4f7d5535d4ffa10d9e4b64f48b39dbb330146..da3214d675fa731cf0469bb1da3b06ca92e0d020 100644 --- a/Tracking/TrkVertexFitter/TrkVertexTools/TrkVertexTools/VertexCollectionSortingTool.h +++ b/Tracking/TrkVertexFitter/TrkVertexTools/TrkVertexTools/VertexCollectionSortingTool.h @@ -2,67 +2,73 @@ Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration */ - #ifndef TrkVertexTools_VertexCollectionSortingTool_H - #define TrkVertexTools_VertexCollectionSortingTool_H - +#ifndef TrkVertexTools_VertexCollectionSortingTool_H +#define TrkVertexTools_VertexCollectionSortingTool_H + +#include "TrkVertexFitterInterfaces/IVertexCollectionSortingTool.h" +#include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h" +/// #include "AthenaBaseComps/AthAlgTool.h" #include "GaudiKernel/ToolHandle.h" -#include "TrkVertexFitterInterfaces/IVertexCollectionSortingTool.h" - -//xAOD include -#include "xAODTracking/VertexFwd.h" +// xAOD include +#include "xAODTracking/TrackParticleAuxContainer.h" +#include "xAODTracking/TrackParticleContainerFwd.h" #include "xAODTracking/TrackParticleFwd.h" -#include "xAODTracking/VertexContainerFwd.h" #include "xAODTracking/VertexAuxContainer.h" -#include "xAODTracking/TrackParticleContainerFwd.h" -#include "xAODTracking/TrackParticleAuxContainer.h" +#include "xAODTracking/VertexContainerFwd.h" +#include "xAODTracking/VertexFwd.h" + +/** + * @class Trk::VertexCollectionSortingTool + * + * @author Johanna Bronner, April 2009 + * + * -------------------------------------- + * Changes: + * + * David Shope <david.richard.shope@cern.ch> (2016-04-26) + * + * EDM Migration to xAOD - remove method using VxCandidate + */ + +namespace Trk { +class IVertexWeightCalculator; + +class VertexCollectionSortingTool final + : public AthAlgTool + , virtual public IVertexCollectionSortingTool +{ +public: + virtual StatusCode initialize() override; + virtual StatusCode finalize() override; + /** + * constructor + */ + VertexCollectionSortingTool(const std::string& t, + const std::string& n, + const IInterface* p); + /** + * destructor + */ + virtual ~VertexCollectionSortingTool() = default; + /** Sort **/ + virtual std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> + sortVertexContainer(const xAOD::VertexContainer& MyVxCont) const override; - /** - * @class Trk::VertexCollectionSortingTool - * - * @author Johanna Bronner, April 2009 - * - * -------------------------------------- - * Changes: - * - * David Shope <david.richard.shope@cern.ch> (2016-04-26) - * - * EDM Migration to xAOD - remove method using VxCandidate - */ - - namespace Trk - { - class IVertexWeightCalculator; - - - class VertexCollectionSortingTool : public AthAlgTool, virtual public IVertexCollectionSortingTool - { - public: - virtual StatusCode initialize() override; - virtual StatusCode finalize() override; - - /** - * constructor - */ - - VertexCollectionSortingTool(const std::string& t, const std::string& n, const IInterface* p); - - /** - * destructor - */ - - virtual ~VertexCollectionSortingTool(); - - /** Sort **/ - virtual std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> - sortVertexContainer(const xAOD::VertexContainer& MyVxCont) const override; +private: + ToolHandle<Trk::IVertexWeightCalculator> m_iVertexWeightCalculator{ + this, + "VertexWeightCalculator", + "Trk::IVertexWeightCalculator" + }; + Gaudi::Property<std::string> m_decorationName{ + this, + "decorationName", + "sumPt2", + "Name to use for the decoration" + }; - private: - ToolHandle < Trk::IVertexWeightCalculator> m_iVertexWeightCalculator; - +}; // end of class description +} // end of namespace definition - - }; //end of class description - }//end of namespace definition - - #endif +#endif diff --git a/Tracking/TrkVertexFitter/TrkVertexTools/src/VertexCollectionSortingTool.cxx b/Tracking/TrkVertexFitter/TrkVertexTools/src/VertexCollectionSortingTool.cxx index 285dec88f3d37f71dc68d220ac4a329528cddb0f..e4a2554d14ec9a18e820c15c8dab9c73a8123202 100644 --- a/Tracking/TrkVertexFitter/TrkVertexTools/src/VertexCollectionSortingTool.cxx +++ b/Tracking/TrkVertexFitter/TrkVertexTools/src/VertexCollectionSortingTool.cxx @@ -3,114 +3,110 @@ */ #include "TrkVertexTools/VertexCollectionSortingTool.h" -#include "TrkVertexFitterInterfaces/IVertexWeightCalculator.h" #include "VxVertex/VxTrackAtVertex.h" -#include <vector> +#include <vector> - - namespace { - - struct Vertex_pair - { - double first; - const xAOD::Vertex* second; - Vertex_pair(double p1, const xAOD::Vertex* p2) - : first (p1), second (p2) {} - bool operator< (const Vertex_pair& other) const - { return first > other.first; } - }; + +struct Vertex_pair +{ + double first; + const xAOD::Vertex* second; + Vertex_pair(double p1, const xAOD::Vertex* p2) + : first(p1) + , second(p2) + {} + bool operator<(const Vertex_pair& other) const { return first > other.first; } +}; } // anonymous namespace +namespace Trk { + +// constructor +VertexCollectionSortingTool::VertexCollectionSortingTool(const std::string& t, + const std::string& n, + const IInterface* p) + : AthAlgTool(t, n, p) +{ + declareInterface<IVertexCollectionSortingTool>(this); +} + +// initialize +StatusCode +VertexCollectionSortingTool::initialize() +{ + if (m_iVertexWeightCalculator.retrieve().isFailure()) { + ATH_MSG_FATAL("Failed to retrieve tool " << m_iVertexWeightCalculator); + return StatusCode::FAILURE; + } -namespace Trk{ - - //constructor - VertexCollectionSortingTool::VertexCollectionSortingTool ( const std::string& t, const std::string& n, const IInterface* p ) - : AthAlgTool ( t,n,p ), - m_iVertexWeightCalculator("Trk::IVertexWeightCalculator") - { - declareInterface<IVertexCollectionSortingTool> ( this ); - declareProperty ( "VertexWeightCalculator",m_iVertexWeightCalculator); + ATH_MSG_INFO("Initialization successful"); + return StatusCode::SUCCESS; +} /// EndOfInitialize + +StatusCode +VertexCollectionSortingTool::finalize() +{ + return StatusCode::SUCCESS; +} + +std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> +VertexCollectionSortingTool::sortVertexContainer( + const xAOD::VertexContainer& MyVxCont) const +{ + std::vector<Vertex_pair> MyVertex_pairs; + + xAOD::VertexContainer::const_iterator beginIter = MyVxCont.begin(); + xAOD::VertexContainer::const_iterator endIter = MyVxCont.end(); + + for (xAOD::VertexContainer::const_iterator i = beginIter; i != endIter; ++i) { + // do not weight dummy!!! (do not delete it either! it is deleted when the + // original MyVxContainer is deleted in InDetPriVxFinder.cxx) + if ((*i)->vertexType() != xAOD::VxType::NoVtx) { + double Weight = + m_iVertexWeightCalculator->estimateSignalCompatibility(**i); + MyVertex_pairs.emplace_back(Weight, (*i)); + ATH_MSG_DEBUG("Weight before sorting: " << Weight); + } } - - //destructor - VertexCollectionSortingTool::~VertexCollectionSortingTool()= default; - -//initialize - StatusCode VertexCollectionSortingTool::initialize() - { - if ( m_iVertexWeightCalculator.retrieve().isFailure() ) - { - msg(MSG::FATAL) << "Failed to retrieve tool " << m_iVertexWeightCalculator << endmsg; - return StatusCode::FAILURE; + + if (!MyVertex_pairs.empty()) { + std::sort(MyVertex_pairs.begin(), MyVertex_pairs.end()); + } + + xAOD::VertexContainer* NewContainer = new xAOD::VertexContainer(); + xAOD::VertexAuxContainer* auxNewContainer = new xAOD::VertexAuxContainer(); + NewContainer->setStore(auxNewContainer); + + SG::AuxElement::Accessor<float> sigWeightDec(m_decorationName); + unsigned int vtxCount(1); + for (std::vector<Vertex_pair>::const_iterator iter = MyVertex_pairs.begin(); + iter != MyVertex_pairs.end(); + ++iter) { + ATH_MSG_DEBUG("Weight after sorting: " << (*iter).first); + xAOD::Vertex* vxCand = new xAOD::Vertex( + *(iter->second)); // use copy-constructor, creates a private store + NewContainer->push_back( + vxCand); // private store is now copied to the container store + if (vtxCount == 1) { + vxCand->setVertexType(xAOD::VxType::PriVtx); + } else { + vxCand->setVertexType(xAOD::VxType::PileUp); } - - msg(MSG::INFO) << "Initialization successful" << endmsg; - return StatusCode::SUCCESS; - }///EndOfInitialize - - StatusCode VertexCollectionSortingTool::finalize() - { - return StatusCode::SUCCESS; + sigWeightDec(*vxCand) = iter->first; + vtxCount++; } - std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> - VertexCollectionSortingTool::sortVertexContainer( - const xAOD::VertexContainer& MyVxCont) const - { - std::vector<Vertex_pair> MyVertex_pairs; - - xAOD::VertexContainer::const_iterator beginIter = MyVxCont.begin(); - xAOD::VertexContainer::const_iterator endIter = MyVxCont.end(); - - for(xAOD::VertexContainer::const_iterator i = beginIter; i!=endIter; ++i) - { - // do not weight dummy!!! (do not delete it either! it is deleted when the original MyVxContainer is deleted in InDetPriVxFinder.cxx) - if ((*i)->vertexType() != xAOD::VxType::NoVtx) - { - double Weight =m_iVertexWeightCalculator->estimateSignalCompatibility(**i); - MyVertex_pairs.emplace_back(Weight,(*i)); - ATH_MSG_DEBUG("Weight before sorting: " << Weight); - } - } - - if (!MyVertex_pairs.empty()) - { - std::sort (MyVertex_pairs.begin(), MyVertex_pairs.end()); - } - - xAOD::VertexContainer *NewContainer = new xAOD::VertexContainer(); - xAOD::VertexAuxContainer* auxNewContainer = new xAOD::VertexAuxContainer(); - NewContainer->setStore( auxNewContainer ); - std::string decorationName = (m_iVertexWeightCalculator->name().find("InDetSumPtVertexWeightCalculator") != std::string::npos) ? "sumPt2" : "signalCompatibility"; - SG::AuxElement::Accessor< float > sigWeightDec(decorationName); - unsigned int vtxCount(1); - for (std::vector<Vertex_pair>::const_iterator iter = MyVertex_pairs.begin() ; iter != MyVertex_pairs.end(); ++iter ) - { - ATH_MSG_DEBUG("Weight after sorting: " << (*iter).first); - xAOD::Vertex* vxCand = new xAOD::Vertex(*(iter->second)); //use copy-constructor, creates a private store - NewContainer->push_back(vxCand); //private store is now copied to the container store - if (vtxCount == 1) { - vxCand->setVertexType(xAOD::VxType::PriVtx); - } else { - vxCand->setVertexType(xAOD::VxType::PileUp); - } - sigWeightDec(*vxCand) = iter->first; - vtxCount++; - } - - // add dummy at position of first vertex - xAOD::Vertex* primaryVtx = NewContainer->front(); - xAOD::Vertex* dummyVxCandidate = new xAOD::Vertex(); - NewContainer->push_back ( dummyVxCandidate ); - dummyVxCandidate->setPosition(primaryVtx->position()); - dummyVxCandidate->setCovariancePosition(primaryVtx->covariancePosition()); - dummyVxCandidate->setVertexType(xAOD::VxType::NoVtx); - - return std::make_pair(NewContainer, auxNewContainer); - } - - -}///End!!! + // add dummy at position of first vertex + xAOD::Vertex* primaryVtx = NewContainer->front(); + xAOD::Vertex* dummyVxCandidate = new xAOD::Vertex(); + NewContainer->push_back(dummyVxCandidate); + dummyVxCandidate->setPosition(primaryVtx->position()); + dummyVxCandidate->setCovariancePosition(primaryVtx->covariancePosition()); + dummyVxCandidate->setVertexType(xAOD::VxType::NoVtx); + + return std::make_pair(NewContainer, auxNewContainer); +} + +}