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 {
64  m_VertexCollectionSortingTool.disable();
65  }
66  if (!m_monTool.empty()) CHECK(m_monTool.retrieve());
67 
68  ATH_CHECK(m_trkTracksName.initialize(!m_useTrackParticles));
69  ATH_CHECK(m_tracksName.initialize(m_useTrackParticles));
70  ATH_CHECK(m_vxCandidatesOutputName.initialize());
71  return StatusCode::SUCCESS;
72  }
73 
74 
75  StatusCode InDetPriVxFinder::execute(const EventContext& ctx) const
76  {
77 
78  SG::WriteHandle<xAOD::VertexContainer> outputVertices (m_vxCandidatesOutputName, ctx);
79 
80  xAOD::VertexContainer* vertexContainer = nullptr;
81  xAOD::VertexAuxContainer* vertexAuxContainer = nullptr;
82  auto vertexContainerPair = std::make_pair(vertexContainer, vertexAuxContainer);
83 
84  if (m_useTrackParticles) {
85  SG::ReadHandle<xAOD::TrackParticleContainer> trackParticleCollection(m_tracksName, ctx);
86  if (trackParticleCollection.isValid()) {
87  vertexContainerPair = m_VertexFinderTool->findVertex(ctx, trackParticleCollection.cptr());
88  } else {
89  ATH_MSG_ERROR("No TrackParticle Collection with key "
90  << m_tracksName.key()
91  << " exists in StoreGate. No Vertexing Possible");
92  return StatusCode::FAILURE;
93  }
94  } else {
95  SG::ReadHandle<TrackCollection> trackCollection(m_trkTracksName, ctx);
96  if (trackCollection.isValid()) {
97  vertexContainerPair = m_VertexFinderTool->findVertex(ctx, trackCollection.cptr());
98  } else {
99  ATH_MSG_ERROR("No Trk::Track Collection with key "
100  << m_trkTracksName.key()
101  << " exists in StoreGate. No Vertexing Possible");
102  return StatusCode::FAILURE;
103  }
104  }
105 
106  // now re-merge and resort the vertex container and store to SG
107  std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer* > 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  ATH_MSG_DEBUG("Successfully reconstructed "
136  << myVertexContainerPair.first->size() - 1
137  << " vertices (excluding dummy)");
138  }
139 
140  ATH_CHECK(outputVertices.record(
141  std::unique_ptr<xAOD::VertexContainer>(myVertexContainerPair.first),
142  std::unique_ptr<xAOD::VertexAuxContainer>(myVertexContainerPair.second)));
143 
144  auto NVertices = Monitored::Scalar<int>( "NVertices" , 0 );
145  for ( xAOD::VertexContainer::iterator vertexIter = myVertexContainerPair.first->begin();
146  vertexIter != myVertexContainerPair.first->end(); ++vertexIter ) {
147  if((*vertexIter)->nTrackParticles() > 0 and (*vertexIter)->vertexType() != 0 ){
148  NVertices++;
149  monitor_vertex( "allVertex", **vertexIter);
150  //This expects that vertices are already sorted by SumpT(or different criteria)!!!
151  if( vertexIter == myVertexContainerPair.first->begin() ) monitor_vertex( "primVertex", **vertexIter);
152  }
153  }
154  auto mon = Monitored::Group( m_monTool, NVertices);
155 
156  return StatusCode::SUCCESS;
157  }
158 
160  {
161  return StatusCode::SUCCESS;
162  }
163 
164  void InDetPriVxFinder::monitor_vertex( const std::string &prefix, const xAOD::Vertex& vertex ) const {
165  if (prefix == "allVertex"){
166  auto x = Monitored::Scalar<double>( "allVertexX", vertex.x() );
167  auto y = Monitored::Scalar<double>( "allVertexY", vertex.y() );
168  auto z = Monitored::Scalar<double>( "allVertexZ", vertex.z() );
169  auto chi2 = Monitored::Scalar<double>( "allVertexChi2", vertex.chiSquared() );
170  auto nDoF = Monitored::Scalar<double>( "allVertexnDoF", vertex.numberDoF() );
171  auto NTracks = Monitored::Scalar<int> ( "allVertexNTracks", vertex.nTrackParticles() );
172  auto mon = Monitored::Group(m_monTool, x, y, z, chi2, nDoF, NTracks );
173  }
174  else if (prefix == "primVertex"){
175  auto x = Monitored::Scalar<double>( "primVertexX", vertex.x() );
176  auto y = Monitored::Scalar<double>( "primVertexY", vertex.y() );
177  auto z = Monitored::Scalar<double>( "primVertexZ", vertex.z() );
178  auto chi2 = Monitored::Scalar<double>( "primVertexChi2", vertex.chiSquared() );
179  auto nDoF = Monitored::Scalar<double>( "primVertexnDoF", vertex.numberDoF() );
180  auto NTracks = Monitored::Scalar<int> ( "primVertexNTracks", vertex.nTrackParticles() );
181  auto mon = Monitored::Group(m_monTool, x, y, z, chi2, nDoF, NTracks );
182  }
183  }
184 
185 } // end namespace InDet
Trk::y
@ y
Definition: ParamDefs.h:56
TrackParticleBaseCollection.h
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
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
Trk::z
@ z
global position (cartesian)
Definition: ParamDefs.h:57
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
initialize
void initialize()
Definition: run_EoverP.cxx:894
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
InDet::InDetPriVxFinder::InDetPriVxFinder
InDetPriVxFinder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: InDetPriVxFinder.cxx:33
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrackParticleAuxContainer.h
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
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
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:525
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Vertex.h
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TrackParticle.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:66
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
Trk::x
@ x
Definition: ParamDefs.h:55