ATLAS Offline Software
Functions
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:
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
run.infile
string infile
Definition: run.py:13
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::TrackVertexAssociationTool
General track-vertex association tool.
Definition: InnerDetector/InDetRecTools/TrackVertexAssociationTool/TrackVertexAssociationTool/TrackVertexAssociationTool.h:53
InDetSecVtxTruthMatchUtils::isMatched
bool isMatched(int matchInfo)
Definition: InDetSecVtxTruthMatchTool.h:48
xAOD::TrackVertexAssociationMap
std::map< const xAOD::Vertex *, xAOD::TrackVertexAssociationList > TrackVertexAssociationMap
Definition: TrackVertexAssociationMap.h:19
PlotCalibFromCool.nentries
nentries
Definition: PlotCalibFromCool.py:798
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
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:184
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
xAOD::Vertex_v1::z
float z() const
Returns the z position.
DataVector< xAOD::TrackParticle_v1 >
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
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:73
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.
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31