2 #ifndef RIVET_PERCENTILEPROJECTION_HH 3 #define RIVET_PERCENTILEPROJECTION_HH 5 #include "Rivet/Projections/SingleValueProjection.hh" 6 #include "Rivet/Tools/RivetYODA.hh" 27 bool increasing =
false)
28 : _calhist(
"EMPTY"), _increasing(increasing) {
30 if ( !calhist )
return;
31 MSG_INFO(
"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));
57 bool increasing =
false)
58 : _calhist(
"EMPTY"), _increasing(increasing) {
61 if ( !calscat )
return;
62 MSG_INFO(
"Constructing PercentileProjection from " << calscat->path());
63 _calhist = calscat->path();
64 int N = calscat->numPoints();
66 for (
const auto & p : calscat->points() ) sum += p.y();
70 _table.insert(make_pair(calscat->point(0).xMin(), 100.0*acc/
sum));
71 for (
int i = 0; i < N; ++i ) {
72 acc += calscat->point(i).y();
73 _table.insert(make_pair(calscat->point(i).xMax(), 100.0*acc/
sum));
76 _table.insert(make_pair(calscat->point(N - 1).xMax(), 100.0*acc/
sum));
77 for (
int i = N - 1; i >= 0; --i ) {
78 acc += calscat->point(i).y();
79 _table.insert(make_pair(calscat->point(i).xMin(), 100.0*acc/
sum));
93 if ( _table.empty() )
return;
94 double obs = apply<SingleValueProjection>(e,
"OBSERVABLE")();
95 double pcnt = lookup(obs);
96 if ( pcnt >= 0.0 )
set(pcnt);
104 return mkNamedPCmp(p,
"OBSERVABLE") ||
cmp(_increasing,pp._increasing) ||
105 cmp(_calhist, pp._calhist);
111 double lookup(
double obs)
const {
112 auto low = _table.upper_bound(obs);
113 if ( low == _table.end() )
return _increasing? 100.0: 0.0;
114 if ( low == _table.begin() )
return _increasing? 0.0: 100.0;
116 return low->second + (obs - low->first)*(high->second - low->second)/
117 (high->first - low->first);
125 map<double,double> _table;
Definition: ALICE_2010_I880049.cc:13
Base class for projections returning a single floating point value.
Definition: SingleValueProjection.hh:18
int compare(const Projection &p) const
Definition: PercentileProjection.hh:101
T sum(const CONTAINER &c, const T &start=T())
Generic sum function, adding x for all x in container c, starting with start.
Definition: Utils.hh:345
void project(const Event &e)
Definition: PercentileProjection.hh:91
Cmp< Projection > mkNamedPCmp(const Projection &otherparent, const std::string &pname) const
Definition: Projection.cc:51
const PROJ & declare(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition: ProjectionApplier.hh:160
class for projections that reports the percentile for a given SingleValueProjection when initialized ...
Definition: PercentileProjection.hh:19
Base class for all Rivet projections.
Definition: Projection.hh:29
void clear()
Unset the value.
Definition: SingleValueProjection.hh:47
Cmp< T > cmp(const T &t1, const T &t2)
Global helper function for easy creation of Cmp objects.
Definition: Cmp.hh:285