herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
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 
126 
130 
134 
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 
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 
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
void overestimate(double v, const std::vector< double > &pos)
set the current overestimate and maximum position
Definition: cell.h:101
double & integral()
access the integral
Definition: cell.h:246
void missing_events(int n)
set the number of missing events
Definition: cell.h:258
double efficiency_threshold
the efficiency threshold below which splits are considered
Definition: adaption_info.h:53
unsigned long accepted() const
get the number of accepted events
Definition: cell.h:119
std::vector< double > last_max_position_
the position of the last encountered maximum in this cell
Definition: cell.h:179
std::vector< std::pair< double, double > > avg_weight_
left-right statistics of average weight
Definition: cell.h:182
double volume_
the volume of this cell
Definition: cell.h:166
void put(OStream &os) const
put to ostream
double split_point() const
return the split value
Definition: cell.h:240
void integral(double v)
set the integral
Definition: cell.h:249
double overestimate() const
get the current overestimate
Definition: cell.h:95
void select(Random &, std::vector< double > &)
generate a flat trial point in this cell
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
std::size_t split_dimension_
the dimension along this cell was split
Definition: cell.h:280
int missing_events_
the number of missing events in this cell
Definition: cell.h:291
double integral() const
return the integral
Definition: cell.h:243
cell_info & info()
access the cell_info object
Definition: cell.h:261
std::vector< double > upper_right_
the upper right corner of this cell
Definition: cell.h:172
void decrease_parametric_missing(const bit_container< parameter_hash_bits > &id)
decrease to the number of missing events for the given parameter bin id
bool bad(const adaption_info &ainfo) const
return true, if below efficiency threshold
Definition: cell.h:69
int parametric_missing(const bit_container< parameter_hash_bits > &id) const
return the number of missing events for the given parameter bin id
int missing_events() const
return the number of missing events
Definition: cell.h:255
std::size_t split_dimension() const
return the split dimension
Definition: cell.h:237
unsigned long accepted_
the number of accepted events in this cell
Definition: cell.h:188
the general cell class
Definition: cell.h:197
void accept()
indicate that a point has been accepted in this cell
Definition: cell.h:61
std::vector< double > mid_point_
midpoint of this cell
Definition: cell.h:175
std::unique_ptr< cell_info > cell_info_
a pointer to the cell info object, if this is a leaf cell
Definition: cell.h:295
const cell_info & info() const
return the cell_info object
Definition: cell.h:264
double overestimate_
the value of the overestimate in this cell
Definition: cell.h:163
unsigned long attempted_
the number of attempts in this cell
Definition: cell.h:185
double integral_
the integral of the absolute value of the overestimate over all the children cells ...
Definition: cell.h:288
adaption_info is a container for parameters relevant to sampling and adaption.
Definition: adaption_info.h:18
unsigned long attempted() const
get the number of attempted events
Definition: cell.h:116
bool parametric_compensating() const
return true, if the cell is compensating in at least one parameter bin
Definition: cell.h:141
Information contained in a leaf cell.
Definition: cell.h:21
int & missing_events()
access the number of missing events
Definition: cell.h:252
const std::vector< double > & lower_left() const
get the lower left corner
Definition: cell.h:110
void selected(const std::vector< double > &, double, const adaption_info &)
indicate a function value for the given point
bool contains_parameter(const std::vector< double > &point, const std::vector< bool > &sampled) const
return true, if the cell contains the indicated parameter point
cell_info()
the default constructor
double split_point_
the value, where this cell was split
Definition: cell.h:283
double volume() const
get the volume
Definition: cell.h:107
void increase_parametric_missing(const bit_container< parameter_hash_bits > &id)
increase to the number of missing events for the given parameter bin id
const std::vector< double > & upper_right() const
get the upper right corner
Definition: cell.h:113
void reject()
reject a previously accepted event
Definition: cell.h:64
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...
statistics is a helper class for keeping track of event generation statistics.
Definition: statistics.h:20
std::vector< double > lower_left_
the lower left corner of this cell
Definition: cell.h:169
const std::vector< double > & last_max_position() const
return the position of the last maximum
Definition: cell.h:98
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