ATLAS Offline Software
TrackVertexAssoValidator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Used for validation the track vertex association tools in RootCore implementation
6 
7 // System include(s):
8 #include <memory>
9 #include <cstdlib>
10 
11 // ROOT include(s):
12 #include <TFile.h>
13 #include <TH1.h>
14 #include <TH1F.h>
15 #include <TH1D.h>
16 #include <TError.h>
17 
18 // xAOD include(s):
19 #ifdef ROOTCORE
20 # include "xAODRootAccess/Init.h"
21 # include "xAODRootAccess/TEvent.h"
23 #endif
24 
26 
27 // EDM include(s):
29 #include "xAODTracking/Vertex.h"
32 
33 // Local include(s):
35 
36 int main() {
37 
38  using namespace asg::msgUserCode;
39 
40  // The name of the application:
41  static const char* APP_NAME = "TrackVertexAssoValidator";
42 
43  // Set up the environment:
45 
46  // Open the input file:
47  std::unique_ptr< TFile > infile( TFile::Open( "$ASG_TEST_FILE_MC",
48  "READ" ) );
49  if( ( ! infile ) || infile->IsZombie() ) {
50  ATH_MSG_ERROR( "Couldn't open the ASG_TEST_FILE_MC file" );
51  return 1;
52  }
53 
54  // Set up a TEvent object to read from it:
57 
58  // Set up the needed tool(s):
60  trktovxtool( "TrackVertexAssociationTool" );
61  RETURN_CHECK( APP_NAME, trktovxtool.setProperty( "OutputLevel",
62  MSG::ERROR ) );
63  RETURN_CHECK( APP_NAME, trktovxtool.setProperty( "WorkingPoint", "Nominal" ) );
64  RETURN_CHECK( APP_NAME, trktovxtool.initialize() );
65 
66  // Loop over the file:
67  const Long64_t nentries = event.getEntries();
68  ATH_MSG_INFO( "Total Number of Events: " << nentries );
69  Long64_t maxEntries = nentries;
70  // run only over the first 100 events
71  if(nentries > 100) {
72  maxEntries = 100;
73  }
74  ATH_MSG_INFO( "Running over first " << maxEntries << " events" );
75  for( Long64_t entry = 0; entry < maxEntries; ++entry ) {
76 
77  // Load the event:
78  if( event.getEntry( entry ) < 0 ) {
79  ATH_MSG_ERROR( "Couldn't load entry " << entry );
80  return 1;
81  }
82 
83  // Retrieve the necessary containers:
84  const xAOD::TrackParticleContainer *trkCont = 0;
85  const xAOD::VertexContainer *vxCont = 0;
87  "InDetTrackParticles" ) );
88  RETURN_CHECK( APP_NAME, event.retrieve( vxCont, "PrimaryVertices" ) );
89 
90  // A sanity check:
91  if( ! vxCont->size() ) {
92  ATH_MSG_WARNING( "Event with no vertex found!" );
93  continue;
94  }
95 
96  // Test isCompitable
97  ATH_MSG_INFO("Testing TrackVertexAssociationTool::isCompatible...");
98  if(trkCont->size()!=0 && vxCont->size()!=0)
99  {
100  bool isMatched = trktovxtool.isCompatible(*(trkCont->at(0)), *(vxCont->at(0)));
101  ATH_MSG_INFO("Is the first track compatible with the first vertex (the PriVx)? "<< isMatched);
102  }
103 
104  // Test getMatchMap
105  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getMatchMap...");
106  xAOD::TrackVertexAssociationMap trkvxassoMap = trktovxtool.getMatchMap(*trkCont, *vxCont);
107  ATH_MSG_INFO("Number of vertices for track-vertex association: " << trkvxassoMap.size());
108  for (const auto& assoc: trkvxassoMap) {
109  const xAOD::Vertex *vx = assoc.first;
110  ATH_MSG_INFO("vertex at x, y, z " << vx->x() << ", " << vx->y() << ", " << vx->z() <<
111  " has " << assoc.second.size() << " associated tracks");
112  }
113  // Test getUniqueMatchVertex
114  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchVertex...");
115  std::vector<const xAOD::Vertex* > v_vx;
116  v_vx.clear();
117  for(auto *vertex : *vxCont) {
118  v_vx.push_back(vertex);
119  }
120  if(trkCont->size()!=0)
121  {
122  const xAOD::Vertex *vx = trktovxtool.getUniqueMatchVertex(*(trkCont->at(0)), v_vx);
123  ATH_MSG_INFO("Unique match vertex for first track: " << vx);
124  }
125 
126  // Test getUniqueMatchVertexLink
127  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchVertexLink...");
128  if(trkCont->size() > 2)
129  {
130  ElementLink<xAOD::VertexContainer> match_vx = trktovxtool.getUniqueMatchVertexLink(*(trkCont->at(2)), *vxCont );
131 
132  if(match_vx.isValid())
133  {
134  ATH_MSG_INFO( "Uniquely matched vertex for third track - ");
135  ATH_MSG_INFO( "Vertex ElementLink address: " << match_vx );
136  ATH_MSG_INFO( "Vertex address: " << *match_vx );
137  ATH_MSG_INFO( "Vertex z pos: " << (*match_vx)->z());
138  }
139  }
140 
141  // Test getUniqueMatchMap
142  ATH_MSG_INFO("Testing TrackVertexAssociationTool::getUniqueMatchMap...");
143  xAOD::TrackVertexAssociationMap trkvxassoUniqueMap = trktovxtool.getUniqueMatchMap(*trkCont, *vxCont);
144  ATH_MSG_INFO("Number of vertices for track-vertex association: " << trkvxassoUniqueMap.size());
145  for (const auto& assoc: trkvxassoUniqueMap) {
146  const xAOD::Vertex *vx = assoc.first;
147  ATH_MSG_INFO("vertex at x, y, z " << vx->x() << ", " << vx->y() << ", " << vx->z() <<
148  " has " << assoc.second.size() << " uniquely associated tracks");
149  }
150 
151  } // end event loop
152 
153  // Return gracefully:
154  return 0;
155 }
xAOD::Vertex_v1::x
float x() const
Returns the x position.
RETURN_CHECK
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition: ReturnCheck.h:26
CP::TrackVertexAssociationTool::isCompatible
virtual bool isCompatible(const xAOD::TrackParticle &trk, const xAOD::Vertex &vx) const override
This function just return the decision of whether the track is matched to the Vertex Not sure whether...
Definition: InnerDetector/InDetRecTools/TrackVertexAssociationTool/Root/TrackVertexAssociationTool.cxx:325
run.infile
string infile
Definition: run.py:13
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::TrackVertexAssociationTool::getUniqueMatchVertex
virtual const xAOD::Vertex * getUniqueMatchVertex(const xAOD::TrackParticle &trk, std::vector< const xAOD::Vertex * > &vx_list) const override
Definition: InnerDetector/InDetRecTools/TrackVertexAssociationTool/Root/TrackVertexAssociationTool.cxx:355
CP::TrackVertexAssociationTool
General track-vertex association tool.
Definition: InnerDetector/InDetRecTools/TrackVertexAssociationTool/TrackVertexAssociationTool/TrackVertexAssociationTool.h:53
TrackVertexAssociationTool.h
CP::TrackVertexAssociationTool::getMatchMap
virtual xAOD::TrackVertexAssociationMap getMatchMap(std::vector< const xAOD::TrackParticle * > &trk_list, std::vector< const xAOD::Vertex * > &vx_list) const override
Definition: InnerDetector/InDetRecTools/TrackVertexAssociationTool/Root/TrackVertexAssociationTool.cxx:345
CP::TrackVertexAssociationTool::getUniqueMatchVertexLink
virtual ElementLink< xAOD::VertexContainer > getUniqueMatchVertexLink(const xAOD::TrackParticle &trk, const xAOD::VertexContainer &vxCont) const override
This functions will return the best matched vertex.
Definition: InnerDetector/InDetRecTools/TrackVertexAssociationTool/Root/TrackVertexAssociationTool.cxx:360
InDetSecVtxTruthMatchUtils::isMatched
bool isMatched(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:48
xAOD::TrackVertexAssociationMap
std::map< const xAOD::Vertex *, xAOD::TrackVertexAssociationList > TrackVertexAssociationMap
Definition: TrackVertexAssociationMap.h:19
ReturnCheck.h
CP::TrackVertexAssociationTool::getUniqueMatchMap
virtual xAOD::TrackVertexAssociationMap getUniqueMatchMap(std::vector< const xAOD::TrackParticle * > &trk_list, std::vector< const xAOD::Vertex * > &vx_list) const override
This functions related to the previous functions, will return a 2D vector to store the best matched t...
Definition: InnerDetector/InDetRecTools/TrackVertexAssociationTool/Root/TrackVertexAssociationTool.cxx:370
PlotCalibFromCool.nentries
nentries
Definition: PlotCalibFromCool.py:798
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
POOL::TEvent::getEntry
int getEntry(long entry)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:185
MessageCheck.h
macros for messaging and checking status codes
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
TEvent.h
Init.h
xAOD::Vertex_v1::z
float z() const
Returns the z position.
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
Vertex.h
main
int main()
Definition: TrackVertexAssoValidator.cxx:36
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
TrackParticle.h
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
xAOD::Vertex_v1::y
float y() const
Returns the y position.
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackParticleContainer.h
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31
CP::TrackVertexAssociationTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: InnerDetector/InDetRecTools/TrackVertexAssociationTool/Root/TrackVertexAssociationTool.cxx:251