rivet is hosted by Hepforge, IPPP Durham
Rivet 4.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
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 {
38 if (!ge) throw UserError("User provided a null GenEvent pointer for analysis");
39 // if (strip) _strip(_genevent);
40 _fixGenEvent();
41 }
42
49 Event(GenEvent& ge, const vector<size_t>& weightindices={}) //, bool strip=false)
50 : _weightIndices(weightindices), _genevent(ge)
51 {
52 // if (strip) _strip(_genevent);
53 _fixGenEvent();
54 }
55
57 Event(const Event& e)
58 : _weightIndices(e._weightIndices),
59 _genevent(e._genevent) { }
60
62
63
66
68 const GenEvent& hepmcEvent() const { return _genevent; }
69 // /// @brief The generated HepMC event obtained from an external event generator
70 // ///
71 // /// Convenience alias for hepmcEventPtr()
72 // const GenEvent& hepmc() const { return _genevent; }
73
75 const GenEvent* hepmcEventPtr() const { return &_genevent; }
79 const GenEvent* genEvent() const { return &_genevent; }
80
83
85 double sqrtS() const;
86
88 double asqrtS() const;
89
91
92
95
97 const Particles& allParticles() const;
98
102 inline Particles allParticles(const Cut& c) const {
103 return select(allParticles(), c);
104 }
105
109 template <typename FN>
110 inline Particles allParticles(const FN& f) const {
111 return select(allParticles(), f);
112 }
113
121 std::valarray<double> weights() const;
122
130 std::vector<std::pair<double, double>> crossSections() const;
131
133
136
150 template <typename PROJ>
151 const PROJ& applyProjection(PROJ& p) const {
152 static bool docaching = getEnvParam("RIVET_CACHE_PROJECTIONS", true);
153 if (docaching) {
154 MSG_TRACE("Applying projection " << &p << " (" << p.name() << ") -> comparing to projections " << _projections);
155 // First search for this projection *or an equivalent* in the already-executed list
156 const Projection* cpp(&p);
158 // std::set<const Projection*>::const_iterator old = _projections.find(cpp);
159 std::set<const Projection*>::const_iterator old = std::begin(_projections);
160 std::uintptr_t recpp = reinterpret_cast<std::uintptr_t>(cpp);
161 for (; old != _projections.end(); ++old)
162 if (reinterpret_cast<std::uintptr_t>(*old) == recpp) break;
163 if (old != _projections.end()) {
164 MSG_TRACE("Equivalent projection found -> returning already-run projection " << *old);
165 const Projection& pRef = **old;
166 return pcast<PROJ>(pRef);
167 }
168 MSG_TRACE("No equivalent projection in the already-run list -> projecting now");
169 } else {
170 MSG_TRACE("Applying projection " << &p << " (" << p.name() << ") WITHOUT projection caching & comparison");
171 }
172 // If this one hasn't been run yet on this event, run it and add to the list
173 Projection* pp = const_cast<Projection*>(&p);
174 pp->_isValid = true;
175 pp->project(*this);
176 if (docaching) _projections.insert(pp);
177 return p;
178 }
179
180
182 template <typename PROJ>
183 const PROJ& applyProjection(PROJ* pp) const {
184 if (!pp) throw Error("Event::applyProjection(PROJ*): Projection pointer is null.");
185 return applyProjection(*pp);
186 }
187
189
190
191 private:
192
194 void _fixGenEvent();
195
197 Log& getLog() const;
198
199
200 // /// @brief Remove uninteresting or unphysical particles in the
201 // /// GenEvent to speed up searches
202 // ///
203 // /// @todo Remove!
204 // void _strip(GenEvent& ge);
205
206 // /// @brief Convert the GenEvent to use conventional alignment
207 // ///
208 // /// For example, FHerwig only produces DIS events in the unconventional
209 // /// hadron-lepton orientation and has to be corrected for DIS analysis
210 // /// portability.
211 // void _geNormAlignment();
212
217 const std::vector<size_t> _weightIndices;
218
220 const GenEvent& _genevent;
221
225 mutable Particles _particles;
226
228 mutable std::set<ConstProjectionPtr> _projections;
229
231 mutable std::valarray<double> _weights;
232
234 mutable std::vector<std::pair<double,double>> _xsecs;
235 };
236
237
238}
239
240#endif
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:151
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:183
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:75
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:102
Event(const Event &e)
Copy constructor.
Definition Event.hh:57
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:110
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:79
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:68
Event(GenEvent &ge, const vector< size_t > &weightindices={})
Definition Event.hh:49
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:157
#define MSG_TRACE(x)
Lowest-level, most verbose messaging, using MSG_LVL.
Definition Logging.hh:180
T getEnvParam(const std::string name, const T &fallback)
Get a parameter from a named environment variable, with automatic type conversion.
Definition Utils.hh:847
Definition MC_CENT_PPB_Projections.hh:10
std::pair< Particle, Particle > ParticlePair
Typedef for a pair of Particle objects.
Definition Particle.hh:38
Generic runtime Rivet error.
Definition Exceptions.hh:12
Error specialisation for where the problem is between the chair and the computer.
Definition Exceptions.hh:67