Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:06:48

0001 // -*- C++ -*-
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   /// @brief Used together with the percentile-based analysis objects Percentile and PercentileXaxis
0013   ///
0014   /// The interior actually defines several different centrality
0015   /// estimates: the centrality observable used in the experiment with a
0016   /// reference calibration ("REF"); the same but using a user-defined
0017   /// calibration done with the corresponding minimum bias analysis
0018   /// ("GEN"); a centrality based on the impact parameter reported in
0019   /// HepMC::HeavyIon::impact_parameter, using a calibration histogram
0020   /// generated with the same minimum bias analysis ("IMP"). For HepMC3
0021   /// it may optionally also include a direct report from the generator
0022   /// about the centrality, if available in HepMC::HeavyIon::centrality
0023   /// ("RAW"), and a user-defined generated centrality estimate
0024   /// communicated via the HepMC::HeavyIon::user_cent_estimate ("USR").
0025   ///
0026   /// @author Leif Lönnblad
0027   class CentralityProjection: public SingleValueProjection {
0028   public:
0029 
0030     using SingleValueProjection::operator=;
0031 
0032     /// Default constructor
0033     CentralityProjection() { setName("CentralityProjection"); }
0034 
0035 
0036     RIVET_DEFAULT_PROJ_CLONE(CentralityProjection);
0037 
0038 
0039     /// Import to avoid warnings about overload-hiding
0040     using Projection::operator =;
0041 
0042 
0043     /// @brief Add a new centrality estimate.
0044     ///
0045     /// The SingleValueProjection, @a p, should return a value between 0
0046     /// and 100, and the @a pname should be one of "REF", "GEN", "IMP",
0047     /// "USR", or "RAW", as described above.
0048     void add(const SingleValueProjection & p, string pname) {
0049       _projNames.push_back(pname);
0050       declare(p, pname);
0051     }
0052 
0053     /// Perform all internal projections.
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     /// Cheek if no internal projections have been added.
0062     bool empty() const {
0063       return _projNames.empty();
0064     }
0065 
0066     /// Return the percentile of the @a i'th projection.
0067     ///
0068     /// Note that operator() will return the zero'th projection.
0069     double operator[](int i) const {
0070       return _values[i];
0071     }
0072 
0073     // Standard comparison function.
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       // cholm: This is not enough.  The contained projections may be
0078       // different but have the same names.  We need to compare the
0079       // projections directly.
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     /// The list of names of the internal projections.
0095     vector<string> projections() const {
0096       return _projNames;
0097     }
0098 
0099 
0100   protected:
0101 
0102     /// The list of names of the internal projections.
0103     vector<string> _projNames;
0104 
0105     /// The list of percentiles resulting from the last projection.
0106     vector<double> _values;
0107 
0108   };
0109 
0110 
0111 }
0112 
0113 #endif