ATLAS Offline Software
Loading...
Searching...
No Matches
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
8#include <LHAPDF/LHAPDF.h>
9#include "LHAPDF/Reweighting.h"
10
13
15
16namespace CP
17{
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
48 ATH_CHECK(eventInfo.isValid());
49
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
79 handle(*eventInfo) = reweight;
80 }
81
82 return StatusCode::SUCCESS;
83
84 }
85
86}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
LHAPDF::PDF * m_p0
virtual StatusCode initialize() final
std::vector< LHAPDF::PDF * > m_p1_vars
Gaudi::Property< std::string > m_additionalPdfPath
Gaudi::Property< std::vector< std::string > > m_outPDF
Gaudi::Property< std::string > m_inPDF
std::vector< SG::WriteDecorHandleKey< xAOD::EventInfo > > m_reweightKeys
SG::ReadHandleKey< xAOD::TruthEventContainer > m_TruthEventKey
virtual StatusCode execute(const EventContext &ctx) const final
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Handle class for adding a decoration to an object.
Select isolated Photons, Electrons and Muons.
TruthEventContainer_v1 TruthEventContainer
Declare the latest version of the truth event container.
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition TruthEvent.h:17