ATLAS Offline Software
Loading...
Searching...
No Matches
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):
17// Local include(s):
18#include "VertexCnvAlg.h"
19
20namespace 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
51 StatusCode VertexCnvAlg::execute() {
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:
80 xAOD::Vertex* vertex = new xAOD::Vertex();
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
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define AmgSymMatrix(dim)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Element link to XAOD NeutralParticle.
The VxTrackAtVertex is a common class for all present TrkVertexFitters The VxTrackAtVertex is designe...
double vtxCompatibility(void) const
Information about fast compatibility estimation, to be given to the annealing.
const ITrackLink * trackOrParticleLink(void) const
VertexCnvAlg(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
virtual StatusCode initialize()
Function initialising the algorithm.
SG::ReadHandle< VxContainer > m_aod
The key of the input Container.
SG::WriteHandle< xAOD::VertexAuxContainer > m_xauxout
SG::WriteHandle< xAOD::VertexContainer > m_xaodout
The key for the output xAOD::Container.
virtual StatusCode execute()
Function executing the algorithm.
std::string m_TPContainerName
The key for the track particle links Container.
std::string m_NPContainerName
The key for the neutral particle links Container.
Eigen::Matrix< double, 3, 1 > Vector3D
VertexType
Vertex types.
Vertex_v1 Vertex
Define the latest version of the vertex class.