herwig is hosted by Hepforge, IPPP Durham
Herwig  7.1.5
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-2017 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();
60 
64  double generate(double cutoff) {
65  double oldcut = evolution_cutoff_;
66  evolution_cutoff_ = cutoff;
67  double w = 0.0;
68  try {
69  w = generate();
70  } catch(...) {
71  evolution_cutoff_ = oldcut;
72  throw;
73  }
74  evolution_cutoff_ = oldcut;
75  return w;
76  }
77 
79  const std::vector<double>& last_point() const { return last_point_; }
80 
82  double last_value() const { return last_value_; }
83 
85  void reject() {
86  last_cell_->info().reject();
87  }
88 
89  public:
90 
92  bool initialized() const { return initialized_; }
93 
95  bool did_split() const { return did_split_; }
96 
98  Function& function() { return *function_; }
99 
101  void function(Function * f) { function_ = f; }
102 
104  adaption_info& sampling_parameters() { return adaption_info_; }
105 
107  void docompensate(bool yes = true) { docompensate_ = yes; }
108 
110  void detuning(double val) { detuning_ = val; }
111 
112  public:
113 
115  template<class OStream>
116  void put(OStream& os) const;
117 
119  template<class IStream>
120  void get(IStream& is);
121 
122  private:
123 
126  bool split();
127 
134  void get_exponent();
135 
137  void compensate();
138 
141  std::set<std::vector<double> > parameter_points();
142 
145  void recursive_parameter_points(std::set<std::vector<double> >&,
146  std::vector<double>&,
147  size_t);
148 
150  Function * function_;
151 
154  unsigned long check_events_;
155 
158 
161 
164 
167 
170 
172  std::size_t evolution_variable_;
173 
176 
179  std::vector<bool> sample_variables_;
180 
183  std::vector<bool> sample_other_variables_;
184 
187  std::map<std::size_t,std::vector<double> > parameter_splits_;
188 
191 
193  std::vector<double> last_point_;
194 
196  double last_value_;
197 
200 
202  std::map<bit_container<parameter_hash_bits>,linear_interpolator > exponents_;
203 
205  std::vector<double> last_exponent_integrand_;
206 
208  std::map<bit_container<parameter_hash_bits>,linear_interpolator >::iterator last_exponent_;
209 
212 
215 
218 
221 
224 
227 
229  unsigned long attempts_;
230 
232  unsigned long accepts_;
233 
235  unsigned long splits_;
236 
239 
241  double detuning_;
242 
243  };
244 
245 }
246 
247 #include "exponential_generator.icc"
248 
249 #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
double generate(double cutoff)
generate an event, returning the sign of the weight or zero for an event below the evolution cutoff ...
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
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