Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:22

0001 // -*- C++ -*-
0002 //
0003 // exponential_generator.h is part of ExSample -- A Library for Sampling Sudakov-Type Distributions
0004 //
0005 // Copyright (C) 2008-2019 Simon Platzer -- simon.plaetzer@desy.de, The Herwig Collaboration
0006 //
0007 // ExSample is licenced under version 3 of the GPL, see COPYING for details.
0008 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0009 //
0010 //
0011 #ifndef EXSAMPLE_exponential_generator_h_included
0012 #define EXSAMPLE_exponential_generator_h_included
0013 
0014 #include "cell.h"
0015 #include "selectors.h"
0016 #include "statistics.h"
0017 #include "linear_interpolator.h"
0018 #include "binary_tree.h"
0019 
0020 namespace exsample {
0021 
0022   /// \brief Exception thrown, if the exponential_generator has just changed its
0023   /// state. The attempt of generating an event should be repeated.
0024   struct exponential_regenerate{};
0025 
0026   /// \brief The generator for sudakov-type distributions.
0027   template<class Function, class Random>
0028   class exponential_generator {
0029 
0030   public:
0031 
0032     /// default constructor
0033     exponential_generator()
0034       : function_(0), check_events_(0), adaption_info_(), root_cell_(),
0035     rnd_gen_(), did_split_(false), initialized_(false),
0036     evolution_variable_(0), evolution_cutoff_(0.),
0037     sample_variables_(), sample_other_variables_(),
0038     parameter_splits_(),
0039     last_cell_(), last_point_(), last_value_(0.),
0040     last_parameter_bin_(), exponents_(),
0041     last_exponent_integrand_(),
0042     last_exponent_(), compensating_(false),
0043         integral_accessor_(), missing_accessor_(),
0044     parametric_selector_(), exponent_selector_(),
0045     parametric_sampler_(), attempts_(0), accepts_(0),
0046       splits_(0), docompensate_(false), detuning_(1.0) {}
0047 
0048   public:
0049 
0050     /// initialize this generator
0051     void initialize();
0052 
0053     /// finalize this generator
0054     void finalize() {}
0055 
0056     /// generate an event, returning
0057     /// the sign of the weight or zero
0058     /// for an event below the evolution cutoff
0059     double generate(double enhance = 1.);
0060 
0061     /// generate an event, returning
0062     /// the sign of the weight or zero
0063     /// for an event below the evolution cutoff
0064     double generate(double cutoff,
0065             double enhance) {
0066       double oldcut = evolution_cutoff_;
0067       evolution_cutoff_ = cutoff;
0068       double w = 0.0;
0069       try {
0070     w = generate(enhance);
0071       } catch(...) {
0072     evolution_cutoff_ = oldcut;
0073     throw;
0074       }
0075       evolution_cutoff_ = oldcut;
0076       return w;
0077     }
0078 
0079     /// return the last sampled phase space point
0080     const std::vector<double>& last_point() const { return last_point_; }
0081 
0082     /// return the last evaluated function
0083     double last_value() const { return last_value_; }
0084 
0085     /// indicate that the last generated point has been rejected
0086     void reject() {
0087       last_cell_->info().reject();
0088     }
0089 
0090   public:
0091 
0092     /// return true, if this generator has been initialized
0093     bool initialized() const { return initialized_; }
0094 
0095     /// return true, if at least one split has been performed
0096     bool did_split() const { return did_split_; }
0097 
0098     /// access the function
0099     Function& function() { return *function_; }
0100 
0101     /// set the function
0102     void function(Function * f) { function_ = f; }
0103 
0104     /// access the adaption_info object
0105     adaption_info& sampling_parameters() { return adaption_info_; }
0106 
0107     /// indicate, if compensation should be applied
0108     void docompensate(bool yes = true) { docompensate_ = yes; }
0109 
0110     /// set the detuning parameter
0111     void detuning(double val) { detuning_ = val; }
0112 
0113   public:
0114 
0115     /// put to ostream
0116     template<class OStream>
0117     void put(OStream& os) const;
0118 
0119     /// get from istream
0120     template<class IStream>
0121     void get(IStream& is);
0122 
0123   private:
0124 
0125     /// check for and possibly split
0126     /// the last selected cell
0127     bool split();
0128 
0129     /// get the projection of the density integrating over every
0130     /// variable to be sampled, except the evolution variable for the
0131     /// indicated parameter point.  the k'th entry in
0132     /// last_exponent_integrand_ is the value in the evolution
0133     /// variable bin from evolution_splits_[k] to
0134     /// evolution_splits_[k+1]
0135     void get_exponent();
0136 
0137     /// compensate 
0138     void compensate();
0139 
0140     /// get all parameter points to build
0141     /// all possible sub tree hashes
0142     std::set<std::vector<double> > parameter_points();
0143 
0144     /// get all parameter points to build
0145     /// all possible sub tree hashes
0146     void recursive_parameter_points(std::set<std::vector<double> >&,
0147                     std::vector<double>&,
0148                     size_t);
0149 
0150     /// function to be sampled
0151     Function * function_;
0152 
0153     /// the number of events after which
0154     /// a cell is checked for splits
0155     unsigned long check_events_;
0156 
0157     /// the adaption info object
0158     adaption_info adaption_info_;
0159 
0160     /// the root cell
0161     binary_tree<cell> root_cell_;
0162 
0163     /// the random number generator to be used
0164     rnd_generator<Random> rnd_gen_;
0165 
0166     /// wether a split has already been performed
0167     bool did_split_;
0168 
0169     /// wether this generator has been initialized
0170     bool initialized_;
0171 
0172     /// the position of the evolution variable
0173     std::size_t evolution_variable_;
0174 
0175     /// the cutoff on the evolution variable
0176     double evolution_cutoff_;
0177 
0178     /// flags of variables to be sampled
0179     /// including the evolution variable
0180     std::vector<bool> sample_variables_;
0181 
0182     /// flags of variables to be sampled
0183     /// excluding the evolution variable
0184     std::vector<bool> sample_other_variables_;
0185 
0186     /// the splits in any parameter done so far
0187     /// (including the evolution variable)
0188     std::map<std::size_t,std::vector<double> > parameter_splits_;
0189 
0190     /// the last selected cell
0191     binary_tree<cell>::iterator last_cell_;      
0192 
0193     /// the last sampled phasespace point
0194     std::vector<double> last_point_;
0195 
0196     /// the last function value
0197     double last_value_;
0198 
0199     /// the last parameter bin id
0200     bit_container<parameter_hash_bits> last_parameter_bin_;
0201 
0202     /// map parameter bin ids to exponent interpolations
0203     std::map<bit_container<parameter_hash_bits>,linear_interpolator > exponents_;
0204 
0205     /// the last exponent integrand
0206     std::vector<double> last_exponent_integrand_;
0207 
0208     /// the last exponent
0209     std::map<bit_container<parameter_hash_bits>,linear_interpolator >::iterator last_exponent_;
0210 
0211     /// wether or not we are compensating
0212     bool compensating_;
0213 
0214     /// the integral accessor to be used
0215     integral_accessor integral_accessor_;
0216 
0217     /// the missing events accessor to be used
0218     parametric_missing_accessor missing_accessor_;
0219 
0220     /// the parametric selector to be used
0221     parametric_selector parametric_selector_;
0222 
0223     /// the parametric selector to be used for parameter bins
0224     parametric_selector exponent_selector_;
0225 
0226     /// the parametric sampler to be used
0227     parametric_sampling_selector<rnd_generator<Random> > parametric_sampler_;
0228 
0229     /// the number of trials in the veto loo so far
0230     unsigned long attempts_;
0231 
0232     /// the number of accepted events so far
0233     unsigned long accepts_;
0234 
0235     /// number of splits done
0236     unsigned long splits_;
0237 
0238     /// true, if compensation should be applied
0239     bool docompensate_;
0240 
0241     /// a detuning factor to be applied to the overestimate
0242     double detuning_;
0243 
0244   };
0245 
0246 }
0247 
0248 #include "exponential_generator.icc"
0249 
0250 #endif // EXSAMPLE_exponential_generator_h_included