ATLAS Offline Software
VertexCnvAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Gaudi/Athena include(s):
7 
8 // EDM include(s):
11 #include "VxVertex/VxContainer.h"
17 // Local include(s):
18 #include "VertexCnvAlg.h"
19 
20 namespace xAODMaker {
21 
22  VertexCnvAlg::VertexCnvAlg( const std::string& name,
23  ISvcLocator* svcLoc )
24  : AthAlgorithm( name, svcLoc ),
25  m_aod("VxPrimaryCandidate"),
26  m_xaodout("PrimaryVertices")
27  {
28 
29  declareProperty( "AODContainerName",
30  m_aod );
31  declareProperty( "xAODContainerName",
32  m_xaodout );
33  declareProperty( "TPContainerName",
34  m_TPContainerName = "InDetTrackParticles" );
35  declareProperty( "NPContainerName",
36  m_NPContainerName = "VertexNeutralParticles" );
37  }
38 
40 
41  ATH_MSG_INFO( "Initializing" );
42  ATH_MSG_INFO( "AODContainerName = " << m_aod.name() );
43  ATH_MSG_INFO( "xAODContainerName = " << m_xaodout.name() );
44  ATH_MSG_INFO( "TPContainerName = " << m_TPContainerName );
45  ATH_MSG_INFO( "NPContainerName = " << m_NPContainerName );
46 
47  // Return gracefully:
48  return StatusCode::SUCCESS;
49  }
50 
52  // Retrieve the AOD vertexes:
53 
54  if (!m_aod.isValid()) {
55  ATH_MSG_DEBUG("No VxContainer with key " << m_aod.name() << " found. Do nothing.");
56  return StatusCode::SUCCESS;
57  }
58 
59  ATH_MSG_DEBUG( "Retrieved particles with key: " << m_aod.name() );
60 
61  // Create the xAOD container and its auxiliary store:
62 
63  m_xaodout = std::make_unique<xAOD::VertexContainer>();
64  m_xauxout = std::make_unique<xAOD::VertexAuxContainer>();
65 
66  if(!m_xaodout.isValid() || !m_xauxout.isValid()){
67  ATH_MSG_ERROR( "Problem creating " << m_xaodout.name() );
68  }
69 
70  m_xaodout->setStore( *m_xauxout );
71 
72 
73  // Create the xAOD objects:
74  auto itr = m_aod->cbegin();
75  auto end = m_aod->cend();
76  m_xaodout->reserve(m_aod->size());
77 
78  for( ; itr != end; ++itr ) {
79  // Create the xAOD object:
81  m_xaodout->push_back( vertex );
82  // Get & set the Position
83  const Amg::Vector3D& position = (*itr)->recVertex().position();
84  vertex->setPosition(position);
85  // Get & set the Covariance Position
86  const AmgSymMatrix(3)& covariance = (*itr)->recVertex().covariancePosition();
87  vertex->setCovariancePosition(covariance);
88  // Get & set the Fit quality
89  vertex->setFitQuality((*itr)->recVertex().fitQuality().chiSquared(), static_cast<float>((*itr)->recVertex().fitQuality().doubleNumberDoF ()));
90  //Type of the vertex
91  vertex->setVertexType((xAOD::VxType::VertexType)(*itr)->vertexType());
92  //Set Links
93  unsigned int VTAVsize = (*itr)->vxTrackAtVertex()->size();
94  for (unsigned int i = 0 ; i < VTAVsize ; ++i)
95  {
96  Trk::VxTrackAtVertex* VTAV = (*((*itr)->vxTrackAtVertex()))[i];
97  Trk::ITrackLink* trklink = VTAV->trackOrParticleLink();
98  Trk::LinkToTrackParticleBase* linkToTrackPB = dynamic_cast<Trk::LinkToTrackParticleBase*>(trklink);
99  if (linkToTrackPB) {
101  newLink.resetWithKeyAndIndex( m_TPContainerName, linkToTrackPB->index());
102  //Now set the newlink to the new xAOD vertex
103  vertex->addTrackAtVertex(newLink, VTAV->vtxCompatibility());
104  }
105  else {
106  Trk::LinkToXAODNeutralParticle* linkToTrackNP = dynamic_cast<Trk::LinkToXAODNeutralParticle*>(trklink);
107  if (linkToTrackNP) {
109  newLink.resetWithKeyAndIndex( m_NPContainerName, linkToTrackNP->index());
110  //Now set the newlink to the new xAOD vertex
111  vertex->addNeutralAtVertex(newLink, VTAV->vtxCompatibility());
112  }
113  else {
114  ATH_MSG_DEBUG ("Cast of element link failed, skip this VxTrack/NeutralAtVertex !!!!!");
115  }
116  }
117  }
118  }
119  // Return gracefully:
120  return StatusCode::SUCCESS;
121  }//execute
122 
123 } // namespace xAODMaker
xAODMaker::VertexCnvAlg::m_aod
SG::ReadHandle< VxContainer > m_aod
The key of the input Container.
Definition: VertexCnvAlg.h:41
Trk::VxTrackAtVertex
The VxTrackAtVertex is a common class for all present TrkVertexFitters The VxTrackAtVertex is designe...
Definition: VxTrackAtVertex.h:77
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
xAODMaker::VertexCnvAlg::m_NPContainerName
std::string m_NPContainerName
The key for the neutral particle links Container.
Definition: VertexCnvAlg.h:50
DataVector::cend
const_iterator cend() const noexcept
Return a const_iterator pointing past the end of the collection.
Trk::VxTrackAtVertex::trackOrParticleLink
const ITrackLink * trackOrParticleLink(void) const
xAODMaker
Definition: StoreGateSvc.h:72
xAODMaker::VertexCnvAlg::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: VertexCnvAlg.cxx:39
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:52
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
xAOD::VxType::VertexType
VertexType
Vertex types.
Definition: TrackingPrimitives.h:569
xAODMaker::VertexCnvAlg::m_xauxout
SG::WriteHandle< xAOD::VertexAuxContainer > m_xauxout
Definition: VertexCnvAlg.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LinkToXAODTrackParticle.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
VxTrackAtVertex.h
VxContainer.h
LinkToXAODNeutralParticle.h
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
LinkToTrackParticleBase.h
Trk::LinkToTrackParticleBase
Definition: LinkToTrackParticleBase.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
xAODMaker::VertexCnvAlg::VertexCnvAlg
VertexCnvAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: VertexCnvAlg.cxx:22
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::LinkToXAODNeutralParticle
Element link to XAOD NeutralParticle.
Definition: LinkToXAODNeutralParticle.h:32
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAODMaker::VertexCnvAlg::m_TPContainerName
std::string m_TPContainerName
The key for the track particle links Container.
Definition: VertexCnvAlg.h:48
DataVector::cbegin
const_iterator cbegin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
VertexCnvAlg.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAODMaker::VertexCnvAlg::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: VertexCnvAlg.cxx:51
VertexAuxContainer.h
Trk::VxTrackAtVertex::vtxCompatibility
double vtxCompatibility(void) const
Information about fast compatibility estimation, to be given to the annealing.
xAODMaker::VertexCnvAlg::m_xaodout
SG::WriteHandle< xAOD::VertexContainer > m_xaodout
The key for the output xAOD::Container.
Definition: VertexCnvAlg.h:44