rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.2
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
115 std::valarray<double> weights() const;
116
118 std::vector<std::pair<double, double>> crossSections() const;
119
121
124
138 template <typename PROJ>
139 const PROJ& applyProjection(PROJ& p) const {
140 static bool docaching = getEnvParam("RIVET_CACHE_PROJECTIONS", true);
141 if (docaching) {
142 MSG_TRACE("Applying projection " << &p << " (" << p.name() << ") -> comparing to projections " << _projections);
143 // First search for this projection *or an equivalent* in the already-executed list
144 const Projection* cpp(&p);
146 // std::set<const Projection*>::const_iterator old = _projections.find(cpp);
147 std::set<const Projection*>::const_iterator old = std::begin(_projections);
148 std::uintptr_t recpp = reinterpret_cast<std::uintptr_t>(cpp);
149 for (; old != _projections.end(); ++old)
150 if (reinterpret_cast<std::uintptr_t>(*old) == recpp) break;
151 if (old != _projections.end()) {
152 MSG_TRACE("Equivalent projection found -> returning already-run projection " << *old);
153 const Projection& pRef = **old;
154 return pcast<PROJ>(pRef);
155 }
156 MSG_TRACE("No equivalent projection in the already-run list -> projecting now");
157 } else {
158 MSG_TRACE("Applying projection " << &p << " (" << p.name() << ") WITHOUT projection caching & comparison");
159 }
160 // If this one hasn't been run yet on this event, run it and add to the list
161 Projection* pp = const_cast<Projection*>(&p);
162 pp->_isValid = true;
163 pp->project(*this);
164 if (docaching) _projections.insert(pp);
165 return p;
166 }
167
168
170 template <typename PROJ>
171 const PROJ& applyProjection(PROJ* pp) const {
172 if (!pp) throw Error("Event::applyProjection(PROJ*): Projection pointer is null.");
173 return applyProjection(*pp);
174 }
175
177
178
179 private:
180
182 void _fixGenEvent();
183
185 Log& getLog() const;
186
187
188 // /// @brief Remove uninteresting or unphysical particles in the
189 // /// GenEvent to speed up searches
190 // ///
191 // /// @todo Remove!
192 // void _strip(GenEvent& ge);
193
194 // /// @brief Convert the GenEvent to use conventional alignment
195 // ///
196 // /// For example, FHerwig only produces DIS events in the unconventional
197 // /// hadron-lepton orientation and has to be corrected for DIS analysis
198 // /// portability.
199 // void _geNormAlignment();
200
205 const std::vector<size_t> _weightIndices;
206
208 const GenEvent& _genevent;
209
213 mutable Particles _particles;
214
216 mutable std::set<ConstProjectionPtr> _projections;
217
219 mutable std::valarray<double> _weights;
220
222 mutable std::vector<std::pair<double,double>> _xsecs;
223 };
224
225
226}
227
228#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:139
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:171
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:152
#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:61