ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackBiasingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include <cmath>
11#include <TH2.h>
12#include <TFile.h>
13
14namespace {
16}
17
18namespace InDet {
19
20 InDetTrackBiasingTool::InDetTrackBiasingTool(const std::string& name) :
22 {
23
24#ifndef XAOD_STANDALONE
25 declareInterface<IInDetTrackBiasingTool>(this);
26#endif
27
28 }
29
31 {
32 if (m_biasD0 != 0.) {
33 ATH_MSG_INFO( "overall d0 bias added = " << m_biasD0
34 << " mm (not part of an official recommendation)" );
35 }
36 if (m_biasZ0 != 0.) {
37 ATH_MSG_INFO( "overall z0 bias added = " << m_biasZ0
38 << " mm (not part of an official recommendation)" );
39 }
40 if (m_biasQoverPsagitta != 0.) {
41 ATH_MSG_INFO( "overall QoverP sagitta bias added = " << m_biasQoverPsagitta
42 << " TeV^-1 (not part of an official recommendation)" );
43 }
44
45 if (m_runNumber > 0) {
46 ATH_MSG_WARNING( "Using manually-set run number (" << m_runNumber << ") to determine which calibration file to use." );
47 }
48
50
51 ATH_CHECK(m_evtInfoKey.initialize());
52 ATH_CHECK(m_randomRunNumberKey.initialize(m_isMC.value()));
53
55
56 return StatusCode::SUCCESS;
57 }
58
62
64 if (m_activeSysts == nullptr) {
65 ATH_MSG_ERROR( "applySystematicVariation() was not called before applyCorrection()." );
67 }
68 return applyBiasWithSyst(track, *m_activeSysts);
69 }
70
72 xAOD::TrackParticle& track, const CP::SystematicSet& syst) const
73 {
74 const CP::SystematicSet* filtered = getFilteredSysts(syst);
75 if (filtered == nullptr) return CP::CorrectionCode::Error;
76 return applyBiasWithSyst(track, *filtered);
77 }
78
80 xAOD::TrackParticle& track, const CP::SystematicSet& filtered) const
81 {
82 if ( !m_isMC ) {
83 ATH_MSG_ERROR( "InDetTrackBiasingTool should only be run on MC." );
85 }
86
87 // determine which run number to use
90 const unsigned int runNumber = randomRunNumber(*eventInfo);
91
92 if (runNumber <= 0) {
93 ATH_MSG_WARNING( "Run number not set." );
94 }
95 // 5 TeV and heavy-ion runs have no biasing maps
96 if (runNumber >= 286282 && runNumber <= 287931) {
97 ATH_MSG_ERROR( "The 5 TeV and heavy ion runs do not have biasing maps for release 22. "
98 "Contact the tracking CP group to discuss the derivation of these maps." );
100 }
101
102 // find which configured period this run belongs to
103 size_t periodIdx = m_calibFiles.size(); // sentinel: no match
104 if (m_runNumberBounds.empty()) {
105 periodIdx = 0; // single period, accept all run numbers
106 } else {
107 for (size_t i = 0; i + 1 < m_runNumberBounds.size(); ++i) {
108 if (runNumber > m_runNumberBounds[i] && runNumber <= m_runNumberBounds[i+1]) {
109 periodIdx = i;
110 break;
111 }
112 }
113 }
114 if (periodIdx >= m_calibFiles.size()) {
115 ATH_MSG_ERROR( "Run number = " << runNumber << " does not fall within any configured calibration period." );
117 }
118
119 // select histograms for the matched period
120 TH2* biasD0Histogram = m_biasD0Histograms[periodIdx].get();
121 TH2* biasZ0Histogram = m_biasZ0Histograms[periodIdx].get();
122 TH2* biasQoverPsagittaHistogram = m_biasQoverPsagittaHistograms[periodIdx].get();
123
124 bool doD0Bias = m_applyD0Bias && biasD0Histogram != nullptr;
125 bool doZ0Bias = m_applyZ0Bias && biasZ0Histogram != nullptr;
126 bool doQoverPBias = m_applyQoverPBias && biasQoverPsagittaHistogram != nullptr;
127
128 if (m_applyD0Bias && !biasD0Histogram) ATH_MSG_WARNING( "d0 bias histogram is nullptr. Will not perform d0 bias." );
129 if (m_applyZ0Bias && !biasZ0Histogram) ATH_MSG_WARNING( "z0 bias histogram is nullptr. Will not perform z0 bias." );
130 if (m_applyQoverPBias && !biasQoverPsagittaHistogram) ATH_MSG_WARNING( "q/p bias histogram is nullptr. Will not perform q/p sagitta bias." );
131
132 // declare static accessors to avoid repeating string lookups
133 static const SG::Accessor< float > accD0( "d0" );
134 static const SG::Accessor< float > accZ0( "z0" );
135 static const SG::Accessor< float > accQOverP( "qOverP" );
136
137 const float phi = track.phi0();
138 const float eta = track.eta();
139
140 // do the biasing
141 // Always apply the correction to the nominal; undo it for systematic variations
142 if ( doD0Bias ) {
143 const float d0Corr = readHistogram(m_biasD0, biasD0Histogram, phi, eta);
144 accD0( track ) += d0Corr;
145 if ( isActive( TRK_BIAS_D0_WM, filtered ) ) {
146 accD0( track ) -= d0Corr;
147 }
148 }
149 if ( doZ0Bias ) {
150 const float z0Corr = readHistogram(m_biasZ0, biasZ0Histogram, phi, eta);
151 accZ0( track ) += z0Corr;
152 if ( isActive( TRK_BIAS_Z0_WM, filtered ) ) {
153 accZ0( track ) -= z0Corr;
154 }
155 }
156 if ( doQoverPBias ) {
157 auto sinTheta = 1.0 / std::cosh(eta);
158 const float qOverPCorr = 1.e-6*sinTheta*readHistogram(m_biasQoverPsagitta, biasQoverPsagittaHistogram, phi, eta);
159 accQOverP( track ) += qOverPCorr;
160 if ( isActive( TRK_BIAS_QOVERP_SAGITTA_WM, filtered ) ) {
161 accQOverP( track ) -= qOverPCorr;
162 }
163 }
164
166 }
167
169 {
170
171 if (m_calibFiles.empty()) {
172 ATH_MSG_ERROR( "No calibration files configured. Set 'calibFiles' and (for multiple periods) "
173 "'runNumberBounds' for the relevant MC campaign via the python configuration." );
174 return StatusCode::FAILURE;
175 }
176 if (!m_runNumberBounds.empty() && m_runNumberBounds.size() != m_calibFiles.size() + 1) {
177 ATH_MSG_ERROR( "'runNumberBounds' (size " << m_runNumberBounds.size() << ") must have "
178 "calibFiles.size() + 1 = " << (m_calibFiles.size() + 1) << " entries." );
179 return StatusCode::FAILURE;
180 }
181 if (m_runNumberBounds.empty() && m_calibFiles.size() > 1) {
182 ATH_MSG_ERROR( "'runNumberBounds' must be set when multiple calibration files are configured." );
183 return StatusCode::FAILURE;
184 }
185
186 for (size_t i = 0; i < m_calibFiles.size(); ++i) {
187 if (m_runNumberBounds.empty()) {
188 ATH_MSG_INFO( "Calibration period 0 (all run numbers): file: "
190 } else {
191 ATH_MSG_INFO( "Calibration period " << i << ": run range ["
192 << m_runNumberBounds[i] << ", " << m_runNumberBounds[i+1]
193 << "], file: " << PathResolverFindCalibFile(m_calibFiles[i]) );
194 }
195 m_biasD0Histograms.emplace_back(nullptr);
197 m_biasZ0Histograms.emplace_back(nullptr);
199 m_biasQoverPsagittaHistograms.emplace_back(nullptr);
201 }
202
203 return StatusCode::SUCCESS;
204 }
205
206 float InDetTrackBiasingTool::readHistogram(float fDefault, TH2* histogram, float phi, float eta) const {
207 if (histogram == nullptr) {
208 ATH_MSG_ERROR( "Configuration histogram is invalid. Check the run number and systematic configuration combination.");
209 throw std::runtime_error( "invalid configuration" );
210 }
211
212 // safety measure:
213 if( eta>2.499 ) eta= 2.499;
214 if( eta<-2.499 ) eta=-2.499;
215
216 float f = histogram->GetBinContent(histogram->FindBin(eta, phi));
217 f += fDefault; // should be zero unless a manual override is provided
218
219 return f;
220 }
221
223 xAOD::TrackParticle*& out )
224 {
225 return TrackCorrTool_t::correctedCopy(in, out);
226 }
227
229 {
230 return TrackCorrTool_t::applyContainerCorrection(cont);
231 }
232
237
239 {
240 CP::SystematicSet result;
241 if (m_applyD0Bias) result.insert(InDet::TrackSystematicMap.at(TRK_BIAS_D0_WM));
242 if (m_applyZ0Bias) result.insert(InDet::TrackSystematicMap.at(TRK_BIAS_Z0_WM));
243 if (m_applyQoverPBias) result.insert(InDet::TrackSystematicMap.at(TRK_BIAS_QOVERP_SAGITTA_WM));
244 return result;
245 }
246
251
256
257
258}
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_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
std::string histogram
Definition chains.cxx:52
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
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
virtual bool isAffectedBySystematic(const CP::SystematicVariation &) const override
returns: whether the tool is affected by the systematic
Gaudi::Property< uint32_t > m_runNumber
Gaudi::Property< float > m_biasQoverPsagitta
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
std::vector< std::unique_ptr< TH2 > > m_biasD0Histograms
Gaudi::Property< bool > m_applyQoverPBias
Gaudi::Property< std::vector< std::string > > m_calibFiles
Gaudi::Property< float > m_biasZ0
virtual ASG_TOOL_CLASS(InDetTrackBiasingTool, InDet::IInDetTrackBiasingTool) public ~InDetTrackBiasingTool()
virtual CP::CorrectionCode correctedCopy(const xAOD::TrackParticle &in, xAOD::TrackParticle *&out) override
Gaudi::Property< float > m_biasD0
Gaudi::Property< std::vector< unsigned int > > m_runNumberBounds
virtual CP::CorrectionCode applyContainerCorrection(xAOD::TrackParticleContainer &cont) override
CP::CorrectionCode applyBiasWithSyst(xAOD::TrackParticle &track, const CP::SystematicSet &filtered) const
Core biasing logic; delegates from both applyCorrection overloads.
virtual CP::SystematicSet affectingSystematics() const override
returns: list of systematics this tool can be affected by
std::vector< std::unique_ptr< TH2 > > m_biasQoverPsagittaHistograms
Gaudi::Property< bool > m_applyZ0Bias
std::vector< std::unique_ptr< TH2 > > m_biasZ0Histograms
Gaudi::Property< bool > m_applyD0Bias
virtual StatusCode initialize() override
SG::ReadDecorHandleKey< xAOD::EventInfo > m_randomRunNumberKey
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
const CP::SystematicSet * getFilteredSysts(const CP::SystematicSet &syst) const
Look up the pre-filtered systematic set for syst.
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
Handle class for reading a decoration on an object.
Primary Vertex Finder.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".