ATLAS Offline Software
Loading...
Searching...
No Matches
PDFWeight.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// ReweightUtils includes
7
9
10#include "LHAPDF/LHAPDF.h"
11#include "LHAPDF/PDFSet.h"
12
14
15using namespace LHAPDF;
16
17PDFWeight::PDFWeight( const std::string& name )
18 : WeightToolBase( name ),
19 m_eventInfoName("EventInfo") {
20 declareProperty("index", m_index = 0);
21 declareProperty("PDFName", m_pdfName = "CT10");
22 declareProperty("TruthEventContainerName", m_truthEventContainerName = "TruthEvents");
23
24 m_weight = 0;
25}
26
28 StatusCode sc = WeightToolBase::initialize();
29 if (sc.isFailure()) {
30 return StatusCode::FAILURE;
31 }
32 try {
33 LHAPDF::pathsPrepend("/cvmfs/atlas.cern.ch/repo/sw/Generators/lhapdfsets/current"); // hack!
34 if(m_pdf) delete m_pdf;
35 m_pdf = mkPDF(m_pdfName, m_index);
36 } catch (...) {
37 m_pdf = 0;
38 }
39 return StatusCode::SUCCESS;
40}
41
42// returns: the value that was calculated from the xAOD::IParticle composite built event
43// This is the implementation of the interface
44double PDFWeight::evaluate( const xAOD::IParticle* /*part*/ ) const
45{
46 ATH_MSG_DEBUG ("Evaluating " << name() << "...");
47
48 // Get the proper weight (from EventInfo)
49 return this->getWeight();
50}
51
52double PDFWeight::computeWeight(const xAOD::EventInfo* evtInfo) const {
53 // don't do anything for data
55 ATH_MSG_DEBUG (" Returning weight=1. for data.");
56 return 1.;
57 }
58 if (!m_pdf)
59 return 1.;
60
61 int pdf_id1 = 0;
62 int pdf_id2 = 0;
63 int pdg_id1 = 0;
64 int pdg_id2 = 0;
65 float x1 = 0;
66 float x2 = 0;
67 float q = 0;
68 float xf1 = 0;
69 float xf2 = 0;
70
71 const xAOD::TruthEventContainer* truthEventContainer(nullptr);
72 StatusCode sc = evtStore()->retrieve(truthEventContainer, m_truthEventContainerName);
73 if (sc.isFailure()) { ATH_MSG_ERROR("Could not retrieve TruthEventContainer."); return 0; }
74
75 float weight = 1.0;
76
77 for (auto truthEvent : *truthEventContainer) {
78
79 try {
80 if ( !truthEvent->pdfInfoParameter( pdg_id1, xAOD::TruthEvent::PdfParam::PDGID1 ) ) {
81 ATH_MSG_DEBUG("Could not retrieve PDG id1.");
82 }
83 if ( !truthEvent->pdfInfoParameter( pdg_id2, xAOD::TruthEvent::PdfParam::PDGID2 ) ) {
84 ATH_MSG_DEBUG("Could not retrieve PDG id2.");
85 }
86 if ( !truthEvent->pdfInfoParameter( pdf_id1, xAOD::TruthEvent::PdfParam::PDFID1 ) ) {
87 ATH_MSG_DEBUG("Could not retrieve PDF id1.");
88 }
89 if ( !truthEvent->pdfInfoParameter( pdf_id2, xAOD::TruthEvent::PdfParam::PDFID2 ) ) {
90 ATH_MSG_DEBUG("Could not retrieve PDF id2.");
91 }
92 if ( !truthEvent->pdfInfoParameter( x1, xAOD::TruthEvent::PdfParam::X1 ) ) {
93 ATH_MSG_DEBUG("Could not retrieve x_1.");
94 }
95 if ( !truthEvent->pdfInfoParameter( x2, xAOD::TruthEvent::PdfParam::X2 ) ) {
96 ATH_MSG_DEBUG("Could not retrieve x_2.");
97 }
98 if ( !truthEvent->pdfInfoParameter( q, xAOD::TruthEvent::PdfParam::Q ) ) {
99 ATH_MSG_DEBUG("Could not retrieve Q.");
100 }
101 if ( !truthEvent->pdfInfoParameter( xf1, xAOD::TruthEvent::PdfParam::XF1 ) ) {
102 ATH_MSG_DEBUG("Could not retrieve x_f1.");
103 }
104 if ( !truthEvent->pdfInfoParameter( xf2, xAOD::TruthEvent::PdfParam::XF2 ) ) {
105 ATH_MSG_DEBUG("Could not retrieve x_f2.");
106 }
107 } catch (...) {
108 // set this to debug only because this is a frequent problem in ttbar samples
109 // sending the message in every event will only flood the logs until a newer version is available
110 ATH_MSG_DEBUG("Could not retrieve PDF information. xAODs generated with a version earlier than AtlasProduction-19.2.3.7 might have a bug that causes this. Please check your input xAOD. All PDF weights will be 1.");
111 return 1.0;
112 }
113
114 if (xf1 == 0 || xf2 == 0) {
115 ATH_MSG_DEBUG("Skipping event, as this TruthEvent is not reliable.");
116 // this can happen for some PDFs which cross zero and go negative at NLO
117 // not sure this is the best to do, so leaving the weight == 0 for now
118 weight = 0;
119 continue;
120 }
121
122 float reweighted_xf1 = 0;
123 float reweighted_xf2 = 0;
124 try {
125 reweighted_xf1 = m_pdf->xfxQ(pdg_id1, x1, q);
126 reweighted_xf2 = m_pdf->xfxQ(pdg_id2, x2, q);
127 } catch (...) {
128 ATH_MSG_DEBUG("LHAPDF exception.");
129 }
130 weight = reweighted_xf1*reweighted_xf2/(xf1*xf2);
131
132 break;
133 }
134
135 return weight;
136}
137
138double PDFWeight::getWeight() const {
139 //Retrieveing eventInfo
140 const xAOD::EventInfo* evtInfo;
141 StatusCode sc = evtStore()->retrieve( evtInfo, m_eventInfoName );
142 if(sc.isFailure() || !evtInfo) {
143 ATH_MSG_ERROR (" EventInfo could not be retrieved !!");
144 return 0.;
145 }
146
147 double weight = this->computeWeight(evtInfo);
148 ATH_MSG_DEBUG (" " << name() << " returning weight= " << weight << ".");
149 return weight;
150}
151
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
std::string m_eventInfoName
Definition PDFWeight.h:47
double computeWeight(const xAOD::EventInfo *) const
Definition PDFWeight.cxx:52
float m_weight
Definition PDFWeight.h:48
virtual double getWeight() const override
returns: the value that was calculated from the usual Athena storegate
virtual double evaluate(const xAOD::IParticle *part) const override
returns: the value that was calculated from the xAOD::IParticle (composite built event object for ins...
Definition PDFWeight.cxx:44
std::string m_pdfName
Definition PDFWeight.h:45
int m_index
Definition PDFWeight.h:52
std::string m_truthEventContainerName
Definition PDFWeight.h:46
StatusCode initialize() override
Usual initialize method of the framework.
Definition PDFWeight.cxx:27
LHAPDF::PDF * m_pdf
Definition PDFWeight.h:50
PDFWeight(const std::string &name)
Create a proper constructor for Athena.
Definition PDFWeight.cxx:17
WeightToolBase(const std::string &name)
Create a proper constructor for Athena.
virtual StatusCode initialize() override
Usual initialize method of the framework.
bool eventType(EventType type) const
Check for one particular bitmask value.
@ IS_SIMULATION
true: simulation, false: data
Class providing the definition of the 4-vector interface.
TruthEventContainer_v1 TruthEventContainer
Declare the latest version of the truth event container.
EventInfo_v1 EventInfo
Definition of the latest event info version.