ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackSystsToolTester.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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:
26
27// Local include(s):
33
34// Smart slim testing includes:
37
38// Other includes:
40
41
42#define CHECK( ARG ) \
43 do { \
44 const bool result = ARG; \
45 if( ! result ) { \
46 ::Error( APP_NAME, "Failed to execute: \"%s\"", \
47 #ARG ); \
48 return 1; \
49 } \
50 } while( false )
51
52
53int main( int argc, char* argv[] ) {
54
55 // The application's name:
56 const char* APP_NAME = argv[ 0 ];
57 std::string fileName;
58 // Check if we received a file name:
59 if( argc < 2 ) {
60 fileName = std::getenv("ROOTCORE_TEST_FILE");
61 if (fileName.empty()) Error( APP_NAME, "Could not open $ROOTCORE_TEST_FILE" );
62 } else {
63 fileName = argv[ 1 ];
64 }
65
66 StatusCode::enableFailure();
68 StatusCode::enableFailure();
69
70 // Initialise the application:
72
73 // Open the input file:
74 Info( APP_NAME, "Opening file: %s", fileName.data() );
75 std::unique_ptr< TFile > ifile( TFile::Open( fileName.data(), "READ" ) );
76 CHECK( ifile.get() );
77
78 // Create a TEvent object:
79 // xAOD::TEvent event( xAOD::TEvent::kClassAccess );
80 xAOD::TEvent event( xAOD::TEvent::kAthenaAccess ); // at time of writing this is required for the rootcore test file
81 CHECK( event.readFrom( ifile.get() ) );
82 Info( APP_NAME, "Number of events in the file: %i",
83 static_cast< int >( event.getEntries() ) );
84
85 // Create a transient object store. Needed for the tools.
86 xAOD::TStore store;
87
88 // Decide how many events to run over:
89 Long64_t entries = event.getEntries();
90 if( argc > 2 ) {
91 const Long64_t e = atoll( argv[ 2 ] );
92 if( e < entries ) {
93 entries = e;
94 }
95 } else {
96 // set maximum to 500
97 if (entries > 500) entries = 500;
98 }
99
100 // Create the tool(s) to test:
101 InDet::InDetTrackSmearingTool smearingTool( "InDetTrackSmearingTool" );
102
103 InDet::InDetTrackBiasingTool biasingTool( "InDetTrackBiasingTool" );
105 // CHECK( biasingTool.setProperty( "isData", true ) ); // override to test, since ROOTCORE_TEST_FILE is simluation
106 // uint32_t testRunNumber = 287000;
107 // CHECK( biasingTool.setProperty( "runNumber", testRunNumber ) ); // this line is only for testing that other files are properly accessible
108
109 InDet::InDetTrackTruthFilterTool filterTool( "InDetTrackFilterTool" );
110 auto originTool = std::make_unique<InDet::InDetTrackTruthOriginTool> ( "InDetTrackTruthOriginTool" );
111 CHECK( originTool->initialize() );
112 ToolHandle< InDet::IInDetTrackTruthOriginTool > trackTruthOriginToolHandle( originTool.get() );
113 CHECK( filterTool.setProperty("trackOriginTool", trackTruthOriginToolHandle) );
114
115 InDet::JetTrackFilterTool jetFilterTool( "JetTrackFilterTool" );
116 CHECK( jetFilterTool.setProperty("trackOriginTool", trackTruthOriginToolHandle) );
117
118 // Not a realistic set of systematics - we just want to make sure they can all be applied without breaking the tools
119 CP::SystematicSet systSet = {
120 CP::SystematicVariation("TRK_RES_D0_MEAS", -1),
121 CP::SystematicVariation("TRK_RES_Z0_MEAS", -1),
122 CP::SystematicVariation("TRK_BIAS_D0_WM"),
123 CP::SystematicVariation("TRK_BIAS_Z0_WM"),
124 CP::SystematicVariation("TRK_BIAS_QOVERP_SAGITTA_WM"),
125 CP::SystematicVariation("TRK_FAKE_RATE_LOOSE"),
126 // CP::SystematicVariation("TRK_FAKE_RATE_TIGHT"), // have to pick one of these, and TIGHT isn't implemented yet
127 CP::SystematicVariation("TRK_EFF_LOOSE_GLOBAL"),
128 CP::SystematicVariation("TRK_EFF_LOOSE_IBL"),
129 CP::SystematicVariation("TRK_EFF_LOOSE_PP0"),
130 CP::SystematicVariation("TRK_EFF_LOOSE_PHYSMODEL"),
131 // CP::SystematicVariation("TRK_EFF_TIGHT_GLOBAL"),
132 // CP::SystematicVariation("TRK_EFF_TIGHT_IBL"),
133 // CP::SystematicVariation("TRK_EFF_TIGHT_PP0"),
134 // CP::SystematicVariation("TRK_EFF_TIGHT_PHYSMODEL"),
135 CP::SystematicVariation("TRK_EFF_LOOSE_TIDE"),
136 CP::SystematicVariation("TRK_FAKE_RATE_LOOSE_TIDE")
137 };
138 std::vector< InDet::InDetTrackSystematicsTool* > tools = {&smearingTool, &biasingTool, &filterTool, &jetFilterTool};
139
142 tool->msg().setLevel( MSG::DEBUG );
143 CHECK( tool->initialize() );
144 auto systCode = tool->applySystematicVariation(systSet);
145 if (systCode != StatusCode::SUCCESS) {
146 Error( APP_NAME, "Failed to apply systematic variation on tool %s", tool->name().data() );
147 return 2;
148 }
149 }
150
151 bool doTIDE = true;
152 std::string jetCollectionName = "AntiKt4EMTopoJets";
153 if ( !event.contains< xAOD::JetContainer >( jetCollectionName ) ) doTIDE = false;
154
155 auto outfile = std::make_unique<TFile>("InDetTrackSystsToolTester.out.root","RECREATE");
156
157 TH1* d0_before = new TH1F("d0_before","original d_{0}",100,-5,5);
158 TH1* z0_before = new TH1F("z0_before","original z_{0}",100,-200,200);
159 TH1* qOverP_before = new TH1F("qOverP_before", "original q/p", 200, -0.05, 0.05);
160 TH1* d0_after = new TH1F("d0_after","d_{0} after",100,-5,5);
161 TH1* z0_after = new TH1F("z0_after","z_{0} after",100,-200,200);
162 TH1* qOverP_after = new TH1F("qOverP_after", "q/p after", 200, -0.05, 0.05);
163 TH1* d0_diff = new TH1F("d0_diff","#delta d_{0}",100,-1.0,1.0);
164 TH1* z0_diff = new TH1F("z0_diff","#delta z_{0}",100,-10.0,10.0);
165 TH1* qOverP_diff = new TH1F("qOverP_diff", "#delta q/p", 200, -1.e-5, 1.e-5);
166
167 bool isSim = true;
168 const xAOD::EventInfo* ei = nullptr;
169 auto sc = event.retrieve( ei, "EventInfo" );
170 if ( ! sc.isSuccess() ) {
171 Error( __func__, "Could not retreive event ahead of time to detect data/MC" );
172 } else {
174 }
175
176
177 int debugN = 8; // number of tracks to print debug output for
178 // Loop over the events:
179 for( Long64_t entry = 0; entry < entries; ++entry ) {
180
181 // Tell the object which entry to look at:
182 event.getEntry( entry );
183
184 // Create a shallow copy of InDetTrackParticles:
185 const xAOD::TrackParticleContainer* ParticlesID = nullptr;
186 CHECK( event.retrieve( ParticlesID , "InDetTrackParticles" ) );
187
188 const xAOD::JetContainer* jets = nullptr;
189 if (doTIDE) {
190 CHECK( event.retrieve( jets, jetCollectionName ) );
191 }
192
194 xAOD::shallowCopy( *ParticlesID );
195 for ( xAOD::TrackParticle* trkCpy : *ParticlesID_shallowCopy.first ) {
196
197 if ( isSim ) {
198 if ( !filterTool.accept(trkCpy) ) continue;
199 }
200 if ( doTIDE && !jetFilterTool.accept( trkCpy, jets ) ) continue;
201
202 auto d0b = trkCpy->d0();
203 auto z0b = trkCpy->z0();
204 auto qOverPb = trkCpy->qOverP();
205
206 if (biasingTool.applyCorrection(*trkCpy) == CP::CorrectionCode::Error) {
207 Error(__func__, "Could not apply bias correction!" );
208 }
209 if (smearingTool.applyCorrection(*trkCpy) == CP::CorrectionCode::Error) {
210 Error(__func__, "Could not apply smearing correction!" );
211 }
212
213 auto d0a = trkCpy->d0();
214 auto z0a = trkCpy->z0();
215 auto qOverPa = trkCpy->qOverP();
216 auto d0d = d0a - d0b;
217 auto z0d = z0a - z0b;
218 auto qOverPd = qOverPa - qOverPb;
219
220 if (debugN > 0) {
221 std::cout << "d0, before/after/diff:\t" << d0b
222 << "/" << d0a << "/" << d0d << std::endl;
223 std::cout << "z0, before/after/diff:\t" << z0b
224 << "/" << z0a << "/" << z0d << std::endl;
225 std::cout << "q/p, before/after/diff:\t" << qOverPb
226 << "/" << qOverPa << "/" << qOverPd << std::endl;
227 --debugN;
228 }
229 if (debugN == 0) {
230 std::cout << "supressing debug output..." << std::endl;
231 --debugN;
232 }
233
234 d0_before->Fill( d0b );
235 z0_before->Fill( z0b );
236 qOverP_before->Fill( qOverPb );
237 d0_after->Fill( d0a );
238 z0_after->Fill( z0a );
239 qOverP_after->Fill( qOverPa );
240 d0_diff->Fill( d0d );
241 z0_diff->Fill( z0d );
242 qOverP_diff->Fill( qOverPd );
243 }
244 }
245
246 outfile->Write();
247
248 // testing smart slimming feature:
250
251 // Return gracefully:
252 return 0;
253}
#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
float z0() const
Returns the parameter.
float d0() const
Returns the parameter.
float qOverP() const
Returns the parameter.
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
typename ShallowCopyResult< T >::type ShallowCopyResult_t
Return type of xAOD::shallowCopy.
Definition ShallowCopy.h:68
EventInfo_v1 EventInfo
Definition of the latest event info version.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
ShallowCopyResult_t< T > shallowCopy(const T &cont, const EventContext &ctx)
Create a shallow copy of an existing container.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".