herwig
is hosted by
Hepforge
,
IPPP Durham
Herwig
7.3.0
Sampling
exsample
cell.h
1
// -*- C++ -*-
2
//
3
// cell.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_cell_h_included
12
#define EXSAMPLE_cell_h_included
13
14
#include "utility.h"
15
#include "adaption_info.h"
16
#include "statistics.h"
17
18
namespace
exsample {
19
21
class
cell_info
{
22
23
public
:
24
26
cell_info
();
27
29
cell_info
(
const
std::vector<double>& ll,
30
const
std::vector<double>& ur,
31
const
adaption_info
& ainfo);
32
35
cell_info
(
const
std::vector<double>& ll,
36
const
std::vector<double>& ur,
37
const
std::vector<bool>& sampled_variables,
38
const
adaption_info
& ainfo);
39
40
public
:
41
43
template
<
class
Random>
44
void
select
(Random&,
45
std::vector<double>&);
46
49
template
<
class
Random>
50
void
select
(Random&,
51
std::vector<double>&,
52
const
std::vector<bool>&);
53
55
void
selected
(
const
std::vector<double>&,
56
double
,
57
const
adaption_info
&);
58
61
void
accept
() { ++
accepted_
; }
62
64
void
reject
() { --
accepted_
; }
65
66
public
:
67
69
bool
bad
(
const
adaption_info
& ainfo)
const
{
70
return
((
static_cast<
double
>
(
accepted_
)/
static_cast<
double
>
(
attempted_
)) <
71
ainfo.
efficiency_threshold
);
72
}
73
76
std::pair<std::size_t,double>
get_split
(
const
adaption_info
&,
77
bool
&)
const
;
78
82
template
<
class
Random,
class
Function,
class
SlaveStatistics>
83
void
explore
(Random&,
const
adaption_info
&, Function*,
statistics
*,
84
SlaveStatistics& opt);
85
89
template
<
class
Random,
class
Function>
90
void
explore
(Random&,
const
adaption_info
&, Function*);
91
92
public
:
93
95
double
overestimate
()
const
{
return
overestimate_
; }
96
98
const
std::vector<double>&
last_max_position
()
const
{
return
last_max_position_
; }
99
101
void
overestimate
(
double
v,
const
std::vector<double>& pos) {
102
overestimate_
=
v
;
103
last_max_position_
= pos;
104
}
105
107
double
volume
()
const
{
return
volume_
; }
108
110
const
std::vector<double>&
lower_left
()
const
{
return
lower_left_
; }
111
113
const
std::vector<double>&
upper_right
()
const
{
return
upper_right_
; }
114
116
unsigned
long
attempted
()
const
{
return
attempted_
; }
117
119
unsigned
long
accepted
()
const
{
return
accepted_
; }
120
121
public
:
122
125
int
parametric_missing
(
const
bit_container<parameter_hash_bits>
&
id
)
const
;
126
129
void
parametric_missing
(
const
bit_container<parameter_hash_bits>
&
id
,
int
n);
130
133
void
increase_parametric_missing
(
const
bit_container<parameter_hash_bits>
&
id
);
134
137
void
decrease_parametric_missing
(
const
bit_container<parameter_hash_bits>
&
id
);
138
141
bool
parametric_compensating
()
const
{
142
return
!
parametric_missing_map_
.empty();
143
}
144
147
bool
contains_parameter
(
const
std::vector<double>& point,
148
const
std::vector<bool>& sampled)
const
;
149
150
public
:
151
153
template
<
class
OStream>
154
void
put
(OStream& os)
const
;
155
157
template
<
class
IStream>
158
void
get
(IStream& is);
159
160
private
:
161
163
double
overestimate_
;
164
166
double
volume_
;
167
169
std::vector<double>
lower_left_
;
170
172
std::vector<double>
upper_right_
;
173
175
std::vector<double>
mid_point_
;
176
179
std::vector<double>
last_max_position_
;
180
182
std::vector<std::pair<double,double> >
avg_weight_
;
183
185
unsigned
long
attempted_
;
186
188
unsigned
long
accepted_
;
189
192
std::map<bit_container<parameter_hash_bits>,
int
>
parametric_missing_map_
;
193
194
};
195
197
class
cell
{
198
199
public
:
200
202
cell
();
203
205
cell
(
const
std::vector<double>& ll,
206
const
std::vector<double>& ur,
207
const
adaption_info
& ainfo);
208
211
cell
(
const
std::vector<double>& ll,
212
const
std::vector<double>& ur,
213
const
std::vector<bool>& sampled_variables,
214
const
adaption_info
& ainfo);
215
217
cell
(
const
cell
& x);
218
220
cell
&
operator=
(
const
cell
& x);
221
222
public
:
223
226
template
<
class
Random,
class
Function>
227
std::pair<cell,cell>
split
(std::pair<std::size_t,double> split_d,
228
Random& rnd_gen,
229
Function* f,
230
const
adaption_info
& ainfo,
231
const
std::vector<bool>& sampled =
232
std::vector<bool>());
233
234
public
:
235
237
std::size_t
split_dimension
()
const
{
return
split_dimension_
; }
238
240
double
split_point
()
const
{
return
split_point_
; }
241
243
double
integral
()
const
{
return
integral_
; }
244
246
double
&
integral
() {
return
integral_
; }
247
249
void
integral
(
double
v) {
integral_
=
v
; }
250
252
int
&
missing_events
() {
return
missing_events_
; }
253
255
int
missing_events
()
const
{
return
missing_events_
; }
256
258
void
missing_events
(
int
n) {
missing_events_
= n; }
259
261
cell_info
&
info
() { assert(
cell_info_
);
return
*
cell_info_
; }
262
264
const
cell_info
&
info
()
const
{ assert(
cell_info_
);
return
*
cell_info_
; }
265
266
public
:
267
269
template
<
class
OStream>
270
void
put
(OStream& os)
const
;
271
273
template
<
class
IStream>
274
void
get
(IStream& is);
275
276
private
:
277
280
std::size_t
split_dimension_
;
281
283
double
split_point_
;
284
288
double
integral_
;
289
291
int
missing_events_
;
292
295
std::unique_ptr<cell_info>
cell_info_
;
296
297
298
};
299
300
}
301
302
#include "cell.icc"
303
304
#endif
// EXSAMPLE_cell_h_included
exsample::cell_info
Information contained in a leaf cell.
Definition:
cell.h:21
exsample::cell_info::last_max_position
const std::vector< double > & last_max_position() const
return the position of the last maximum
Definition:
cell.h:98
exsample::cell_info::parametric_missing
void parametric_missing(const bit_container< parameter_hash_bits > &id, int n)
set the number of missing events for the given parameter bin id
exsample::cell_info::explore
void explore(Random &, const adaption_info &, Function *, statistics *, SlaveStatistics &opt)
explore this cell performing a flat sampling, updating the given statistics object and pre-filling th...
exsample::cell_info::attempted
unsigned long attempted() const
get the number of attempted events
Definition:
cell.h:116
exsample::cell_info::get_split
std::pair< std::size_t, double > get_split(const adaption_info &, bool &) const
suggest a split and indicate wether it is worth to be performed
exsample::cell_info::contains_parameter
bool contains_parameter(const std::vector< double > &point, const std::vector< bool > &sampled) const
return true, if the cell contains the indicated parameter point
exsample::cell_info::explore
void explore(Random &, const adaption_info &, Function *)
explore this cell in a more refined way, which is however not suited for already calculating integral...
exsample::cell_info::mid_point_
std::vector< double > mid_point_
midpoint of this cell
Definition:
cell.h:175
exsample::cell_info::cell_info
cell_info(const std::vector< double > &ll, const std::vector< double > &ur, const adaption_info &ainfo)
construct from boundaries and adaption info
exsample::cell_info::put
void put(OStream &os) const
put to ostream
exsample::cell_info::bad
bool bad(const adaption_info &ainfo) const
return true, if below efficiency threshold
Definition:
cell.h:69
exsample::cell_info::reject
void reject()
reject a previously accepted event
Definition:
cell.h:64
exsample::cell_info::volume_
double volume_
the volume of this cell
Definition:
cell.h:166
exsample::cell_info::get
void get(IStream &is)
get from istream
exsample::cell_info::upper_right_
std::vector< double > upper_right_
the upper right corner of this cell
Definition:
cell.h:172
exsample::cell_info::select
void select(Random &, std::vector< double > &, const std::vector< bool > &)
generate a flat trial point in this cell only for the variables falgged as true
exsample::cell_info::cell_info
cell_info()
the default constructor
exsample::cell_info::decrease_parametric_missing
void decrease_parametric_missing(const bit_container< parameter_hash_bits > &id)
decrease to the number of missing events for the given parameter bin id
exsample::cell_info::accepted_
unsigned long accepted_
the number of accepted events in this cell
Definition:
cell.h:188
exsample::cell_info::parametric_missing
int parametric_missing(const bit_container< parameter_hash_bits > &id) const
return the number of missing events for the given parameter bin id
exsample::cell_info::lower_left
const std::vector< double > & lower_left() const
get the lower left corner
Definition:
cell.h:110
exsample::cell_info::accept
void accept()
indicate that a point has been accepted in this cell
Definition:
cell.h:61
exsample::cell_info::attempted_
unsigned long attempted_
the number of attempts in this cell
Definition:
cell.h:185
exsample::cell_info::lower_left_
std::vector< double > lower_left_
the lower left corner of this cell
Definition:
cell.h:169
exsample::cell_info::last_max_position_
std::vector< double > last_max_position_
the position of the last encountered maximum in this cell
Definition:
cell.h:179
exsample::cell_info::parametric_compensating
bool parametric_compensating() const
return true, if the cell is compensating in at least one parameter bin
Definition:
cell.h:141
exsample::cell_info::cell_info
cell_info(const std::vector< double > &ll, const std::vector< double > &ur, const std::vector< bool > &sampled_variables, const adaption_info &ainfo)
construct from boundaries, flags for variables to be sampled, and adaption info
exsample::cell_info::volume
double volume() const
get the volume
Definition:
cell.h:107
exsample::cell_info::selected
void selected(const std::vector< double > &, double, const adaption_info &)
indicate a function value for the given point
exsample::cell_info::overestimate
void overestimate(double v, const std::vector< double > &pos)
set the current overestimate and maximum position
Definition:
cell.h:101
exsample::cell_info::upper_right
const std::vector< double > & upper_right() const
get the upper right corner
Definition:
cell.h:113
exsample::cell_info::avg_weight_
std::vector< std::pair< double, double > > avg_weight_
left-right statistics of average weight
Definition:
cell.h:182
exsample::cell_info::overestimate_
double overestimate_
the value of the overestimate in this cell
Definition:
cell.h:163
exsample::cell_info::parametric_missing_map_
std::map< bit_container< parameter_hash_bits >, int > parametric_missing_map_
an optional map of parameter bin ids to the number of missing events
Definition:
cell.h:192
exsample::cell_info::accepted
unsigned long accepted() const
get the number of accepted events
Definition:
cell.h:119
exsample::cell_info::select
void select(Random &, std::vector< double > &)
generate a flat trial point in this cell
exsample::cell_info::increase_parametric_missing
void increase_parametric_missing(const bit_container< parameter_hash_bits > &id)
increase to the number of missing events for the given parameter bin id
exsample::cell_info::overestimate
double overestimate() const
get the current overestimate
Definition:
cell.h:95
exsample::cell
the general cell class
Definition:
cell.h:197
exsample::cell::integral
double & integral()
access the integral
Definition:
cell.h:246
exsample::cell::missing_events
int & missing_events()
access the number of missing events
Definition:
cell.h:252
exsample::cell::cell
cell(const std::vector< double > &ll, const std::vector< double > &ur, const adaption_info &ainfo)
construct from boundaries and adaption info
exsample::cell::info
cell_info & info()
access the cell_info object
Definition:
cell.h:261
exsample::cell::split_dimension
std::size_t split_dimension() const
return the split dimension
Definition:
cell.h:237
exsample::cell::split_point
double split_point() const
return the split value
Definition:
cell.h:240
exsample::cell::missing_events
int missing_events() const
return the number of missing events
Definition:
cell.h:255
exsample::cell::cell_info_
std::unique_ptr< cell_info > cell_info_
a pointer to the cell info object, if this is a leaf cell
Definition:
cell.h:295
exsample::cell::operator=
cell & operator=(const cell &x)
assignment
exsample::cell::info
const cell_info & info() const
return the cell_info object
Definition:
cell.h:264
exsample::cell::split
std::pair< cell, cell > split(std::pair< std::size_t, double > split_d, Random &rnd_gen, Function *f, const adaption_info &ainfo, const std::vector< bool > &sampled=std::vector< bool >())
split this cell, exploring the child not containing the current overestimate
exsample::cell::put
void put(OStream &os) const
put to ostream
exsample::cell::cell
cell()
default constructor
exsample::cell::integral_
double integral_
the integral of the absolute value of the overestimate over all the children cells
Definition:
cell.h:288
exsample::cell::missing_events
void missing_events(int n)
set the number of missing events
Definition:
cell.h:258
exsample::cell::cell
cell(const std::vector< double > &ll, const std::vector< double > &ur, const std::vector< bool > &sampled_variables, const adaption_info &ainfo)
construct from boundaries, flags for variables to be sampled, and adaption info
exsample::cell::get
void get(IStream &is)
get from istream
exsample::cell::cell
cell(const cell &x)
copy constructor
exsample::cell::split_dimension_
std::size_t split_dimension_
the dimension along this cell was split
Definition:
cell.h:280
exsample::cell::integral
double integral() const
return the integral
Definition:
cell.h:243
exsample::cell::split_point_
double split_point_
the value, where this cell was split
Definition:
cell.h:283
exsample::cell::missing_events_
int missing_events_
the number of missing events in this cell
Definition:
cell.h:291
exsample::cell::integral
void integral(double v)
set the integral
Definition:
cell.h:249
exsample::statistics
statistics is a helper class for keeping track of event generation statistics.
Definition:
statistics.h:20
SpinorType::v
@ v
exsample::adaption_info
adaption_info is a container for parameters relevant to sampling and adaption.
Definition:
adaption_info.h:18
exsample::adaption_info::efficiency_threshold
double efficiency_threshold
the efficiency threshold below which splits are considered
Definition:
adaption_info.h:53
exsample::bit_container
Fixed-size, packed vector of bools.
Definition:
utility.h:55
Generated on Thu Jun 20 2024 17:50:53 for Herwig by
1.9.6