herwig
is hosted by
Hepforge
,
IPPP Durham
Herwig
7.3.0
Sampling
exsample
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
19
namespace
exsample {
20
23
struct
generator_update
{};
24
26
template
<
class
Function,
class
Random>
27
class
generator
{
28
29
public
:
30
32
generator
()
33
:
function_
(0),
statistics_
(),
check_events_
(0),
34
adaption_info_
(),
root_cell_
(),
35
rnd_gen_
(),
did_split_
(false),
initialized_
(false),
36
last_cell_
(),
last_point_
(),
last_value_
(0.),
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
() {
55
statistics_
.
reject
(
last_value_
);
56
last_cell_
->info().reject();
57
}
58
60
void
finalize
() {
61
statistics_
.
reset
();
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
{
88
return
volume
() *
statistics_
.
average_weight
();
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
102
double
current_integral_uncertainty
()
const
{
103
return
volume
() * std::sqrt(
statistics_
.
current
().second);
104
}
105
107
double
integral_variance
()
const
{
108
return
sqr
(
volume
()) *
statistics_
.
average_weight_variance
();
109
}
110
112
adaption_info
&
sampling_parameters
() {
return
adaption_info_
; }
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
135
void
compensate
();
136
138
Function *
function_
;
139
141
statistics
statistics_
;
142
145
unsigned
long
check_events_
;
146
148
adaption_info
adaption_info_
;
149
151
binary_tree<cell>
root_cell_
;
152
154
rnd_generator<Random>
rnd_gen_
;
155
157
bool
did_split_
;
158
160
bool
initialized_
;
161
163
binary_tree<cell>::iterator
last_cell_
;
164
166
std::vector<double>
last_point_
;
167
169
double
last_value_
;
170
172
bool
compensating_
;
173
174
};
175
176
}
177
178
#include "generator.icc"
179
180
#endif
// EXSAMPLE_generator_h_included
181
exsample::binary_tree::iterator
iterator
Definition:
binary_tree.h:97
exsample::binary_tree
binary_tree represents a binary tree with the ability to ‘cascade’ visitor objects down the tree
Definition:
binary_tree.h:21
exsample::generator
A generator for plain sampling and integrating.
Definition:
generator.h:27
exsample::generator::generator
generator()
default constructor
Definition:
generator.h:32
exsample::generator::did_split_
bool did_split_
wether a split has already been performed
Definition:
generator.h:157
exsample::generator::function_
Function * function_
function to be sampled
Definition:
generator.h:138
exsample::generator::put
void put(OStream &os) const
put to ostream
exsample::generator::initialized_
bool initialized_
wether this generator has been initialized
Definition:
generator.h:160
exsample::generator::rnd_gen_
rnd_generator< Random > rnd_gen_
the random number generator to be used
Definition:
generator.h:154
exsample::generator::check_events_
unsigned long check_events_
the number of events after which a cell is checked for splits
Definition:
generator.h:145
exsample::generator::compensate
void compensate()
compensate the last selected cell indicating the value and position of the new overestimate
exsample::generator::sampling_parameters
adaption_info & sampling_parameters()
access the adaption_info object
Definition:
generator.h:112
exsample::generator::volume
double volume() const
return the sampled volume
Definition:
generator.h:82
exsample::generator::finalize
void finalize()
finalize this generator
Definition:
generator.h:60
exsample::generator::function
void function(Function *f)
set the function
Definition:
generator.h:76
exsample::generator::did_split
bool did_split() const
return true, if at least one split has been performed
Definition:
generator.h:70
exsample::generator::get
void get(IStream &is)
get from istream
exsample::generator::initialize
void initialize(SlaveStatistics &)
initialize this generator
exsample::generator::statistics_
statistics statistics_
the global statistics object
Definition:
generator.h:141
exsample::generator::root_cell_
binary_tree< cell > root_cell_
the root cell
Definition:
generator.h:151
exsample::generator::last_point_
std::vector< double > last_point_
the last sampled phasespace point
Definition:
generator.h:166
exsample::generator::adaption_info_
adaption_info adaption_info_
the adaption info object
Definition:
generator.h:148
exsample::generator::current_integral_uncertainty
double current_integral_uncertainty() const
return the error on the integral
Definition:
generator.h:102
exsample::generator::stats
const statistics & stats() const
return the statistics object
Definition:
generator.h:79
exsample::generator::last_point
const std::vector< double > & last_point() const
return the last sampled phase space point
Definition:
generator.h:51
exsample::generator::generate
double generate(SlaveStatistics &)
generate an event, returning the sign of the weight
exsample::generator::last_value_
double last_value_
the last function value
Definition:
generator.h:169
exsample::generator::integral_uncertainty
double integral_uncertainty() const
return the error on the integral
Definition:
generator.h:92
exsample::generator::compensating
bool compensating() const
return true, if still compensating
Definition:
generator.h:115
exsample::generator::integral
double integral() const
return the integral
Definition:
generator.h:87
exsample::generator::function
Function & function()
access the function
Definition:
generator.h:73
exsample::generator::initialized
bool initialized() const
return true, if this generator has been initialized
Definition:
generator.h:67
exsample::generator::reject
void reject()
indicate that the last generated point has been rejected
Definition:
generator.h:54
exsample::generator::last_cell_
binary_tree< cell >::iterator last_cell_
the last selected cell
Definition:
generator.h:163
exsample::generator::split
bool split()
check for and possibly split the last selected cell
exsample::generator::integral_variance
double integral_variance() const
return the variance of the integral estimate
Definition:
generator.h:107
exsample::generator::compensating_
bool compensating_
wether or not we are compensating
Definition:
generator.h:172
exsample::generator::current_integral
double current_integral() const
return the integral
Definition:
generator.h:97
exsample::statistics
statistics is a helper class for keeping track of event generation statistics.
Definition:
statistics.h:20
exsample::statistics::average_weight_variance
double average_weight_variance() const
the variance of the weight
Definition:
statistics.h:66
exsample::statistics::average_weight
double average_weight() const
the average weight
Definition:
statistics.h:56
exsample::statistics::reset
void reset()
reset the statistics object
exsample::statistics::reject
void reject(double weight)
reject a prviously accepted event
Definition:
statistics.h:43
exsample::statistics::current
std::pair< double, double > current() const
return the integral's estimate and its uncertainty at the currently accumulated statistics
sqr
constexpr auto sqr(const T &x) -> decltype(x *x)
exsample::adaption_info
adaption_info is a container for parameters relevant to sampling and adaption.
Definition:
adaption_info.h:18
exsample::adaption_info::lower_left
std::vector< double > lower_left
the lower left corner of the function's support
Definition:
adaption_info.h:32
exsample::adaption_info::upper_right
std::vector< double > upper_right
the upper right corner of the function's support
Definition:
adaption_info.h:35
exsample::generator_update
Exception thrown, if the generator has just changed its state.
Definition:
generator.h:23
exsample::rnd_generator
Random generator traits.
Definition:
utility.h:319
Generated on Thu Jun 20 2024 17:50:53 for Herwig by
1.9.6