Rivet API documentation

Rivet 4.1.3
Event.hh
1// -*- C++ -*-
2#ifndef RIVET_Event_HH
3#define RIVET_Event_HH
4
5#include "Rivet/Particle.hh"
6#include "Rivet/Projection.hh"
7#include "Rivet/Config/RivetCommon.hh"
8
9namespace Rivet {
10
11
22 class Event {
23 public:
24
27
35 Event(GenEvent* ge, const vector<size_t>& weightindices = {}) //, bool strip=false)
36 : _weightIndices(weightindices), _genevent(*ge) {
37 if (!ge) throw UserError("User provided a null GenEvent pointer for analysis");
38 // if (strip) _strip(_genevent);
39 _fixGenEvent();
40 }
41
48 Event(GenEvent& ge, const vector<size_t>& weightindices = {}) //, bool strip=false)
49 : _weightIndices(weightindices), _genevent(ge) {
50 // if (strip) _strip(_genevent);
51 _fixGenEvent();
52 }
53
55 Event(const Event& e)
56 : _weightIndices(e._weightIndices), _genevent(e._genevent) { }
57
59
60
63
65 const GenEvent& hepmcEvent() const {
66 return _genevent;
67 }
68 // /// @brief The generated HepMC event obtained from an external event generator
69 // ///
70 // /// Convenience alias for hepmcEventPtr()
71 // const GenEvent& hepmc() const { return _genevent; }
72
74 const GenEvent* hepmcEventPtr() const {
75 return &_genevent;
76 }
77
80 const GenEvent* genEvent() const {
81 return &_genevent;
82 }
83
86
88 double sqrtS() const;
89
91 double asqrtS() const;
92
94
95
98
100 const Particles& allParticles() const;
101
105 inline Particles allParticles(const Cut& c) const {
106 return select(allParticles(), c);
107 }
108
112 template <typename FN>
113 inline Particles allParticles(const FN& f) const {
114 return select(allParticles(), f);
115 }
116
124 std::valarray<double> weights() const;
125
133 std::vector<std::pair<double, double>> crossSections() const;
134
136
139
153 template <typename PROJ>
154 const PROJ& applyProjection(PROJ& p) const {
155 static bool docaching = getEnvParam("RIVET_CACHE_PROJECTIONS", true);
156 if (docaching) {
157 MSG_TRACE("Applying projection " << &p << " (" << p.name() << ") -> comparing to projections "
158 << _projections);
159 // First search for this projection *or an equivalent* in the already-executed list
160 const Projection* cpp(&p);
162 // std::set<const Projection*>::const_iterator old = _projections.find(cpp);
163 std::set<const Projection*>::const_iterator old = std::begin(_projections);
164 std::uintptr_t recpp = reinterpret_cast<std::uintptr_t>(cpp);
165 for (; old != _projections.end(); ++old)
166 if (reinterpret_cast<std::uintptr_t>(*old) == recpp) break;
167 if (old != _projections.end()) {
168 MSG_TRACE("Equivalent projection found -> returning already-run projection " << *old);
169 const Projection& pRef = **old;
170 return pcast<PROJ>(pRef);
171 }
172 MSG_TRACE("No equivalent projection in the already-run list -> projecting now");
173 }
174 else {
175 MSG_TRACE("Applying projection " << &p << " (" << p.name()
176 << ") WITHOUT projection caching & comparison");
177 }
178 // If this one hasn't been run yet on this event, run it and add to the list
179 Projection* pp = const_cast<Projection*>(&p);
180 pp->_isValid = true;
181 pp->project(*this);
182 if (docaching) _projections.insert(pp);
183 return p;
184 }
185
186
188 template <typename PROJ>
189 const PROJ& applyProjection(PROJ* pp) const {
190 if (!pp) throw Error("Event::applyProjection(PROJ*): Projection pointer is null.");
191 return applyProjection(*pp);
192 }
193
195
196
197 private:
198
200 void _fixGenEvent();
201
203 Log& getLog() const;
204
205
206 // /// @brief Remove uninteresting or unphysical particles in the
207 // /// GenEvent to speed up searches
208 // ///
209 // /// @todo Remove!
210 // void _strip(GenEvent& ge);
211
212 // /// @brief Convert the GenEvent to use conventional alignment
213 // ///
214 // /// For example, FHerwig only produces DIS events in the unconventional
215 // /// hadron-lepton orientation and has to be corrected for DIS analysis
216 // /// portability.
217 // void _geNormAlignment();
218
223 const std::vector<size_t> _weightIndices;
224
226 const GenEvent& _genevent;
227
231 mutable Particles _particles;
232
234 mutable std::set<ConstProjectionPtr> _projections;
235
237 mutable std::valarray<double> _weights;
238
240 mutable std::vector<std::pair<double, double>> _xsecs;
241 };
242
243
244}
245
246#endif
const PROJ & applyProjection(PROJ &p) const
Add a projection p to this Event.
Definition Event.hh:154
Event(GenEvent *ge, const vector< size_t > &weightindices={})
Definition Event.hh:35
const PROJ & applyProjection(PROJ *pp) const
Add a projection p to this Event by pointer.
Definition Event.hh:189
double asqrtS() const
Get the beam centre-of-mass energy per nucleon.
const GenEvent * hepmcEventPtr() const
The generated HepMC event pointer obtained from an external event generator.
Definition Event.hh:74
double sqrtS() const
Get the beam centre-of-mass energy.
Particles allParticles(const Cut &c) const
All the raw GenEvent particles, wrapped in Rivet::Particle objects, but with a Cut applied.
Definition Event.hh:105
Event(const Event &e)
Copy constructor.
Definition Event.hh:55
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:113
const Particles & allParticles() const
All the raw GenEvent particles, wrapped in Rivet::Particle objects.
const GenEvent * genEvent() const
The generated HepMC event pointer obtained from an external event generator.
Definition Event.hh:80
std::valarray< double > weights() const
The generation weights associated with the event.
const GenEvent & hepmcEvent() const
The generated HepMC event obtained from an external event generator.
Definition Event.hh:65
Event(GenEvent &ge, const vector< size_t > &weightindices={})
Definition Event.hh:48
std::vector< std::pair< double, double > > crossSections() const
The generation cross-sections associated with the event.
ParticlePair beams() const
Get the beam particles.
Logging system for controlled & formatted writing to stdout.
Definition Logging.hh:10
Specialised vector of Particle objects.
Definition Particle.hh:21
Base class for all Rivet projections.
Definition Projection.hh:29
virtual void project(const Event &e)=0
Jets select(const Jets &jets, const Cut &c)
Filter a jet collection in-place to the subset that passes the supplied Cut.
Definition JetUtils.hh:183
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:193
double p(const ParticleBase &p)
Unbound function access to p.
Definition ParticleBaseUtils.hh:819
T getEnvParam(const std::string name, const T &fallback)
Get a parameter from a named environment variable, with automatic type conversion.
Definition Utils.hh:921
Definition LHCbCommon.hh:9
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition Particle.hh:43
Generic runtime Rivet error.
Definition Exceptions.hh:12
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:75