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 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}
#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 ...
HepMC3::FourVector FourVector
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
Ensure that the ATLAS eigen extensions are properly loaded.
@ z
global position (cartesian)
Definition ParamDefs.h:57
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.