4#include "Rivet/Event.hh"
5#include "Rivet/Projections/CentralityProjection.hh"
6#include "Rivet/ProjectionApplier.hh"
28 : _ana(ana), _projName(projName) {}
41 static bool inRange(
double x, pair<float,float> range) {
42 return x >= range.first && ( x < range.second || ( x == 100.0 && x == range.second ) );
48 _projName = other._projName;
54 return ( _ana == other._ana &&
55 _projName == other._projName &&
56 _cent == other._cent );
78 vector<int> _activeBins;
82 vector<pair<float, float> > _cent;
123 pair<float,float> cent = {0.0, 100.0} ) {
124 _cent.push_back(cent);
125 _histos.push_back( { ao, cnt } );
135 if ( tv.size() != _cent.size() )
return false;
146 for (
const auto bin : _activeBins)
147 _histos[bin].second->fill();
148 return !_activeBins.empty();
156 for (
const auto &hist : _histos)
157 if ( hist.second->numEntries() > 0 && hist.first->numEntries() > 0)
158 hist.first->scaleW(1./hist.second->val());
163 for (
const auto hist : _histos)
164 hist.first->scaleW(scale);
168 void exec(function<
void(T&)> f) {
for (
auto hist : _histos) f(hist); }
176 const vector<pair<TPtr, CounterPtr > > &
188 vector<pair<TPtr, CounterPtr > > _histos;
228 template<
typename... Args>
230 for (
const auto bin : _activeBins) {
231 _histos[bin].first->fill(args...);
237 const int nCent = _histos.size();
238 for (
int iCent = 0; iCent < nCent; ++iCent) {
239 *_histos[iCent].first -= *rhs._histos[iCent].first;
245 const int nCent = _histos.size();
246 for (
int iCent = 0; iCent < nCent; ++iCent) {
247 *_histos[iCent].first += *rhs._histos[iCent].first;
302 template<
typename... Args>
304 for (
const auto bin : _activeBins) {
305 _histos[bin].first->fill(bin, args...);
311 const int nCent = _histos.size();
312 for (
int iCent = 0; iCent < nCent; ++iCent) {
313 *_histos[iCent].first -= *rhs._histos[iCent].first;
319 const int nCent = this->_histos.size();
320 for (
int iCent = 0; iCent < nCent; ++iCent) {
321 *_histos[iCent].first += *rhs._histos[iCent].first;
340 template <
typename T>
341 Percentile<typename ReferenceTraits<T>::RefT>
342 divide(
const Percentile<T> numer,
const Percentile<T> denom) {
343 typedef typename ReferenceTraits<T>::RefT ScatT;
344 Percentile<ScatT> ret;
345 vector<typename ScatT::Ptr> scatters;
346 assert( numer.compatible(denom) );
347 for (
int i = 0, N = numer.analysisObjects().size(); i < N; ++i )
348 scatters.push_back(make_shared<ScatT>(divide(*numer.analysisObjects()[i].first,
349 *denom.analysisObjects()[i].first)));
350 ret.add(numer, scatters);
354 template <
typename T>
355 Percentile<typename ReferenceTraits<T>::RefT>
356 divide(
const Percentile<T> numer,
357 const Percentile<
typename ReferenceTraits<T>::RefT> denom) {
358 typedef typename ReferenceTraits<T>::RefT ScatT;
359 Percentile<ScatT> ret;
360 vector<typename ScatT::Ptr> scatters;
361 assert( numer.compatible(denom) );
362 for (
int i = 0, N = numer.analysisObjects().size(); i < N; ++i )
363 scatters.push_back(make_shared<ScatT>(divide(*numer.analysisObjects()[i].first,
364 *denom.analysisObjects()[i].first)));
365 ret.add(numer, scatters);
369 template <
typename T>
370 Percentile<typename ReferenceTraits<T>::RefT>
371 divide(
const Percentile<
typename ReferenceTraits<T>::RefT> numer,
372 const Percentile<T> denom) {
373 typedef typename ReferenceTraits<T>::RefT ScatT;
374 Percentile<typename ReferenceTraits<T>::RefT> ret;
375 vector<typename ScatT::Ptr> scatters;
376 assert( numer.compatible(denom) );
377 for (
int i = 0, N = numer.analysisObjects().size(); i < N; ++i )
378 scatters.push_back(make_shared<ScatT>(divide(*numer.analysisObjects()[i].first,
379 *denom.analysisObjects()[i].first)));
380 ret.add(numer, scatters);
384 template <
typename T>
385 Percentile<T> add(
const Percentile<T> pctla,
const Percentile<T> pctlb) {
387 vector<typename T::Ptr> aos;
388 assert( pctla.compatible(pctlb) );
389 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
390 aos.push_back(make_shared<T>(add(*pctla.analysisObjects()[i].first,
391 *pctlb.analysisObjects()[i].first)));
396 template <
typename T>
397 Percentile<typename ReferenceTraits<T>::RefT>
398 add(
const Percentile<T> pctla,
399 const Percentile<
typename ReferenceTraits<T>::RefT> pctlb) {
400 typedef typename ReferenceTraits<T>::RefT ScatT;
401 Percentile<ScatT> ret;
402 vector<typename ScatT::Ptr> scatters;
403 assert( pctla.compatible(pctlb) );
404 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
405 scatters.push_back(make_shared<ScatT>(add(*pctla.analysisObjects()[i].first,
406 *pctlb.analysisObjects()[i].first)));
407 ret.add(pctla, scatters);
411 template <
typename T>
412 Percentile<typename ReferenceTraits<T>::RefT>
413 add(
const Percentile<
typename ReferenceTraits<T>::RefT> pctla,
414 const Percentile<T> pctlb) {
415 typedef typename ReferenceTraits<T>::RefT ScatT;
416 Percentile<ScatT> ret;
417 vector<typename ScatT::Ptr> scatters;
418 assert( pctla.compatible(pctlb) );
419 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
420 scatters.push_back(make_shared<ScatT>(add(*pctla.analysisObjects()[i].first,
421 *pctlb.analysisObjects()[i].first)));
422 ret.add(pctla, scatters);
426 template <
typename T>
427 Percentile<T> subtract(
const Percentile<T> pctla,
const Percentile<T> pctlb) {
429 vector<typename T::Ptr> aos;
430 assert( pctla.compatible(pctlb) );
431 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
432 aos.push_back(make_shared<T>(subtract(*pctla.analysisObjects()[i].first,
433 *pctlb.analysisObjects()[i].first)));
438 template <
typename T>
439 Percentile<typename ReferenceTraits<T>::RefT>
440 subtract(
const Percentile<T> pctla,
441 const Percentile<
typename ReferenceTraits<T>::RefT> pctlb) {
442 typedef typename ReferenceTraits<T>::RefT ScatT;
443 Percentile<ScatT> ret;
444 vector<typename ScatT::Ptr> scatters;
445 assert( pctla.compatible(pctlb) );
446 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
447 scatters.push_back(make_shared<ScatT>(subtract(*pctla.analysisObjects()[i].first,
448 *pctlb.analysisObjects()[i].first)));
449 ret.add(pctla, scatters);
453 template <
typename T>
454 Percentile<typename ReferenceTraits<T>::RefT>
455 subtract(
const Percentile<
typename ReferenceTraits<T>::RefT> pctla,
456 const Percentile<T> pctlb) {
457 typedef typename ReferenceTraits<T>::RefT ScatT;
458 Percentile<ScatT> ret;
459 vector<typename ScatT::Ptr> scatters;
460 assert( pctla.compatible(pctlb) );
461 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
462 scatters.push_back(make_shared<ScatT>(subtract(*pctla.analysisObjects()[i].first,
463 *pctlb.analysisObjects()[i].first)));
464 ret.add(pctla, scatters);
468 template <
typename T>
469 Percentile<typename ReferenceTraits<T>::RefT>
470 multiply(
const Percentile<T> pctla,
471 const Percentile<
typename ReferenceTraits<T>::RefT> pctlb) {
472 typedef typename ReferenceTraits<T>::RefT ScatT;
473 Percentile<ScatT> ret;
474 vector<typename ScatT::Ptr> scatters;
475 assert( pctla.compatible(pctlb) );
476 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
477 scatters.push_back(make_shared<ScatT>(multiply(*pctla.analysisObjects()[i].first,
478 *pctlb.analysisObjects()[i].first)));
479 ret.add(pctla, scatters);
483 template <
typename T>
484 Percentile<typename ReferenceTraits<T>::RefT>
485 multiply(
const Percentile<
typename ReferenceTraits<T>::RefT> pctla,
486 const Percentile<T> pctlb) {
487 typedef typename ReferenceTraits<T>::RefT ScatT;
488 Percentile<ScatT> ret;
489 vector<typename ScatT::Ptr> scatters;
490 assert( pctla.compatible(pctlb) );
491 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
492 scatters.push_back(make_shared<ScatT>(multiply(*pctla.analysisObjects()[i].first,
493 *pctlb.analysisObjects()[i].first)));
494 ret.add(pctla, scatters);
500 template <
typename T>
501 PercentileXaxis<typename ReferenceTraits<T>::RefT>
502 divide(
const PercentileXaxis<T> numer,
const PercentileXaxis<T> denom) {
503 typedef typename ReferenceTraits<T>::RefT ScatT;
504 PercentileXaxis<ScatT> ret;
505 vector<typename ScatT::Ptr> scatters;
506 assert( numer.compatible(denom) );
507 for (
int i = 0, N = numer.analysisObjects().size(); i < N; ++i )
508 scatters.push_back(make_shared<ScatT>(divide(*numer.analysisObjects()[i].first,
509 *denom.analysisObjects()[i].first)));
510 ret.add(numer, scatters);
514 template <
typename T>
515 PercentileXaxis<typename ReferenceTraits<T>::RefT>
516 divide(
const PercentileXaxis<T> numer,
517 const PercentileXaxis<
typename ReferenceTraits<T>::RefT> denom) {
518 typedef typename ReferenceTraits<T>::RefT ScatT;
519 PercentileXaxis<ScatT> ret;
520 vector<typename ScatT::Ptr> scatters;
521 assert( numer.compatible(denom) );
522 for (
int i = 0, N = numer.analysisObjects().size(); i < N; ++i )
523 scatters.push_back(make_shared<ScatT>(divide(*numer.analysisObjects()[i].first,
524 *denom.analysisObjects()[i].first)));
525 ret.add(numer, scatters);
529 template <
typename T>
530 PercentileXaxis<typename ReferenceTraits<T>::RefT>
531 divide(
const PercentileXaxis<
typename ReferenceTraits<T>::RefT> numer,
532 const PercentileXaxis<T> denom) {
533 typedef typename ReferenceTraits<T>::RefT ScatT;
534 PercentileXaxis<typename ReferenceTraits<T>::RefT> ret;
535 vector<typename ScatT::Ptr> scatters;
536 assert( numer.compatible(denom) );
537 for (
int i = 0, N = numer.analysisObjects().size(); i < N; ++i )
538 scatters.push_back(make_shared<ScatT>(divide(*numer.analysisObjects()[i].first,
539 *denom.analysisObjects()[i].first)));
540 ret.add(numer, scatters);
544 template <
typename T>
545 PercentileXaxis<T> add(
const PercentileXaxis<T> pctla,
const PercentileXaxis<T> pctlb) {
546 PercentileXaxis<T> ret;
547 vector<typename T::Ptr> aos;
548 assert( pctla.compatible(pctlb) );
549 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
550 aos.push_back(make_shared<T>(add(*pctla.analysisObjects()[i].first,
551 *pctlb.analysisObjects()[i].first)));
556 template <
typename T>
557 PercentileXaxis<typename ReferenceTraits<T>::RefT>
558 add(
const PercentileXaxis<T> pctla,
559 const PercentileXaxis<
typename ReferenceTraits<T>::RefT> pctlb) {
560 typedef typename ReferenceTraits<T>::RefT ScatT;
561 PercentileXaxis<ScatT> ret;
562 vector<typename ScatT::Ptr> scatters;
563 assert( pctla.compatible(pctlb) );
564 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
565 scatters.push_back(make_shared<ScatT>(add(*pctla.analysisObjects()[i].first,
566 *pctlb.analysisObjects()[i].first)));
567 ret.add(pctla, scatters);
571 template <
typename T>
572 PercentileXaxis<typename ReferenceTraits<T>::RefT>
573 add(
const PercentileXaxis<
typename ReferenceTraits<T>::RefT> pctla,
574 const PercentileXaxis<T> pctlb) {
575 typedef typename ReferenceTraits<T>::RefT ScatT;
576 PercentileXaxis<ScatT> ret;
577 vector<typename ScatT::Ptr> scatters;
578 assert( pctla.compatible(pctlb) );
579 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
580 scatters.push_back(make_shared<ScatT>(add(*pctla.analysisObjects()[i].first,
581 *pctlb.analysisObjects()[i].first)));
582 ret.add(pctla, scatters);
586 template <
typename T>
587 PercentileXaxis<T> subtract(
const PercentileXaxis<T> pctla,
const PercentileXaxis<T> pctlb) {
588 PercentileXaxis<T> ret;
589 vector<typename T::Ptr> aos;
590 assert( pctla.compatible(pctlb) );
591 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
592 aos.push_back(make_shared<T>(subtract(*pctla.analysisObjects()[i].first,
593 *pctlb.analysisObjects()[i].first)));
598 template <
typename T>
599 PercentileXaxis<typename ReferenceTraits<T>::RefT>
600 subtract(
const PercentileXaxis<T> pctla,
601 const PercentileXaxis<
typename ReferenceTraits<T>::RefT> pctlb) {
602 typedef typename ReferenceTraits<T>::RefT ScatT;
603 PercentileXaxis<ScatT> ret;
604 vector<typename ScatT::Ptr> scatters;
605 assert( pctla.compatible(pctlb) );
606 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
607 scatters.push_back(make_shared<ScatT>(subtract(*pctla.analysisObjects()[i].first,
608 *pctlb.analysisObjects()[i].first)));
609 ret.add(pctla, scatters);
613 template <
typename T>
614 PercentileXaxis<typename ReferenceTraits<T>::RefT>
615 subtract(
const PercentileXaxis<
typename ReferenceTraits<T>::RefT> pctla,
616 const PercentileXaxis<T> pctlb) {
617 typedef typename ReferenceTraits<T>::RefT ScatT;
618 PercentileXaxis<ScatT> ret;
619 vector<typename ScatT::Ptr> scatters;
620 assert( pctla.compatible(pctlb) );
621 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
622 scatters.push_back(make_shared<ScatT>(subtract(*pctla.analysisObjects()[i].first,
623 *pctlb.analysisObjects()[i].first)));
624 ret.add(pctla, scatters);
628 template <
typename T>
629 PercentileXaxis<typename ReferenceTraits<T>::RefT>
630 multiply(
const PercentileXaxis<T> pctla,
631 const PercentileXaxis<
typename ReferenceTraits<T>::RefT> pctlb) {
632 typedef typename ReferenceTraits<T>::RefT ScatT;
633 PercentileXaxis<ScatT> ret;
634 vector<typename ScatT::Ptr> scatters;
635 assert( pctla.compatible(pctlb) );
636 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
637 scatters.push_back(make_shared<ScatT>(multiply(*pctla.analysisObjects()[i].first,
638 *pctlb.analysisObjects()[i].first)));
639 ret.add(pctla, scatters);
643 template <
typename T>
644 PercentileXaxis<typename ReferenceTraits<T>::RefT>
645 multiply(
const PercentileXaxis<
typename ReferenceTraits<T>::RefT> pctla,
646 const PercentileXaxis<T> pctlb) {
647 typedef typename ReferenceTraits<T>::RefT ScatT;
648 PercentileXaxis<ScatT> ret;
649 vector<typename ScatT::Ptr> scatters;
650 assert( pctla.compatible(pctlb) );
651 for (
int i = 0, N = pctla.analysisObjects().size(); i < N; ++i )
652 scatters.push_back(make_shared<ScatT>(multiply(*pctla.analysisObjects()[i].first,
653 *pctlb.analysisObjects()[i].first)));
654 ret.add(pctla, scatters);
658 template <
typename T>
660 operator+(
const Percentile<T> pctla,
const Percentile<T> pctlb) {
661 return add(pctla, pctlb);
664 template <
typename T>
666 operator-(
const Percentile<T> pctla,
const Percentile<T> pctlb) {
667 return subtract(pctla, pctlb);
670 template <
typename T>
671 Percentile<typename ReferenceTraits<T>::RefT>
672 operator/(
const Percentile<T> numer,
const Percentile<T> denom) {
673 return divide(numer, denom);
676 template <
typename T>
678 operator+(
const PercentileXaxis<T> pctla,
const PercentileXaxis<T> pctlb) {
679 return add(pctla, pctlb);
682 template <
typename T>
684 operator-(
const PercentileXaxis<T> pctla,
const PercentileXaxis<T> pctlb) {
685 return subtract(pctla, pctlb);
688 template <
typename T>
689 PercentileXaxis<typename ReferenceTraits<T>::RefT>
690 operator/(
const PercentileXaxis<T> numer,
const PercentileXaxis<T> denom) {
691 return divide(numer, denom);
This is the base class of all analysis classes in Rivet.
Definition Analysis.hh:69
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
Definition RivetYODA.hh:1330
PercentileBase is the base class of all Percentile classes.
Definition Percentile.hh:19
void selectBins(const Event &)
Initialize the PercentileBase for a new event.
static bool inRange(double x, pair< float, float > range)
Helper function to check if x is within range.
Definition Percentile.hh:41
PercentileBase(Analysis *ana, string projName)
Constructor.
Definition Percentile.hh:27
bool compatible(const PercentileBase &other) const
check if other PercentileBase is compatible with this.
Definition Percentile.hh:53
void copyFrom(const PercentileBase &other)
Copy information from other PercentileBase.
Definition Percentile.hh:46
const vector< pair< float, float > > & centralities() const
return the list of centrality bins.
Definition Percentile.hh:63
PercentileBase()
Default constructor.
Definition Percentile.hh:31
PercentileTBase is the base class of all Percentile classes.
Definition Percentile.hh:93
const vector< pair< TPtr, CounterPtr > > & analysisObjects() const
Access the underlyng AnalysisObjects.
Definition Percentile.hh:177
void normalizePerEvent()
Normalize each AnalysisObject.
Definition Percentile.hh:155
bool init(const Event &event)
Initialize for a new event. Select which AnalysisObjects should be filled for this event....
Definition Percentile.hh:144
bool add(const PercentileBase &other, const vector< TPtr > &tv)
Copy the information from an other Percentile object.
Definition Percentile.hh:133
~PercentileTBase()
Empty destructor.
Definition Percentile.hh:111
void scale(float scale)
Simple scaling of each AnalysisObject.
Definition Percentile.hh:162
void add(TPtr ao, CounterPtr cnt, pair< float, float > cent={0.0, 100.0})
Add a new percentile bin.
Definition Percentile.hh:122
void exec(function< void(T &)> f)
Execute a function for each AnalysisObject.
Definition Percentile.hh:168
PercentileTBase(Analysis *ana, string projName)
Main constructor.
Definition Percentile.hh:104
PercentileTBase()
Default constructor.
Definition Percentile.hh:108
The PercentileXaxis class for centrality binning.
Definition Percentile.hh:277
PercentileXaxis< T > & operator-=(const PercentileXaxis< T > &rhs)
Subtract the contents from another PercentileXaxis.
Definition Percentile.hh:310
void fill(Args... args)
Definition Percentile.hh:303
PercentileXaxis< T > & operator+=(const PercentileXaxis< T > &rhs)
Add the contents from another PercentileXaxis.
Definition Percentile.hh:318
PercentileXaxis(Analysis *ana, string projName)
Main constructor.
Definition Percentile.hh:285
PercentileXaxis()
Default constructor.
Definition Percentile.hh:289
PercentileXaxis< T > & operator->*(function< void(T &)> f)
Pointer to member operator.
Definition Percentile.hh:329
~PercentileXaxis()
Empty destructor.
Definition Percentile.hh:292
PercentileXaxis< T > * operator->()
Make this object look like a pointer.
Definition Percentile.hh:326
The Percentile class for centrality binning.
Definition Percentile.hh:203
void fill(Args... args)
Definition Percentile.hh:229
Percentile< T > & operator->*(function< void(T &)> f)
Pointer to member operator.
Definition Percentile.hh:256
Percentile< T > & operator-=(const Percentile< T > &rhs)
Subtract the contents fro another Pecentile.
Definition Percentile.hh:236
~Percentile()
Empty destructor.
Definition Percentile.hh:218
Percentile< T > & operator+=(const Percentile< T > &rhs)
Add the contents fro another Pecentile.
Definition Percentile.hh:244
Percentile(Analysis *ana, string projName)
Main constructor.
Definition Percentile.hh:211
Percentile()
Default constructor.
Definition Percentile.hh:215
Percentile< T > * operator->()
Make this object look like a pointer.
Definition Percentile.hh:253
Definition MC_CENT_PPB_Projections.hh:10