ATLAS Offline Software
Loading...
Searching...
No Matches
run_vertex_tool_test.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifdef XAOD_STANDALONE
6#include <memory>
7#include <string>
10#include "AsgMessaging/Check.h"
11#include "CxxUtils/make_unique.h"
15#include "TError.h"
16#include "TFile.h"
17
18using std::string;
19using std::unique_ptr;
20using CxxUtils::make_unique;
21
22int main(int argc, char* argv[])
23{
24 string appName = argv[0];
25 if( !xAOD::Init(appName.data()).isSuccess() ) {
26 Error( appName.data(), "Could not call xAOD::Init()" );
27 return 1;
28 }
29
30 string fileName;
31 // Check if we received a file name:
32 if( argc < 2 ) {
33 fileName = getenv("ROOTCORE_TEST_FILE");
34 if (fileName.empty()) {
35 Error( appName.data(), "No file name received!" );
36 Error( appName.data(), " Usage: %s [xAOD file name]", appName.data() );
37 return 1;
38 }
39 } else {
40 fileName = argv[ 1 ];
41 }
42
43 unique_ptr<TFile> fin( TFile::Open( fileName.data(), "READ" ) );
44
45 auto event = make_unique<xAOD::TEvent>( fin.get(), xAOD::TEvent::kClassAccess );
46 Long64_t entries = event->getEntries();
47 Info( appName.data(), "Number of events in file: %llu", entries );
48
49 auto vertexSelTool = make_unique< HI::HIVertexSelectionTool >("vertexSelectionTool");
50 ASG_CHECK_SA( appName, vertexSelTool->setProperty( "MinNTrk", 10 ) );
51 ASG_CHECK_SA( appName, vertexSelTool->setProperty( "MinRmsPt", 10000. ) );
52
53 auto vtxTrkTool = make_unique<InDet::InDetTrackSelectionTool>("vtxTrkTool", "HILoose");
54 ToolHandle< InDet::IInDetTrackSelectionTool > vtxTrkToolHandle = vtxTrkTool.get();
55 ASG_CHECK_SA( appName, vtxTrkTool->initialize() );
56 ASG_CHECK_SA( appName, vertexSelTool->setProperty( "TrackSelectionTool", vtxTrkToolHandle ) );
57
58 ASG_CHECK_SA( appName, vertexSelTool->initialize() );
59
60
61 Long64_t nVtxPass = 0;
62 Long64_t nVtxFail = 0;
63 for (Long64_t i_evt=0; i_evt<entries; ++i_evt) {
64 event->getEntry( i_evt );
65
66 const xAOD::VertexContainer* vertices = nullptr;
67 if ( !event->retrieve( vertices, "PrimaryVertices" ).isSuccess() ) {
68 Error( appName.data(), "Could not retrieve PrimaryVertices" );
69 return 1;
70 }
71
72 for (const auto* vtx : *vertices) {
73 if (vertexSelTool->accept( *vtx )) nVtxPass++;
74 else nVtxFail++;
75 }
76
77 }
78 Info( appName.data(), "%llu passed.", nVtxPass );
79 Info( appName.data(), "%llu failed.", nVtxFail );
80
81 ASG_CHECK_SA( appName, vertexSelTool->finalize() );
82 ASG_CHECK_SA( appName, vtxTrkTool->finalize() );
83 return 0;
84}
85#endif // XAOD_STANDALONE
#define ASG_CHECK_SA(SOURCE, EXP)
Helper macro for checking the status code of a call outside of an ASG tool.
Definition Check.h:76
STL class.
@ kClassAccess
Access auxiliary data using the aux containers.
int main()
Definition hello.cxx:18
double entries
Definition listroot.cxx:49
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition Error.h:16
std::string getenv(const std::string &variableName)
get an environment variable
@ Info
Definition ZDCMsg.h:20
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".