ATLAS Offline Software
Loading...
Searching...
No Matches
VertexCollectionSortingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include <vector>
8
9namespace {
10
11struct Vertex_pair
12{
13 double first;
14 const xAOD::Vertex* second;
15 Vertex_pair(double p1, const xAOD::Vertex* p2)
16 : first(p1)
17 , second(p2)
18 {}
19 bool operator<(const Vertex_pair& other) const { return first > other.first; }
20};
21
22} // anonymous namespace
23
24namespace Trk {
25
26// constructor
28 const std::string& n,
29 const IInterface* p)
30 : AthAlgTool(t, n, p)
31{
32 declareInterface<IVertexCollectionSortingTool>(this);
33}
34
35// initialize
36StatusCode
38{
39 if (m_iVertexWeightCalculator.retrieve().isFailure()) {
40 ATH_MSG_FATAL("Failed to retrieve tool " << m_iVertexWeightCalculator);
41 return StatusCode::FAILURE;
42 }
43
44 ATH_MSG_INFO("Initialization successful");
45 return StatusCode::SUCCESS;
46}
47
48StatusCode
50{
51 return StatusCode::SUCCESS;
52}
53
54std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
56 const xAOD::VertexContainer& MyVxCont) const
57{
58 std::vector<Vertex_pair> MyVertex_pairs;
59
60 xAOD::VertexContainer* NewContainer = new xAOD::VertexContainer();
62 NewContainer->setStore(auxNewContainer);
64
65 if(MyVxCont.size()<=1){
66 xAOD::Vertex* dummyVxCandidate = new xAOD::Vertex();
67 NewContainer->push_back(dummyVxCandidate);
68 if(MyVxCont.size()==1){
69 const xAOD::Vertex* existVtx = MyVxCont.back();
70 dummyVxCandidate->setPosition(existVtx->position());
71 dummyVxCandidate->setCovariancePosition(existVtx->covariancePosition());
72 }else{
73 dummyVxCandidate->setPosition(Amg::Vector3D(0.,0.,0.));
74 AmgSymMatrix(3) tmpCovar; tmpCovar.setIdentity();
75 dummyVxCandidate->setCovariancePosition(tmpCovar);
76 }
77 dummyVxCandidate->setVertexType(xAOD::VxType::NoVtx);
78 sigWeightDec(*dummyVxCandidate) = 0.;
79 return std::make_pair(NewContainer, auxNewContainer);
80 }
81
82 xAOD::VertexContainer::const_iterator beginIter = MyVxCont.begin();
83 xAOD::VertexContainer::const_iterator endIter = MyVxCont.end();
84
85 for (xAOD::VertexContainer::const_iterator i = beginIter; i != endIter; ++i) {
86 // do not weight dummy!!! (do not delete it either! it is deleted when the
87 // original MyVxContainer is deleted in InDetPriVxFinder.cxx)
88 if ((*i)->vertexType() != xAOD::VxType::NoVtx) {
89 double Weight =
90 m_iVertexWeightCalculator->estimateSignalCompatibility(**i);
91 MyVertex_pairs.emplace_back(Weight, (*i));
92 ATH_MSG_DEBUG("Weight before sorting: " << Weight);
93 }
94 }
95
96 if (!MyVertex_pairs.empty()) {
97 std::sort(MyVertex_pairs.begin(), MyVertex_pairs.end());
98 }
99
100 unsigned int vtxCount(1);
101 for (auto MyVertex_pair : MyVertex_pairs) {
102 ATH_MSG_DEBUG("Weight after sorting: " << MyVertex_pair.first);
103 xAOD::Vertex* vxCand = new xAOD::Vertex(
104 *(MyVertex_pair.second)); // use copy-constructor, creates a private store
105 NewContainer->push_back(
106 vxCand); // private store is now copied to the container store
107 if (vtxCount == 1) {
109 } else {
111 }
112 sigWeightDec(*vxCand) = MyVertex_pair.first;
113 vtxCount++;
114 }
115
116 // add dummy at position of first vertex
117 xAOD::Vertex* primaryVtx = NewContainer->front();
118 xAOD::Vertex* dummyVxCandidate = new xAOD::Vertex();
119 NewContainer->push_back(dummyVxCandidate);
120 dummyVxCandidate->setPosition(primaryVtx->position());
121 dummyVxCandidate->setCovariancePosition(primaryVtx->covariancePosition());
122 dummyVxCandidate->setVertexType(xAOD::VxType::NoVtx);
123 sigWeightDec(*dummyVxCandidate) = 0.;
124
125 return std::make_pair(NewContainer, auxNewContainer);
126}
127
128}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
bool operator<(const DataVector< T > &a, const DataVector< T > &b)
Vector ordering relation.
#define AmgSymMatrix(dim)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const T * back() const
Access the last element in the collection as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const T * front() const
Access the first element in the collection as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
ToolHandle< Trk::IVertexWeightCalculator > m_iVertexWeightCalculator
virtual std::pair< xAOD::VertexContainer *, xAOD::VertexAuxContainer * > sortVertexContainer(const xAOD::VertexContainer &MyVxCont) const override
Sort.
Gaudi::Property< std::string > m_decorationName
virtual StatusCode finalize() override
EndOfInitialize.
VertexCollectionSortingTool(const std::string &t, const std::string &n, const IInterface *p)
constructor
void setCovariancePosition(const AmgSymMatrix(3)&covariancePosition)
Sets the vertex covariance matrix.
void setVertexType(VxType::VertexType vType)
Set the type of the vertex.
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
const Amg::Vector3D & position() const
Returns the 3-pos.
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
@ PileUp
Pile-up vertex.
@ PriVtx
Primary vertex.
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.