ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackSystsToolTester.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// System includes:
6#include <memory>
7#include <cstdlib>
8
9// ROOT includes:
10#include <TFile.h>
11#include <TError.h>
12#include <TString.h>
13#include <TH1.h>
14
15// Infrastructure includes:
16#ifdef ROOTCORE
17#include "xAODRootAccess/Init.h"
20#endif // ROOTCORE
21
22// EDM includes:
25
26// Local include(s):
32
33// Smart slim testing includes:
36
37// Other includes:
39
40
41#define CHECK( ARG ) \
42 do { \
43 const bool result = ARG; \
44 if( ! result ) { \
45 ::Error( APP_NAME, "Failed to execute: \"%s\"", \
46 #ARG ); \
47 return 1; \
48 } \
49 } while( false )
50
51
52int main( int argc, char* argv[] ) {
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.
85 xAOD::TStore store;
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", -1),
120 CP::SystematicVariation("TRK_RES_Z0_MEAS", -1),
121 CP::SystematicVariation("TRK_BIAS_D0_WM"),
122 CP::SystematicVariation("TRK_BIAS_Z0_WM"),
123 CP::SystematicVariation("TRK_BIAS_QOVERP_SAGITTA_WM"),
124 CP::SystematicVariation("TRK_FAKE_RATE_LOOSE"),
125 // CP::SystematicVariation("TRK_FAKE_RATE_TIGHT"), // have to pick one of these, and TIGHT isn't implemented yet
126 CP::SystematicVariation("TRK_EFF_LOOSE_GLOBAL"),
127 CP::SystematicVariation("TRK_EFF_LOOSE_IBL"),
128 CP::SystematicVariation("TRK_EFF_LOOSE_PP0"),
129 CP::SystematicVariation("TRK_EFF_LOOSE_PHYSMODEL"),
130 // CP::SystematicVariation("TRK_EFF_TIGHT_GLOBAL"),
131 // CP::SystematicVariation("TRK_EFF_TIGHT_IBL"),
132 // CP::SystematicVariation("TRK_EFF_TIGHT_PP0"),
133 // CP::SystematicVariation("TRK_EFF_TIGHT_PHYSMODEL"),
134 CP::SystematicVariation("TRK_EFF_LOOSE_TIDE"),
135 CP::SystematicVariation("TRK_FAKE_RATE_LOOSE_TIDE")
136 };
137 std::vector< InDet::InDetTrackSystematicsTool* > tools = {&smearingTool, &biasingTool, &filterTool, &jetFilterTool};
138
141 tool->msg().setLevel( MSG::DEBUG );
142 CHECK( tool->initialize() );
143 auto systCode = tool->applySystematicVariation(systSet);
144 if (systCode != StatusCode::SUCCESS) {
145 Error( APP_NAME, "Failed to apply systematic variation on tool %s", tool->name().data() );
146 return 2;
147 }
148 }
149
150 bool doTIDE = true;
151 std::string jetCollectionName = "AntiKt4EMTopoJets";
152 if ( !event.contains< xAOD::JetContainer >( jetCollectionName ) ) doTIDE = false;
153
154 auto outfile = std::make_unique<TFile>("InDetTrackSystsToolTester.out.root","RECREATE");
155
156 TH1* d0_before = new TH1F("d0_before","original d_{0}",100,-5,5);
157 TH1* z0_before = new TH1F("z0_before","original z_{0}",100,-200,200);
158 TH1* qOverP_before = new TH1F("qOverP_before", "original q/p", 200, -0.05, 0.05);
159 TH1* d0_after = new TH1F("d0_after","d_{0} after",100,-5,5);
160 TH1* z0_after = new TH1F("z0_after","z_{0} after",100,-200,200);
161 TH1* qOverP_after = new TH1F("qOverP_after", "q/p after", 200, -0.05, 0.05);
162 TH1* d0_diff = new TH1F("d0_diff","#delta d_{0}",100,-1.0,1.0);
163 TH1* z0_diff = new TH1F("z0_diff","#delta z_{0}",100,-10.0,10.0);
164 TH1* qOverP_diff = new TH1F("qOverP_diff", "#delta q/p", 200, -1.e-5, 1.e-5);
165
166 bool isSim = true;
167 const xAOD::EventInfo* ei = nullptr;
168 auto sc = event.retrieve( ei, "EventInfo" );
169 if ( ! sc.isSuccess() ) {
170 Error( __func__, "Could not retreive event ahead of time to detect data/MC" );
171 } else {
173 }
174
175
176 int debugN = 8; // number of tracks to print debug output for
177 // Loop over the events:
178 for( Long64_t entry = 0; entry < entries; ++entry ) {
179
180 // Tell the object which entry to look at:
181 event.getEntry( entry );
182
183 // Create a shallow copy of InDetTrackParticles:
184 const xAOD::TrackParticleContainer* ParticlesID = nullptr;
185 CHECK( event.retrieve( ParticlesID , "InDetTrackParticles" ) );
186
187 const xAOD::JetContainer* jets = nullptr;
188 if (doTIDE) {
189 CHECK( event.retrieve( jets, jetCollectionName ) );
190 }
191
192 std::pair< xAOD::TrackParticleContainer*, xAOD::ShallowAuxContainer* > ParticlesID_shallowCopy = xAOD::shallowCopyContainer( *ParticlesID );
193 for ( xAOD::TrackParticle* trkCpy : *(ParticlesID_shallowCopy.first) ) {
194
195 if ( isSim ) {
196 if ( !filterTool.accept(trkCpy) ) continue;
197 }
198 if ( doTIDE && !jetFilterTool.accept( trkCpy, jets ) ) continue;
199
200 auto d0b = trkCpy->d0();
201 auto z0b = trkCpy->z0();
202 auto qOverPb = trkCpy->qOverP();
203
204 if (biasingTool.applyCorrection(*trkCpy) == CP::CorrectionCode::Error) {
205 Error(__func__, "Could not apply bias correction!" );
206 }
207 if (smearingTool.applyCorrection(*trkCpy) == CP::CorrectionCode::Error) {
208 Error(__func__, "Could not apply smearing correction!" );
209 }
210
211 auto d0a = trkCpy->d0();
212 auto z0a = trkCpy->z0();
213 auto qOverPa = trkCpy->qOverP();
214 auto d0d = d0a - d0b;
215 auto z0d = z0a - z0b;
216 auto qOverPd = qOverPa - qOverPb;
217
218 if (debugN > 0) {
219 std::cout << "d0, before/after/diff:\t" << d0b
220 << "/" << d0a << "/" << d0d << std::endl;
221 std::cout << "z0, before/after/diff:\t" << z0b
222 << "/" << z0a << "/" << z0d << std::endl;
223 std::cout << "q/p, before/after/diff:\t" << qOverPb
224 << "/" << qOverPa << "/" << qOverPd << std::endl;
225 --debugN;
226 }
227 if (debugN == 0) {
228 std::cout << "supressing debug output..." << std::endl;
229 --debugN;
230 }
231
232 d0_before->Fill( d0b );
233 z0_before->Fill( z0b );
234 qOverP_before->Fill( qOverPb );
235 d0_after->Fill( d0a );
236 z0_after->Fill( z0a );
237 qOverP_after->Fill( qOverPa );
238 d0_diff->Fill( d0d );
239 z0_diff->Fill( z0d );
240 qOverP_diff->Fill( qOverPd );
241 }
242
243 delete ParticlesID_shallowCopy.first;
244 delete ParticlesID_shallowCopy.second;
245
246 }
247
248 outfile->Write();
249
250 // testing smart slimming feature:
252
253 // Return gracefully:
254 return 0;
255}
#define APP_NAME
#define CHECK(ARG)
static Double_t sc
@ Error
Some error happened during the object correction.
static void enableFailure() noexcept
Class to wrap a set of SystematicVariations.
This class biases tracks to emulate systematic distortions of the tracking geometry.
virtual CP::CorrectionCode applyCorrection(xAOD::TrackParticle &track) override
Computes the tracks origin.
virtual CP::CorrectionCode applyCorrection(xAOD::TrackParticle &ID) override
Smearing method.
This class selects tracks based on their truth origin.
virtual bool accept(const xAOD::TrackParticle *track) const override
This class randomly rejects tracks in the core of a jet.
virtual bool accept(const xAOD::TrackParticle *, const xAOD::Jet *) const override
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
ReadStats & stats()
Access the object belonging to the current thread.
Definition IOStats.cxx:17
static IOStats & instance()
Singleton object accessor.
Definition IOStats.cxx:11
void printSmartSlimmingBranchList(bool autoIncludeLinks=false) const
Print the accessed variables, formatted for smart slimming.
Tool for accessing xAOD files outside of Athena.
@ kAthenaAccess
Access containers/objects like Athena does.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
int main()
Definition hello.cxx:18
double entries
Definition listroot.cxx:49
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
EventInfo_v1 EventInfo
Definition of the latest event info version.
std::pair< std::unique_ptr< T >, std::unique_ptr< ShallowAuxContainer > > shallowCopyContainer(const T &cont, const EventContext &ctx)
Function making a shallow copy of a constant container.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".