ATLAS Offline Software
Loading...
Searching...
No Matches
TruthVertexSelectionTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "CLHEP/Random/RandFlat.h"
10#include <vector>
11
12namespace Trk{
13
14 //constructor
15 TruthVertexSelectionTool::TruthVertexSelectionTool ( const std::string& t, const std::string& n, const IInterface* p )
16 : AthAlgTool ( t,n,p )
17 {
18 declareInterface<IVertexSelectionTool> ( this );
19 }
20
21 //destructor
23
24//initialize
26 {
27 ATH_CHECK( m_mcEventCollectionKey.initialize() );
28 msg(MSG::INFO) << "Initialization successful" << endmsg;
29
30 return StatusCode::SUCCESS;
31 }
32
34 {
35 return StatusCode::SUCCESS;
36 }
37
39 {
41
42 if ( !mcCollptr.isValid() )
43 {
44 ATH_MSG_WARNING( "Could not retrieve McEventCollection" );
45 return 0;
46 }
47 ATH_MSG_DEBUG( "HepMC info loaded" );
48
49// taking the first event in the truth collection as the signal one
50 McEventCollection::const_iterator itr = mcCollptr->begin();
51
52//and the first vertex in its respective collection
53 const HepMC::GenEvent *evt = (*itr);
54
55//protection
56 if(!evt) return 0;
57
58#ifdef HEPMC3
59 auto vitr = evt->vertices().begin();
60#else
61 HepMC::GenEvent::vertex_const_iterator vitr = evt->vertices_begin();
62#endif
63//another one
64 if(!*vitr) return 0;
65
66//and its position
67 HepMC::FourVector vxGenPos = (*vitr)->position();
68
69//selecting the container vertex closest in Z to the truth one
70 unsigned int res_pos = 0;
71
72 if(vertexContainer)
73 {
74 unsigned int cont_size = vertexContainer->size();
75 if(cont_size>1)
76 {
77 float z_sim = vxGenPos.z();
78
79 float significance = fabs(z_sim - (*vertexContainer)[0]->position().z());//start with the pv value
80 for(unsigned int i = 1; i < cont_size; ++i)
81 {
82 const xAOD::Vertex * vrt = (*vertexContainer)[i];
83 float loc_significance = fabs(z_sim - vrt->position().z())/Amg::error(vrt->covariancePosition(), Trk::z);
84 if(loc_significance < significance)
85 {
86 significance = loc_significance;
87 res_pos = i;
88 }//end of comparison
89 } //end of the vertex container loop
90
91 }//end of the container size check
92 }//end of container check
93//nothing happened, return the default primary vertex position
94 return res_pos;
95 }
96
97}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
size_type size() const noexcept
Returns the number of elements in the collection.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TruthVertexSelectionTool(const std::string &t, const std::string &n, const IInterface *p)
constructor
SG::ReadHandleKey< McEventCollection > m_mcEventCollectionKey
StatusCode finalize()
EndOfInitialize.
virtual ~TruthVertexSelectionTool()
destructor
virtual unsigned int findVertexInContainer(const xAOD::VertexContainer *) const
Selection method returning the position of selected the PV in the container.
const Amg::Vector3D & position() const
Returns the 3-pos.
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Ensure that the ATLAS eigen extensions are properly loaded.
@ z
global position (cartesian)
Definition ParamDefs.h:57
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.