2#ifndef RIVET_PERCENTILEPROJECTION_HH
3#define RIVET_PERCENTILEPROJECTION_HH
5#include "Rivet/Projections/SingleValueProjection.hh"
6#include "Rivet/Tools/RivetYODA.hh"
28 bool increasing =
false)
29 : _calhist(
"EMPTY"), _increasing(increasing) {
30 setName(
"PercentileProjection");
33 MSG_DEBUG(
"Constructing PercentileProjection from " << calhist.path());
34 _calhist = calhist.path();
35 int N = calhist.numBins();
36 double sum = calhist.sumW();
39 double acc = calhist.underflow().sumW();
40 _table.insert(make_pair(calhist.bin(0).xEdges().first, 100.0*acc/
sum));
41 for (
int i = 0; i < N; ++i ) {
42 acc += calhist.bin(i).sumW();
43 _table.insert(make_pair(calhist.bin(i).xEdges().second, 100.0*acc/
sum));
46 double acc = calhist.overflow().sumW();
47 _table.insert(make_pair(calhist.bin(N - 1).xEdges().second, 100.0*acc/
sum));
48 for (
int i = N - 1; i >= 0; --i ) {
49 acc += calhist.bin(i).sumW();
50 _table.insert(make_pair(calhist.bin(i).xEdges().first, 100.0*acc/
sum));
53 if (
getLog().isActive(Log::DEBUG)) {
54 MSG_DEBUG(
"Mapping from observable to percentile:");
55 for (
auto p : _table) {
56 std::cout << std::setw(16) <<
p.first <<
" -> "
57 << std::setw(16) <<
p.second <<
"%" << std::endl;
58 if (not increasing and
p.second <= 0)
break;
59 if (increasing and
p.second >= 100)
break;
68 bool increasing =
false)
69 : _calhist(
"EMPTY"), _increasing(increasing) {
73 MSG_DEBUG(
"Constructing PercentileProjection from " << calscat.path());
74 _calhist = calscat.path();
75 int N = calscat.numPoints();
77 for (
const auto &
p : calscat.points() )
sum +=
p.y();
81 _table.insert(make_pair(calscat.point(0).xMin(), 100.0*acc/
sum));
82 for (
int i = 0; i < N; ++i ) {
83 acc += calscat.point(i).y();
84 _table.insert(make_pair(calscat.point(i).xMax(), 100.0*acc/
sum));
87 _table.insert(make_pair(calscat.point(N - 1).xMax(), 100.0*acc/
sum));
88 for (
int i = N - 1; i >= 0; --i ) {
89 acc += calscat.point(i).y();
90 _table.insert(make_pair(calscat.point(i).xMin(), 100.0*acc/
sum));
104 if ( _table.empty() )
return;
105 auto& pobs = apply<SingleValueProjection>(e,
"OBSERVABLE");
107 double pcnt = lookup(obs);
108 if ( pcnt >= 0.0 )
set(pcnt);
109 MSG_DEBUG(
"Observable(" << pobs.name() <<
")="
110 << std::setw(16) << obs
111 <<
"-> Percentile=" << std::setw(16) << pcnt <<
"%");
119 cmp(_increasing, pp._increasing) ||
120 cmp(_calhist, pp._calhist);
126 double lookup(
double obs)
const {
127 auto low = _table.upper_bound(obs);
128 if ( low == _table.end() )
return _increasing? 100.0: 0.0;
129 if ( low == _table.begin() )
return _increasing? 0.0: 100.0;
131 return low->second + (obs - low->first)*(high->second - low->second)/
132 (high->first - low->first);
140 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:19
PercentileProjection(const SingleValueProjection &sv, const Histo1D &calhist, bool increasing=false)
Definition: PercentileProjection.hh:27
void project(const Event &e)
Definition: PercentileProjection.hh:102
CmpState compare(const Projection &p) const
Definition: PercentileProjection.hh:116
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:51
void clear()
Unset the value.
Definition: SingleValueProjection.hh:54
CONTAINER::value_type sum(const CONTAINER &c)
Generic sum function, adding x for all x in container c.
Definition: Utils.hh:445
#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:653
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