ATLAS Offline Software
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 
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
23 
24 //initialize
26  {
28  msg(MSG::INFO) << "Initialization successful" << endmsg;
29 
30  return StatusCode::SUCCESS;
31  }
32 
34  {
35  return StatusCode::SUCCESS;
36  }
37 
38  unsigned int TruthVertexSelectionTool::findVertexInContainer(const xAOD::VertexContainer * vertexContainer ) const
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 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
Trk::z
@ z
global position (cartesian)
Definition: ParamDefs.h:57
Trk::TruthVertexSelectionTool::m_mcEventCollectionKey
SG::ReadHandleKey< McEventCollection > m_mcEventCollectionKey
Definition: TruthVertexSelectionTool.h:59
SG::ReadHandle< McEventCollection >
EventPrimitivesHelpers.h
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ParamDefs.h
Trk::TruthVertexSelectionTool::initialize
StatusCode initialize()
Definition: TruthVertexSelectionTool.cxx:25
Trk::TruthVertexSelectionTool::TruthVertexSelectionTool
TruthVertexSelectionTool(const std::string &t, const std::string &n, const IInterface *p)
constructor
Definition: TruthVertexSelectionTool.cxx:15
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
TruthVertexSelectionTool.h
SimpleVector.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Trk::TruthVertexSelectionTool::finalize
StatusCode finalize()
EndOfInitialize.
Definition: TruthVertexSelectionTool.cxx:33
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
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
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
AthAlgTool
Definition: AthAlgTool.h:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
Trk::TruthVertexSelectionTool::~TruthVertexSelectionTool
virtual ~TruthVertexSelectionTool()
destructor
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.