ATLAS Offline Software
VertexParametersPlots.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "VertexParametersPlots.h"
12 #include "../TrackParametersHelper.h" // also includes VertexParametersHelper.h
13 
14 
19  PlotMgr* pParent,
20  const std::string& dirName,
21  const std::string& anaTag,
22  const std::string& vertexType,
23  bool doTrackPlots,
24  bool doGlobalPlots,
25  bool doTruthMuPlots ) :
26  PlotMgr( dirName, anaTag, pParent ),
27  m_vertexType( vertexType ),
28  m_doTrackPlots( doTrackPlots ),
29  m_doGlobalPlots( doGlobalPlots ),
30  m_doTruthMuPlots( doTruthMuPlots ) { }
31 
32 
37 {
38  StatusCode sc = bookPlots();
39  if( sc.isFailure() ) {
40  ATH_MSG_ERROR( "Failed to book vertex parameters plots" );
41  }
42 }
43 
44 
46 {
47  ATH_MSG_DEBUG( "Booking vertex parameters plots in " << getDirectory() );
48 
49  if( not m_doGlobalPlots ) {
51  ATH_CHECK( retrieveAndBook( m_vtx_x, m_vertexType+"_vtx_x" ) );
52  ATH_CHECK( retrieveAndBook( m_vtx_y, m_vertexType+"_vtx_y" ) );
53  ATH_CHECK( retrieveAndBook( m_vtx_z, m_vertexType+"_vtx_z" ) );
54  ATH_CHECK( retrieveAndBook( m_vtx_time, m_vertexType+"_vtx_time" ) );
55  if( m_vertexType != "truth" ) {
57  ATH_CHECK( retrieveAndBook( m_vtx_x_err, m_vertexType+"_vtx_x_err" ) );
58  ATH_CHECK( retrieveAndBook( m_vtx_y_err, m_vertexType+"_vtx_y_err" ) );
59  ATH_CHECK( retrieveAndBook( m_vtx_z_err, m_vertexType+"_vtx_z_err" ) );
60  ATH_CHECK( retrieveAndBook( m_vtx_time_err, m_vertexType+"_vtx_time_err" ) );
61  ATH_CHECK( retrieveAndBook( m_vtx_chi2OverNdof, m_vertexType+"_vtx_chi2OverNdof" ) );
62  ATH_CHECK( retrieveAndBook( m_vtx_type, m_vertexType+"_vtx_type" ) );
63  }
64  if( m_doTrackPlots ) {
66  ATH_CHECK( retrieveAndBook( m_vtx_nTracks, m_vertexType+"_vtx_nTracks" ) );
67  ATH_CHECK( retrieveAndBook( m_vtx_track_weight, m_vertexType+"_vtx_track_weight" ) );
68  ATH_CHECK( retrieveAndBook( m_vtx_track_pt, m_vertexType+"_vtx_track_pt" ) );
69  ATH_CHECK( retrieveAndBook( m_vtx_track_eta, m_vertexType+"_vtx_track_eta" ) );
70  ATH_CHECK( retrieveAndBook( m_vtx_track_nSiHits, m_vertexType+"_vtx_track_nSiHits" ) );
71  ATH_CHECK( retrieveAndBook( m_vtx_track_nSiHoles, m_vertexType+"_vtx_track_nSiHoles" ) );
72  ATH_CHECK( retrieveAndBook( m_vtx_track_d0, m_vertexType+"_vtx_track_d0" ) );
73  ATH_CHECK( retrieveAndBook( m_vtx_track_z0, m_vertexType+"_vtx_track_z0" ) );
74  ATH_CHECK( retrieveAndBook( m_vtx_track_d0_err, m_vertexType+"_vtx_track_d0_err" ) );
75  ATH_CHECK( retrieveAndBook( m_vtx_track_z0_err, m_vertexType+"_vtx_track_z0_err" ) );
76  }
77  } else {
79  ATH_CHECK( retrieveAndBook( m_nVtx_vs_actualMu_2D, m_vertexType+"_nVtx_vs_actualMu_2D" ) );
80  ATH_CHECK( retrieveAndBook( m_nVtx_vs_actualMu, m_vertexType+"_nVtx_vs_actualMu" ) );
81  if( m_doTruthMuPlots ) {
82  ATH_CHECK( retrieveAndBook( m_nVtx_vs_truthMu_2D, m_vertexType+"_nVtx_vs_truthMu_2D" ) );
83  ATH_CHECK( retrieveAndBook( m_nVtx_vs_truthMu, m_vertexType+"_nVtx_vs_truthMu" ) );
84  }
85  }
86 
87  return StatusCode::SUCCESS;
88 }
89 
90 
95 template< typename VERTEX, typename PARTICLE >
97  const VERTEX& vertex,
98  const std::vector< const PARTICLE* >& associatedTracks,
99  const std::vector< float >& associatedTrackWeights,
100  float weight )
101 {
102  if( m_doGlobalPlots ) return StatusCode::SUCCESS;
103 
105  float vx = posX( vertex );
106  float vy = posY( vertex );
107  float vz = posZ( vertex );
108  float vtime = time( vertex );
109  bool vhasValidTime = bool( hasValidTime( vertex ) );
110 
111  ATH_CHECK( fill( m_vtx_x, vx, weight ) );
112  ATH_CHECK( fill( m_vtx_y, vy, weight ) );
113  ATH_CHECK( fill( m_vtx_z, vz, weight ) );
114  if( vhasValidTime ) ATH_CHECK( fill( m_vtx_time, vtime, weight ) );
115 
116  if( m_vertexType != "truth" ) {
118  float vxErr = error( vertex, VposX );
119  float vyErr = error( vertex, VposY );
120  float vzErr = error( vertex, VposZ );
121  float vtimeErr = timeErr( vertex );
122  float vchi2 = chiSquared( vertex );
123  float vndof = ndof( vertex );
124  float vchi2OverNdof = ( vndof > 0 ) ? vchi2 / vndof : -9999.;
125  float vtype = vertexType( vertex );
126 
127  ATH_CHECK( fill( m_vtx_x_err, vxErr, weight ) );
128  ATH_CHECK( fill( m_vtx_y_err, vyErr, weight ) );
129  ATH_CHECK( fill( m_vtx_z_err, vzErr, weight ) );
130  if( vhasValidTime ) ATH_CHECK( fill( m_vtx_time_err, vtimeErr, weight ) );
131  ATH_CHECK( fill( m_vtx_chi2OverNdof, vchi2OverNdof, weight ) );
132  ATH_CHECK( fill( m_vtx_type, vtype, weight ) );
133  } // close if m_vertexType != "truth"
134 
136  if( m_doTrackPlots ) {
137  size_t nvTracks = associatedTracks.size();
138  if( nvTracks != associatedTrackWeights.size() ) {
139  ATH_MSG_ERROR( "Vertex-associated track number mismatch" );
140  return StatusCode::FAILURE;
141  }
142 
143  ATH_CHECK( fill( m_vtx_nTracks, nvTracks, weight ) );
144 
145  for( size_t it=0 ; it<nvTracks ; it++ ) {
146  ATH_CHECK( fill( m_vtx_track_weight, associatedTrackWeights[it], weight ) );
147 
148  float tpt = pT( *associatedTracks[it] ) / Gaudi::Units::GeV;
149  float teta = eta( *associatedTracks[it] );
150  float tnSiHits = nSiHits( *associatedTracks[it] );
151  float tnSiHoles = nSiHoles( *associatedTracks[it] );
152  float td0 = d0( *associatedTracks[it] );
153  float tz0 = z0( *associatedTracks[it] ) - vz;
154  float td0Err = error( *associatedTracks[it], Trk::d0 );
155  // TODO: should this also account for the vertex z error?
156  float tz0Err = error( *associatedTracks[it], Trk::z0 );
157 
158  ATH_CHECK( fill( m_vtx_track_pt, tpt, weight ) );
159  ATH_CHECK( fill( m_vtx_track_eta, teta, weight ) );
160  ATH_CHECK( fill( m_vtx_track_nSiHits, tnSiHits, weight ) );
161  ATH_CHECK( fill( m_vtx_track_nSiHoles, tnSiHoles, weight ) );
162  ATH_CHECK( fill( m_vtx_track_d0, td0, weight ) );
163  ATH_CHECK( fill( m_vtx_track_z0, tz0, weight ) );
164  ATH_CHECK( fill( m_vtx_track_d0_err, td0Err, weight ) );
165  ATH_CHECK( fill( m_vtx_track_z0_err, tz0Err, weight ) );
166  } // close loop over tracks
167  } // close if m_doTrackPlots
168 
169  return StatusCode::SUCCESS;
170 }
171 
173  const xAOD::Vertex& vertex,
174  const std::vector< const xAOD::TrackParticle* >& associatedTracks,
175  const std::vector< float >& associatedTrackWeights,
176  float weight );
177 
179  const xAOD::TruthVertex& vertex,
180  const std::vector< const xAOD::TruthParticle* >& associatedTracks,
181  const std::vector< float >& associatedTrackWeights,
182  float weight );
183 
184 
187  int nVertices,
188  float truthMu,
189  float actualMu,
190  float weight )
191 {
192  if( not m_doGlobalPlots ) return StatusCode::SUCCESS;
193 
195  ATH_CHECK( fill( m_nVtx_vs_actualMu_2D, actualMu, nVertices, weight ) );
196  ATH_CHECK( fill( m_nVtx_vs_actualMu, actualMu, nVertices, weight ) );
197  if( m_doTruthMuPlots ) {
198  ATH_CHECK( fill( m_nVtx_vs_truthMu_2D, truthMu, nVertices, weight ) );
199  ATH_CHECK( fill( m_nVtx_vs_truthMu, truthMu, nVertices, weight ) );
200  }
201 
202  return StatusCode::SUCCESS;
203 }
204 
205 
210 {
211  ATH_MSG_DEBUG( "Finalising vertex parameters plots" );
213 }
IDTPM::ndof
float ndof(const U &p)
Definition: TrackParametersHelper.h:134
IDTPM::VertexParametersPlots::bookPlots
StatusCode bookPlots()
Definition: VertexParametersPlots.cxx:45
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
NSWL1::nVertices
int nVertices(const Polygon &p)
Definition: GeoUtils.cxx:35
IDTPM::z0
float z0(const U &p)
Definition: TrackParametersHelper.h:72
skel.it
it
Definition: skel.GENtoEVGEN.py:396
IDTPM::time
float time(const U &p)
Definition: TrackParametersHelper.h:159
Trk::z0
@ z0
Definition: ParamDefs.h:64
IDTPM::VertexParametersPlots::initializePlots
void initializePlots()
Book the histograms.
Definition: VertexParametersPlots.cxx:36
IDTPM::VertexParametersPlots::VertexParametersPlots
VertexParametersPlots(PlotMgr *pParent, const std::string &dirName, const std::string &anaTag, const std::string &vertexType, bool doTrackPlots=false, bool doGlobalPlots=false, bool doTruthMuPlots=false)
Constructor.
Definition: VertexParametersPlots.cxx:18
IDTPM::nSiHoles
float nSiHoles(const U &p)
Accessor utility function for getting the value of nSiHoles.
Definition: TrackParametersHelper.h:431
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
IDTPM::posY
float posY(const V &v)
Accessor utility function for getting the value of vertex position y.
Definition: VertexParametersHelper.h:33
IDTPM::PlotMgr
Definition: PlotMgr.h:33
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IDTPM::eta
float eta(const U &p)
Accessor utility function for getting the value of eta.
Definition: TrackParametersHelper.h:43
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
IDTPM::d0
float d0(const U &p)
Definition: TrackParametersHelper.h:84
IDTPM::VertexParametersPlots::fillPlots
StatusCode fillPlots(const VERTEX &vertex, const std::vector< const PARTICLE * > &associatedTracks, const std::vector< float > &associatedTrackWeights, float weight)
Dedicated fill method (for reco and/or truth vertices)
Definition: VertexParametersPlots.cxx:96
IDTPM::pT
float pT(const U &p)
Accessor utility function for getting the value of pT.
Definition: TrackParametersHelper.h:33
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IDTPM::posZ
float posZ(const V &v)
Accessor utility function for getting the value of vertex position z.
Definition: VertexParametersHelper.h:37
IDTPM::VposX
@ VposX
Definition: VertexParametersHelper.h:72
IDTPM::timeErr
float timeErr(const V &v)
Definition: VertexParametersHelper.h:96
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
Trk::d0
@ d0
Definition: ParamDefs.h:63
IDTPM::posX
float posX(const V &v)
Accessor utility function for getting the value of vertex position x.
Definition: VertexParametersHelper.h:29
xAOD::vertexType
vertexType
Definition: Vertex_v1.cxx:166
IDTPM::chiSquared
float chiSquared(const U &p)
Definition: TrackParametersHelper.h:128
IDTPM::VposY
@ VposY
Definition: VertexParametersHelper.h:72
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
IDTPM::vertexType
int vertexType(const V &v)
Definition: VertexParametersHelper.h:69
fillPlots< xAOD::Vertex, xAOD::TrackParticle >
template StatusCode IDTPM::VertexParametersPlots::fillPlots< xAOD::Vertex, xAOD::TrackParticle >(const xAOD::Vertex &vertex, const std::vector< const xAOD::TrackParticle * > &associatedTracks, const std::vector< float > &associatedTrackWeights, float weight)
IDTPM::error
float error(const U &p, Trk::ParamDefs par)
Definition: TrackParametersHelper.h:174
IDTPM::hasValidTime
uint8_t hasValidTime(const U &p)
Definition: TrackParametersHelper.h:153
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
IDTPM::VertexParametersPlots::finalizePlots
void finalizePlots()
Print out final stats on histograms.
Definition: VertexParametersPlots.cxx:209
IDTPM::VposZ
@ VposZ
Definition: VertexParametersHelper.h:72
VertexParametersPlots.h
fillPlots< xAOD::TruthVertex, xAOD::TruthParticle >
template StatusCode IDTPM::VertexParametersPlots::fillPlots< xAOD::TruthVertex, xAOD::TruthParticle >(const xAOD::TruthVertex &vertex, const std::vector< const xAOD::TruthParticle * > &associatedTracks, const std::vector< float > &associatedTrackWeights, float weight)
IDTPM::nSiHits
float nSiHits(const U &p)
Definition: TrackParametersHelper.h:427