ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackBiasingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include <math.h>
8
10
11#include <TH2.h>
12#include <TFile.h>
13
14namespace {
16}
17
18namespace InDet {
19
26
27 InDetTrackBiasingTool::InDetTrackBiasingTool(const std::string& name) :
28 InDetTrackSystematicsTool(name)
29 {
30
31#ifndef XAOD_STANDALONE
32 declareInterface<IInDetTrackBiasingTool>(this);
33#endif
34
35 declareProperty("biasD0", m_biasD0);
36 declareProperty("biasZ0", m_biasZ0);
37 declareProperty("biasQoverPsagitta", m_biasQoverPsagitta);
38 declareProperty("runNumber", m_runNumber);
39 declareProperty("isData", m_isData);
40 declareProperty("isSimulation", m_isSimulation);
41
42 declareProperty("calibFileData15", m_calibFileData15 = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2015.root");
43 declareProperty("calibFileData16_1stPart", m_calibFileData16_1stPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2016_1stPart.root");
44 declareProperty("calibFileData16_2ndPart", m_calibFileData16_2ndPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2016_2ndPart.root");
45 declareProperty("calibFileData17_1stPart", m_calibFileData17_1stPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2017_1stPart.root");
46 declareProperty("calibFileData17_2ndPart", m_calibFileData17_2ndPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2017_2ndPart.root");
47 declareProperty("calibFileData18_1stPart", m_calibFileData18_1stPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2018_1stPart.root");
48 declareProperty("calibFileData18_2stPart", m_calibFileData18_2ndPart = "InDetTrackSystematicsTools/CalibData_22.0_2022-v00/REL22_REPRO_2018_2ndPart.root");
49
50
51 }
52
54 {
55
56 if (m_isData && m_isSimulation) {
57 ATH_MSG_ERROR( "Cannot manually set for both data and simulation!" );
58 return StatusCode::FAILURE;
59 }
60
61 if (m_biasD0 != 0.) {
62 ATH_MSG_INFO( "overall d0 bias added = " << m_biasD0
63 << " mm (not part of an official recommendation)" );
64 }
65 if (m_biasZ0 != 0.) {
66 ATH_MSG_INFO( "overall z0 bias added = " << m_biasZ0
67 << " mm (not part of an official recommendation)" );
68 }
69 if (m_biasQoverPsagitta != 0.) {
70 ATH_MSG_INFO( "overall QoverP sagitta bias added = " << m_biasQoverPsagitta
71 << " TeV^-1 (not part of an official recommendation)" );
72 }
73
74 if (m_runNumber > 0) {
75 ATH_MSG_WARNING( "Using manually-set run number (" << m_runNumber << ") to determine which calibration file to use." );
76 }
77
79
81
82 return StatusCode::SUCCESS;
83 }
84
88
90
91 [[maybe_unused]] static const bool firstTime = [&]() {
92 if ( ! firstCall().isSuccess() ) { // this will check data vs. MC and run number.
93 throw std::runtime_error("Error calling InDetTrackBiasingTool::firstCall");
94 }
95 return false;
96 }();
97
98 // specific histograms to be used based on the run number
99 TH2* biasD0Histogram = nullptr;
100 TH2* biasZ0Histogram = nullptr;
101 TH2* biasQoverPsagittaHistogram = nullptr;
102 TH2* biasD0HistError = nullptr;
103 TH2* biasZ0HistError = nullptr;
104 TH2* biasQoverPsagittaHistError = nullptr;
105
106 // determine which run number to use
107 const xAOD::EventInfo* eventInfo = evtStore()->retrieve<const xAOD::EventInfo>("EventInfo");
108 if (!eventInfo) {
109 ATH_MSG_ERROR("Could not retrieve EventInfo object!");
111 }
112 auto runNumber = eventInfo->runNumber(); // start with run number stored in event info
113 static const SG::AuxElement::Accessor<unsigned int> randomRunNumber("RandomRunNumber");
114 if (m_runNumber > 0) { // if manually-set run number is provided, use it
115 runNumber = m_runNumber;
116 } else if (m_isSimulation && randomRunNumber.isAvailable(*eventInfo)) { // use RandomRunNumber for simulation if available
117 runNumber = randomRunNumber(*(eventInfo));
118 }
119
120 // figure out which "IOV" the run number corresponds to
121 // TODO: replace StatusCodes with CP::CorrectionCodes
122 if (runNumber <= 0) {
123 ATH_MSG_WARNING( "Run number not set." );
124 }
125 if (runNumber >= 286282 && runNumber <= 287931) {
126 ATH_MSG_INFO( "Calibrating for 2015 HI and 5 TeV pp runs (286282 to 287931)." );
127 ATH_MSG_ERROR( "The 5 TeV and heavy ion runs do not have biasing maps for release 22. "
128 "Contact the tracking CP group to discuss the derivation of these maps." );
130 } else if (runNumber <= 364485) {
131 if (runNumber < 296939) { // data15 (before 296939)
132 biasD0Histogram = m_data15_biasD0Histogram.get();
133 biasZ0Histogram = m_data15_biasZ0Histogram.get();
134 biasQoverPsagittaHistogram = m_data15_biasQoverPsagittaHistogram.get();
135 biasD0HistError = m_data15_biasD0HistError.get();
136 biasZ0HistError = m_data15_biasZ0HistError.get();
137 biasQoverPsagittaHistError = m_data15_biasQoverPsagittaHistError.get();
138 } else if (runNumber <= 301912) { // data16 part 1/2 (296939 to 301912)
139 biasD0Histogram = m_data16_1stPart_biasD0Histogram.get();
140 biasZ0Histogram = m_data16_1stPart_biasZ0Histogram.get();
141 biasQoverPsagittaHistogram = m_data16_1stPart_biasQoverPsagittaHistogram.get();
142 biasD0HistError = m_data16_1stPart_biasD0HistError.get();
143 biasZ0HistError = m_data16_1stPart_biasZ0HistError.get();
144 biasQoverPsagittaHistError = m_data16_1stPart_biasQoverPsagittaHistError.get();
145 } else if (runNumber <= 312649) { // data16 part 2/2 (301912 to 312649)
146 biasD0Histogram = m_data16_2ndPart_biasD0Histogram.get();
147 biasZ0Histogram = m_data16_2ndPart_biasZ0Histogram.get();
148 biasQoverPsagittaHistogram = m_data16_2ndPart_biasQoverPsagittaHistogram.get();
149 biasD0HistError = m_data16_2ndPart_biasD0HistError.get();
150 biasZ0HistError = m_data16_2ndPart_biasZ0HistError.get();
151 biasQoverPsagittaHistError = m_data16_2ndPart_biasQoverPsagittaHistError.get();
152 } else if (runNumber <= 334842) { // data17 part 1/2 (324320 to 334842)
153 biasD0Histogram = m_data17_1stPart_biasD0Histogram.get();
154 biasZ0Histogram = m_data17_1stPart_biasZ0Histogram.get();
155 biasQoverPsagittaHistogram = m_data17_1stPart_biasQoverPsagittaHistogram.get();
156 biasD0HistError = m_data17_1stPart_biasD0HistError.get();
157 biasZ0HistError = m_data17_1stPart_biasZ0HistError.get();
158 biasQoverPsagittaHistError = m_data17_1stPart_biasQoverPsagittaHistError.get();
159 } else if (runNumber <= 348197) { // data17 (part 2/2 (334842 to 348197)
160 biasD0Histogram = m_data17_2ndPart_biasD0Histogram.get();
161 biasZ0Histogram = m_data17_2ndPart_biasZ0Histogram.get();
162 biasQoverPsagittaHistogram = m_data17_2ndPart_biasQoverPsagittaHistogram.get();
163 biasD0HistError = m_data17_2ndPart_biasD0HistError.get();
164 biasZ0HistError = m_data17_2ndPart_biasZ0HistError.get();
165 biasQoverPsagittaHistError = m_data17_2ndPart_biasQoverPsagittaHistError.get();
166 } else if (runNumber <= 353000) { // data18 (part 1/2 (348197 to 353000)
167 biasD0Histogram = m_data18_1stPart_biasD0Histogram.get();
168 biasZ0Histogram = m_data18_1stPart_biasZ0Histogram.get();
169 biasQoverPsagittaHistogram = m_data18_1stPart_biasQoverPsagittaHistogram.get();
170 biasD0HistError = m_data18_1stPart_biasD0HistError.get();
171 biasZ0HistError = m_data18_1stPart_biasZ0HistError.get();
172 biasQoverPsagittaHistError = m_data18_1stPart_biasQoverPsagittaHistError.get();
173 } else { // data18 (part 2/2 (353000 to 364485)
174 biasD0Histogram = m_data18_2ndPart_biasD0Histogram.get();
175 biasZ0Histogram = m_data18_2ndPart_biasZ0Histogram.get();
176 biasQoverPsagittaHistogram = m_data18_2ndPart_biasQoverPsagittaHistogram.get();
177 biasD0HistError = m_data18_2ndPart_biasD0HistError.get();
178 biasZ0HistError = m_data18_2ndPart_biasZ0HistError.get();
179 biasQoverPsagittaHistError = m_data18_2ndPart_biasQoverPsagittaHistError.get();
180 }
181 } else {
182 ATH_MSG_ERROR( "Run number = " << runNumber << " not in recognized range (< 364485)." );
184 }
185
186 // don't do the biasing if the histograms are null
187 m_doD0Bias = biasD0Histogram != nullptr;
188 m_doZ0Bias = biasZ0Histogram != nullptr;
189 m_doQoverPBias = biasQoverPsagittaHistogram != nullptr;
190
191 if (!m_doD0Bias) ATH_MSG_WARNING( "Will not perform d0 bias." );
192 if (!m_doZ0Bias) ATH_MSG_WARNING( "Will not perform z0 bias." );
193 if (!m_doQoverPBias) ATH_MSG_WARNING( "Will not perform q/p sagitta bias." );
194
195 // declare static accessors to avoid repeating string lookups
196 static const SG::AuxElement::Accessor< float > accD0( "d0" );
197 static const SG::AuxElement::Accessor< float > accZ0( "z0" );
198 static const SG::AuxElement::Accessor< float > accQOverP( "qOverP" );
199
200 const float phi = track.phi0();
201 const float eta = track.eta();
202
203 // do the biasing
204 if ( m_doD0Bias ) {
205 bool d0WmActive = isActive( TRK_BIAS_D0_WM );
206 if ( m_isData || d0WmActive ) {
207 accD0( track ) += readHistogram(m_biasD0, biasD0Histogram, phi, eta);
208 if ( m_isData && d0WmActive ) {
209 accD0( track ) += readHistogram(0., biasD0HistError, phi, eta);
210 }
211 }
212 }
213 if ( m_doZ0Bias ) {
214 bool z0WmActive = isActive( TRK_BIAS_Z0_WM );
215 if ( m_isData || z0WmActive ) {
216 accZ0( track ) += readHistogram(m_biasZ0, biasZ0Histogram, phi, eta);
217 if ( m_isData && z0WmActive ) {
218 accZ0( track ) += readHistogram(0., biasZ0HistError, phi, eta);
219 }
220 }
221 }
222 if ( m_doQoverPBias ) {
223 bool qOverPWmActive = isActive( TRK_BIAS_QOVERP_SAGITTA_WM );
224 if ( m_isData || qOverPWmActive ) {
225 auto sinTheta = 1.0/cosh(eta);
226 // readHistogram flips the sign of the correction if m_isSimulation is true
227 accQOverP( track ) += 1.e-6*sinTheta*readHistogram(m_biasQoverPsagitta, biasQoverPsagittaHistogram, phi, eta);
228 if ( m_isData && qOverPWmActive ) {
229 accQOverP( track ) += 1.e-6*sinTheta*readHistogram(0., biasQoverPsagittaHistError, phi, eta);
230 }
231 }
232 }
233
235 }
236
238 {
239
240 ATH_MSG_INFO( "Using for data15 (before 296939) the calibration file " << PathResolverFindCalibFile(m_calibFileData15) );
247
248 ATH_MSG_INFO( "Using for data16 part 1/2 (296939 to 301912) the calibration file " << PathResolverFindCalibFile(m_calibFileData16_1stPart) );
255
256 ATH_MSG_INFO( "Using for data16 part 2/2 (301912 to 312649) the calibration file " << PathResolverFindCalibFile(m_calibFileData16_2ndPart) );
263
264 ATH_MSG_INFO( "Using for data17 part 1/2 (324320 to 334842) the calibration file " << PathResolverFindCalibFile(m_calibFileData17_1stPart) );
271
272 ATH_MSG_INFO( "Using for data17 (part 2/2 (334842 to 348197) the calibration file " << PathResolverFindCalibFile(m_calibFileData17_2ndPart) );
279
280 ATH_MSG_INFO( "Using for data18 (part 1/2 (348197 to 353000) the calibration file " << PathResolverFindCalibFile(m_calibFileData18_1stPart) );
287
288 ATH_MSG_INFO( "Using for data18 (part 2/2 (353000 to 364485) the calibration file " << PathResolverFindCalibFile(m_calibFileData18_2ndPart) );
295
296 return StatusCode::SUCCESS;
297 }
298
300 {
301 assert( ! (m_isData && m_isSimulation) );
302
303 const xAOD::EventInfo* ei = nullptr;
304 auto sc = evtStore()->retrieve( ei, "EventInfo" );
305 if ( ! sc.isSuccess() ) {
306 if (m_runNumber <= 0 || !(m_isData||m_isSimulation)) {
307 ATH_MSG_ERROR( "Unable to retrieve from event store. Manually set data/simulation and/or run number." );
308 return StatusCode::FAILURE;
309 }
310 }
311 bool isSim = ei->eventType( xAOD::EventInfo::IS_SIMULATION );
312 if (isSim) {
313 if ( m_isData ) {
314 ATH_MSG_WARNING( "Manually set to data setting, but the type is detected as simulation." );
315 ATH_MSG_WARNING( "Ensure that this behaviour is desired." );
316 } else {
317 m_isSimulation = true;
318 }
319 } else {
320 if ( m_isSimulation ) {
321 ATH_MSG_WARNING( "Manually set to simulation setting, but the type is detected as data." );
322 ATH_MSG_WARNING( "Ensure that this behaviour is desired." );
323 } else {
324 m_isData = true;
325 }
326 }
327 assert( m_isData != m_isSimulation ); // one must be true and the other false
328 if (m_isData) ATH_MSG_INFO( "Set to data. Will apply biases to correct those observed in data." );
329 if (m_isSimulation) ATH_MSG_INFO( "Set to simulation. Will apply biases in direction that is observed in data." );
330
331 // warn if set to simulation but RandomRunNumber not found and no run number provided (will use run number set in event info)
332 static const SG::AuxElement::Accessor<unsigned int> randomRunNumber("RandomRunNumber");
333 if (m_isSimulation && !randomRunNumber.isAvailable(*ei) && m_runNumber <= 0) {
334 ATH_MSG_WARNING("Set to simulation with no run number provided, but RandomRunNumber not available. Will use default run number from EventInfo, "
335 "but biasing won't accurately reflect intervals of validity throughout the year. Run PileupReweightingTool first to pick up RandomRunNumber decorations.");
336 }
337 return StatusCode::SUCCESS;
338 }
339
340 float InDetTrackBiasingTool::readHistogram(float fDefault, TH2* histogram, float phi, float eta) const {
341 if (histogram == nullptr) {
342 ATH_MSG_ERROR( "Configuration histogram is invalid. Check the run number and systematic configuration combination.");
343 throw std::runtime_error( "invalid configuration" );
344 }
345
346 // safety measure:
347 if( eta>2.499 ) eta= 2.499;
348 if( eta<-2.499 ) eta=-2.499;
349
350 // the sign assumes that we apply a correction opposite to what the maps give
351 float f = histogram->GetBinContent(histogram->FindBin(eta, phi));
352 if (m_isSimulation) f = -f;
353 f += fDefault; // should be zero unless a manual override is provided
354
355 return f;
356 }
357
359 xAOD::TrackParticle*& out )
360 {
361 return TrackCorrTool_t::correctedCopy(in, out);
362 }
363
365 {
366 return TrackCorrTool_t::applyContainerCorrection(cont);
367 }
368
373
375 {
376 return BiasSystematics;
377 }
378
383
388
389
390}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
static Double_t sc
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
std::string histogram
Definition chains.cxx:52
ServiceHandle< StoreGateSvc > & evtStore()
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ Ok
The correction was done successfully.
Class to wrap a set of SystematicVariations.
virtual StatusCode applySystematicVariation(const CP::SystematicSet &) override
configure the tool to apply a given list of systematic variations
std::unique_ptr< TH2 > m_data16_1stPart_biasD0Histogram
std::unique_ptr< TH2 > m_data18_1stPart_biasQoverPsagittaHistogram
std::unique_ptr< TH2 > m_data18_1stPart_biasD0HistError
std::unique_ptr< TH2 > m_data15_biasD0Histogram
std::unique_ptr< TH2 > m_data18_1stPart_biasQoverPsagittaHistError
std::unique_ptr< TH2 > m_data17_2ndPart_biasD0HistError
virtual CP::CorrectionCode applyCorrection(xAOD::TrackParticle &track) override
Computes the tracks origin.
float readHistogram(float fDefault, TH2 *histogram, float phi, float eta) const
virtual CP::SystematicSet recommendedSystematics() const override
returns: list of recommended systematics to use with this tool
std::unique_ptr< TH2 > m_data16_1stPart_biasZ0HistError
virtual bool isAffectedBySystematic(const CP::SystematicVariation &) const override
returns: whether the tool is affected by the systematic
std::unique_ptr< TH2 > m_data18_1stPart_biasZ0HistError
std::unique_ptr< TH2 > m_data17_2ndPart_biasZ0Histogram
std::unique_ptr< TH2 > m_data17_1stPart_biasD0HistError
std::unique_ptr< TH2 > m_data17_1stPart_biasQoverPsagittaHistogram
std::unique_ptr< TH2 > m_data17_2ndPart_biasQoverPsagittaHistogram
std::unique_ptr< TH2 > m_data18_2ndPart_biasZ0Histogram
std::unique_ptr< TH2 > m_data17_2ndPart_biasZ0HistError
std::unique_ptr< TH2 > m_data16_2ndPart_biasD0HistError
std::unique_ptr< TH2 > m_data17_1stPart_biasZ0Histogram
std::unique_ptr< TH2 > m_data17_1stPart_biasD0Histogram
std::unique_ptr< TH2 > m_data18_2ndPart_biasQoverPsagittaHistogram
std::unique_ptr< TH2 > m_data16_2ndPart_biasZ0HistError
std::unique_ptr< TH2 > m_data18_2ndPart_biasD0Histogram
std::unique_ptr< TH2 > m_data16_1stPart_biasQoverPsagittaHistogram
std::unique_ptr< TH2 > m_data15_biasQoverPsagittaHistError
virtual ASG_TOOL_CLASS(InDetTrackBiasingTool, InDet::IInDetTrackBiasingTool) public ~InDetTrackBiasingTool()
std::unique_ptr< TH2 > m_data15_biasZ0HistError
std::unique_ptr< TH2 > m_data18_1stPart_biasZ0Histogram
std::unique_ptr< TH2 > m_data17_1stPart_biasQoverPsagittaHistError
virtual CP::CorrectionCode correctedCopy(const xAOD::TrackParticle &in, xAOD::TrackParticle *&out) override
std::unique_ptr< TH2 > m_data18_1stPart_biasD0Histogram
std::unique_ptr< TH2 > m_data18_2ndPart_biasZ0HistError
virtual CP::CorrectionCode applyContainerCorrection(xAOD::TrackParticleContainer &cont) override
std::unique_ptr< TH2 > m_data18_2ndPart_biasQoverPsagittaHistError
std::unique_ptr< TH2 > m_data15_biasD0HistError
std::unique_ptr< TH2 > m_data17_2ndPart_biasD0Histogram
std::unique_ptr< TH2 > m_data18_2ndPart_biasD0HistError
std::unique_ptr< TH2 > m_data16_1stPart_biasZ0Histogram
std::unique_ptr< TH2 > m_data16_2ndPart_biasQoverPsagittaHistError
virtual CP::SystematicSet affectingSystematics() const override
returns: list of systematics this tool can be affected by
std::unique_ptr< TH2 > m_data15_biasQoverPsagittaHistogram
std::unique_ptr< TH2 > m_data17_2ndPart_biasQoverPsagittaHistError
std::unique_ptr< TH2 > m_data16_2ndPart_biasD0Histogram
std::unique_ptr< TH2 > m_data15_biasZ0Histogram
std::unique_ptr< TH2 > m_data17_1stPart_biasZ0HistError
std::unique_ptr< TH2 > m_data16_1stPart_biasD0HistError
virtual StatusCode initialize() override
std::unique_ptr< TH2 > m_data16_2ndPart_biasQoverPsagittaHistogram
std::unique_ptr< TH2 > m_data16_2ndPart_biasZ0Histogram
std::unique_ptr< TH2 > m_data16_1stPart_biasQoverPsagittaHistError
virtual bool isAffectedBySystematic(const CP::SystematicVariation &) const override
returns: whether the tool is affected by the systematic
virtual CP::SystematicSet recommendedSystematics() const override
returns: list of recommended systematics to use with this tool
StatusCode initObject(std::unique_ptr< T > &obj, const std::string &rootFileName, const std::string &objName) const
a function to initialize an object from a root file
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual StatusCode applySystematicVariation(const CP::SystematicSet &) override
configure the tool to apply a given list of systematic variations
static const CP::SystematicSet BiasSystematics
static const std::unordered_map< InDet::TrackSystematic, CP::SystematicVariation, std::hash< int > > TrackSystematicMap
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
uint32_t runNumber() const
The current event's run number.
Primary Vertex Finder.
EventInfo_v1 EventInfo
Definition of the latest event info version.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".