1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
// -*- C++ -*-
//
// exponential_generator.h is part of ExSample -- A Library for Sampling Sudakov-Type Distributions
//
// Copyright (C) 2008-2011 Simon Platzer -- simon.plaetzer@desy.de
//
// ExSample is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
//
#ifndef EXSAMPLE_exponential_generator_h_included
#define EXSAMPLE_exponential_generator_h_included
#include "cell.h"
#include "selectors.h"
#include "statistics.h"
#include "linear_interpolator.h"
#include "binary_tree.h"
namespace exsample {
/// \brief Exception thrown, if the exponential_generator has just changed its
/// state. The attempt of generating an event should be repeated.
struct exponential_regenerate{};
/// \brief The generator for sudakov-type distributions.
template<class Function, class Random>
class exponential_generator {
public:
/// default constructor
exponential_generator()
: function_(0), check_events_(0), adaption_info_(), root_cell_(),
rnd_gen_(), did_split_(false), initialized_(false),
evolution_variable_(0), evolution_cutoff_(0.),
sample_variables_(), sample_other_variables_(),
parameter_splits_(),
last_cell_(), last_point_(), last_value_(0.),
last_parameter_bin_(), exponents_(),
last_exponent_integrand_(),
last_exponent_(), compensating_(false),
integral_accessor_(), missing_accessor_(),
parametric_selector_(), exponent_selector_(),
parametric_sampler_(), attempts_(0), accepts_(0),
splits_(0) {}
public:
/// initialize this generator
void initialize();
/// finalize this generator
void finalize() {}
/// generate an event, returning
/// the sign of the weight or zero
/// for an event below the evolution cutoff
double generate();
/// return the last sampled phase space point
const std::vector<double>& last_point() const { return last_point_; }
/// return the last evaluated function
double last_value() const { return last_value_; }
/// indicate that the last generated point has been rejected
void reject() {
last_cell_->info().reject();
}
public:
/// return true, if this generator has been initialized
bool initialized() const { return initialized_; }
/// return true, if at least one split has been performed
bool did_split() const { return did_split_; }
/// access the function
Function& function() { return *function_; }
/// set the function
void function(Function * f) { function_ = f; }
/// access the adaption_info object
adaption_info& sampling_parameters() { return adaption_info_; }
private:
/// check for and possibly split
/// the last selected cell
bool split();
/// get the projection of the density integrating over every
/// variable to be sampled, except the evolution variable for the
/// indicated parameter point. the k'th entry in
/// last_exponent_integrand_ is the value in the evolution
/// variable bin from evolution_splits_[k] to
/// evolution_splits_[k+1]
void get_exponent();
/// compensate
void compensate();
/// get all parameter points to build
/// all possible sub tree hashes
std::set<std::vector<double> > parameter_points();
/// get all parameter points to build
/// all possible sub tree hashes
void recursive_parameter_points(std::set<std::vector<double> >&,
std::vector<double>&,
size_t);
/// function to be sampled
Function * function_;
/// the number of events after which
/// a cell is checked for splits
unsigned long check_events_;
/// the adaption info object
adaption_info adaption_info_;
/// the root cell
binary_tree<cell> root_cell_;
/// the random number generator to be used
rnd_generator<Random> rnd_gen_;
/// wether a split has already been performed
bool did_split_;
/// wether this generator has been initialized
bool initialized_;
/// the position of the evolution variable
std::size_t evolution_variable_;
/// the cutoff on the evolution variable
double evolution_cutoff_;
/// flags of variables to be sampled
/// including the evolution variable
std::vector<bool> sample_variables_;
/// flags of variables to be sampled
/// excluding the evolution variable
std::vector<bool> sample_other_variables_;
/// the splits in any parameter done so far
/// (including the evolution variable)
std::map<std::size_t,std::vector<double> > parameter_splits_;
/// the last selected cell
binary_tree<cell>::iterator last_cell_;
/// the last sampled phasespace point
std::vector<double> last_point_;
/// the last function value
double last_value_;
/// the last parameter bin id
bit_container<parameter_hash_bits> last_parameter_bin_;
/// map parameter bin ids to exponent interpolations
std::map<bit_container<parameter_hash_bits>,linear_interpolator > exponents_;
/// the last exponent integrand
std::vector<double> last_exponent_integrand_;
/// the last exponent
std::map<bit_container<parameter_hash_bits>,linear_interpolator >::iterator last_exponent_;
/// wether or not we are compensating
bool compensating_;
/// the integral accessor to be used
integral_accessor integral_accessor_;
/// the missing events accessor to be used
parametric_missing_accessor missing_accessor_;
/// the parametric selector to be used
parametric_selector parametric_selector_;
/// the parametric selector to be used for parameter bins
parametric_selector exponent_selector_;
/// the parametric sampler to be used
parametric_sampling_selector<rnd_generator<Random> > parametric_sampler_;
/// the number of trials in the veto loo so far
unsigned long attempts_;
/// the number of accepted events so far
unsigned long accepts_;
/// number of splits done
unsigned long splits_;
};
}
#include "exponential_generator.icc"
#endif // EXSAMPLE_exponential_generator_h_included
|