ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Reconstruction
Jet
JetCalibTools
src
SmearingCalibStep.cxx
Go to the documentation of this file.
1
2
3
/*
4
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5
*/
6
7
// SmearingCalibStep.cxx
8
// Implementation file for class SmearingCalibStep
10
11
#include "
JetCalibTools/SmearingCalibStep.h
"
12
13
14
SmearingCalibStep::SmearingCalibStep
(
const
std::string& name)
15
:
asg
::
AsgTool
( name ){ }
16
17
18
StatusCode
SmearingCalibStep::initialize
(){
19
20
ATH_MSG_DEBUG
(
"Initializing "
<< name() );
21
22
ATH_MSG_DEBUG
(
"Reading from "
<<
m_jetInScale
<<
" and writing to "
<<
m_jetOutScale
);
23
24
// Check the specified smearing type
25
if
(
m_smearType
==
""
)
26
{
27
ATH_MSG_FATAL
(
"No jet smearing type was specified. Aborting."
);
28
return
StatusCode::FAILURE;
29
}
30
else
if
(
m_smearType
==
"pt"
)
31
{
32
m_smearTypeClass
=
SmearType::Pt
;
33
}
34
else
if
(
m_smearType
==
"mass"
)
35
{
36
m_smearTypeClass
=
SmearType::Mass
;
37
}
38
else
if
(
m_smearType
==
"FourVec"
)
39
{
40
m_smearTypeClass
=
SmearType::FourVec
;
41
}
42
else
43
{
44
ATH_MSG_FATAL
(
"Unrecognized jet smearing type: "
<<
m_smearType
<<
"--> the available options are 'pt', 'mass' or 'FourVec'"
);
45
return
StatusCode::FAILURE;
46
}
47
48
49
// Retrieve the histograms
50
ATH_CHECK
(
m_histToolMC
.retrieve() );
51
ATH_CHECK
(
m_histToolData
.retrieve() );
52
53
return
StatusCode::SUCCESS;
54
}
55
56
TRandom3*
SmearingCalibStep::getTLSRandomGen
(
unsigned
long
seed)
const
57
{
58
TRandom3* random =
m_rand_tls
.get();
59
if
(!random) {
60
random =
new
TRandom3();
61
m_rand_tls
.reset(random);
62
}
63
random->SetSeed(seed);
64
return
random;
65
}
66
67
StatusCode
SmearingCalibStep::getSigmaSmear
(
xAOD::Jet
&
jet
,
const
JetHelper::JetContext
& jc,
double
& sigmaSmear)
const
68
{
69
/*
70
Nominal jet smearing
71
If sigma_data > sigma_MC, then we want to smear MC to match data
72
If sigma_data < sigma_MC, then we do not want to smear data to match MC
73
The second case is instead the source of an uncertainty (see JetUncertainties)
74
75
To make MC agree with data:
76
if (sigma_data > sigma_MC) then sigma_smear^2 = sigma_data^2 - sigma_MC^2
77
if (sigma_data < sigma_MC) then do nothing
78
Smearing using a Gaussian centered at 1 and with a width of sigma_smear
79
80
Note that data is never smeared, as blocked in JetCalibrationTool.cxx
81
--> TODO: JetCalibrationTool.cxx throws an error if you try to run smearing calibration on data - include this in new tool
82
*/
83
84
double
resolutionMC = 0;
85
if
(
getNominalResolutionMC
(
jet
, jc, resolutionMC).isFailure())
86
return
StatusCode::FAILURE;
87
88
double
resolutionData = 0;
89
if
(
getNominalResolutionData
(
jet
, jc, resolutionData).isFailure())
90
return
StatusCode::FAILURE;
91
92
// Nominal smearing only if data resolution is larger than MC resolution
93
// This is because we want to smear the MC to match the data
94
// if MC is larger than data, don't make the nominal data worse, so smear is 0
95
if
(resolutionMC < resolutionData)
96
sigmaSmear = sqrt(resolutionData*resolutionData - resolutionMC*resolutionMC);
97
else
98
sigmaSmear = 0;
99
100
return
StatusCode::SUCCESS;
101
}
102
103
StatusCode
SmearingCalibStep::getNominalResolutionData
(
const
xAOD::Jet
&
jet
,
const
JetHelper::JetContext
& jc,
double
& resolution)
const
104
{
105
resolution =
m_histToolData
->getValue(
jet
, jc);
106
return
StatusCode::SUCCESS;
107
}
108
109
StatusCode
SmearingCalibStep::getNominalResolutionMC
(
const
xAOD::Jet
&
jet
,
const
JetHelper::JetContext
& jc,
double
& resolution)
const
110
{
111
resolution =
m_histToolMC
->getValue(
jet
, jc);
112
return
StatusCode::SUCCESS;
113
}
114
115
StatusCode
SmearingCalibStep::calibrate
(
xAOD::JetContainer
& jets)
const
{
116
ATH_MSG_DEBUG
(
"Applying smearing calibration step to jet collection."
);
117
118
JetHelper::JetContext
jc;
119
120
for
(
const
auto
jet
: jets){
121
122
const
xAOD::JetFourMom_t
jetStartP4 =
jet
->getAttribute<
xAOD::JetFourMom_t
>(
m_jetInScale
);
123
jet
->setJetP4(jetStartP4);
124
125
double
sigmaSmear = 0;
126
if
(
getSigmaSmear
(*
jet
, jc, sigmaSmear).isFailure())
127
return
StatusCode::FAILURE;
128
129
// Set the random seed deterministically using jet phi
130
unsigned
long
seed =
static_cast<
unsigned
long
>
(1.e5*fabs(
jet
->phi()));
131
// SetSeed(0) uses the clock, so avoid this
132
if
(seed == 0) seed = 45583453;
// arbitrary number which the seed couldn't otherwise be
133
TRandom3* rng =
getTLSRandomGen
(seed);
134
135
// Get the Gaussian-distributed random number
136
// Force this to be a positive value
137
// Negative values should be extraordinarily rare, but they do exist
138
double
smearingFactor = -1;
139
while
(smearingFactor < 0)
140
smearingFactor = rng->Gaus(1.,sigmaSmear);
141
142
xAOD::JetFourMom_t
calibP4 = jetStartP4;
143
144
switch
(
m_smearTypeClass
)
145
{
146
case
SmearType::Pt
:
147
calibP4 =
xAOD::JetFourMom_t
(
jet
->pt()*smearingFactor,
jet
->eta(),
jet
->phi(),
jet
->m());
148
break
;
149
150
case
SmearType::Mass
:
151
calibP4 =
xAOD::JetFourMom_t
(
jet
->pt(),
jet
->eta(),
jet
->phi(),smearingFactor*
jet
->m());
152
break
;
153
154
case
SmearType::FourVec
:
155
calibP4 =
xAOD::JetFourMom_t
(
jet
->pt()*smearingFactor,
jet
->eta(),
jet
->phi(),
jet
->m()*smearingFactor);
156
break
;
157
158
default
:
159
// We should never reach this, it was checked during initialization
160
ATH_MSG_ERROR
(
"Cannot smear the jet, the smearing type was not set"
);
161
return
StatusCode::FAILURE;
162
}
163
164
// Set the output scale
165
jet
->setAttribute<
xAOD::JetFourMom_t
>(
m_jetOutScale
,calibP4);
166
jet
->setJetP4(calibP4);
167
}
168
169
return
StatusCode::SUCCESS;
170
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
SmearingCalibStep.h
JetHelper::JetContext
Class JetContext Designed to read AOD information related to the event, N vertices,...
Definition
JetContext.h:27
SmearingCalibStep::m_histToolMC
ToolHandle< JetHelper::IVarTool > m_histToolMC
Definition
SmearingCalibStep.h:48
SmearingCalibStep::getNominalResolutionData
virtual StatusCode getNominalResolutionData(const xAOD::Jet &jet, const JetHelper::JetContext &jc, double &resolution) const override
Definition
SmearingCalibStep.cxx:103
SmearingCalibStep::m_smearTypeClass
SmearType m_smearTypeClass
Definition
SmearingCalibStep.h:64
SmearingCalibStep::SmearType::FourVec
@ FourVec
Definition
SmearingCalibStep.h:62
SmearingCalibStep::SmearType::Pt
@ Pt
Definition
SmearingCalibStep.h:60
SmearingCalibStep::SmearType::Mass
@ Mass
Definition
SmearingCalibStep.h:61
SmearingCalibStep::getTLSRandomGen
TRandom3 * getTLSRandomGen(unsigned long seed) const
Definition
SmearingCalibStep.cxx:56
SmearingCalibStep::m_jetOutScale
Gaudi::Property< std::string > m_jetOutScale
Definition
SmearingCalibStep.h:45
SmearingCalibStep::m_histToolData
ToolHandle< JetHelper::IVarTool > m_histToolData
Definition
SmearingCalibStep.h:49
SmearingCalibStep::SmearingCalibStep
SmearingCalibStep(const std::string &name="SmearingCalibStep")
Definition
SmearingCalibStep.cxx:14
SmearingCalibStep::m_smearType
Gaudi::Property< std::string > m_smearType
Definition
SmearingCalibStep.h:46
SmearingCalibStep::calibrate
virtual StatusCode calibrate(xAOD::JetContainer &) const override
Apply calibration to a jet container.
Definition
SmearingCalibStep.cxx:115
SmearingCalibStep::getNominalResolutionMC
virtual StatusCode getNominalResolutionMC(const xAOD::Jet &jet, const JetHelper::JetContext &jc, double &resolution) const override
Definition
SmearingCalibStep.cxx:109
SmearingCalibStep::m_jetInScale
Gaudi::Property< std::string > m_jetInScale
Definition
SmearingCalibStep.h:44
SmearingCalibStep::m_rand_tls
boost::thread_specific_ptr< TRandom3 > m_rand_tls
Definition
SmearingCalibStep.h:66
SmearingCalibStep::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition
SmearingCalibStep.cxx:18
SmearingCalibStep::getSigmaSmear
StatusCode getSigmaSmear(xAOD::Jet &jet, const JetHelper::JetContext &jc, double &sigmaSmear) const
Definition
SmearingCalibStep.cxx:67
asg::AsgTool::AsgTool
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition
AsgTool.cxx:58
asg
Definition
DataHandleTestTool.h:28
jet
Definition
JetCalibTools_PlotJESFactors.cxx:23
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition
Event/xAOD/xAODJet/xAODJet/Jet.h:17
xAOD::JetContainer
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Definition
JetContainer.h:17
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition
JetTypes.h:17
Generated on
for ATLAS Offline Software by
1.17.0