ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackSelectionToolTester.cxx File Reference
#include <memory>
#include <cstdlib>
#include <TFile.h>
#include <TError.h>
#include <TH2F.h>
#include "InDetTrackSelectionTool/InDetTrackSelectionTool.h"
#include "xAODTracking/TrackingPrimitives.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "xAODTracking/VertexContainer.h"
Include dependency graph for InDetTrackSelectionToolTester.cxx:

Go to the source code of this file.

Classes

struct  HistFamily
class  unique_ptr< T >
 STL class. More...

Macros

#define CHECK(ARG)
#define HIST_INIT(NAME, AXIS_LABEL, AXIS_N, AXIS_XL, AXIS_XH)

Typedefs

using TrkSelTool = InDet::InDetTrackSelectionTool

Functions

int main (int argc, char *argv[])

Macro Definition Documentation

◆ CHECK

#define CHECK ( ARG)
Value:
do {ASG_CHECK_SA( APP_NAME, ARG );} while (false)
#define APP_NAME
#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

◆ HIST_INIT

#define HIST_INIT ( NAME,
AXIS_LABEL,
AXIS_N,
AXIS_XL,
AXIS_XH )
Value:
do{ \
h_##NAME = new TH2F(#NAME, #NAME ";#eta;" AXIS_LABEL, 50,-2.5,2.5, \
AXIS_N, AXIS_XL, AXIS_XH); \
} while (false)

Typedef Documentation

◆ TrkSelTool

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 69 of file InDetTrackSelectionToolTester.cxx.

69 {
70
71 // The application's name:
72 const char* APP_NAME = argv[ 0 ];
73#define CHECK( ARG ) do {ASG_CHECK_SA( APP_NAME, ARG );} while (false)
74
75 string fileName;
76 // Check if we received a file name:
77 if( argc < 2 ) {
78 fileName = getenv("ROOTCORE_TEST_FILE");
79 if (fileName.empty()) {
80 Error( APP_NAME, "No file name received!" );
81 Error( APP_NAME, " Usage: %s [xAOD file name]", APP_NAME );
82 return 1;
83 }
84 } else {
85 fileName = argv[ 1 ];
86 }
87
88 // fail on an unchecked StatusCode
89 StatusCode::enableFailure();
90
91 // Initialise the application:
92 CHECK( static_cast<StatusCode>(xAOD::Init( APP_NAME )) );
93
94 // Open the input file:
95 Info( APP_NAME, "Opening file: %s", fileName.data() );
96 unique_ptr< TFile > ifile( TFile::Open( fileName.data(), "READ" ) );
97 StatusCode gotFile = ifile.get()!=nullptr ? StatusCode::SUCCESS : StatusCode::FAILURE;
98 CHECK( gotFile );
99
100 // Create a TEvent object:
101 xAOD::TEvent event( static_cast<TFile*>(nullptr), xAOD::TEvent::kClassAccess );
102 CHECK( static_cast<StatusCode>(event.readFrom( ifile.get() )) );
103 Info( APP_NAME, "Number of events in the file: %llu", event.getEntries() );
104
105 // Decide how many events to run over:
106 Long64_t entries = event.getEntries();
107 if( argc > 2 ) {
108 const Long64_t e = atoll( argv[ 2 ] );
109 if( e < entries ) {
110 entries = e;
111 }
112 }
113
114 unique_ptr< TFile > outFile(new TFile("IDTrackSelectionToolTestOut.root", "RECREATE"));
115 Info( APP_NAME, "Creating output file %s", outFile->GetName() );
116
117 const vector<string> cutNames = {"NoCut", "Loose", "LoosePrimary", "TightPrimary", "LooseMuon", "LooseElectron", "MinBias", "HILoose", "HITight", "HILooseOptimized", "HITightOptimized"}; // these are names of pre-defined selections
118 const vector<string> otherCutNames = {"IP", "IPSigma", "IPSignificance"}; // other configurations we will define manually
119 std::map<string, unique_ptr<TrkSelTool> > selToolMap;
120 std::map<string, unique_ptr<HistFamily> > histFamilyMap;
121 for (const auto& cut : cutNames) {
122 selToolMap[cut] = unique_ptr<TrkSelTool>(new TrkSelTool( (cut+"TrackSelection") ));
123 CHECK( selToolMap[cut]->setProperty( "CutLevel", cut) );
124 CHECK( selToolMap[cut]->initialize() );
125 histFamilyMap[cut] = unique_ptr<HistFamily>(new HistFamily(cut));
126 }
127 selToolMap["IP"] = unique_ptr<TrkSelTool>(new TrkSelTool("IPTrackSelection"));
128 CHECK( selToolMap["IP"]->setProperty( "maxD0", 1.5 ) );
129 CHECK( selToolMap["IP"]->setProperty( "maxZ0SinTheta", 1.5 ) );
130 CHECK( selToolMap["IP"]->initialize() );
131 histFamilyMap["IP"] = unique_ptr<HistFamily>(new HistFamily("IP"));
132 selToolMap["IPSigma"] = unique_ptr<TrkSelTool>(new TrkSelTool("IPSigmaTrackSelection"));
133 CHECK( selToolMap["IPSigma"]->setProperty( "maxSigmaD0", 1.5 ) );
134 CHECK( selToolMap["IPSigma"]->setProperty( "maxSigmaZ0SinTheta", 1.5 ) );
135 CHECK( selToolMap["IPSigma"]->initialize() );
136 histFamilyMap["IPSigma"] = unique_ptr<HistFamily>(new HistFamily("IPSigma"));
137 selToolMap["IPSignificance"] = unique_ptr<TrkSelTool>(new TrkSelTool("IPSignificanceTrackSelection"));
138 CHECK( selToolMap["IPSignificance"]->setProperty( "maxD0overSigmaD0", 3.0 ) );
139 CHECK( selToolMap["IPSignificance"]->setProperty( "maxZ0SinThetaoverSigmaZ0SinTheta", 3.0 ) );
140 CHECK( selToolMap["IPSignificance"]->initialize() );
141 histFamilyMap["IPSignificance"] = unique_ptr<HistFamily>(new HistFamily("IPSignificance"));
142
143 // Loop over the events:
144 for( Long64_t entry = 0; entry < entries; ++entry ) {
145
146 // Tell the object which entry to look at:
147 CHECK( !event.getEntry( entry ) );
148
149 // Get the InDetTrackParticles from the event:
150 const xAOD::TrackParticleContainer* tracks = nullptr;
151 CHECK( static_cast<StatusCode>(event.retrieve( tracks, "InDetTrackParticles" )) );
152
153 const xAOD::VertexContainer* vertices = nullptr;
154 CHECK( static_cast<StatusCode>(event.retrieve( vertices, "PrimaryVertices" )) );
155 const auto it_pv = std::find_if(vertices->cbegin(), vertices->cend(),
156 [](const xAOD::Vertex* vtx)
157 {return vtx->vertexType() == xAOD::VxType::PriVtx;});
158 const xAOD::Vertex* primaryVertex = (it_pv == vertices->cend()) ? nullptr : *it_pv;
159 if (primaryVertex == nullptr) Warning( APP_NAME, "No primary vertex found." );
160
161 for( const xAOD::TrackParticle* track : *tracks ) {
162 if (track == nullptr) {
163 Error( APP_NAME, "Null pointer to track!" );
164 continue;
165 }
166 for (const auto& cut : cutNames) {
167 if (selToolMap[cut]->accept(*track, primaryVertex)) histFamilyMap[cut]->fill(*track, primaryVertex);
168 }
169 for (const auto& cut : otherCutNames) {
170 if (selToolMap[cut]->accept(*track, primaryVertex)) histFamilyMap[cut]->fill(*track, primaryVertex);
171 }
172
173 } // end loop over tracks
174
175 } // end loop over events
176
177 for (const auto& selTool : selToolMap) CHECK( selTool.second->finalize() );
178
179 // draw histogram
180 outFile->Write();
181
182 // Return gracefully:
183 return 0;
184}
#define CHECK(ARG)
InDet::InDetTrackSelectionTool TrkSelTool
void setProperty(columnar::PythonToolHandle &self, const std::string &key, nb::object value)
const_iterator cbegin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const_iterator cend() const noexcept
Return a const_iterator pointing past the end of the collection.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
double entries
Definition listroot.cxx:49
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
StatusCode accept(const xAOD::Muon *mu)
outFile
Comment Out Those You do not wish to run.
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
TrackParticle_v1 TrackParticle
Reference the current persistent version:
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".
void initialize()