herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
exponential_generator.h
1 // -*- C++ -*-
2 //
3 // exponential_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_exponential_generator_h_included
12 #define EXSAMPLE_exponential_generator_h_included
13 
14 #include "cell.h"
15 #include "selectors.h"
16 #include "statistics.h"
17 #include "linear_interpolator.h"
18 #include "binary_tree.h"
19 
20 namespace exsample {
21 
25 
27  template<class Function, class Random>
29 
30  public:
31 
34  : function_(0), check_events_(0), adaption_info_(), root_cell_(),
35  rnd_gen_(), did_split_(false), initialized_(false),
36  evolution_variable_(0), evolution_cutoff_(0.),
37  sample_variables_(), sample_other_variables_(),
38  parameter_splits_(),
39  last_cell_(), last_point_(), last_value_(0.),
40  last_parameter_bin_(), exponents_(),
41  last_exponent_integrand_(),
42  last_exponent_(), compensating_(false),
43  integral_accessor_(), missing_accessor_(),
44  parametric_selector_(), exponent_selector_(),
45  parametric_sampler_(), attempts_(0), accepts_(0),
46  splits_(0), docompensate_(false), detuning_(1.0) {}
47 
48  public:
49 
51  void initialize();
52 
54  void finalize() {}
55 
59  double generate(double enhance = 1.);
60 
64  double generate(double cutoff,
65  double enhance) {
66  double oldcut = evolution_cutoff_;
67  evolution_cutoff_ = cutoff;
68  double w = 0.0;
69  try {
70  w = generate(enhance);
71  } catch(...) {
72  evolution_cutoff_ = oldcut;
73  throw;
74  }
75  evolution_cutoff_ = oldcut;
76  return w;
77  }
78 
80  const std::vector<double>& last_point() const { return last_point_; }
81 
83  double last_value() const { return last_value_; }
84 
86  void reject() {
87  last_cell_->info().reject();
88  }
89 
90  public:
91 
93  bool initialized() const { return initialized_; }
94 
96  bool did_split() const { return did_split_; }
97 
99  Function& function() { return *function_; }
100 
102  void function(Function * f) { function_ = f; }
103 
105  adaption_info& sampling_parameters() { return adaption_info_; }
106 
108  void docompensate(bool yes = true) { docompensate_ = yes; }
109 
111  void detuning(double val) { detuning_ = val; }
112 
113  public:
114 
116  template<class OStream>
117  void put(OStream& os) const;
118 
120  template<class IStream>
121  void get(IStream& is);
122 
123  private:
124 
127  bool split();
128 
135  void get_exponent();
136 
138  void compensate();
139 
142  std::set<std::vector<double> > parameter_points();
143 
146  void recursive_parameter_points(std::set<std::vector<double> >&,
147  std::vector<double>&,
148  size_t);
149 
151  Function * function_;
152 
155  unsigned long check_events_;
156 
159 
162 
165 
168 
171 
173  std::size_t evolution_variable_;
174 
177 
180  std::vector<bool> sample_variables_;
181 
184  std::vector<bool> sample_other_variables_;
185 
188  std::map<std::size_t,std::vector<double> > parameter_splits_;
189 
192 
194  std::vector<double> last_point_;
195 
197  double last_value_;
198 
201 
203  std::map<bit_container<parameter_hash_bits>,linear_interpolator > exponents_;
204 
206  std::vector<double> last_exponent_integrand_;
207 
209  std::map<bit_container<parameter_hash_bits>,linear_interpolator >::iterator last_exponent_;
210 
213 
216 
219 
222 
225 
228 
230  unsigned long attempts_;
231 
233  unsigned long accepts_;
234 
236  unsigned long splits_;
237 
240 
242  double detuning_;
243 
244  };
245 
246 }
247 
248 #include "exponential_generator.icc"
249 
250 #endif // EXSAMPLE_exponential_generator_h_included
A linear interpolation allowing for inversion of the linear interpolation.
std::vector< bool > sample_variables_
flags of variables to be sampled including the evolution variable
std::vector< double > last_point_
the last sampled phasespace point
double evolution_cutoff_
the cutoff on the evolution variable
void detuning(double val)
set the detuning parameter
binary_tree represents a binary tree with the ability to `cascade&#39; visitor objects down the tree ...
Definition: binary_tree.h:21
unsigned long splits_
number of splits done
accessor returning the integral of a cell
Definition: selectors.h:137
Exception thrown, if the exponential_generator has just changed its state.
selector selecting only bins which contain the given parameter point
Definition: selectors.h:48
integral_accessor integral_accessor_
the integral accessor to be used
sampling selector selecting only bins which contain the given parameter point
Definition: selectors.h:84
unsigned long attempts_
the number of trials in the veto loo so far
bool did_split_
wether a split has already been performed
parametric_missing_accessor missing_accessor_
the missing events accessor to be used
void docompensate(bool yes=true)
indicate, if compensation should be applied
parametric_selector parametric_selector_
the parametric selector to be used
double last_value_
the last function value
The generator for sudakov-type distributions.
Random generator traits.
Definition: utility.h:319
std::map< bit_container< parameter_hash_bits >, linear_interpolator > exponents_
map parameter bin ids to exponent interpolations
adaption_info & sampling_parameters()
access the adaption_info object
Function * function_
function to be sampled
rnd_generator< Random > rnd_gen_
the random number generator to be used
double detuning_
a detuning factor to be applied to the overestimate
std::vector< bool > sample_other_variables_
flags of variables to be sampled excluding the evolution variable
std::size_t evolution_variable_
the position of the evolution variable
parametric_selector exponent_selector_
the parametric selector to be used for parameter bins
exponential_generator()
default constructor
bool did_split() const
return true, if at least one split has been performed
std::vector< double > last_exponent_integrand_
the last exponent integrand
adaption_info is a container for parameters relevant to sampling and adaption.
Definition: adaption_info.h:18
void reject()
indicate that the last generated point has been rejected
std::map< bit_container< parameter_hash_bits >, linear_interpolator >::iterator last_exponent_
the last exponent
double last_value() const
return the last evaluated function
binary_tree< cell > root_cell_
the root cell
bool docompensate_
true, if compensation should be applied
pair< double, double > generate(const Generator< Density > &gen, double r)
Generate a random variable and return its weight.
bool compensating_
wether or not we are compensating
binary_tree< cell >::iterator last_cell_
the last selected cell
const std::vector< double > & last_point() const
return the last sampled phase space point
adaption_info adaption_info_
the adaption info object
std::map< std::size_t, std::vector< double > > parameter_splits_
the splits in any parameter done so far (including the evolution variable)
bool initialized() const
return true, if this generator has been initialized
bool initialized_
wether this generator has been initialized
parametric_sampling_selector< rnd_generator< Random > > parametric_sampler_
the parametric sampler to be used
accessor returning the number of missing events for given parameter bin id
Definition: selectors.h:168
double generate(double cutoff, double enhance)
generate an event, returning the sign of the weight or zero for an event below the evolution cutoff ...
void finalize()
finalize this generator
unsigned long accepts_
the number of accepted events so far
unsigned long check_events_
the number of events after which a cell is checked for splits
bit_container< parameter_hash_bits > last_parameter_bin_
the last parameter bin id