ATLAS Offline Software
Macros | Functions
InDetTrackSystsToolTester.cxx File Reference
#include <memory>
#include <cstdlib>
#include <TFile.h>
#include <TError.h>
#include <TString.h>
#include <TH1.h>
#include "xAODEventInfo/EventInfo.h"
#include "xAODTracking/TrackParticleContainer.h"
#include "InDetTrackSystematicsTools/InDetTrackSmearingTool.h"
#include "InDetTrackSystematicsTools/InDetTrackBiasingTool.h"
#include "InDetTrackSystematicsTools/InDetTrackTruthFilterTool.h"
#include "InDetTrackSystematicsTools/InDetTrackTruthOriginTool.h"
#include "InDetTrackSystematicsTools/JetTrackFilterTool.h"
#include "xAODCore/tools/IOStats.h"
#include "xAODCore/tools/ReadStats.h"
#include "xAODCore/ShallowCopy.h"

Go to the source code of this file.

Macros

#define CHECK(ARG)
 

Functions

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

Macro Definition Documentation

◆ CHECK

#define CHECK (   ARG)
Value:
do { \
const bool result = ARG; \
if( ! result ) { \
::Error( APP_NAME, "Failed to execute: \"%s\"", \
#ARG ); \
return 1; \
} \
} while( false )

Definition at line 42 of file InDetTrackSystsToolTester.cxx.

Function Documentation

◆ main()

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

comment / uncomment these lines to test

Configure and initialise the tool(s):

Definition at line 52 of file InDetTrackSystsToolTester.cxx.

52  {
53 
54  // The application's name:
55  const char* APP_NAME = argv[ 0 ];
56  std::string fileName;
57  // Check if we received a file name:
58  if( argc < 2 ) {
59  fileName = std::getenv("ROOTCORE_TEST_FILE");
60  if (fileName.empty()) Error( APP_NAME, "Could not open $ROOTCORE_TEST_FILE" );
61  } else {
62  fileName = argv[ 1 ];
63  }
64 
65  StatusCode::enableFailure();
67  StatusCode::enableFailure();
68 
69  // Initialise the application:
71 
72  // Open the input file:
73  Info( APP_NAME, "Opening file: %s", fileName.data() );
74  std::unique_ptr< TFile > ifile( TFile::Open( fileName.data(), "READ" ) );
75  CHECK( ifile.get() );
76 
77  // Create a TEvent object:
78  // xAOD::TEvent event( xAOD::TEvent::kClassAccess );
79  xAOD::TEvent event( xAOD::TEvent::kAthenaAccess ); // at time of writing this is required for the rootcore test file
80  CHECK( event.readFrom( ifile.get() ) );
81  Info( APP_NAME, "Number of events in the file: %i",
82  static_cast< int >( event.getEntries() ) );
83 
84  // Create a transient object store. Needed for the tools.
86 
87  // Decide how many events to run over:
88  Long64_t entries = event.getEntries();
89  if( argc > 2 ) {
90  const Long64_t e = atoll( argv[ 2 ] );
91  if( e < entries ) {
92  entries = e;
93  }
94  } else {
95  // set maximum to 500
96  if (entries > 500) entries = 500;
97  }
98 
99  // Create the tool(s) to test:
100  InDet::InDetTrackSmearingTool smearingTool( "InDetTrackSmearingTool" );
101 
102  InDet::InDetTrackBiasingTool biasingTool( "InDetTrackBiasingTool" );
104  // CHECK( biasingTool.setProperty( "isData", true ) ); // override to test, since ROOTCORE_TEST_FILE is simluation
105  // uint32_t testRunNumber = 287000;
106  // CHECK( biasingTool.setProperty( "runNumber", testRunNumber ) ); // this line is only for testing that other files are properly accessible
107 
108  InDet::InDetTrackTruthFilterTool filterTool( "InDetTrackFilterTool" );
109  auto originTool = std::make_unique<InDet::InDetTrackTruthOriginTool> ( "InDetTrackTruthOriginTool" );
110  CHECK( originTool->initialize() );
111  ToolHandle< InDet::IInDetTrackTruthOriginTool > trackTruthOriginToolHandle( originTool.get() );
112  CHECK( filterTool.setProperty("trackOriginTool", trackTruthOriginToolHandle) );
113 
114  InDet::JetTrackFilterTool jetFilterTool( "JetTrackFilterTool" );
115  CHECK( jetFilterTool.setProperty("trackOriginTool", trackTruthOriginToolHandle) );
116 
117  // Not a realistic set of systematics - we just want to make sure they can all be applied without breaking the tools
118  CP::SystematicSet systSet = {
119  // CP::SystematicVariation("TRK_RES_D0_MEAS"),
120  // CP::SystematicVariation("TRK_RES_Z0_MEAS"),
121  // CP::SystematicVariation("TRK_RES_D0_MEAS", 1), // these options are recommended for advanced users only
122  // CP::SystematicVariation("TRK_RES_Z0_MEAS", 1),
123  CP::SystematicVariation("TRK_RES_D0_MEAS", -1),
124  CP::SystematicVariation("TRK_RES_Z0_MEAS", -1),
125  CP::SystematicVariation("TRK_RES_D0_DEAD"),
126  CP::SystematicVariation("TRK_RES_Z0_DEAD"),
127  CP::SystematicVariation("TRK_BIAS_D0_WM"),
128  CP::SystematicVariation("TRK_BIAS_Z0_WM"),
129  CP::SystematicVariation("TRK_BIAS_QOVERP_SAGITTA_WM"),
130  CP::SystematicVariation("TRK_FAKE_RATE_LOOSE"),
131  // CP::SystematicVariation("TRK_FAKE_RATE_TIGHT"), // have to pick one of these, and TIGHT isn't implemented yet
132  CP::SystematicVariation("TRK_EFF_LOOSE_GLOBAL"),
133  CP::SystematicVariation("TRK_EFF_LOOSE_IBL"),
134  CP::SystematicVariation("TRK_EFF_LOOSE_PP0"),
135  CP::SystematicVariation("TRK_EFF_LOOSE_PHYSMODEL"),
136  // CP::SystematicVariation("TRK_EFF_TIGHT_GLOBAL"),
137  // CP::SystematicVariation("TRK_EFF_TIGHT_IBL"),
138  // CP::SystematicVariation("TRK_EFF_TIGHT_PP0"),
139  // CP::SystematicVariation("TRK_EFF_TIGHT_PHYSMODEL"),
140  CP::SystematicVariation("TRK_EFF_LOOSE_TIDE"),
141  CP::SystematicVariation("TRK_FAKE_RATE_LOOSE_TIDE")
142  };
143  std::vector< InDet::InDetTrackSystematicsTool* > tools = {&smearingTool, &biasingTool, &filterTool, &jetFilterTool};
144 
147  tool->msg().setLevel( MSG::DEBUG );
148  CHECK( tool->initialize() );
149  auto systCode = tool->applySystematicVariation(systSet);
150  if (systCode != StatusCode::SUCCESS) {
151  Error( APP_NAME, "Failed to apply systematic variation on tool %s", tool->name().data() );
152  return 2;
153  }
154  }
155 
156  bool doTIDE = true;
157  std::string jetCollectionName = "AntiKt4EMTopoJets";
158  if ( !event.contains< xAOD::JetContainer >( jetCollectionName ) ) doTIDE = false;
159 
160  auto outfile = std::make_unique<TFile>("InDetTrackSystsToolTester.out.root","RECREATE");
161 
162  TH1* d0_before = new TH1F("d0_before","original d_{0}",100,-5,5);
163  TH1* z0_before = new TH1F("z0_before","original z_{0}",100,-200,200);
164  TH1* qOverP_before = new TH1F("qOverP_before", "original q/p", 200, -0.05, 0.05);
165  TH1* d0_after = new TH1F("d0_after","d_{0} after",100,-5,5);
166  TH1* z0_after = new TH1F("z0_after","z_{0} after",100,-200,200);
167  TH1* qOverP_after = new TH1F("qOverP_after", "q/p after", 200, -0.05, 0.05);
168  TH1* d0_diff = new TH1F("d0_diff","#delta d_{0}",100,-1.0,1.0);
169  TH1* z0_diff = new TH1F("z0_diff","#delta z_{0}",100,-10.0,10.0);
170  TH1* qOverP_diff = new TH1F("qOverP_diff", "#delta q/p", 200, -1.e-5, 1.e-5);
171 
172  bool isSim = true;
173  const xAOD::EventInfo* ei = nullptr;
174  auto sc = event.retrieve( ei, "EventInfo" );
175  if ( ! sc.isSuccess() ) {
176  Error( __func__, "Could not retreive event ahead of time to detect data/MC" );
177  } else {
179  }
180 
181 
182  int debugN = 8; // number of tracks to print debug output for
183  // Loop over the events:
184  for( Long64_t entry = 0; entry < entries; ++entry ) {
185 
186  // Tell the object which entry to look at:
187  event.getEntry( entry );
188 
189  // Create a shallow copy of InDetTrackParticles:
190  const xAOD::TrackParticleContainer* ParticlesID = nullptr;
191  CHECK( event.retrieve( ParticlesID , "InDetTrackParticles" ) );
192 
193  const xAOD::JetContainer* jets = nullptr;
194  if (doTIDE) {
196  }
197 
198  std::pair< xAOD::TrackParticleContainer*, xAOD::ShallowAuxContainer* > ParticlesID_shallowCopy = xAOD::shallowCopyContainer( *ParticlesID );
199  for ( xAOD::TrackParticle* trkCpy : *(ParticlesID_shallowCopy.first) ) {
200 
201  if ( isSim ) {
202  if ( !filterTool.accept(trkCpy) ) continue;
203  }
204  if ( doTIDE && !jetFilterTool.accept( trkCpy, jets ) ) continue;
205 
206  auto d0b = trkCpy->d0();
207  auto z0b = trkCpy->z0();
208  auto qOverPb = trkCpy->qOverP();
209 
210  if (biasingTool.applyCorrection(*trkCpy) == CP::CorrectionCode::Error) {
211  Error(__func__, "Could not apply bias correction!" );
212  }
213  if (smearingTool.applyCorrection(*trkCpy) == CP::CorrectionCode::Error) {
214  Error(__func__, "Could not apply smearing correction!" );
215  }
216 
217  auto d0a = trkCpy->d0();
218  auto z0a = trkCpy->z0();
219  auto qOverPa = trkCpy->qOverP();
220  auto d0d = d0a - d0b;
221  auto z0d = z0a - z0b;
222  auto qOverPd = qOverPa - qOverPb;
223 
224  if (debugN > 0) {
225  std::cout << "d0, before/after/diff:\t" << d0b
226  << "/" << d0a << "/" << d0d << std::endl;
227  std::cout << "z0, before/after/diff:\t" << z0b
228  << "/" << z0a << "/" << z0d << std::endl;
229  std::cout << "q/p, before/after/diff:\t" << qOverPb
230  << "/" << qOverPa << "/" << qOverPd << std::endl;
231  --debugN;
232  }
233  if (debugN == 0) {
234  std::cout << "supressing debug output..." << std::endl;
235  --debugN;
236  }
237 
238  d0_before->Fill( d0b );
239  z0_before->Fill( z0b );
240  qOverP_before->Fill( qOverPb );
241  d0_after->Fill( d0a );
242  z0_after->Fill( z0a );
243  qOverP_after->Fill( qOverPa );
244  d0_diff->Fill( d0d );
245  z0_diff->Fill( z0d );
246  qOverP_diff->Fill( qOverPd );
247  }
248 
249  delete ParticlesID_shallowCopy.first;
250  delete ParticlesID_shallowCopy.second;
251 
252  }
253 
254  outfile->Write();
255 
256  // testing smart slimming feature:
258 
259  // Return gracefully:
260  return 0;
261 }
TestSUSYToolsAlg.ifile
ifile
Definition: TestSUSYToolsAlg.py:92
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
InDet::InDetTrackSystematicsTool
Definition: InDetTrackSystematicsTool.h:22
get_generator_info.result
result
Definition: get_generator_info.py:21
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
CP::CorrectionCode::enableFailure
static void enableFailure() noexcept
Definition: CorrectionCode.h:64
xAOD::TEvent::kAthenaAccess
@ kAthenaAccess
Access containers/objects like Athena does.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:98
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
CP::SystematicVariation
Definition: SystematicVariation.h:47
InDet::InDetTrackSmearingTool
Definition: InDetTrackSmearingTool.h:32
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
xAOD::EventInfo_v1::IS_SIMULATION
@ IS_SIMULATION
true: simulation, false: data
Definition: EventInfo_v1.h:151
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
POOL::TEvent::contains
PyObject * contains(PyObject *tp, PyObject *pykey)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:210
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:132
FortranAlgorithmOptions.fileName
fileName
Definition: FortranAlgorithmOptions.py:13
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
CHECK
#define CHECK(ARG)
Definition: InDetTrackSystsToolTester.cxx:41
POOL::TEvent::getEntries
long getEntries()
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:123
InDet::InDetTrackBiasingTool
Definition: InDetTrackBiasingTool.h:36
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::ReadStats::printSmartSlimmingBranchList
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
InDet::JetTrackFilterTool
Definition: JetTrackFilterTool.h:37
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
tools
Definition: DataQuality/ZLumiScripts/python/tools/__init__.py:1
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
InDet::InDetTrackTruthFilterTool
Definition: InDetTrackTruthFilterTool.h:36
xAOD::shallowCopyContainer
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, [[maybe_unused]] const EventContext &ctx)
Function making a shallow copy of a constant container.
Definition: ShallowCopy.h:110
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
PhysDESDM_VH_DV.jetCollectionName
jetCollectionName
Definition: PhysDESDM_VH_DV.py:50
POOL::TEvent::retrieve
StatusCode retrieve(const T *&obj)
Definition: PhysicsAnalysis/POOLRootAccess/POOLRootAccess/TEvent.h:73
TH1
Definition: rootspy.cxx:268
DEBUG
#define DEBUG
Definition: page_access.h:11
entries
double entries
Definition: listroot.cxx:49
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
xAOD::EventInfo_v1::eventType
bool eventType(EventType type) const
Check for one particular bitmask value.
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31