ATLAS Offline Software
Loading...
Searching...
No Matches
PDFReweightAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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{
18 void PDFReweightAlg::PDFDeleter::operator() (const LHAPDF::PDF *pdf) const
19 {
20 delete pdf;
21 }
22
24 {
25
26 ATH_CHECK(m_EventInfoKey.initialize());
27 ATH_CHECK(m_TruthEventKey.initialize());
28
29 if(m_additionalPdfPath != "")
30 LHAPDF::pathsAppend(m_additionalPdfPath);
31
32 m_p0.reset(LHAPDF::mkPDF(m_inPDF));
33 for (const auto& pdfstring : m_outPDF) {
34 m_p1_vars.emplace_back(LHAPDF::mkPDF(pdfstring));
35 }
36
37 for(auto temp_name : m_outPDF){
38 if (auto pos = temp_name.find('/'); pos != std::string::npos)
39 temp_name[pos] = '_';
40
41 m_reweightKeys.emplace_back(m_EventInfoKey, "PDFReweightSF_"+temp_name);
42
43 ATH_CHECK(m_reweightKeys.back().initialize());
44#ifndef XAOD_STANDALONE
45 // declare the output dependency for MT scheduling
46 addDependency(m_reweightKeys.back().fullKey(), m_reweightKeys.back().mode());
47#endif
48 }
49
50 return StatusCode::SUCCESS;
51 }
52
53 StatusCode PDFReweightAlg::execute(const EventContext &ctx) const
54 {
55
57 ATH_CHECK(eventInfo.isValid());
58
61
62 if(TruthEventContainer->size() != 1){
63 ATH_MSG_ERROR("ERROR. Multiple Truth Events Detected");
64 return StatusCode::FAILURE;
65 }
66
67 const xAOD::TruthEvent *truthEvent = TruthEventContainer->at(0);
68
69 static const SG::AuxElement::ConstAccessor<int> accPDGID1("PDGID1");
70 static const SG::AuxElement::ConstAccessor<int> accPDGID2("PDGID2");
71 static const SG::AuxElement::ConstAccessor<float> accX1("X1");
72 static const SG::AuxElement::ConstAccessor<float> accX2("X2");
73 static const SG::AuxElement::ConstAccessor<float> accQ("Q");
74
75 int pdgid1 = accPDGID1(*truthEvent);
76 int pdgid2 = accPDGID2(*truthEvent);
77 float X1 = accX1(*truthEvent);
78 float X2 = accX2(*truthEvent);
79 float Q = accQ(*truthEvent);
80
81 for (size_t i = 0; i<m_outPDF.size(); ++i) {
82
83 float reweight = LHAPDF::weightxxQ(pdgid1, pdgid2, X1, X2, Q,
84 m_p0.get(), m_p1_vars[i].get()); // reweight is the scale factor around 1
85
87 handle(*eventInfo) = reweight;
88 }
89
90 return StatusCode::SUCCESS;
91
92 }
93
94}
#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
virtual StatusCode initialize() final
Gaudi::Property< std::string > m_additionalPdfPath
Gaudi::Property< std::vector< std::string > > m_outPDF
std::vector< PDFPtr > m_p1_vars
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
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
void operator()(const LHAPDF::PDF *pdf) const