Rivet  3.1.4
CentralityProjection.hh
1 // -*- C++ -*-
2 #ifndef RIVET_CENTRALITYPROJECTION_HH
3 #define RIVET_CENTRALITYPROJECTION_HH
4 
5 #include "Rivet/Projections/PercentileProjection.hh"
6 #include "Rivet/Tools/RivetYODA.hh"
7 #include <map>
8 
9 namespace Rivet {
10 
27 public:
28 
30  CentralityProjection() { setName("CentralityProjection"); }
31 
32 
33  DEFAULT_RIVET_PROJ_CLONE(CentralityProjection);
34 
35 
41  void add(const SingleValueProjection & p, string pname) {
42  _projNames.push_back(pname);
43  declare(p, pname);
44  }
45 
47  void project(const Event& e) {
48  _values.clear();
49  for ( string pname : _projNames )
50  _values.push_back(apply<SingleValueProjection>(e, pname)());
51  if ( !_values.empty() ) set(_values[0]);
52  }
53 
55  bool empty() const {
56  return _projNames.empty();
57  }
58 
62  double operator[](int i) const {
63  return _values[i];
64  }
65 
66  // Standard comparison function.
67  CmpState compare(const Projection& p) const {
68  const CentralityProjection* other = dynamic_cast<const CentralityProjection*>(&p);
69  if (other->_projNames.size() == 0) return CmpState::NEQ;
70  // cholm: This is not enough. The contained projections may be
71  // different but have the same names. We need to compare the
72  // projections directly.
73  for (string pname : _projNames) {
74  auto& proj = getProjection(pname);
75  bool hasPname = true;
76  for (string p2name : other->_projNames){
77  if (pname != p2name) hasPname = false;
78  }
79  if (!hasPname) return CmpState::NEQ;
80 
81  auto& oth = other->getProjection(pname);
82  if (proj.compare(oth) != CmpState::EQ) return CmpState::NEQ;
83  }
84  return CmpState::EQ;
85  }
86 
88  vector<string> projections() const {
89  return _projNames;
90  }
91 
92 private:
93 
95  vector<string> _projNames;
96 
98  vector<double> _values;
99 
100 };
101 
102 }
103 
104 #endif
void setName(const std::string &name)
Used by derived classes to set their name.
Definition: Projection.hh:142
bool empty() const
Cheek if no internal projections have been added.
Definition: CentralityProjection.hh:55
Definition: MC_Cent_pPb.hh:10
CmpState compare(const Projection &p) const
Definition: CentralityProjection.hh:67
Used together with the percentile-based analysis objects Percentile and PercentileXaxis.
Definition: CentralityProjection.hh:26
Base class for projections returning a single floating point value.
Definition: SingleValueProjection.hh:17
void project(const Event &e)
Perform all internal projections.
Definition: CentralityProjection.hh:47
double operator[](int i) const
Definition: CentralityProjection.hh:62
Representation of a HepMC event, and enabler of Projection caching.
Definition: Event.hh:22
CentralityProjection()
Default constructor.
Definition: CentralityProjection.hh:30
void add(const SingleValueProjection &p, string pname)
Add a new centrality estimate.
Definition: CentralityProjection.hh:41
const PROJ & getProjection(const std::string &name) const
Definition: ProjectionApplier.hh:56
const PROJ & declare(const PROJ &proj, const std::string &name)
Register a contained projection (user-facing version)
Definition: ProjectionApplier.hh:170
vector< string > projections() const
The list of names of the internal projections.
Definition: CentralityProjection.hh:88
Base class for all Rivet projections.
Definition: Projection.hh:29