ATLAS Offline Software
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>
8 #include "xAODRootAccess/Init.h"
10 #include "AsgMessaging/Check.h"
11 #include "CxxUtils/make_unique.h"
15 #include "TError.h"
16 #include "TFile.h"
17 
18 using std::string;
19 using std::unique_ptr;
21 
22 int 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
Check.h
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
HIVertexSelectionTool.h
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
main
int main(int, char **)
Main class for all the CppUnit test classes
Definition: CppUnit_SGtestdriver.cxx:141
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
TEvent.h
InDetTrackSelectionTool.h
Init.h
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
VertexContainer.h
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
ASG_CHECK_SA
#define ASG_CHECK_SA(SOURCE, EXP)
Helper macro for checking the status code of a call outside of an ASG tool.
Definition: Check.h:69
entries
double entries
Definition: listroot.cxx:49
compute_lumi.fin
fin
Definition: compute_lumi.py:19
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31