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::WeightCalculator Class Referenceabstract

Abstract base class for objects that compute numerical weights for an input event. More...

#include <WeightCalculator.hh>

Inheritance diagram for marley::WeightCalculator:
marley::OMPWeightCalculator marley::StrengthVariationWeightCalculator marley::TrivialWeightCalculator

Public Member Functions

 WeightCalculator (const marley::JSON &config)
 
 WeightCalculator (const std::string &name)
 
const std::string & name () const
 
virtual double weight (HepMC3::GenEvent &event, marley::Generator &gen) const =0
 Compute the weight for the given event.
 

Protected Attributes

std::string name_
 Name used to label the output event weight.
 

Detailed Description

Abstract base class for objects that compute numerical weights for an input event.

Definition at line 32 of file WeightCalculator.hh.

Constructor & Destructor Documentation

◆ WeightCalculator() [1/2]

marley::WeightCalculator::WeightCalculator ( const marley::JSON & config)

Definition at line 22 of file WeightCalculator.cc.

23{
24 if ( !config.is_object() ) {
25 throw marley::Error( "Non-object JSON configuration passed to constructor"
26 " of marley::WeightCalculator" );
27 }
28
29 if ( !config.has_key("name") ) {
30 throw marley::Error( "Missing \"name\" key in weight calculator JSON"
31 " configuration" );
32 }
33
34 name_ = config.at( "name" ).to_string();
35}
std::string name_
Name used to label the output event weight.

◆ WeightCalculator() [2/2]

marley::WeightCalculator::WeightCalculator ( const std::string & name)

Definition at line 37 of file WeightCalculator.cc.

38 : name_( name ) {}

Member Function Documentation

◆ name()

const std::string & marley::WeightCalculator::name ( ) const
inline

Definition at line 58 of file WeightCalculator.hh.

58{ return name_; }

◆ weight()

virtual double marley::WeightCalculator::weight ( HepMC3::GenEvent & event,
marley::Generator & gen ) const
pure virtual

Compute the weight for the given event.

Note
If a derived class uses random numbers, it MUST own its own random number generator (seeded with a fixed value from its JSON config) rather than using the Generator's RNG. Random numbers MUST also only be used by derived classes during initialization, not on an event-by-event basis. These rules ensure that the calculated weights remain deterministic and replayable regardless of when or in what context the calculator is used. In particular, this allows the "resume" behavior of the "marley generate" command to be correct even after reweighting has been run on an existing sample.
Todo
Revisit this constraint if a clear use case is found for event-by-event random numbers sampled within a WeightCalculator derived class implementation.

Implemented in marley::OMPWeightCalculator, marley::StrengthVariationWeightCalculator, and marley::TrivialWeightCalculator.

References name_.

Member Data Documentation

◆ name_

std::string marley::WeightCalculator::name_
protected

Name used to label the output event weight.

Definition at line 63 of file WeightCalculator.hh.

Referenced by weight().


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