ATLAS Offline Software
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 <TRandom.h>
7 #include <TH2F.h>
8 #include <TFile.h>
9 
10 // std includes
11 #include <utility>
12 
13 // EDM include(s):
15 //#include "AthenaBaseComps/AthCheckMacros.h"
16 
18 
19 // Local include(s):
21 
22 namespace {
24 }
25 
26 namespace InDet {
27 
29  {
32  };
33 
34  InDetTrackSmearingTool::InDetTrackSmearingTool( const std::string& name )
35  : InDet::InDetTrackSystematicsTool( name )
36  {
37 
38 #ifndef XAOD_STANDALONE
39  declareInterface<IInDetTrackSmearingTool>(this);
40 #endif
41 
42  }
43 
44 
46 
47  // Greet the user:
48  ATH_MSG_INFO( "Initializing..." );
49 
50  ATH_MSG_INFO( "Using seed of " << m_seed << " to initialize RNG" );
51  m_rnd = std::make_unique<TRandom3>(m_seed);
52 
53  ATH_MSG_INFO( "Using dedicated CTIDE smearing maps for tracks in jets" );
54  ATH_MSG_INFO( "Using for the full pT range the CTIDE calibration file " << PathResolverFindCalibFile(m_calibFileIP_CTIDE) );
55 
56  std::string rootfileName = m_calibFileIP_CTIDE;
57 
58  ATH_CHECK( initObject<TH2>(m_smearD0, rootfileName, "d0quaddiff_Pt_Eta" ) );
59  ATH_CHECK( initObject<TH2>(m_smearZ0, rootfileName, "z0quaddiff_Pt_Eta" ) );
60 
61  // do common initialization (at time of writing, register affecting systematics)
63 
64  // Return gracefully:
65  return StatusCode::SUCCESS;
66  }
67 
68  float InDetTrackSmearingTool::GetSmearD0Sigma(const xAOD::TrackParticle& track) const {
69  float pt = 1.e-3*track.pt(); // need to convert pt to GeV
70  float eta = track.eta();
71  float sigma_D0 = 0.f;
72 
73  bool isActiveD0Meas = isActive(TRK_RES_D0_MEAS);
74 
75  if (isActiveD0Meas == 0) {
76  // pass-through D0Meas, return sigma_D0 early
77  return std::sqrt(sigma_D0);
78  }
79 
80  TH2* d0hist = m_smearD0.get();
81 
82  if (d0hist == nullptr) ATH_MSG_ERROR( "d0 histogram is null!" );
83 
84  float d0Smear = readHistogram(d0hist, pt, eta);
85 
86  // Apply a minimum smearing in the case where there is an empty bin
87  // TODO: Remove for next round of recommendations
88  if (d0Smear == 0) {
89  d0Smear = 0.002;
90  }
91 
92  sigma_D0 += d0Smear*d0Smear;
93 
94  return std::sqrt(sigma_D0);
95  }
96 
97 
98  float InDetTrackSmearingTool::GetSmearZ0Sigma(const xAOD::TrackParticle& track) const {
99  float pt = 1.e-3*track.pt(); // need to convert pt to GeV
100  float eta = track.eta();
101  float sigma_Z0 = 0.f;
102 
103  bool isActiveZ0Meas = isActive(TRK_RES_Z0_MEAS);
104 
105  if (isActiveZ0Meas == 0) {
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 
127 CP::CorrectionCode InDetTrackSmearingTool::applyCorrection( xAOD::TrackParticle& track ) {
128 
129  float sigmaD0 = GetSmearD0Sigma( track );
130  float sigmaZ0 = GetSmearZ0Sigma( track );
131 
132  static const SG::AuxElement::Accessor< float > accD0( "d0" );
133  static const SG::AuxElement::Accessor< float > accZ0( "z0" );
134 
135  //NB: only call the RNG if the widths are greater than 0
136  if ( sigmaD0 > 0. ) accD0( track ) = m_rnd->Gaus( track.d0(), sigmaD0 );
137  if ( sigmaZ0 > 0. ) accZ0( track ) = m_rnd->Gaus( track.z0(), sigmaZ0 );
138 
139  return CP::CorrectionCode::Ok;
140  }
141 
142  CP::CorrectionCode InDetTrackSmearingTool::correctedCopy( const xAOD::TrackParticle& in,
144  {
145  return TrackCorrTool_t::correctedCopy(in, out);
146  }
147 
148  CP::CorrectionCode InDetTrackSmearingTool::applyContainerCorrection( xAOD::TrackParticleContainer& cont )
149  {
150  return TrackCorrTool_t::applyContainerCorrection(cont);
151  }
152 
153  bool InDetTrackSmearingTool::isAffectedBySystematic( const CP::SystematicVariation& syst ) const
154  {
155  return InDetTrackSystematicsTool::isAffectedBySystematic( syst );
156  }
157 
158  CP::SystematicSet InDetTrackSmearingTool::affectingSystematics() const
159  {
160  return RecommendedSystematics;
161  }
162 
163  CP::SystematicSet InDetTrackSmearingTool::recommendedSystematics() const
164  {
165  // return InDetTrackSystematicsTool::recommendedSystematics();
166  return RecommendedSystematics;
167  }
168 
169  StatusCode InDetTrackSmearingTool::applySystematicVariation( const CP::SystematicSet& systs )
170  {
171  // should do check in here and return StatusCode::FAILURE if LOOSE and TIGHT versions are set simultaneously
172  return InDetTrackSystematicsTool::applySystematicVariation(systs);
173  }
174 
175  float InDetTrackSmearingTool::readHistogram(const TH2* histogram, float pt, float eta) const {
176  // safety measure:
177  if( eta>2.499 ) eta= 2.499;
178  if( eta<-2.499 ) eta=-2.499;
179  if ( pt < histogram->GetXaxis()->GetXmin() ) {
180  pt = histogram->GetXaxis()->GetXmin() + 0.01;
181  }
182  if ( pt >= histogram->GetXaxis()->GetXmax() ) {
183  pt = histogram->GetXaxis()->GetXmax() - 0.01;
184  }
185 
186  int bin = histogram->FindFixBin(pt, eta);
187  float val = histogram->GetBinContent(bin);
188  return val;
189  }
190 
191 } // namespace InDet
192 
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
InDet
Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
initialize
void initialize()
Definition: run_EoverP.cxx:894
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
bin
Definition: BinsDiffFromStripMedian.h:43
CP::SystematicVariation
Definition: SystematicVariation.h:47
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
InDet::TrackSystematicMap
static const std::unordered_map< InDet::TrackSystematic, CP::SystematicVariation, std::hash< int > > TrackSystematicMap
Definition: InDetTrackSystematics.h:50
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
CP::CorrectionTool< xAOD::TrackParticleContainer >
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
InDet::TRK_RES_D0_MEAS
@ TRK_RES_D0_MEAS
Definition: InDetTrackSystematics.h:16
InDet::RecommendedSystematics
static const CP::SystematicSet RecommendedSystematics
Definition: InDetTrackSmearingTool.cxx:28
EventInfo.h
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:283
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
InDet::TRK_RES_Z0_MEAS
@ TRK_RES_Z0_MEAS
Definition: InDetTrackSystematics.h:17
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
InDetTrackSmearingTool.h
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
histogram
std::string histogram
Definition: chains.cxx:52