ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
TrkVertexFitter
TrkVertexTools
src
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
5
#include "
TrkVertexTools/TruthVertexSelectionTool.h
"
6
#include "
TrkEventPrimitives/ParamDefs.h
"
7
#include "CLHEP/Random/RandFlat.h"
8
#include "
AtlasHepMC/SimpleVector.h
"
9
#include "
EventPrimitives/EventPrimitivesHelpers.h
"
10
#include <vector>
11
12
namespace
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
22
TruthVertexSelectionTool::~TruthVertexSelectionTool
()=
default
;
23
24
//initialize
25
StatusCode
TruthVertexSelectionTool::initialize
()
26
{
27
ATH_CHECK
(
m_mcEventCollectionKey
.initialize() );
28
msg
(MSG::INFO) <<
"Initialization successful"
<<
endmsg
;
29
30
return
StatusCode::SUCCESS;
31
}
32
33
StatusCode
TruthVertexSelectionTool::finalize
()
34
{
35
return
StatusCode::SUCCESS;
36
}
37
38
unsigned
int
TruthVertexSelectionTool::findVertexInContainer
(
const
xAOD::VertexContainer
* vertexContainer )
const
39
{
40
SG::ReadHandle<McEventCollection>
mcCollptr(
m_mcEventCollectionKey
);
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
auto
vitr = evt->vertices().begin();
59
//another one
60
if
(!*vitr)
return
0;
61
62
//and its position
63
HepMC::FourVector
vxGenPos = (*vitr)->position();
64
65
//selecting the container vertex closest in Z to the truth one
66
unsigned
int
res_pos = 0;
67
68
if
(vertexContainer)
69
{
70
unsigned
int
cont_size = vertexContainer->
size
();
71
if
(cont_size>1)
72
{
73
float
z_sim = vxGenPos.z();
74
75
float
significance = fabs(z_sim - (*vertexContainer)[0]->
position
().
z
());
//start with the pv value
76
for
(
unsigned
int
i = 1; i < cont_size; ++i)
77
{
78
const
xAOD::Vertex
* vrt = (*vertexContainer)[i];
79
float
loc_significance = fabs(z_sim - vrt->
position
().z())/
Amg::error
(vrt->covariancePosition(),
Trk::z
);
80
if
(loc_significance < significance)
81
{
82
significance = loc_significance;
83
res_pos = i;
84
}
//end of comparison
85
}
//end of the vertex container loop
86
87
}
//end of the container size check
88
}
//end of container check
89
//nothing happened, return the default primary vertex position
90
return
res_pos;
91
}
92
93
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
EventPrimitivesHelpers.h
ParamDefs.h
SimpleVector.h
TruthVertexSelectionTool.h
AthAlgTool::AthAlgTool
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Definition
AthAlgTool.cxx:16
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
DataVector< HepMC::GenEvent >::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Definition
DataVector.h:838
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::TruthVertexSelectionTool::TruthVertexSelectionTool
TruthVertexSelectionTool(const std::string &t, const std::string &n, const IInterface *p)
constructor
Definition
TruthVertexSelectionTool.cxx:15
Trk::TruthVertexSelectionTool::m_mcEventCollectionKey
SG::ReadHandleKey< McEventCollection > m_mcEventCollectionKey
Definition
TruthVertexSelectionTool.h:59
Trk::TruthVertexSelectionTool::finalize
StatusCode finalize()
EndOfInitialize.
Definition
TruthVertexSelectionTool.cxx:33
Trk::TruthVertexSelectionTool::~TruthVertexSelectionTool
virtual ~TruthVertexSelectionTool()
destructor
Trk::TruthVertexSelectionTool::findVertexInContainer
virtual unsigned int findVertexInContainer(const xAOD::VertexContainer *) const
Selection method returning the position of selected the PV in the container.
Definition
TruthVertexSelectionTool.cxx:38
Trk::TruthVertexSelectionTool::initialize
StatusCode initialize()
Definition
TruthVertexSelectionTool.cxx:25
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
Definition
Vertex_v1.cxx:106
Amg::error
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 ...
Definition
EventPrimitivesHelpers.h:40
HepMC::FourVector
HepMC3::FourVector FourVector
Definition
SimpleVector.h:11
HepMC::GenEvent
HepMC3::GenEvent GenEvent
Definition
GenEvent.h:39
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition
FakeTrackBuilder.h:9
Trk::z
@ z
global position (cartesian)
Definition
ParamDefs.h:57
Trk::position
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
xAOD::VertexContainer
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Definition
VertexContainer.h:14
xAOD::Vertex
Vertex_v1 Vertex
Define the latest version of the vertex class.
Definition
Event/xAOD/xAODTracking/xAODTracking/Vertex.h:16
Generated on
for ATLAS Offline Software by
1.17.0