ATLAS Offline Software
EMVertexBuilder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /***************************************************************************
6 
7 EMVertexBuilder.cxx - Description
8 -------------------
9 begin : 11-03-2011
10 authors : Kerstin Tackmann, Bruno Lenzi
11 email : kerstin.tackmann@cern.ch, Bruno.Lenzi@cern.ch
12 changes :
13  Nov 2011 (KT) Initial version
14  Mar 2014 (BL) xAOD migration, creates both double and single track vertices
15 
16 ***************************************************************************/
17 
18 #include "EMVertexBuilder.h"
19 
20 #include "GaudiKernel/EventContext.h"
25 #include "StoreGate/ReadHandle.h"
26 #include "StoreGate/WriteHandle.h"
27 #include "GeoPrimitives/GeoPrimitives.h" // Amg::Vector3D
28 
30  ISvcLocator* pSvcLocator)
31  : AthReentrantAlgorithm(name, pSvcLocator)
32 {
33 }
34 
36 
37  ATH_MSG_DEBUG( "Initializing " << name() << "...");
38 
41 
42  // Get the ID VertexFinderTool
43  ATH_CHECK( m_vertexFinderTool.retrieve());
44  // Retrieve EMExtrapolationTool
45  ATH_CHECK(m_EMExtrapolationTool.retrieve());
46 
47  return StatusCode::SUCCESS;
48 }
49 
51  return StatusCode::SUCCESS;
52 }
53 
54 StatusCode EMVertexBuilder::execute(const EventContext& ctx) const
55 {
56 
57  //retrieve TrackParticleContainer
59 
60  // check for serial running only, remove in MT
61  ATH_CHECK(TPCol.isValid());
62 
63  std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*> verticesPair =
64  m_vertexFinderTool->findVertex(ctx,TPCol.cptr());
65 
66  if (!verticesPair.first || !verticesPair.second){
67  ATH_MSG_ERROR("Null pointer to conversion container");
68  return StatusCode::SUCCESS;
69  }
70 
72 
73  ATH_CHECK(vertices.record(std::unique_ptr<xAOD::VertexContainer>(verticesPair.first),
74  std::unique_ptr<xAOD::VertexAuxContainer>(verticesPair.second)));
75 
76  ATH_MSG_DEBUG("New conversion container size: " << vertices->size());
77 
78  // Remove vertices with radii above m_maxRadius
79  xAOD::VertexContainer::iterator itVtx = vertices->begin();
80  xAOD::VertexContainer::iterator itVtxEnd = vertices->end();
81 
82  while (itVtx != itVtxEnd){
83  xAOD::Vertex* vertex = *itVtx;
84 
85  Amg::Vector3D momentum(0., 0., 0.);
86  for (unsigned int i = 0; i < vertex->nTrackParticles(); ++i){
87  momentum += m_EMExtrapolationTool->getMomentumAtVertex(ctx,*vertex, i);
88  }
89 
90  static const SG::AuxElement::Accessor<float> accPx("px");
91  static const SG::AuxElement::Accessor<float> accPy("py");
92  static const SG::AuxElement::Accessor<float> accPz("pz");
93  accPx(*vertex) = momentum.x();
94  accPy(*vertex) = momentum.y();
95  accPz(*vertex) = momentum.z();
96 
98  const bool vxDoubleTRT = (convType == xAOD::EgammaParameters::doubleTRT);
99  const bool vxSingleTRT = (convType == xAOD::EgammaParameters::singleTRT);
100 
101  if ((vxDoubleTRT && momentum.perp() < m_minPtCut_DoubleTrack) ||
102  (vxSingleTRT && momentum.perp() < m_minPtCut_SingleTrack) ||
103  ((*itVtx)->position().perp() > m_maxRadius)) {
104 
105  itVtx = vertices->erase(itVtx);
106  itVtxEnd = vertices->end();
107  } else {
108  // Decorate the vertices with the momentum at the conversion point and
109  // etaAtCalo, phiAtCalo (extrapolate each vertex)
110  float etaAtCalo = -9999.;
111  float phiAtCalo = -9999.;
112 
113  if (!m_EMExtrapolationTool->getEtaPhiAtCalo(
114  ctx, vertex, &etaAtCalo, &phiAtCalo)) {
115  ATH_MSG_DEBUG("getEtaPhiAtCalo failed!");
116  }
117 
118  static const SG::AuxElement::Accessor<float> accetaAtCalo("etaAtCalo");
119  static const SG::AuxElement::Accessor<float> accphiAtCalo("phiAtCalo");
120  accetaAtCalo(*vertex) = etaAtCalo;
121  accphiAtCalo(*vertex) = phiAtCalo;
122 
123  ++itVtx;
124  }
125  }
126 
127  return StatusCode::SUCCESS;
128 }
EMVertexBuilder::m_outputConversionContainerKey
SG::WriteHandleKey< xAOD::VertexContainer > m_outputConversionContainerKey
conversion container output name
Definition: EMVertexBuilder.h:74
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
EMVertexBuilder::m_inputTrackParticleContainerKey
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_inputTrackParticleContainerKey
TrackParticle container input name.
Definition: EMVertexBuilder.h:70
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
EMVertexBuilder::EMVertexBuilder
EMVertexBuilder(const std::string &name, ISvcLocator *pSvcLocator)
Definition: EMVertexBuilder.cxx:29
EMVertexBuilder::m_minPtCut_DoubleTrack
Gaudi::Property< float > m_minPtCut_DoubleTrack
Minimum Pt, less than that TRT track are pileup for double/single track conversion.
Definition: EMVertexBuilder.h:61
xAOD::EgammaParameters::ConversionType
ConversionType
Definition: EgammaEnums.h:268
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
GeoPrimitives.h
WriteHandle.h
Handle class for recording to StoreGate.
EMVertexBuilder::finalize
virtual StatusCode finalize() override final
Definition: EMVertexBuilder.cxx:50
EgammaxAODHelpers.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
EMVertexBuilder.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::EgammaParameters::singleTRT
@ singleTRT
one track only, no Si hits (TRT only)
Definition: EgammaEnums.h:276
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
EMVertexBuilder::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: EMVertexBuilder.cxx:54
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.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
EMVertexBuilder::m_maxRadius
Gaudi::Property< float > m_maxRadius
Maximum radius accepted for conversion vertices.
Definition: EMVertexBuilder.h:57
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
EMVertexBuilder::m_minPtCut_SingleTrack
Gaudi::Property< float > m_minPtCut_SingleTrack
Definition: EMVertexBuilder.h:65
EMVertexBuilder::m_EMExtrapolationTool
ToolHandle< IEMExtrapolationTools > m_EMExtrapolationTool
EMExtrapolationTool.
Definition: EMVertexBuilder.h:84
xAOD::EgammaHelpers::conversionType
xAOD::EgammaParameters::ConversionType conversionType(const xAOD::Photon *ph)
return the photon conversion type (see EgammaEnums)
Definition: PhotonxAODHelpers.cxx:26
EMVertexBuilder::initialize
virtual StatusCode initialize() override final
Definition: EMVertexBuilder.cxx:35
xAOD::EgammaParameters::doubleTRT
@ doubleTRT
two tracks, none with Si hits (TRT only)
Definition: EgammaEnums.h:282
EMVertexBuilder::m_vertexFinderTool
ToolHandle< InDet::IVertexFinder > m_vertexFinderTool
Tool to find vertices (creates double-track conversions)
Definition: EMVertexBuilder.h:79
ReadHandle.h
Handle class for reading from StoreGate.
DataVector::erase
iterator erase(iterator position)
Remove element at a given position.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackParticleContainer.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
VertexAuxContainer.h