Engine for TabulatedRandomGenerator. More...
#include <TabulatedRandomGenerator.h>
Public Member Functions | |
TabulatedRngEngine (Dataset &dataset) | |
Constructor from a dataset. | |
constexpr value_t | MaxValue () const |
Returns maximal possible value of stored random numbers. | |
value_t | Read (int channel) const |
Reads the random number for the given channel for the current event. | |
int | Register (int numChannels=1) |
Registers a new consumer of random numbers. | |
Private Attributes | |
int | numChannelsRegistered_ |
Total number of channels registered. | |
int const | kSeed_ = 1439 |
The seed to fill the table of random numbers. | |
int const | kVolume_ = 100'000 |
Number of random numbers to generate. | |
std::vector< value_t > | table_ |
Table of pre-generated random numbers. | |
TTreeReaderValue< ULong64_t > | event_ |
Reader to access the event number from event ID. |
Engine for TabulatedRandomGenerator.
This class provides fixed random numbers. Multiple numbers per event can be obtained using different channels. The number returned for a given channel in an event with a given ID, is always the same.
This class is not expected to be used directly but via TabulatedRandomGenerator instead. Each instance of the latter registers itself as a consumer of random numbers.
Internally, a table of pre-generated random integer numbers is maintained. Its elements are indexed by the current event number and given channel number. The table is treated as a circular buffer.
value_t TabulatedRngEngine::Read | ( | int | channel | ) | const |
Reads the random number for the given channel for the current event.
It is responsibility of the caller to include the offset returned by Register into the provided channel number. No check on the given channel number is done.
int TabulatedRngEngine::Register | ( | int | numChannels = 1 |
) |
Registers a new consumer of random numbers.
The consumer must respect the returned offset to ensure that the set of random numbers it reads does not overlap with the sets read by other consumers.
[in] | numChannels | Number of random numbers that can be used by this consumer per event. |