ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
AsgAnalysisAlgorithms
Root
PDFReweightAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
#include "
AsgAnalysisAlgorithms/PDFReweightAlg.h
"
8
#include <LHAPDF/LHAPDF.h>
9
#include "LHAPDF/Reweighting.h"
10
11
#include <
AsgDataHandles/ReadHandle.h
>
12
#include <
AsgDataHandles/WriteDecorHandle.h
>
13
14
#include <
xAODTruth/TruthEvent.h
>
15
16
namespace
CP
17
{
18
StatusCode
PDFReweightAlg::initialize
()
19
{
20
21
ATH_CHECK
(
m_EventInfoKey
.initialize());
22
ATH_CHECK
(
m_TruthEventKey
.initialize());
23
24
m_p0
= LHAPDF::mkPDF(
m_inPDF
);
25
for
(
const
auto
& pdfstring :
m_outPDF
) {
26
m_p1_vars
.push_back(LHAPDF::mkPDF(pdfstring));
27
}
28
29
for
(
auto
temp_name :
m_outPDF
){
30
if
(
auto
pos = temp_name.find(
'/'
); pos != std::string::npos)
31
temp_name[pos] =
'_'
;
32
33
m_reweightKeys
.emplace_back(
m_EventInfoKey
,
"PDFReweightSF_"
+temp_name);
34
35
ATH_CHECK
(
m_reweightKeys
.back().initialize());
36
}
37
38
if
(
m_additionalPdfPath
!=
""
)
39
LHAPDF::pathsAppend(
m_additionalPdfPath
);
40
41
return
StatusCode::SUCCESS;
42
}
43
44
StatusCode
PDFReweightAlg::execute
(
const
EventContext &ctx)
const
45
{
46
47
SG::ReadHandle<xAOD::EventInfo>
eventInfo(
m_EventInfoKey
, ctx);
48
ATH_CHECK
(eventInfo.
isValid
());
49
50
SG::ReadHandle<xAOD::TruthEventContainer>
TruthEventContainer
(
m_TruthEventKey
, ctx);
51
ATH_CHECK
(
TruthEventContainer
.isValid());
52
53
if
(
TruthEventContainer
->size() != 1){
54
ATH_MSG_ERROR
(
"ERROR. Multiple Truth Events Detected"
);
55
return
StatusCode::FAILURE;
56
}
57
58
const
xAOD::TruthEvent
*truthEvent =
TruthEventContainer
->at(0);
59
60
static
const
SG::AuxElement::ConstAccessor<int> accPDGID1(
"PDGID1"
);
61
static
const
SG::AuxElement::ConstAccessor<int> accPDGID2(
"PDGID2"
);
62
static
const
SG::AuxElement::ConstAccessor<float> accX1(
"X1"
);
63
static
const
SG::AuxElement::ConstAccessor<float> accX2(
"X2"
);
64
static
const
SG::AuxElement::ConstAccessor<float> accQ(
"Q"
);
65
66
int
pdgid1 = accPDGID1(*truthEvent);
67
int
pdgid2 = accPDGID2(*truthEvent);
68
float
X1 = accX1(*truthEvent);
69
float
X2 = accX2(*truthEvent);
70
float
Q = accQ(*truthEvent);
71
72
for
(
size_t
i = 0; i<
m_outPDF
.size(); ++i) {
73
74
float
reweight = LHAPDF::weightxxQ(pdgid1, pdgid2, X1, X2, Q,
75
static_cast<
const
LHAPDF::PDF*
>
(
m_p0
),
76
static_cast<
const
LHAPDF::PDF*
>
(
m_p1_vars
[i]));
// reweight is the scale factor around 1
77
78
SG::WriteDecorHandle<xAOD::EventInfo, float>
handle(
m_reweightKeys
[i], ctx);
79
handle(*eventInfo) = reweight;
80
}
81
82
return
StatusCode::SUCCESS;
83
84
}
85
86
}
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
ReadHandle.h
Handle class for reading from StoreGate.
WriteDecorHandle.h
Handle class for adding a decoration to an object.
PDFReweightAlg.h
TruthEvent.h
CP::PDFReweightAlg::m_EventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Definition
PDFReweightAlg.h:38
CP::PDFReweightAlg::m_p0
LHAPDF::PDF * m_p0
Definition
PDFReweightAlg.h:44
CP::PDFReweightAlg::initialize
virtual StatusCode initialize() final
Definition
PDFReweightAlg.cxx:18
CP::PDFReweightAlg::m_p1_vars
std::vector< LHAPDF::PDF * > m_p1_vars
Definition
PDFReweightAlg.h:45
CP::PDFReweightAlg::m_additionalPdfPath
Gaudi::Property< std::string > m_additionalPdfPath
Definition
PDFReweightAlg.h:48
CP::PDFReweightAlg::m_outPDF
Gaudi::Property< std::vector< std::string > > m_outPDF
Definition
PDFReweightAlg.h:47
CP::PDFReweightAlg::m_inPDF
Gaudi::Property< std::string > m_inPDF
Definition
PDFReweightAlg.h:46
CP::PDFReweightAlg::m_reweightKeys
std::vector< SG::WriteDecorHandleKey< xAOD::EventInfo > > m_reweightKeys
Definition
PDFReweightAlg.h:49
CP::PDFReweightAlg::m_TruthEventKey
SG::ReadHandleKey< xAOD::TruthEventContainer > m_TruthEventKey
Definition
PDFReweightAlg.h:41
CP::PDFReweightAlg::execute
virtual StatusCode execute(const EventContext &ctx) const final
Definition
PDFReweightAlg.cxx:44
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
CP
Select isolated Photons, Electrons and Muons.
Definition
Control/xAODRootAccess/xAODRootAccess/TEvent.h:27
xAOD::TruthEventContainer
TruthEventContainer_v1 TruthEventContainer
Declare the latest version of the truth event container.
Definition
TruthEventContainer.h:18
xAOD::TruthEvent
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition
TruthEvent.h:17
Generated on
for ATLAS Offline Software by
1.17.0