MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
marley::ProjectileDirectionRotator Class Reference

If needed, rotates the coordinate system of a GenEvent so that the projectile 3-momentum lies along a desired direction. More...

#include <ProjectileDirectionRotator.hh>

Inheritance diagram for marley::ProjectileDirectionRotator:
marley::EventProcessor

Public Member Functions

 ProjectileDirectionRotator (const ThreeVector &dir={0., 0., 1.})
 
virtual void process_event (HepMC3::GenEvent &ev, marley::Generator &gen) override
 Rotates all 3-momenta in the input event so that the projectile 3-momentum lies along dir_vec_ in the new coordinate system.
 
const ThreeVector & projectile_direction () const
 
ThreeVector sample_isotropic_direction (marley::Generator &gen) const
 
void set_projectile_direction (const ThreeVector &dir)
 
void set_randomize_directions (bool do_sampling)
 

Protected Member Functions

void rotate_event (HepMC3::GenEvent &ev)
 Helper function that does the coordinate system rotation.
 

Protected Attributes

ThreeVector dir_vec_ = {{ 0., 0., 1. }}
 3-vector that points in the desired direction of the projectile
 
ThreeVector last_pdir_ = {{ 0., 0., 1. }}
 Stores the direction 3-vector for the last projectile that triggered a recalculation of the rotation matrix.
 
bool randomize_projectile_direction_ = false
 Flag that indicates whether the (rotated) projectile direction should be sampled isotropically for each event (true) or kept fixed across all events (false)
 
marley::RotationMatrix rot_matrix_
 RotationMatrix used to rotate the coordinate system of the input GenEvent.
 

Detailed Description

If needed, rotates the coordinate system of a GenEvent so that the projectile 3-momentum lies along a desired direction.

Definition at line 27 of file ProjectileDirectionRotator.hh.

Constructor & Destructor Documentation

◆ ProjectileDirectionRotator()

marley::ProjectileDirectionRotator::ProjectileDirectionRotator ( const ThreeVector & dir = {0., 0., 1.})
Parameters
dirA 3-vector pointing in the desired direction of the projectile in the rotated coordinate system

Definition at line 28 of file ProjectileDirectionRotator.cc.

29 : EventProcessor(),
30 dir_vec_( dir )
31{
32 constexpr ThreeVector null_three_vector = { 0., 0., 0. };
33 if ( dir_vec_ == null_three_vector ) throw marley::Error( "Null 3-vector"
34 " passed to constructor of marley::ProjectileDirectionRotator" );
35
36 dir_vec_ = marley::RotationMatrix::normalize( dir_vec_ );
37}
ThreeVector dir_vec_
3-vector that points in the desired direction of the projectile

References dir_vec_.

Member Function Documentation

◆ process_event()

void marley::ProjectileDirectionRotator::process_event ( HepMC3::GenEvent & ev,
marley::Generator & gen )
overridevirtual

Rotates all 3-momenta in the input event so that the projectile 3-momentum lies along dir_vec_ in the new coordinate system.

Implements marley::EventProcessor.

Definition at line 39 of file ProjectileDirectionRotator.cc.

41{
42 // First check that the projectile 3-momentum is not a null vector.
43 // If it is, don't bother to rotate coordinates. Also don't bother if
44 // (somehow) the magnitude of the projectile momentum is negative.
45 const auto projectile = marley_hepmc3::get_projectile( ev );
46 HepMC3::FourVector mom4 = projectile->momentum();
47 double pmom = mom4.p3mod();
48 if ( pmom <= 0. ) return;
49
50 ThreeVector pdir = { mom4.px() / pmom, mom4.py() / pmom, mom4.pz() / pmom };
51
52 // If random projectile directions have been requested, then sample
53 // a new one isotropically for this event
55 ThreeVector random_dir = sample_isotropic_direction( gen );
56 this->set_projectile_direction( random_dir );
57 }
58
59 // If the (unrotated) projectile direction from the event exactly matches the
60 // desired direction, then we can skip the coordinate rotation.
61 if ( pdir == dir_vec_ ) return;
62
63 // If the (unrotated) projectile direction from the event differs from
64 // the last one that was processed, then we need to recompute the
65 // rotation matrix. Do so and save the unrotated projectile direction
66 // to repeat this check next time.
67 if ( pdir != last_pdir_ ) {
68 last_pdir_ = pdir;
69 rot_matrix_ = marley::RotationMatrix( pdir, dir_vec_ );
70 }
71
72 // Do the actual rotation of the Particle 3-momenta in the event
73 this->rotate_event( ev );
74}
double px() const
x-component of momentum
Definition FourVector.h:114
double py() const
y-component of momentum
Definition FourVector.h:121
double p3mod() const
Magnitude of p3 = (px, py, pz) vector.
Definition FourVector.h:163
double pz() const
z-component of momentum
Definition FourVector.h:128
ThreeVector last_pdir_
Stores the direction 3-vector for the last projectile that triggered a recalculation of the rotation ...
bool randomize_projectile_direction_
Flag that indicates whether the (rotated) projectile direction should be sampled isotropically for ea...
marley::RotationMatrix rot_matrix_
RotationMatrix used to rotate the coordinate system of the input GenEvent.
void rotate_event(HepMC3::GenEvent &ev)
Helper function that does the coordinate system rotation.

References dir_vec_, last_pdir_, HepMC3::FourVector::p3mod(), HepMC3::FourVector::px(), HepMC3::FourVector::py(), HepMC3::FourVector::pz(), randomize_projectile_direction_, rot_matrix_, and rotate_event().

Referenced by marley::Generator::create_event().

◆ projectile_direction()

const ThreeVector & marley::ProjectileDirectionRotator::projectile_direction ( ) const
inline

Definition at line 45 of file ProjectileDirectionRotator.hh.

46 { return dir_vec_; }

◆ rotate_event()

void marley::ProjectileDirectionRotator::rotate_event ( HepMC3::GenEvent & ev)
protected

Helper function that does the coordinate system rotation.

Parameters
[in,out]evGenEvent whose Particle 3-vectors will be rotated

Definition at line 76 of file ProjectileDirectionRotator.cc.

76 {
77
78 for ( auto& p : ev.particles() ) {
79 rot_matrix_.rotate_particle_inplace( *p );
80 }
81
82}
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)

References HepMC3::GenEvent::particles(), and rot_matrix_.

Referenced by process_event().

◆ sample_isotropic_direction()

marley::ProjectileDirectionRotator::ThreeVector marley::ProjectileDirectionRotator::sample_isotropic_direction ( marley::Generator & gen) const

Definition at line 85 of file ProjectileDirectionRotator.cc.

87{
88 // Sample a polar cosine on the interval [-1, 1]
89 double cos_theta = gen.uniform_random_double( -1., 1., true );
90
91 // Sample an azimuthal angle on the interval [0, 2*pi)
92 double phi = gen.uniform_random_double( 0., marley_utils::two_pi, false );
93
94 // Compute direction unit vector components
95 double sin_theta = marley_utils::real_sqrt( 1. - std::pow(cos_theta, 2) );
96 double ux = sin_theta * std::cos( phi );
97 double uy = sin_theta * std::sin( phi );
98 double uz = cos_theta;
99
100 ThreeVector direction = { ux, uy, uz };
101 return direction;
102}
double uniform_random_double(double min, double max, bool inclusive)
Sample a random number uniformly on either [min, max) or [min, max].
Definition Generator.cc:235

◆ set_projectile_direction()

void marley::ProjectileDirectionRotator::set_projectile_direction ( const ThreeVector & dir)
inline

Definition at line 48 of file ProjectileDirectionRotator.hh.

48 {
49 dir_vec_ = marley::RotationMatrix::normalize( dir );
51 }

◆ set_randomize_directions()

void marley::ProjectileDirectionRotator::set_randomize_directions ( bool do_sampling)

Definition at line 104 of file ProjectileDirectionRotator.cc.

106{
108}

Member Data Documentation

◆ dir_vec_

ThreeVector marley::ProjectileDirectionRotator::dir_vec_ = {{ 0., 0., 1. }}
protected

3-vector that points in the desired direction of the projectile

Definition at line 61 of file ProjectileDirectionRotator.hh.

61{{ 0., 0., 1. }};

Referenced by ProjectileDirectionRotator(), and process_event().

◆ last_pdir_

ThreeVector marley::ProjectileDirectionRotator::last_pdir_ = {{ 0., 0., 1. }}
protected

Stores the direction 3-vector for the last projectile that triggered a recalculation of the rotation matrix.

Using this information avoids unnecessary recalculations

Definition at line 66 of file ProjectileDirectionRotator.hh.

66{{ 0., 0., 1. }};

Referenced by process_event().

◆ randomize_projectile_direction_

bool marley::ProjectileDirectionRotator::randomize_projectile_direction_ = false
protected

Flag that indicates whether the (rotated) projectile direction should be sampled isotropically for each event (true) or kept fixed across all events (false)

Definition at line 79 of file ProjectileDirectionRotator.hh.

Referenced by process_event().

◆ rot_matrix_

marley::RotationMatrix marley::ProjectileDirectionRotator::rot_matrix_
protected

RotationMatrix used to rotate the coordinate system of the input GenEvent.

Definition at line 70 of file ProjectileDirectionRotator.hh.

Referenced by process_event(), and rotate_event().


The documentation for this class was generated from the following files: