MARLEY (Model of Argon Reaction Low Energy Yields)  v1.2.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Event.hh
1 //
5 // This file is part of MARLEY (Model of Argon Reaction Low Energy Yields)
6 //
7 // MARLEY is free software: you can redistribute it and/or modify it under the
8 // terms of version 3 of the GNU General Public License as published by the
9 // Free Software Foundation.
10 //
11 // For the full text of the license please see COPYING or
12 // visit http://opensource.org/licenses/GPL-3.0
13 //
14 // Please respect the MCnet academic usage guidelines. See GUIDELINES
15 // or visit https://www.montecarlonet.org/GUIDELINES for details.
16 
17 #pragma once
18 
19 // Standard library includes
20 #include <string>
21 #include <vector>
22 
23 // MARLEY includes
24 #include "marley/Parity.hh"
25 #include "marley/Particle.hh"
26 
27 namespace marley {
28 
29  #ifndef __MAKECINT__
30  // TODO: Make these into an enum at some point
32  constexpr int HEPEVT_INITIAL_STATE_STATUS_CODE = 3;
34  constexpr int HEPEVT_FINAL_STATE_STATUS_CODE = 1;
37  constexpr int HEPEVT_MARLEY_INFO_STATUS_CODE = 11;
38 
39  // Forward declare the JSON class so that we can define a function that
40  // creates a JSON representation of a Event. Hide the JSON class from
41  // rootcint so that we won't have issues using marley::Event objects with
42  // ROOT 5.
43  class JSON;
44  #endif
45 
66  class Event {
67 
68  public:
69 
71  Event(double Ex = 0.);
72 
80  Event(const marley::Particle& a,
81  const marley::Particle& b, const marley::Particle& c,
82  const marley::Particle& d, double Ex, int twoJ,
83  const marley::Parity& P);
84 
85  // Destructor
86  ~Event();
87 
89  Event(const Event& other_event);
90 
92  Event(Event&& other_event);
93 
95  Event& operator=(const Event& other_event);
96 
98  Event& operator=(Event&& other_event);
99 
101  const marley::Particle& projectile() const;
103  const marley::Particle& target() const;
105  const marley::Particle& ejectile() const;
107  const marley::Particle& residue() const;
108 
117 
119  inline const std::vector<marley::Particle*>& get_initial_particles()
120  const;
121 
123  inline std::vector<marley::Particle*>& get_initial_particles();
124 
126  inline const std::vector<marley::Particle*>& get_final_particles() const;
127 
129  inline std::vector<marley::Particle*>& get_final_particles();
130 
132  inline size_t initial_particle_count() const;
133 
135  inline size_t final_particle_count() const;
136 
142  inline const marley::Particle& initial_particle( size_t idx ) const;
143 
149  inline const marley::Particle& final_particle( size_t idx ) const;
150 
153  inline double Ex() const;
154 
157  inline int twoJ() const;
158 
161  inline marley::Parity parity() const;
162 
164  void add_initial_particle(const marley::Particle& p);
165 
167  void add_final_particle(const marley::Particle& p);
168 
183  void write_hepevt(size_t event_num, double flux_avg_tot_xsec,
184  std::ostream& out) const;
185 
188  void print(std::ostream& out) const;
189 
195  void print_human_readable(std::ostream& out, int num = -1) const;
196 
200  void read(std::istream& in);
201 
222  bool read_hepevt(std::istream& in, double* flux_avg_tot_xsec = nullptr);
223 
226  void clear();
227 
228  #ifndef __MAKECINT__
230  marley::JSON to_json() const;
231 
234  void from_json(const marley::JSON& json);
235  #endif
236 
237  protected:
238 
240  std::vector<marley::Particle*> initial_particles_;
241 
243  std::vector<marley::Particle*> final_particles_;
244 
249  double Ex_;
250 
253  int twoJ_;
254 
258 
268  void dump_hepevt_particle(const marley::Particle& p, std::ostream& os,
269  int status, int jmohep1 = 0, int jmohep2 = 0) const;
270 
273  void delete_particles();
274  };
275 
276  // Inline function definitions
277  inline double Event::Ex() const { return Ex_; }
278  inline int Event::twoJ() const { return twoJ_; }
279  inline marley::Parity Event::parity() const { return parity_; }
280 
281  inline const std::vector<marley::Particle*>& Event::get_initial_particles()
282  const { return initial_particles_; }
283 
284  inline std::vector<marley::Particle*>& Event::get_initial_particles()
285  { return initial_particles_; }
286 
287  inline const std::vector<marley::Particle*>& Event::get_final_particles()
288  const { return final_particles_; }
289 
290  inline std::vector<marley::Particle*>& Event::get_final_particles()
291  { return final_particles_; }
292 
293  inline size_t Event::initial_particle_count() const
294  { return initial_particles_.size(); }
295 
296  inline size_t Event::final_particle_count() const
297  { return final_particles_.size(); }
298 
299  inline const marley::Particle& Event::initial_particle( size_t idx ) const {
300  return *initial_particles_.at( idx );
301  }
302 
303  inline const marley::Particle& Event::final_particle( size_t idx ) const {
304  return *final_particles_.at( idx );
305  }
306 
307 }
308 
309 inline std::ostream& operator<<(std::ostream& out, const marley::Event& e) {
310  e.print(out);
311  return out;
312 }
313 
314 inline std::istream& operator>>(std::istream& in, marley::Event& e) {
315  e.read(in);
316  return in;
317 }
Container for ingoing and outgoing momentum 4-vectors from a reaction.
Definition: Event.hh:66
const marley::Particle & final_particle(size_t idx) const
Returns a const reference to the final particle with the given index.
Definition: Event.hh:303
void print(std::ostream &out) const
Print this event to a std::ostream.
Definition: Event.cc:226
void dump_hepevt_particle(const marley::Particle &p, std::ostream &os, int status, int jmohep1=0, int jmohep2=0) const
Helper function for write_hepevt()
Definition: Event.cc:294
void from_json(const marley::JSON &json)
Replace the existing event contents with those read from a JSON representation.
Definition: Event.cc:574
size_t initial_particle_count() const
Returns the number of initial particles in the Event.
Definition: Event.hh:293
void add_initial_particle(const marley::Particle &p)
Add a Particle to the vector of initial particles.
Definition: Event.cc:202
const marley::Particle & residue() const
Get a const reference to the residue.
Definition: Event.cc:198
void delete_particles()
Deletes all owned Particle objects and clears the vectors of initial and final particles.
Definition: Event.cc:219
double Ex() const
Get the excitation energy of the residue just after the initial two-body reaction.
Definition: Event.hh:277
size_t final_particle_count() const
Returns the number of final particles in the Event.
Definition: Event.hh:296
const std::vector< marley::Particle * > & get_final_particles() const
Get a const reference to the vector of final particles.
Definition: Event.hh:287
const std::vector< marley::Particle * > & get_initial_particles() const
Get a const reference to the vector of initial particles.
Definition: Event.hh:281
Parity parity_
The parity of the residue immediately after the two-two scattering reaction.
Definition: Event.hh:257
void print_human_readable(std::ostream &out, int num=-1) const
Print this event to a std::ostream in an annotated format easily readable by humans.
Definition: Event.cc:641
double Ex_
Excitation energy (MeV) of the residue immediately after the two-two scattering reaction.
Definition: Event.hh:249
bool read_hepevt(std::istream &in, double *flux_avg_tot_xsec=nullptr)
Read in this event from a std::istream, assuming it will appear there in HEPEVT format....
Definition: Event.cc:380
const marley::Particle & target() const
Get a const reference to the target.
Definition: Event.cc:190
void clear()
Deletes all particles from the event and resets the nuclear excitation energy to zero.
Definition: Event.cc:212
const marley::Particle & ejectile() const
Get a const reference to the ejectile.
Definition: Event.cc:194
void add_final_particle(const marley::Particle &p)
Add a Particle to the vector of final particles.
Definition: Event.cc:207
std::vector< marley::Particle * > final_particles_
Vector of pointers to each of the final state particles.
Definition: Event.hh:243
Event & operator=(const Event &other_event)
Copy assignment operator.
Definition: Event.cc:116
std::vector< marley::Particle * > initial_particles_
Vector of pointers to each of the initial state particles.
Definition: Event.hh:240
Event(double Ex=0.)
Create an event with dummy particles.
Definition: Event.cc:58
void write_hepevt(size_t event_num, double flux_avg_tot_xsec, std::ostream &out) const
Write a HEPEVT record for this event to a std::ostream. Use the spacetime origin (t = 0 mm/c,...
Definition: Event.cc:313
marley::JSON to_json() const
Create a JSON representation of this event.
Definition: Event.cc:357
int twoJ() const
Get two times the spin of the residue just after the initial two-body reaction.
Definition: Event.hh:278
const marley::Particle & projectile() const
Get a const reference to the projectile.
Definition: Event.cc:186
marley::Parity parity() const
Get the intrinsic parity of the residue just after the initial two-body reaction.
Definition: Event.hh:279
int twoJ_
Two times the spin of the residue immediately after the two-two scattering reaction.
Definition: Event.hh:253
void read(std::istream &in)
Read in this event from a std::istream. Any previous contents of this event will be deleted.
Definition: Event.cc:243
const marley::Particle & initial_particle(size_t idx) const
Returns a const reference to the initial particle with the given index.
Definition: Event.hh:299
Definition: JSON.hh:62
Type-safe representation of a parity value (either +1 or -1)
Definition: Parity.hh:25
Momentum four-vector for a simulated particle.
Definition: Particle.hh:32