ATLAS Offline Software
Loading...
Searching...
No Matches
TrackVertexAssoValidator.cxx File Reference
#include <memory>
#include <cstdlib>
#include <TFile.h>
#include <TH1.h>
#include <TH1F.h>
#include <TH1D.h>
#include <TError.h>
#include <AsgMessaging/MessageCheck.h>
#include "xAODTracking/TrackParticle.h"
#include "xAODTracking/Vertex.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "xAODTracking/VertexContainer.h"
#include "TrackVertexAssociationTool/TrackVertexAssociationTool.h"

Go to the source code of this file.

Functions

int main ()

Function Documentation

◆ main()

int main ( )

Definition at line 36 of file TrackVertexAssoValidator.cxx.

36 {
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:
56 RETURN_CHECK( APP_NAME, event.readFrom( infile.get() ) );
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;
86 RETURN_CHECK( APP_NAME, event.retrieve( trkCont,
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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define APP_NAME
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition ReturnCheck.h:26
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
Tool for accessing xAOD files outside of Athena.
float z() const
Returns the z position.
float y() const
Returns the y position.
float x() const
Returns the x position.
str infile
Definition run.py:13
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
std::map< const xAOD::Vertex *, xAOD::TrackVertexAssociationList > TrackVertexAssociationMap
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".