Rivet  3.1.0
Event.hh
1 // -*- C++ -*-
2 #ifndef RIVET_Event_HH
3 #define RIVET_Event_HH
4 
5 #include "Rivet/Config/RivetCommon.hh"
6 #include "Rivet/Particle.hh"
7 #include "Rivet/Projection.hh"
8 
9 namespace Rivet {
10 
11 
22  class Event {
23  public:
24 
26 
27 
29  Event(const GenEvent* ge, bool strip = false)
30  : _genevent_original(ge) {
31  assert(ge);
32  _genevent = *ge;
33  if ( strip ) _strip(_genevent);
34  _init(*ge);
35  }
36 
39  Event(const GenEvent& ge, bool strip = false)
40  : _genevent_original(&ge), _genevent(ge) {
41  if ( strip ) _strip(_genevent);
42  _init(ge);
43  }
44 
46  Event(const Event& e)
47  : _genevent_original(e._genevent_original), _genevent(e._genevent)
48  { }
49 
51 
52 
54 
55 
57  const GenEvent* genEvent() const { return &_genevent; }
58 
60  const GenEvent* originalGenEvent() const { return _genevent_original; }
61 
63  ParticlePair beams() const;
64 
66  double sqrtS() const;
67 
69  double asqrtS() const;
70 
72 
73 
75 
76 
78  const Particles& allParticles() const;
79 
83  inline Particles allParticles(const Cut& c) const {
84  return filter_select(allParticles(), c);
85  }
86 
90  template <typename FN>
91  inline Particles allParticles(const FN& f) const {
92  return filter_select(allParticles(), f);
93  }
94 
99  std::valarray<double> weights() const;
100 
102  DEPRECATED("Event weight does not need to be included anymore. For compatibility, it's always == 1 now.")
103  double weight() const { return 1.0; }
105 
106 
108 
109 
123  template <typename PROJ>
124  const PROJ& applyProjection(PROJ& p) const {
125  Log& log = Log::getLog("Rivet.Event");
126  static bool docaching = getEnvParam("RIVET_CACHE_PROJECTIONS", true);
127  if (docaching) {
128  log << Log::TRACE << "Applying projection " << &p << " (" << p.name() << ") -> comparing to projections " << _projections << std::endl;
129  // First search for this projection *or an equivalent* in the already-executed list
130  const Projection* cpp(&p);
132  // std::set<const Projection*>::const_iterator old = _projections.find(cpp);
133  std::set<const Projection*>::const_iterator old = std::begin(_projections);
134  std::uintptr_t recpp = reinterpret_cast<std::uintptr_t>(cpp);
135  for (; old != _projections.end(); ++old)
136  if (reinterpret_cast<std::uintptr_t>(*old) == recpp) break;
137  if (old != _projections.end()) {
138  log << Log::TRACE << "Equivalent projection found -> returning already-run projection " << *old << std::endl;
139  const Projection& pRef = **old;
140  return pcast<PROJ>(pRef);
141  }
142  log << Log::TRACE << "No equivalent projection in the already-run list -> projecting now" << std::endl;
143  } else {
144  log << Log::TRACE << "Applying projection " << &p << " (" << p.name() << ") WITHOUT projection caching & comparison" << std::endl;
145  }
146  // If this one hasn't been run yet on this event, run it and add to the list
147  Projection* pp = const_cast<Projection*>(&p);
148  pp->_isValid = true;
149  pp->project(*this);
150  if (docaching) _projections.insert(pp);
151  return p;
152  }
153 
154 
156  template <typename PROJ>
157  const PROJ& applyProjection(PROJ* pp) const {
158  if (!pp) throw Error("Event::applyProjection(PROJ*): Projection pointer is null.");
159  return applyProjection(*pp);
160  }
161 
163 
164 
165  private:
166 
168  void _init(const GenEvent& ge);
169 
172  void _strip(GenEvent & ge);
173 
174  // /// @brief Convert the GenEvent to use conventional alignment
175  // ///
176  // /// For example, FHerwig only produces DIS events in the unconventional
177  // /// hadron-lepton orientation and has to be corrected for DIS analysis
178  // /// portability.
179  // void _geNormAlignment();
180 
187  const GenEvent* _genevent_original;
188 
198  mutable GenEvent _genevent;
199 
202  mutable Particles _particles;
203 
205  mutable std::set<ConstProjectionPtr> _projections;
206 
207  };
208 
209 
210 }
211 
212 #endif
const GenEvent * originalGenEvent() const
The generated event obtained from an external event generator.
Definition: Event.hh:60
Particles allParticles(const FN &f) const
All the raw GenEvent particles, wrapped in Rivet::Particle objects, but with a selection function app...
Definition: Event.hh:91
Definition: MC_Cent_pPb.hh:10
T getEnvParam(const std::string name, const T &fallback)
Get a parameter from a named environment variable, with automatic type conversion.
Definition: Utils.hh:655
double asqrtS() const
Get the beam centre-of-mass energy per nucleon.
const Particles & allParticles() const
All the raw GenEvent particles, wrapped in Rivet::Particle objects.
static Log & getLog(const std::string &name)
Jets filter_select(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Definition: JetUtils.hh:160
Particles allParticles(const Cut &c) const
All the raw GenEvent particles, wrapped in Rivet::Particle objects, but with a Cut applied...
Definition: Event.hh:83
const PROJ & applyProjection(PROJ *pp) const
Add a projection p to this Event by pointer.
Definition: Event.hh:157
Event(const GenEvent *ge, bool strip=false)
Constructor from a HepMC GenEvent pointer.
Definition: Event.hh:29
ParticlePair beams() const
Get the beam particles.
const GenEvent * genEvent() const
The generated event obtained from an external event generator.
Definition: Event.hh:57
Logging system for controlled & formatted writing to stdout.
Definition: Logging.hh:10
Generic runtime Rivet error.
Definition: Exceptions.hh:12
virtual void project(const Event &e)=0
double sqrtS() const
Get the beam centre-of-mass energy.
Representation of a HepMC event, and enabler of Projection caching.
Definition: Event.hh:22
const PROJ & applyProjection(PROJ &p) const
Add a projection p to this Event.
Definition: Event.hh:124
Event(const Event &e)
Copy constructor.
Definition: Event.hh:46
std::valarray< double > weights() const
The generation weight associated with the event.
double weight() const
Obsolete weight method. Always returns 1 now.
Definition: Event.hh:103
Event(const GenEvent &ge, bool strip=false)
Definition: Event.hh:39
Base class for all Rivet projections.
Definition: Projection.hh:29