2#ifndef RIVET_PERCENTILEPROJECTION_HH
3#define RIVET_PERCENTILEPROJECTION_HH
5#include "Rivet/Projections/SingleValueProjection.hh"
6#include "Rivet/Tools/RivetYODA.hh"
26 bool increasing =
false)
27 : _calhist(
"EMPTY"), _increasing(increasing) {
28 setName(
"PercentileProjection");
31 MSG_DEBUG(
"Constructing PercentileProjection from " << calhist.path());
32 _calhist = calhist.path();
33 int N = calhist.numBins();
34 double sum = calhist.sumW();
37 double acc = calhist.underflow().sumW();
38 _table.insert(make_pair(calhist.bin(0).xEdges().first, 100.0*acc/
sum));
39 for (
int i = 0; i < N; ++i ) {
40 acc += calhist.bin(i).sumW();
41 _table.insert(make_pair(calhist.bin(i).xEdges().second, 100.0*acc/
sum));
44 double acc = calhist.overflow().sumW();
45 _table.insert(make_pair(calhist.bin(N - 1).xEdges().second, 100.0*acc/
sum));
46 for (
int i = N - 1; i >= 0; --i ) {
47 acc += calhist.bin(i).sumW();
48 _table.insert(make_pair(calhist.bin(i).xEdges().first, 100.0*acc/
sum));
51 if (
getLog().isActive(Log::DEBUG)) {
52 MSG_DEBUG(
"Mapping from observable to percentile:");
53 for (
auto p : _table) {
54 std::cout << std::setw(16) <<
p.first <<
" -> "
55 << std::setw(16) <<
p.second <<
"%" << std::endl;
56 if (not increasing and
p.second <= 0)
break;
57 if (increasing and
p.second >= 100)
break;
66 bool increasing =
false)
67 : _calhist(
"EMPTY"), _increasing(increasing) {
71 MSG_DEBUG(
"Constructing PercentileProjection from " << calscat.path());
72 _calhist = calscat.path();
73 int N = calscat.numPoints();
75 for (
const auto &
p : calscat.points() )
sum +=
p.y();
79 _table.insert(make_pair(calscat.point(0).xMin(), 100.0*acc/
sum));
80 for (
int i = 0; i < N; ++i ) {
81 acc += calscat.point(i).y();
82 _table.insert(make_pair(calscat.point(i).xMax(), 100.0*acc/
sum));
85 _table.insert(make_pair(calscat.point(N - 1).xMax(), 100.0*acc/
sum));
86 for (
int i = N - 1; i >= 0; --i ) {
87 acc += calscat.point(i).y();
88 _table.insert(make_pair(calscat.point(i).xMin(), 100.0*acc/
sum));
93 DEFAULT_RIVET_PROJ_CLONE(PercentileProjection);
96 using Projection::operator =;
106 if ( _table.empty() )
return;
107 auto& pobs = apply<SingleValueProjection>(e,
"OBSERVABLE");
109 double pcnt = lookup(obs);
110 if ( pcnt >= 0.0 )
set(pcnt);
111 MSG_DEBUG(
"Observable(" << pobs.name() <<
")="
112 << std::setw(16) << obs
113 <<
"-> Percentile=" << std::setw(16) << pcnt <<
"%");
121 cmp(_increasing, pp._increasing) ||
122 cmp(_calhist, pp._calhist);
129 double lookup(
double obs)
const {
130 auto low = _table.upper_bound(obs);
131 if ( low == _table.end() )
return _increasing? 100.0: 0.0;
132 if ( low == _table.begin() )
return _increasing? 0.0: 100.0;
134 return low->second + (obs - low->first)*(high->second - low->second)/
135 (high->first - low->first);
143 map<double,double> _table;
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
class for projections that reports the percentile for a given SingleValueProjection when initialized ...
Definition PercentileProjection.hh:17
PercentileProjection(const SingleValueProjection &sv, const Histo1D &calhist, bool increasing=false)
Definition PercentileProjection.hh:25
void project(const Event &e)
Definition PercentileProjection.hh:104
CmpState compare(const Projection &p) const
Definition PercentileProjection.hh:118
const PROJ & declare(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition ProjectionApplier.hh:170
Base class for all Rivet projections.
Definition Projection.hh:29
void setName(const std::string &name)
Used by derived classes to set their name.
Definition Projection.hh:142
Log & getLog() const
Get a Log object based on the getName() property of the calling projection object.
Definition Projection.hh:136
Cmp< Projection > mkNamedPCmp(const Projection &otherparent, const std::string &pname) const
Base class for projections returning a single floating point value.
Definition SingleValueProjection.hh:17
void set(double v)
Definition SingleValueProjection.hh:55
void clear()
Unset the value.
Definition SingleValueProjection.hh:58
CONTAINER::value_type sum(const CONTAINER &c)
Generic sum function, adding x for all x in container c.
Definition Utils.hh:436
#define MSG_DEBUG(x)
Debug messaging, not enabled by default, using MSG_LVL.
Definition Logging.hh:195
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:684
Definition MC_Cent_pPb.hh:10
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition Cmp.hh:255