ATLAS Offline Software
Loading...
Searching...
No Matches
InDetTrackSmearingTool.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// ROOT include(s):
6#include <TH2F.h>
7#include <TFile.h>
8
9// std includes
10#include <random>
11#include <utility>
12
13// EDM include(s):
16//#include "AthenaBaseComps/AthCheckMacros.h"
17
19
20// Local include(s):
22
23namespace {
25}
26
27namespace InDet {
28
34
35 InDetTrackSmearingTool::InDetTrackSmearingTool( const std::string& name )
36 : InDet::InDetTrackSystematicsTool( name )
37 {
38
39#ifndef XAOD_STANDALONE
40 declareInterface<IInDetTrackSmearingTool>(this);
41#endif
42
43 }
44
45
47
48 // Greet the user:
49 ATH_MSG_INFO( "Initializing..." );
50
51 ATH_MSG_INFO( "Using dedicated CTIDE smearing maps for tracks in jets" );
52 ATH_MSG_INFO( "Using for the full pT range the CTIDE calibration file " << PathResolverFindCalibFile(m_calibFileIP_CTIDE) );
53
54 std::string rootfileName = m_calibFileIP_CTIDE;
55
56 ATH_CHECK( initObject<TH2>(m_smearD0, rootfileName, "d0quaddiff_Pt_Eta" ) );
57 ATH_CHECK( initObject<TH2>(m_smearZ0, rootfileName, "z0quaddiff_Pt_Eta" ) );
58
59 // do common initialization (at time of writing, register affecting systematics)
61
62 // Return gracefully:
63 return StatusCode::SUCCESS;
64 }
65
67 const xAOD::TrackParticle& track,
68 const CP::SystematicSet& filtered) const
69 {
70 float pt = 1.e-3*track.pt(); // need to convert pt to GeV
71 float eta = track.eta();
72 float sigma_D0 = 0.f;
73
74 if (!isActive(TRK_RES_D0_MEAS, filtered)) {
75 // pass-through D0Meas, return sigma_D0 early
76 return std::sqrt(sigma_D0);
77 }
78
79 TH2* d0hist = m_smearD0.get();
80
81 if (d0hist == nullptr) ATH_MSG_ERROR( "d0 histogram is null!" );
82
83 float d0Smear = readHistogram(d0hist, pt, eta);
84
85 // Apply a minimum smearing in the case where there is an empty bin
86 // TODO: Remove for next round of recommendations
87 if (d0Smear == 0) {
88 d0Smear = 0.002;
89 }
90
91 sigma_D0 += d0Smear*d0Smear;
92
93 return std::sqrt(sigma_D0);
94 }
95
96
98 const xAOD::TrackParticle& track,
99 const CP::SystematicSet& filtered) const
100 {
101 float pt = 1.e-3*track.pt(); // need to convert pt to GeV
102 float eta = track.eta();
103 float sigma_Z0 = 0.f;
104
105 if (!isActive(TRK_RES_Z0_MEAS, filtered)) {
106 // pass-through Z0Meas, return sigma_Z0 early
107 return std::sqrt(sigma_Z0);
108 }
109
110 TH2* z0hist = m_smearZ0.get();
111
112 if (z0hist == nullptr) ATH_MSG_ERROR( "z0 histogram is null!" );
113
114 float z0Smear = readHistogram(z0hist, pt, eta);
115
116 // Apply a minimum smearing in the case where there is an empty bin
117 // TODO: Remove for next round of recommendations
118 if (z0Smear == 0) {
119 z0Smear = 0.03;
120 }
121
122 sigma_Z0 += z0Smear*z0Smear;
123
124 return std::sqrt(sigma_Z0);
125 }
126
128 xAOD::TrackParticle& track, const CP::SystematicSet& filtered) const
129 {
130 const xAOD::EventInfo* event_info {nullptr};
131 if (evtStore()->retrieve(event_info, "EventInfo").isFailure()) {
132 ATH_MSG_ERROR("No EventInfo object could be retrieved");
134 }
135
136 int seed = std::abs(track.phi()) * 1e6 + std::abs(track.eta()) * 1e3 + event_info->eventNumber();
138
139 float sigmaD0 = GetSmearD0Sigma( track, filtered );
140 float sigmaZ0 = GetSmearZ0Sigma( track, filtered );
141
142 static const SG::AuxElement::Accessor< float > accD0( "d0" );
143 static const SG::AuxElement::Accessor< float > accZ0( "z0" );
144
145 //NB: only call the RNG if the widths are greater than 0
146 if ( sigmaD0 > 0. ) accD0( track ) = std::normal_distribution<double>( track.d0(), sigmaD0 )(prng);
147 if ( sigmaZ0 > 0. ) accZ0( track ) = std::normal_distribution<double>( track.z0(), sigmaZ0 )(prng);
148
150 }
151
156
158 xAOD::TrackParticle& track, const CP::SystematicSet& syst) const
159 {
160 const CP::SystematicSet* filtered = getFilteredSysts(syst);
161 if (filtered == nullptr) return CP::CorrectionCode::Error;
162 return applyCorrectionImpl(track, *filtered);
163 }
164
166 xAOD::TrackParticle*& out )
167 {
168 return TrackCorrTool_t::correctedCopy(in, out);
169 }
170
172 {
173 return TrackCorrTool_t::applyContainerCorrection(cont);
174 }
175
180
182 {
183 return RecommendedSystematics;
184 }
185
187 {
188 // return InDetTrackSystematicsTool::recommendedSystematics();
189 return RecommendedSystematics;
190 }
191
193 {
194 // should do check in here and return StatusCode::FAILURE if LOOSE and TIGHT versions are set simultaneously
196 }
197
198 float InDetTrackSmearingTool::readHistogram(const TH2* histogram, float pt, float eta) const {
199 // safety measure:
200 if( eta>2.499 ) eta= 2.499;
201 if( eta<-2.499 ) eta=-2.499;
202 if ( pt < histogram->GetXaxis()->GetXmin() ) {
203 pt = histogram->GetXaxis()->GetXmin() + 0.01;
204 }
205 if ( pt >= histogram->GetXaxis()->GetXmax() ) {
206 pt = histogram->GetXaxis()->GetXmax() - 0.01;
207 }
208
209 int bin = histogram->FindFixBin(pt, eta);
210 float val = histogram->GetBinContent(bin);
211 return val;
212 }
213
214} // namespace InDet
215
Scalar eta() const
pseudorapidity method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
static const Attributes_t empty
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 CP::CorrectionCode correctedCopy(const xAOD::TrackParticle &in, xAOD::TrackParticle *&out) override
virtual ASG_TOOL_CLASS(InDetTrackSmearingTool, InDet::IInDetTrackSmearingTool) public StatusCode initialize() override
Create a proper constructor for Athena.
virtual CP::CorrectionCode applyContainerCorrection(xAOD::TrackParticleContainer &cont) override
virtual CP::CorrectionCode applyCorrection(xAOD::TrackParticle &ID) override
Smearing method.
Gaudi::Property< std::string > m_calibFileIP_CTIDE
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
float GetSmearD0Sigma(const xAOD::TrackParticle &, const CP::SystematicSet &filtered) const
Get smearing widths to add to IPs.
float GetSmearZ0Sigma(const xAOD::TrackParticle &, const CP::SystematicSet &filtered) const
virtual CP::SystematicSet affectingSystematics() const override
returns: list of systematics this tool can be affected by
CP::CorrectionCode applyCorrectionImpl(xAOD::TrackParticle &track, const CP::SystematicSet &filtered) const
Core smearing logic; filtered is the pre-resolved systematic set.
virtual StatusCode applySystematicVariation(const CP::SystematicSet &) override
configure the tool to apply a given list of systematic variations
float readHistogram(const TH2 *, float pt, float eta) const
virtual bool isAffectedBySystematic(const CP::SystematicVariation &) const override
returns: whether the tool is affected by the systematic
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
static const CP::SystematicSet RecommendedSystematics
static const std::unordered_map< InDet::TrackSystematic, CP::SystematicVariation, std::hash< int > > TrackSystematicMap
uint64_t eventNumber() const
The current event's event 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".