ATLAS Offline Software
PDFScaleFactorCalculator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include "TopEvent/EventTools.h"
9 
10 
13 
14 namespace top {
16  asg::AsgTool(name),
17  m_config(nullptr) {
18  declareProperty("config", m_config);
19  }
20 
22  ATH_MSG_INFO(" top::PDFScaleFactorCalculator initialize");
23 
24  // This prints all the available PDFsets we can use
25  //printAvailablePDFs();
26 
27  for (const std::string& set_name : m_config->LHAPDFSets()) {
28  m_pdf_sets[ set_name ] = PDFSet(set_name);
29  }
30 
31  m_base_pdf_name = m_config->baseLHAPDF();
32  if (!m_base_pdf_name.empty()) {
34  "Enabling " << m_base_pdf_name <<
35  " to recompute PDF weights.\n Content of sumWeight and totalSumWeight trees might be inconsistent with this recalculation.\n Use only PDFSumWeight and for PDF uncertainty estimates.\n");
36  m_basepdf = LHAPDF::mkPDF(m_base_pdf_name, 0);
37  }
38 
39  return StatusCode::SUCCESS;
40  }
41 
43  // Get the event info for the MC weight
44  const xAOD::EventInfo* event_info(nullptr);
45 
46  top::check(evtStore()->retrieve(event_info, m_config->sgKeyEventInfo()), "Failed to retrieve EventInfo");
47  const xAOD::TruthEventContainer* truthEventContainer(nullptr);
48  top::check(evtStore()->retrieve(truthEventContainer,
49  m_config->sgKeyTruthEvent()), "PDFScaleFactorCalculator: Failed to retrieve TruthEvent container");
50 
51  float mc_weight = event_info->auxdataConst<float>("AnalysisTop_eventWeight");
52 
53  // try this...
54  top::check((truthEventContainer->size() == 1), "TruthEvent container size != 1, not sure how to cope with PDF info");
55  int PDFID1(0), PDFID2(0), PDGID1(0), PDGID2(0);
56  float X1(0), X2(0), Q(0), XF1(0), XF2(0);
57 
58  const xAOD::TruthEvent* truthEvent = truthEventContainer->at(0);
59  top::check(truthEvent->pdfInfoParameter(PDGID1,
60  xAOD::TruthEvent::PdfParam::PDGID1), "Failed to get PDFInfo: PDGID1");
61  top::check(truthEvent->pdfInfoParameter(PDGID2,
62  xAOD::TruthEvent::PdfParam::PDGID2), "Failed to get PDFInfo: PDGID2");
63  top::check(truthEvent->pdfInfoParameter(PDFID1,
64  xAOD::TruthEvent::PdfParam::PDFID1), "Failed to get PDFInfo: PDFID1");
65  top::check(truthEvent->pdfInfoParameter(PDFID2,
66  xAOD::TruthEvent::PdfParam::PDFID2), "Failed to get PDFInfo: PDFID2");
67  top::check(truthEvent->pdfInfoParameter(X1, xAOD::TruthEvent::PdfParam::X1), "Failed to get PDFInfo: X1");
68  top::check(truthEvent->pdfInfoParameter(X2, xAOD::TruthEvent::PdfParam::X2), "Failed to get PDFInfo: X2");
69  top::check(truthEvent->pdfInfoParameter(Q, xAOD::TruthEvent::PdfParam::Q), "Failed to get PDFInfo: Q");
70  top::check(truthEvent->pdfInfoParameter(XF1, xAOD::TruthEvent::PdfParam::XF1), "Failed to get PDFInfo: XF1");
71  top::check(truthEvent->pdfInfoParameter(XF2, xAOD::TruthEvent::PdfParam::XF2), "Failed to get PDFInfo: XF2");
72 
73  if (XF1 * XF2 == 0) {
74  if (!m_base_pdf_name.empty()) {
75  XF1 = m_basepdf->xfxQ(PDGID1, X1, Q);
76  XF2 = m_basepdf->xfxQ(PDGID2, X2, Q);
77  } else {
79  "Not enough info to recompute PDF weights (empty XF1,XF2).\n Please try to set LHAPDFBaseSet to a valid PDF set.\n XF1=" << XF1 << " XF2=" << XF2 << " LHAPDFBaseSet=" <<
81  return StatusCode::FAILURE;
82  }
83  }
84 
85  for (auto& pdf : m_pdf_sets) {
86  // Being cautious...
87  pdf.second.event_weights.clear();
88  pdf.second.event_weights.resize(pdf.second.pdf_members.size());
89 
90  int i = 0;
91 
92  for (const auto& pdf_member : pdf.second.pdf_members) {
93  float new_xf1 = pdf_member->xfxQ(PDGID1, X1, Q);
94  float new_xf2 = pdf_member->xfxQ(PDGID2, X2, Q);
95 
96  float weight = (new_xf1 * new_xf2) / (XF1 * XF2);
97 
98  // This is the reweighting each event
99  pdf.second.event_weights[i] = weight;
100  // This is the sum of all event weights for a final scaling
101  pdf.second.sum_of_event_weights[i] += (weight * mc_weight);
102  i++;
103  }
104 
105  // decorate each truth event with a vector of PDF weights
106  if (m_config->saveLHAPDFEvent()) truthEvent->auxdecor< std::vector< float > >(
107  "AnalysisTop_" + pdf.first + "_Weights") = pdf.second.event_weights;
108  }
109 
110  return StatusCode::SUCCESS;
111  }
112 
114  for (auto& pdf : m_pdf_sets)
115  m_config->addLHAPDFResult(pdf.first, pdf.second.sum_of_event_weights);
116 
117  if (m_basepdf) delete m_basepdf;
118 
119  return StatusCode::SUCCESS;
120  }
121 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
top::PDFScaleFactorCalculator::m_basepdf
LHAPDF::PDF * m_basepdf
Definition: PDFScaleFactorCalculator.h:76
xAOD::TruthEvent_v1::pdfInfoParameter
bool pdfInfoParameter(int &value, PdfParam parameter) const
Read an integer PDF info parameter.
Definition: TruthEvent_v1.cxx:51
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
top::PDFScaleFactorCalculator::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: PDFScaleFactorCalculator.cxx:21
top::PDFScaleFactorCalculator::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: PDFScaleFactorCalculator.h:72
asg
Definition: DataHandleTestTool.h:28
top::PDFScaleFactorCalculator::execute
StatusCode execute()
Definition: PDFScaleFactorCalculator.cxx:42
SG::AuxElement::auxdecor
Decorator< T, ALLOC >::reference_type auxdecor(const std::string &name) const
Fetch an aux decoration, as a non-const reference.
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
top::PDFScaleFactorCalculator::PDFSet
Definition: PDFScaleFactorCalculator.h:79
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
SG::AuxElement::auxdataConst
Accessor< T, ALLOC >::const_reference_type auxdataConst(const std::string &name) const
Fetch an aux data variable, as a const reference.
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
lumiFormat.i
int i
Definition: lumiFormat.py:92
top::PDFScaleFactorCalculator::m_pdf_sets
std::unordered_map< std::string, PDFSet > m_pdf_sets
Definition: PDFScaleFactorCalculator.h:97
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthEvent_v1
Class describing a signal truth event in the MC record.
Definition: TruthEvent_v1.h:35
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
top::PDFScaleFactorCalculator::finalize
StatusCode finalize()
Definition: PDFScaleFactorCalculator.cxx:113
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TopConfig.h
top::PDFScaleFactorCalculator::m_base_pdf_name
std::string m_base_pdf_name
Definition: PDFScaleFactorCalculator.h:75
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
top::PDFScaleFactorCalculator::PDFScaleFactorCalculator
PDFScaleFactorCalculator(const std::string &name)
Definition: PDFScaleFactorCalculator.cxx:15
PDFScaleFactorCalculator.h
PowhegPythia8EvtGen_jetjet.pdf
pdf
Definition: PowhegPythia8EvtGen_jetjet.py:4
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
TruthEventContainer.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.