Rivet: /Users/chrisg/software/rivet/include/Rivet/Event.hh Source File

| Rivet 3.1.9

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
9namespace Rivet {
10
11
22 class Event {
23 public:
24
26
27
29 Event(const GenEvent* ge, const vector<size_t>& indices = {}, bool strip = false)
30 : _weightIndices(indices), _genevent_original(ge) {
31 assert(ge);
32 _genevent = *ge;
33 if ( strip ) _strip(_genevent);
34 _init(*ge);
35 }
36
39 Event(const GenEvent& ge, const vector<size_t>& indices = {}, bool strip = false)
40 : _weightIndices(indices), _genevent_original(&ge), _genevent(ge) {
41 if ( strip ) _strip(_genevent);
42 _init(ge);
43 }
44
46 Event(const Event& e)
47 : _weightIndices(e._weightIndices),
48 _genevent_original(e._genevent_original),
49 _genevent(e._genevent) { }
50
52
53
55
56
58 const GenEvent* genEvent() const { return &_genevent; }
59
61 const GenEvent* originalGenEvent() const { return _genevent_original; }
62
64 ParticlePair beams() const;
65
67 double sqrtS() const;
68
70 double asqrtS() const;
71
73
74
76
77
79 const Particles& allParticles() const;
80
84 inline Particles allParticles(const Cut& c) const {
85 return filter_select(allParticles(), c);
86 }
87
91 template <typename FN>
92 inline Particles allParticles(const FN& f) const {
93 return filter_select(allParticles(), f);
94 }
95
97 std::valarray<double> weights() const;
98
100 std::vector<std::pair<double, double>> crossSections() const;
101
103 DEPRECATED("Event weight does not need to be included anymore. For compatibility, it's always == 1 now.")
104 double weight() const { return 1.0; }
106
108
109
123 template <typename PROJ>
124 const PROJ& applyProjection(PROJ& p) const {
125 static bool docaching = getEnvParam("RIVET_CACHE_PROJECTIONS", true);
126 if (docaching) {
127 MSG_TRACE("Applying projection " << &p << " (" << p.name() << ") -> comparing to projections " << _projections);
128 // First search for this projection *or an equivalent* in the already-executed list
129 const Projection* cpp(&p);
131 // std::set<const Projection*>::const_iterator old = _projections.find(cpp);
132 std::set<const Projection*>::const_iterator old = std::begin(_projections);
133 std::uintptr_t recpp = reinterpret_cast<std::uintptr_t>(cpp);
134 for (; old != _projections.end(); ++old)
135 if (reinterpret_cast<std::uintptr_t>(*old) == recpp) break;
136 if (old != _projections.end()) {
137 MSG_TRACE("Equivalent projection found -> returning already-run projection " << *old);
138 const Projection& pRef = **old;
139 return pcast<PROJ>(pRef);
140 }
141 MSG_TRACE("No equivalent projection in the already-run list -> projecting now");
142 } else {
143 MSG_TRACE("Applying projection " << &p << " (" << p.name() << ") WITHOUT projection caching & comparison");
144 }
145 // If this one hasn't been run yet on this event, run it and add to the list
146 Projection* pp = const_cast<Projection*>(&p);
147 pp->_isValid = true;
148 pp->project(*this);
149 if (docaching) _projections.insert(pp);
150 return p;
151 }
152
153
155 template <typename PROJ>
156 const PROJ& applyProjection(PROJ* pp) const {
157 if (!pp) throw Error("Event::applyProjection(PROJ*): Projection pointer is null.");
158 return applyProjection(*pp);
159 }
160
162
163
164 private:
165
167 Log& getLog() const;
168
170 void _init(const GenEvent& ge);
171
174 void _strip(GenEvent & ge);
175
176 // /// @brief Convert the GenEvent to use conventional alignment
177 // ///
178 // /// For example, FHerwig only produces DIS events in the unconventional
179 // /// hadron-lepton orientation and has to be corrected for DIS analysis
180 // /// portability.
181 // void _geNormAlignment();
182
187 const std::vector<size_t> _weightIndices;
188
195 const GenEvent* _genevent_original;
196
206 mutable GenEvent _genevent;
207
210 mutable Particles _particles;
211
213 mutable std::set<ConstProjectionPtr> _projections;
214
216 mutable std::valarray<double> _weights;
217
219 mutable std::vector<std::pair<double,double>> _xsecs;
220 };
221
222
223}
224
225#endif
Rivet::Event
Representation of a HepMC event, and enabler of Projection caching.
Definition Event.hh:22
Rivet::Event::applyProjection
const PROJ & applyProjection(PROJ &p) const
Add a projection p to this Event.
Definition Event.hh:124
Rivet::Event::applyProjection
const PROJ & applyProjection(PROJ *pp) const
Add a projection p to this Event by pointer.
Definition Event.hh:156
Rivet::Event::weight
double weight() const
Obsolete weight method. Always returns 1 now.
Definition Event.hh:104
Rivet::Event::asqrtS
double asqrtS() const
Get the beam centre-of-mass energy per nucleon.
Rivet::Event::Event
Event(const GenEvent &ge, const vector< size_t > &indices={}, bool strip=false)
Definition Event.hh:39
Rivet::Event::sqrtS
double sqrtS() const
Get the beam centre-of-mass energy.
Rivet::Event::allParticles
Particles allParticles(const Cut &c) const
All the raw GenEvent particles, wrapped in Rivet::Particle objects, but with a Cut applied.
Definition Event.hh:84
Rivet::Event::Event
Event(const Event &e)
Copy constructor.
Definition Event.hh:46
Rivet::Event::allParticles
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:92
Rivet::Event::allParticles
const Particles & allParticles() const
All the raw GenEvent particles, wrapped in Rivet::Particle objects.
Rivet::Event::Event
Event(const GenEvent *ge, const vector< size_t > &indices={}, bool strip=false)
Constructor from a HepMC GenEvent pointer.
Definition Event.hh:29
Rivet::Event::originalGenEvent
const GenEvent * originalGenEvent() const
The generated event obtained from an external event generator.
Definition Event.hh:61
Rivet::Event::genEvent
const GenEvent * genEvent() const
The generated event obtained from an external event generator.
Definition Event.hh:58
Rivet::Event::weights
std::valarray< double > weights() const
The generation weights associated with the event.
Rivet::Event::crossSections
std::vector< std::pair< double, double > > crossSections() const
The generation cross-sections associated with the event.
Rivet::Event::beams
ParticlePair beams() const
Get the beam particles.
Rivet::Log
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
Rivet::Particles
Specialised vector of Particle objects.
Definition Particle.hh:25
Rivet::Projection
Base class for all Rivet projections.
Definition Projection.hh:29
Rivet::Projection::project
virtual void project(const Event &e)=0
Rivet::filter_select
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:157
MSG_TRACE
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:193
Rivet::Kin::p
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:684
Rivet::getEnvParam
T getEnvParam(const std::string name, const T &fallback)
Get a parameter from a named environment variable, with automatic type conversion.
Definition Utils.hh:815
Rivet
Definition MC_Cent_pPb.hh:10
Rivet::ParticlePair
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition Particle.hh:42
Rivet::Error
Generic runtime Rivet error.
Definition Exceptions.hh:12