ATLAS Offline Software
Classes | Macros | Typedefs | Functions
InDetTrackSelectionToolTester.cxx File Reference
#include <memory>
#include <cstdlib>
#include <TFile.h>
#include <TError.h>
#include <TH2F.h>
#include "InDetTrackSelectionTool/InDetTrackSelectionTool.h"
Include dependency graph for InDetTrackSelectionToolTester.cxx:

Go to the source code of this file.

Classes

struct  HistFamily
 

Macros

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

◆ 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

Definition at line 28 of file InDetTrackSelectionToolTester.cxx.

Function Documentation

◆ main()

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

Definition at line 66 of file InDetTrackSelectionToolTester.cxx.

66  {
67 
68  // The application's name:
69  const char* APP_NAME = argv[ 0 ];
70 #define CHECK( ARG ) do {ASG_CHECK_SA( APP_NAME, ARG );} while (false)
71 
72  string fileName;
73  // Check if we received a file name:
74  if( argc < 2 ) {
75  fileName = getenv("ROOTCORE_TEST_FILE");
76  if (fileName.empty()) {
77  Error( APP_NAME, "No file name received!" );
78  Error( APP_NAME, " Usage: %s [xAOD file name]", APP_NAME );
79  return 1;
80  }
81  } else {
82  fileName = argv[ 1 ];
83  }
84 
85  // fail on an unchecked StatusCode
86  StatusCode::enableFailure();
87 
88  // Initialise the application:
89  CHECK( static_cast<StatusCode>(xAOD::Init( APP_NAME )) );
90 
91  // Open the input file:
92  Info( APP_NAME, "Opening file: %s", fileName.data() );
93  unique_ptr< TFile > ifile( TFile::Open( fileName.data(), "READ" ) );
94  StatusCode gotFile = ifile.get()!=nullptr ? StatusCode::SUCCESS : StatusCode::FAILURE;
95  CHECK( gotFile );
96 
97  // Create a TEvent object:
98  xAOD::TEvent event( static_cast<TFile*>(nullptr), xAOD::TEvent::kClassAccess );
99  CHECK( static_cast<StatusCode>(event.readFrom( ifile.get() )) );
100  Info( APP_NAME, "Number of events in the file: %llu", event.getEntries() );
101 
102  // Decide how many events to run over:
103  Long64_t entries = event.getEntries();
104  if( argc > 2 ) {
105  const Long64_t e = atoll( argv[ 2 ] );
106  if( e < entries ) {
107  entries = e;
108  }
109  }
110 
111  unique_ptr< TFile > outFile(new TFile("IDTrackSelectionToolTestOut.root", "RECREATE"));
112  Info( APP_NAME, "Creating output file %s", outFile->GetName() );
113 
114  const vector<string> cutNames = {"NoCut", "Loose", "LoosePrimary", "TightPrimary", "LooseMuon", "LooseElectron", "MinBias", "HILoose", "HITight", "HILooseOptimized", "HITightOptimized"}; // these are names of pre-defined selections
115  const vector<string> otherCutNames = {"IP", "IPSigma", "IPSignificance"}; // other configurations we will define manually
116  std::map<string, unique_ptr<TrkSelTool> > selToolMap;
117  std::map<string, unique_ptr<HistFamily> > histFamilyMap;
118  for (const auto& cut : cutNames) {
119  selToolMap[cut] = unique_ptr<TrkSelTool>(new TrkSelTool( (cut+"TrackSelection") ));
120  CHECK( selToolMap[cut]->setProperty( "CutLevel", cut) );
121  CHECK( selToolMap[cut]->initialize() );
122  histFamilyMap[cut] = unique_ptr<HistFamily>(new HistFamily(cut));
123  }
124  selToolMap["IP"] = unique_ptr<TrkSelTool>(new TrkSelTool("IPTrackSelection"));
125  CHECK( selToolMap["IP"]->setProperty( "maxD0", 1.5 ) );
126  CHECK( selToolMap["IP"]->setProperty( "maxZ0SinTheta", 1.5 ) );
127  CHECK( selToolMap["IP"]->initialize() );
128  histFamilyMap["IP"] = unique_ptr<HistFamily>(new HistFamily("IP"));
129  selToolMap["IPSigma"] = unique_ptr<TrkSelTool>(new TrkSelTool("IPSigmaTrackSelection"));
130  CHECK( selToolMap["IPSigma"]->setProperty( "maxSigmaD0", 1.5 ) );
131  CHECK( selToolMap["IPSigma"]->setProperty( "maxSigmaZ0SinTheta", 1.5 ) );
132  CHECK( selToolMap["IPSigma"]->initialize() );
133  histFamilyMap["IPSigma"] = unique_ptr<HistFamily>(new HistFamily("IPSigma"));
134  selToolMap["IPSignificance"] = unique_ptr<TrkSelTool>(new TrkSelTool("IPSignificanceTrackSelection"));
135  CHECK( selToolMap["IPSignificance"]->setProperty( "maxD0overSigmaD0", 3.0 ) );
136  CHECK( selToolMap["IPSignificance"]->setProperty( "maxZ0SinThetaoverSigmaZ0SinTheta", 3.0 ) );
137  CHECK( selToolMap["IPSignificance"]->initialize() );
138  histFamilyMap["IPSignificance"] = unique_ptr<HistFamily>(new HistFamily("IPSignificance"));
139 
140  // Loop over the events:
141  for( Long64_t entry = 0; entry < entries; ++entry ) {
142 
143  // Tell the object which entry to look at:
144  CHECK( !event.getEntry( entry ) );
145 
146  // Get the InDetTrackParticles from the event:
147  const xAOD::TrackParticleContainer* tracks = nullptr;
148  CHECK( static_cast<StatusCode>(event.retrieve( tracks, "InDetTrackParticles" )) );
149 
150  const xAOD::VertexContainer* vertices = nullptr;
151  CHECK( static_cast<StatusCode>(event.retrieve( vertices, "PrimaryVertices" )) );
152  const auto it_pv = std::find_if(vertices->cbegin(), vertices->cend(),
153  [](const xAOD::Vertex* vtx)
154  {return vtx->vertexType() == xAOD::VxType::PriVtx;});
155  const xAOD::Vertex* primaryVertex = (it_pv == vertices->cend()) ? nullptr : *it_pv;
156  if (primaryVertex == nullptr) Warning( APP_NAME, "No primary vertex found." );
157 
158  for( const xAOD::TrackParticle* track : *tracks ) {
159  if (track == nullptr) {
160  Error( APP_NAME, "Null pointer to track!" );
161  continue;
162  }
163  for (const auto& cut : cutNames) {
164  if (selToolMap[cut]->accept(*track, primaryVertex)) histFamilyMap[cut]->fill(*track, primaryVertex);
165  }
166  for (const auto& cut : otherCutNames) {
167  if (selToolMap[cut]->accept(*track, primaryVertex)) histFamilyMap[cut]->fill(*track, primaryVertex);
168  }
169 
170  } // end loop over tracks
171 
172  } // end loop over events
173 
174  for (const auto& selTool : selToolMap) CHECK( selTool.second->finalize() );
175 
176  // draw histogram
177  outFile->Write();
178 
179  // Return gracefully:
180  return 0;
181 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
initialize
void initialize()
Definition: run_EoverP.cxx:894
CutsMETMaker::accept
StatusCode accept(const xAOD::Muon *mu)
Definition: CutsMETMaker.cxx:18
TrkSelTool
InDet::InDetTrackSelectionTool TrkSelTool
Definition: InDetTrackSelectionToolTester.cxx:28
DataVector::cend
const_iterator cend() const noexcept
Return a const_iterator pointing past the end of the collection.
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:100
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
python.TrigEgammaMonitorHelper.TH2F
def TH2F(name, title, nxbins, bins_par2, bins_par3, bins_par4, bins_par5=None, bins_par6=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:45
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
POOL::TEvent::getEntry
int getEntry(long entry)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:185
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:124
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
vector< string >
CHECK
#define CHECK(ARG)
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
BindingsTest.cut
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
Definition: BindingsTest.py:13
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
DQPostProcessTest.outFile
outFile
Comment Out Those You do not wish to run.
Definition: DQPostProcessTest.py:37
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:74
entries
double entries
Definition: listroot.cxx:49
DataVector::cbegin
const_iterator cbegin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
HistFamily
Definition: InDetTrackSelectionToolTester.cxx:31
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:84
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31