herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
generator.h
1// -*- C++ -*-
2//
3// generator.h is part of ExSample -- A Library for Sampling Sudakov-Type Distributions
4//
5// Copyright (C) 2008-2019 Simon Platzer -- simon.plaetzer@desy.de, The Herwig Collaboration
6//
7// ExSample is licenced under version 3 of the GPL, see COPYING for details.
8// Please respect the MCnet academic guidelines, see GUIDELINES for details.
9//
10//
11#ifndef EXSAMPLE_generator_h_included
12#define EXSAMPLE_generator_h_included
13
14#include "cell.h"
15#include "selectors.h"
16#include "statistics.h"
17#include "binary_tree.h"
18
19namespace exsample {
20
24
26 template<class Function, class Random>
27 class generator {
28
29 public:
30
35 rnd_gen_(), did_split_(false), initialized_(false),
37 compensating_(false) {}
38
39 public:
40
42 template<class SlaveStatistics>
43 void initialize(SlaveStatistics&);
44
47 template<class SlaveStatistics>
48 double generate(SlaveStatistics&);
49
51 const std::vector<double>& last_point() const { return last_point_; }
52
54 void reject() {
56 last_cell_->info().reject();
57 }
58
60 void finalize() {
62 }
63
64 public:
65
67 bool initialized() const { return initialized_; }
68
70 bool did_split() const { return did_split_; }
71
73 Function& function() { return *function_; }
74
76 void function(Function * f) { function_ = f; }
77
79 const statistics& stats() const { return statistics_; }
80
82 double volume() const {
83 return exsample::volume(adaption_info_.lower_left, adaption_info_.upper_right);
84 }
85
87 double integral() const {
89 }
90
92 double integral_uncertainty() const {
93 return volume() * std::sqrt(statistics_.average_weight_variance());
94 }
95
97 double current_integral() const {
98 return volume() * statistics_.current().first;
99 }
100
103 return volume() * std::sqrt(statistics_.current().second);
104 }
105
107 double integral_variance() const {
109 }
110
113
115 bool compensating() const { return compensating_; }
116
117 public:
118
120 template<class OStream>
121 void put(OStream& os) const;
122
124 template<class IStream>
125 void get(IStream& is);
126
127 private:
128
131 bool split();
132
136
138 Function * function_;
139
142
145 unsigned long check_events_;
146
149
152
155
158
161
164
166 std::vector<double> last_point_;
167
170
173
174 };
175
176}
177
178#include "generator.icc"
179
180#endif // EXSAMPLE_generator_h_included
181
binary_tree represents a binary tree with the ability to ‘cascade’ visitor objects down the tree
Definition: binary_tree.h:21
A generator for plain sampling and integrating.
Definition: generator.h:27
generator()
default constructor
Definition: generator.h:32
bool did_split_
wether a split has already been performed
Definition: generator.h:157
Function * function_
function to be sampled
Definition: generator.h:138
void put(OStream &os) const
put to ostream
bool initialized_
wether this generator has been initialized
Definition: generator.h:160
rnd_generator< Random > rnd_gen_
the random number generator to be used
Definition: generator.h:154
unsigned long check_events_
the number of events after which a cell is checked for splits
Definition: generator.h:145
void compensate()
compensate the last selected cell indicating the value and position of the new overestimate
adaption_info & sampling_parameters()
access the adaption_info object
Definition: generator.h:112
double volume() const
return the sampled volume
Definition: generator.h:82
void finalize()
finalize this generator
Definition: generator.h:60
void function(Function *f)
set the function
Definition: generator.h:76
bool did_split() const
return true, if at least one split has been performed
Definition: generator.h:70
void get(IStream &is)
get from istream
void initialize(SlaveStatistics &)
initialize this generator
statistics statistics_
the global statistics object
Definition: generator.h:141
binary_tree< cell > root_cell_
the root cell
Definition: generator.h:151
std::vector< double > last_point_
the last sampled phasespace point
Definition: generator.h:166
adaption_info adaption_info_
the adaption info object
Definition: generator.h:148
double current_integral_uncertainty() const
return the error on the integral
Definition: generator.h:102
const statistics & stats() const
return the statistics object
Definition: generator.h:79
const std::vector< double > & last_point() const
return the last sampled phase space point
Definition: generator.h:51
double generate(SlaveStatistics &)
generate an event, returning the sign of the weight
double last_value_
the last function value
Definition: generator.h:169
double integral_uncertainty() const
return the error on the integral
Definition: generator.h:92
bool compensating() const
return true, if still compensating
Definition: generator.h:115
double integral() const
return the integral
Definition: generator.h:87
Function & function()
access the function
Definition: generator.h:73
bool initialized() const
return true, if this generator has been initialized
Definition: generator.h:67
void reject()
indicate that the last generated point has been rejected
Definition: generator.h:54
binary_tree< cell >::iterator last_cell_
the last selected cell
Definition: generator.h:163
bool split()
check for and possibly split the last selected cell
double integral_variance() const
return the variance of the integral estimate
Definition: generator.h:107
bool compensating_
wether or not we are compensating
Definition: generator.h:172
double current_integral() const
return the integral
Definition: generator.h:97
statistics is a helper class for keeping track of event generation statistics.
Definition: statistics.h:20
double average_weight_variance() const
the variance of the weight
Definition: statistics.h:66
double average_weight() const
the average weight
Definition: statistics.h:56
void reset()
reset the statistics object
void reject(double weight)
reject a prviously accepted event
Definition: statistics.h:43
std::pair< double, double > current() const
return the integral's estimate and its uncertainty at the currently accumulated statistics
constexpr auto sqr(const T &x) -> decltype(x *x)
adaption_info is a container for parameters relevant to sampling and adaption.
Definition: adaption_info.h:18
std::vector< double > lower_left
the lower left corner of the function's support
Definition: adaption_info.h:32
std::vector< double > upper_right
the upper right corner of the function's support
Definition: adaption_info.h:35
Exception thrown, if the generator has just changed its state.
Definition: generator.h:23
Random generator traits.
Definition: utility.h:319