Rivet API documentation

Rivet 4.1.3
ResolutionFunctions.hh
1// -*- C++ -*-
2#ifndef RIVET_ResolutionFunctions_HH
3#define RIVET_ResolutionFunctions_HH
4
5#include "Rivet/Jet.hh"
6#include "Rivet/Particle.hh"
7#include "Rivet/Math/Vector4.hh"
8#include "Rivet/Tools/Logging.hh"
9#include "Rivet/Tools/RivetYODA.hh"
10
11
12namespace Rivet {
13
14 // TODO: define functions as well as functors? Not needed (yet)
15
16 // (largely) virtual base class for resolution functions that require refdata,
17 // which should be loaded at construction (in init) only.
18 // TODO: restrict to Jet/Particle (3/4-mom?)
19 template <typename T>
21 public:
22
25 virtual ~ResolutionFunctor() = default;
26 virtual double resolution(const T& input) const = 0;
28
29
32
33 void _cacheRefData() const {
34 // For thread safety, as in Analysis.cc
35 static std::mutex cache_ref_data_mutex_guard{};
36 std::lock_guard<mutex> lock(cache_ref_data_mutex_guard);
37
38 if (_refdata.empty()) {
39 MSG_TRACE("Getting refdata cache for file " << _refFileName);
40 _refdata = getRefData(_refFileName);
41 }
42 }
43
47 // Based on Analysis.cc
49 template <typename T2 = YODA::Estimate1D>
50 const T2& refData(const string& hname) const {
51 _cacheRefData();
52 if (!_refdata[hname]) {
53 MSG_ERROR("Can't find reference histogram " << hname);
54 throw Exception("Reference data " + hname + " not found.");
55 }
56 try {
57 return dynamic_cast<T2&>(*_refdata[hname]);
58 }
59 catch (std::bad_cast& e) {
60 throw Exception("Requested object type "s + typeid(T2).name() + ", but reference data \""s + hname
61 + "\" actually has type " + _refdata[hname]->type() + ".\n");
62 }
63 }
64
65
66 Log& getLog() const {
67 return Log::getLog("Rivet.ResolutionFunctor");
68 }
69
70 protected:
71
72 mutable std::map<std::string, YODA::AnalysisObjectPtr> _refdata;
73 string _refFileName;
74 };
75
76 template <typename T>
77 using ResolutionFunctorPtr = unique_ptr<ResolutionFunctor<T>>;
78
79 // TODO: Is there an useful argument for a ConstResolutionFunctor?
80
81 // TODO: We could auto-generate smearing functions from pairs of
82 // (pT, phi) res functions -- add machinery?
83}
84
85#endif
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
static Log & getLog(const std::string &name)
Definition ResolutionFunctions.hh:20
const T2 & refData(const string &hname) const
Definition ResolutionFunctions.hh:50
map< string, YODA::AnalysisObjectPtr > getRefData(const string &papername)
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:193
#define MSG_ERROR(x)
Highest level messaging for serious problems, using MSG_LVL.
Definition Logging.hh:202
Definition LHCbCommon.hh:9
Error Exception
Rivet::Exception is a synonym for Rivet::Error.
Definition Exceptions.hh:19