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 float pt = 1.e-3*track.pt(); // need to convert pt to GeV
68 float eta = track.eta();
69 float sigma_D0 = 0.f;
70
71 bool isActiveD0Meas = isActive(TRK_RES_D0_MEAS);
72
73 if (isActiveD0Meas == 0) {
74 // pass-through D0Meas, return sigma_D0 early
75 return std::sqrt(sigma_D0);
76 }
77
78 TH2* d0hist = m_smearD0.get();
79
80 if (d0hist == nullptr) ATH_MSG_ERROR( "d0 histogram is null!" );
81
82 float d0Smear = readHistogram(d0hist, pt, eta);
83
84 // Apply a minimum smearing in the case where there is an empty bin
85 // TODO: Remove for next round of recommendations
86 if (d0Smear == 0) {
87 d0Smear = 0.002;
88 }
89
90 sigma_D0 += d0Smear*d0Smear;
91
92 return std::sqrt(sigma_D0);
93 }
94
95
97 float pt = 1.e-3*track.pt(); // need to convert pt to GeV
98 float eta = track.eta();
99 float sigma_Z0 = 0.f;
100
101 bool isActiveZ0Meas = isActive(TRK_RES_Z0_MEAS);
102
103 if (isActiveZ0Meas == 0) {
104 // pass-through Z0Meas, return sigma_Z0 early
105 return std::sqrt(sigma_Z0);
106 }
107
108 TH2* z0hist = m_smearZ0.get();
109
110 if (z0hist == nullptr) ATH_MSG_ERROR( "z0 histogram is null!" );
111
112 float z0Smear = readHistogram(z0hist, pt, eta);
113
114 // Apply a minimum smearing in the case where there is an empty bin
115 // TODO: Remove for next round of recommendations
116 if (z0Smear == 0) {
117 z0Smear = 0.03;
118 }
119
120 sigma_Z0 += z0Smear*z0Smear;
121
122 return std::sqrt(sigma_Z0);
123 }
124
126
127 const xAOD::EventInfo* event_info {nullptr};
128 if (evtStore()->retrieve(event_info, "EventInfo").isFailure()) {
129 ATH_MSG_ERROR("No EventInfo object could be retrieved");
131 }
132
133 int seed = std::abs(track.phi()) * 1e6 + std::abs(track.eta()) * 1e3 + event_info->eventNumber();
135
136 float sigmaD0 = GetSmearD0Sigma( track );
137 float sigmaZ0 = GetSmearZ0Sigma( track );
138
139 static const SG::AuxElement::Accessor< float > accD0( "d0" );
140 static const SG::AuxElement::Accessor< float > accZ0( "z0" );
141
142 //NB: only call the RNG if the widths are greater than 0
143 if ( sigmaD0 > 0. ) accD0( track ) = std::normal_distribution<double>( track.d0(), sigmaD0 )(prng);
144 if ( sigmaZ0 > 0. ) accZ0( track ) = std::normal_distribution<double>( track.z0(), sigmaZ0 )(prng);
145
147 }
148
150 xAOD::TrackParticle*& out )
151 {
152 return TrackCorrTool_t::correctedCopy(in, out);
153 }
154
156 {
157 return TrackCorrTool_t::applyContainerCorrection(cont);
158 }
159
164
166 {
167 return RecommendedSystematics;
168 }
169
171 {
172 // return InDetTrackSystematicsTool::recommendedSystematics();
173 return RecommendedSystematics;
174 }
175
177 {
178 // should do check in here and return StatusCode::FAILURE if LOOSE and TIGHT versions are set simultaneously
180 }
181
182 float InDetTrackSmearingTool::readHistogram(const TH2* histogram, float pt, float eta) const {
183 // safety measure:
184 if( eta>2.499 ) eta= 2.499;
185 if( eta<-2.499 ) eta=-2.499;
186 if ( pt < histogram->GetXaxis()->GetXmin() ) {
187 pt = histogram->GetXaxis()->GetXmin() + 0.01;
188 }
189 if ( pt >= histogram->GetXaxis()->GetXmax() ) {
190 pt = histogram->GetXaxis()->GetXmax() - 0.01;
191 }
192
193 int bin = histogram->FindFixBin(pt, eta);
194 float val = histogram->GetBinContent(bin);
195 return val;
196 }
197
198} // namespace InDet
199
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)
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
float GetSmearZ0Sigma(const xAOD::TrackParticle &) const
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
virtual CP::SystematicSet affectingSystematics() const override
returns: list of systematics this tool can be affected by
float GetSmearD0Sigma(const xAOD::TrackParticle &) const
Get smearing widths to add to IPs.
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
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
SG::Accessor< T, ALLOC > Accessor
Definition AuxElement.h:572
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".