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/Tools/Logging.hh"
6#include "Rivet/Particle.hh"
7#include "Rivet/Jet.hh"
8#include "Rivet/Math/Vector4.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:
24 virtual ~ResolutionFunctor() = default;
25 virtual double resolution(const T& input) const = 0;
27
28
31
32 void _cacheRefData() const {
33 // For thread safety, as in Analysis.cc
34 static std::mutex cache_ref_data_mutex_guard {};
35 std::lock_guard<mutex> lock(cache_ref_data_mutex_guard);
36
37 if (_refdata.empty()) {
38 MSG_TRACE("Getting refdata cache for file " <<_refFileName);
39 _refdata = getRefData(_refFileName);
40 }
41 }
42
46 // Based on Analysis.cc
48 template <typename T2=YODA::Estimate1D>
49 const T2& refData(const string& hname) const {
50 _cacheRefData();
51 if (!_refdata[hname]) {
52 MSG_ERROR("Can't find reference histogram " << hname);
53 throw Exception("Reference data " + hname + " not found.");
54 }
55 try {
56 return dynamic_cast<T2&>(*_refdata[hname]);
57 } catch (std::bad_cast &e) {
58 throw Exception("Requested object type "s + typeid(T2).name() + ", but reference data \""s + hname
59 + "\" actually has type " + _refdata[hname]->type() + ".\n");
60 }
61 }
62
63
64 Log& getLog() const {
65 return Log::getLog("Rivet.ResolutionFunctor");
66 }
67
68 protected:
69 mutable std::map<std::string, YODA::AnalysisObjectPtr> _refdata;
70 string _refFileName;
71 };
72
73 template<typename T>
74 using ResolutionFunctorPtr = unique_ptr<ResolutionFunctor<T>>;
75
76 // TODO: Is there an useful argument for a ConstResolutionFunctor?
77
78 // TODO: We could auto-generate smearing functions from pairs of
79 // (pT, phi) res functions -- add machinery?
80}
81
82#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:49
map< string, YODA::AnalysisObjectPtr > getRefData(const string &papername)
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:180
#define MSG_ERROR(x)
Highest level messaging for serious problems, using MSG_LVL.
Definition Logging.hh:189
Definition MC_CENT_PPB_Projections.hh:10
Error Exception
Rivet::Exception is a synonym for Rivet::Error.
Definition Exceptions.hh:18