ATLAS Offline Software
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 
9 namespace {
10 
11 struct 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 
24 namespace 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
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 
50 {
51  return StatusCode::SUCCESS;
52 }
53 
54 std::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();
61  xAOD::VertexAuxContainer* auxNewContainer = new xAOD::VertexAuxContainer();
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 }
operator<
bool operator<(const DataVector< T > &a, const DataVector< T > &b)
Vector ordering relation.
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
xAOD::Vertex_v1::setPosition
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAOD::VertexAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: VertexAuxContainer_v1.h:32
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition: Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::VertexCollectionSortingTool::finalize
virtual StatusCode finalize() override
EndOfInitialize.
Definition: VertexCollectionSortingTool.cxx:49
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
VertexCollectionSortingTool.h
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
Trk::VertexCollectionSortingTool::sortVertexContainer
virtual std::pair< xAOD::VertexContainer *, xAOD::VertexAuxContainer * > sortVertexContainer(const xAOD::VertexContainer &MyVxCont) const override
Sort.
Definition: VertexCollectionSortingTool.cxx:55
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
xAOD::VertexContainer
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Definition: VertexContainer.h:14
Trk::VertexCollectionSortingTool::initialize
virtual StatusCode initialize() override
Definition: VertexCollectionSortingTool.cxx:37
xAOD::VxType::NoVtx
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
Definition: TrackingPrimitives.h:570
Trk::VertexCollectionSortingTool::VertexCollectionSortingTool
VertexCollectionSortingTool(const std::string &t, const std::string &n, const IInterface *p)
constructor
Definition: VertexCollectionSortingTool.cxx:27
Trk::AmgSymMatrix
AmgSymMatrix(5) &GXFTrackState
Definition: GXFTrackState.h:156
xAOD::Vertex_v1::setVertexType
void setVertexType(VxType::VertexType vType)
Set the type of the vertex.
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
xAOD::VertexAuxContainer
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
Definition: VertexAuxContainer.h:19
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
VxTrackAtVertex.h
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
xAOD::VxType::PileUp
@ PileUp
Pile-up vertex.
Definition: TrackingPrimitives.h:573
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
Trk::VertexCollectionSortingTool::m_iVertexWeightCalculator
ToolHandle< Trk::IVertexWeightCalculator > m_iVertexWeightCalculator
Definition: VertexCollectionSortingTool.h:59
DeMoScan.first
bool first
Definition: DeMoScan.py:536
AthAlgTool
Definition: AthAlgTool.h:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::Vertex_v1::setCovariancePosition
void setCovariancePosition(const AmgSymMatrix(3)&covariancePosition)
Sets the vertex covariance matrix.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Trk::VertexCollectionSortingTool::m_decorationName
Gaudi::Property< std::string > m_decorationName
Definition: VertexCollectionSortingTool.h:64