ATLAS Offline Software
InDetPriVxFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /***************************************************************************
6  InDetPriVxFinder.cxx - Description
7  -------------------
8  begin : 28-01-2004
9  authors : Andreas Wildauer (CERN PH-ATC), Fredrik Akesson (CERN PH-ATC)
10  email : andreas.wildauer@cern.ch, fredrik.akesson@cern.ch
11  changes :
12  ***************************************************************************/
14 #include "xAODTracking/Vertex.h"
18 
19 // normal includes
21 
22 namespace InDet
23 {
24 
26  (const std::string& name,ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator)
27  { }
28 
29 
31  {
32  /* Get the VertexFinderTool */
33  if ( m_VertexFinderTool.retrieve().isFailure() )
34  {
35  ATH_MSG_FATAL("Failed to retrieve tool " << m_VertexFinderTool);
36  return StatusCode::FAILURE;
37  }
38  ATH_MSG_DEBUG("Retrieved tool " << m_VertexFinderTool);
39 
40  /*Get the Vertex Merging Tool*/
41  if (m_doVertexMerging) {
42  if ( m_VertexMergingTool.retrieve().isFailure() )
43  {
44  ATH_MSG_FATAL("Failed to retrieve tool " << m_VertexMergingTool);
45  return StatusCode::FAILURE;
46  }
47  ATH_MSG_DEBUG("Retrieved tool " << m_VertexMergingTool);
48  } else {
49  m_VertexMergingTool.disable();
50  }
51 
52  /*Get the Vertex Collection Sorting Tool*/
53  if (m_doVertexSorting) {
54  if ( m_VertexCollectionSortingTool.retrieve().isFailure() )
55  {
56  ATH_MSG_FATAL("Failed to retrieve tool " << m_VertexCollectionSortingTool);
57  return StatusCode::FAILURE;
58  }
59  else
60  {
61  ATH_MSG_VERBOSE("Retrieved tool " << m_VertexCollectionSortingTool);
62  }
63  } else {
65  }
66  if (!m_monTool.empty()) CHECK(m_monTool.retrieve());
67 
70  ATH_CHECK(m_vxCandidatesOutputName.initialize());
71  return StatusCode::SUCCESS;
72  }
73 
74 
75  StatusCode InDetPriVxFinder::execute(const EventContext& ctx) const
76  {
77 
79 
80  xAOD::VertexContainer* vertexContainer = nullptr;
81  xAOD::VertexAuxContainer* vertexAuxContainer = nullptr;
82  std::pair< xAOD::VertexContainer*, xAOD::VertexAuxContainer* > vertexContainerPair
83  = std::make_pair( vertexContainer, vertexAuxContainer );
84 
86  SG::ReadHandle<xAOD::TrackParticleContainer> trackParticleCollection(m_tracksName, ctx);
87  if(trackParticleCollection.isValid()){
88 
89  vertexContainerPair = m_VertexFinderTool->findVertex ( trackParticleCollection.cptr() );
90  }
91  else{
92  ATH_MSG_ERROR("No TrackParticle Collection with key "<<m_tracksName.key()<<" exists in StoreGate. No Vertexing Possible");
93  return StatusCode::FAILURE;
94  }
95  } else {
97  if(trackCollection.isValid()){
98  vertexContainerPair = m_VertexFinderTool->findVertex ( trackCollection.cptr() );
99  } else {
100  ATH_MSG_ERROR("No Trk::Track Collection with key "<<m_trkTracksName.key()<<" exists in StoreGate. No Vertexing Possible");
101  return StatusCode::FAILURE;
102  }
103  }
104 
105  // now re-merge and resort the vertex container and store to SG
106  std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer* >
107  myVertexContainerPair{nullptr, nullptr};
108  auto deletePair = [](std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer* > &p){
109  delete p.first; p.first = nullptr;
110  delete p.second; p.second = nullptr;
111  };
112 
113  if (vertexContainerPair.first) {
114  //sort xAOD::Vertex container
115  if(m_doVertexMerging && vertexContainerPair.first->size() > 1) {
116  myVertexContainerPair = m_VertexMergingTool->mergeVertexContainer( *vertexContainerPair.first );
117  deletePair(vertexContainerPair); //also cleans up the aux store
118  vertexContainerPair = myVertexContainerPair;
119  }
120 
121  if (m_doVertexSorting) {
122  myVertexContainerPair = m_VertexCollectionSortingTool->sortVertexContainer(*vertexContainerPair.first);
123  deletePair(vertexContainerPair);
124  }
125 
126  if (myVertexContainerPair.first == nullptr) {
127  ATH_MSG_ERROR("Vertex container has no associated store.");
128  return StatusCode::FAILURE;
129  }
130 
131  if (not myVertexContainerPair.first->hasStore()) {
132  ATH_MSG_ERROR("Vertex container has no associated store.");
133  return StatusCode::FAILURE;
134  }
135 
136  ATH_MSG_DEBUG("Successfully reconstructed " << myVertexContainerPair.first->size()-1 << " vertices (excluding dummy)");
137  }
138 
139  ATH_CHECK(outputVertices.record(std::unique_ptr<xAOD::VertexContainer>(myVertexContainerPair.first),std::unique_ptr<xAOD::VertexAuxContainer>(myVertexContainerPair.second)));
140 
141  auto NVertices = Monitored::Scalar<int>( "NVertices" , 0 );
142  for ( xAOD::VertexContainer::iterator vertexIter = myVertexContainerPair.first->begin();
143  vertexIter != myVertexContainerPair.first->end(); ++vertexIter ) {
144  if((*vertexIter)->nTrackParticles() > 0 and (*vertexIter)->vertexType() != 0 ){
145  NVertices++;
146  monitor_vertex( "allVertex", **vertexIter);
147  //This expects that vertices are already sorted by SumpT(or different criteria)!!!
148  if( vertexIter == myVertexContainerPair.first->begin() ) monitor_vertex( "primVertex", **vertexIter);
149  }
150  }
151  auto mon = Monitored::Group( m_monTool, NVertices);
152 
153  return StatusCode::SUCCESS;
154  }
155 
157  {
158  return StatusCode::SUCCESS;
159  }
160 
161  void InDetPriVxFinder::monitor_vertex( const std::string &prefix, const xAOD::Vertex& vertex ) const {
162  if (prefix == "allVertex"){
163  auto x = Monitored::Scalar<double>( "allVertexX", vertex.x() );
164  auto y = Monitored::Scalar<double>( "allVertexY", vertex.y() );
165  auto z = Monitored::Scalar<double>( "allVertexZ", vertex.z() );
166  auto chi2 = Monitored::Scalar<double>( "allVertexChi2", vertex.chiSquared() );
167  auto nDoF = Monitored::Scalar<double>( "allVertexnDoF", vertex.numberDoF() );
168  auto NTracks = Monitored::Scalar<int> ( "allVertexNTracks", vertex.nTrackParticles() );
169  auto mon = Monitored::Group(m_monTool, x, y, z, chi2, nDoF, NTracks );
170  }
171  else if (prefix == "primVertex"){
172  auto x = Monitored::Scalar<double>( "primVertexX", vertex.x() );
173  auto y = Monitored::Scalar<double>( "primVertexY", vertex.y() );
174  auto z = Monitored::Scalar<double>( "primVertexZ", vertex.z() );
175  auto chi2 = Monitored::Scalar<double>( "primVertexChi2", vertex.chiSquared() );
176  auto nDoF = Monitored::Scalar<double>( "primVertexnDoF", vertex.numberDoF() );
177  auto NTracks = Monitored::Scalar<int> ( "primVertexNTracks", vertex.nTrackParticles() );
178  auto mon = Monitored::Group(m_monTool, x, y, z, chi2, nDoF, NTracks );
179  }
180  }
181 
182 } // end namespace InDet
TrackParticleBaseCollection.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
xAOD::VertexAuxContainer_v1
Temporary container used until we have I/O for AuxStoreInternal.
Definition: VertexAuxContainer_v1.h:32
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
InDet::InDetPriVxFinder::m_doVertexMerging
BooleanProperty m_doVertexMerging
Definition: InDetPriVxFinder.h:97
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
InDet::InDetPriVxFinder::m_tracksName
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_tracksName
Definition: InDetPriVxFinder.h:89
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
InDet::InDetPriVxFinder::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: InDetPriVxFinder.cxx:82
x
#define x
InDet::InDetPriVxFinder::m_vxCandidatesOutputName
SG::WriteHandleKey< xAOD::VertexContainer > m_vxCandidatesOutputName
Definition: InDetPriVxFinder.h:90
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
Rec::nDoF
double nDoF(const Trk::Track &track)
Definition: OutwardsCombinedMuonTrackBuilder.cxx:31
InDet::InDetPriVxFinder::m_VertexFinderTool
ToolHandle< IVertexFinder > m_VertexFinderTool
Definition: InDetPriVxFinder.h:92
InDet::InDetPriVxFinder::InDetPriVxFinder
InDetPriVxFinder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: InDetPriVxFinder.cxx:33
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InDet::InDetPriVxFinder::m_useTrackParticles
BooleanProperty m_useTrackParticles
Definition: InDetPriVxFinder.h:99
TrackParticleAuxContainer.h
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
z
#define z
InDet::InDetPriVxFinder::m_VertexMergingTool
ToolHandle< Trk::IVertexMergingTool > m_VertexMergingTool
Definition: InDetPriVxFinder.h:93
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
InDetPriVxFinder.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
InDet::InDetPriVxFinder::m_doVertexSorting
BooleanProperty m_doVertexSorting
Definition: InDetPriVxFinder.h:98
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
InDet::InDetPriVxFinder::monitor_vertex
void monitor_vertex(const std::string &prefix, const xAOD::Vertex &vertex) const
Definition: InDetPriVxFinder.cxx:168
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Vertex.h
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
InDet::InDetPriVxFinder::m_trkTracksName
SG::ReadHandleKey< TrackCollection > m_trkTracksName
Definition: InDetPriVxFinder.h:88
InDet::InDetPriVxFinder::initialize
virtual StatusCode initialize() override
Definition: InDetPriVxFinder.cxx:37
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
InDet::InDetPriVxFinder::finalize
virtual StatusCode finalize() override
Definition: InDetPriVxFinder.cxx:163
TrackParticle.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
y
#define y
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
InDet::InDetPriVxFinder::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: InDetPriVxFinder.h:95
InDet::InDetPriVxFinder::m_VertexCollectionSortingTool
ToolHandle< Trk::IVertexCollectionSortingTool > m_VertexCollectionSortingTool
Definition: InDetPriVxFinder.h:94