File indexing completed on 2025-04-19 09:06:48
0001
0002 #ifndef RIVET_CENTRALITYPROJECTION_HH
0003 #define RIVET_CENTRALITYPROJECTION_HH
0004
0005 #include "Rivet/Projections/PercentileProjection.hh"
0006 #include "Rivet/Tools/RivetYODA.hh"
0007 #include <map>
0008
0009 namespace Rivet {
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 class CentralityProjection: public SingleValueProjection {
0028 public:
0029
0030 using SingleValueProjection::operator=;
0031
0032
0033 CentralityProjection() { setName("CentralityProjection"); }
0034
0035
0036 RIVET_DEFAULT_PROJ_CLONE(CentralityProjection);
0037
0038
0039
0040 using Projection::operator =;
0041
0042
0043
0044
0045
0046
0047
0048 void add(const SingleValueProjection & p, string pname) {
0049 _projNames.push_back(pname);
0050 declare(p, pname);
0051 }
0052
0053
0054 void project(const Event& e) {
0055 _values.clear();
0056 for ( string pname : _projNames )
0057 _values.push_back(apply<SingleValueProjection>(e, pname)());
0058 if ( !_values.empty() ) setValue(_values[0]);
0059 }
0060
0061
0062 bool empty() const {
0063 return _projNames.empty();
0064 }
0065
0066
0067
0068
0069 double operator[](int i) const {
0070 return _values[i];
0071 }
0072
0073
0074 CmpState compare(const Projection& p) const {
0075 const CentralityProjection* other = dynamic_cast<const CentralityProjection*>(&p);
0076 if (other->_projNames.size() == 0) return CmpState::NEQ;
0077
0078
0079
0080 for (string pname : _projNames) {
0081 auto& proj = getProjection(pname);
0082 bool hasPname = true;
0083 for (string p2name : other->_projNames){
0084 if (pname != p2name) hasPname = false;
0085 }
0086 if (!hasPname) return CmpState::NEQ;
0087
0088 auto& oth = other->getProjection(pname);
0089 if (proj.compare(oth) != CmpState::EQ) return CmpState::NEQ;
0090 }
0091 return CmpState::EQ;
0092 }
0093
0094
0095 vector<string> projections() const {
0096 return _projNames;
0097 }
0098
0099
0100 protected:
0101
0102
0103 vector<string> _projNames;
0104
0105
0106 vector<double> _values;
0107
0108 };
0109
0110
0111 }
0112
0113 #endif