Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // selectors.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_selectors_h_included
0012 #define EXSAMPLE_selectors_h_included
0013 
0014 #include "cell.h"
0015 
0016 namespace exsample {
0017 
0018   /// \brief flat sampling selector
0019   template<class Random>
0020   struct sampling_selector {
0021 
0022     /// the default constructor
0023     sampling_selector()
0024       : rnd_gen(), compensate(false) {}
0025 
0026     /// the standard constructor
0027     explicit sampling_selector(const Random& r, bool comp = true)
0028       : rnd_gen(r), compensate(comp) {}
0029 
0030     /// return which of the children cells should be considered
0031     std::pair<bool,bool> use(cell& parent,
0032                  const cell& first_child,
0033                  const cell& second_child) const;
0034 
0035     /// return true, if the leaf cell should be considered
0036     bool use(cell& leaf) const;
0037 
0038     /// The random number generator to be used
0039     Random rnd_gen;
0040 
0041     /// Whether or not compensation is needed
0042     bool compensate;
0043 
0044   };
0045 
0046   /// \brief selector selecting only bins
0047   /// which contain the given parameter point
0048   class parametric_selector {
0049 
0050   public:
0051 
0052     /// the default constructor
0053     parametric_selector ()
0054       : point_(), sampled_variables_() {}
0055 
0056     /// construct from reference to point and flags to sample variables
0057     parametric_selector(std::vector<double> * point,
0058             const std::vector<bool>& sample)
0059       : point_(point), sampled_variables_(sample) {}
0060 
0061   public:
0062 
0063     /// return which of the children cells should be considered
0064     std::pair<bool,bool> use(const cell& parent,
0065                  const cell&,
0066                  const cell&) const;
0067 
0068     /// return true, if the leaf cell should be considered
0069     bool use(const cell&) const { return true; }
0070 
0071   private:
0072 
0073     /// the point chosen
0074     std::vector<double> * point_;
0075 
0076     /// flags for variables to be sampled
0077     std::vector<bool> sampled_variables_;
0078 
0079   };
0080 
0081   /// \brief sampling selector selecting only bins
0082   /// which contain the given parameter point
0083   template<class Random>
0084   class parametric_sampling_selector {
0085 
0086   public:
0087 
0088     /// the default constructor
0089     parametric_sampling_selector()
0090       : point_(), bin_id_(),
0091     sampled_variables_(), rnd_gen_(),
0092     compensate_(false) {}
0093 
0094     /// construct from reference to point, subtree hash, flags of
0095     /// variables to be sampled, and random number generator
0096     parametric_sampling_selector(std::vector<double> * p,
0097                  bit_container<parameter_hash_bits> * bin_id,
0098                  const std::vector<bool>& sample,
0099                  const Random& rnd_gen)
0100       : point_(p), bin_id_(bin_id),
0101     sampled_variables_(sample), rnd_gen_(rnd_gen),
0102     compensate_(false) {}
0103 
0104   public:
0105 
0106     /// return which of the children cells should be considered
0107     std::pair<bool,bool> use(cell& parent,
0108                  const cell& first_child,
0109                  const cell& second_child) const;
0110 
0111     /// return true, if the leaf cell should be considered
0112     bool use(cell& leaf) const;
0113 
0114     /// indicate that compensation is to take place
0115     void compensate (bool doit = true) { compensate_ = doit; }
0116 
0117   private:
0118 
0119     /// the point chosen
0120     std::vector<double> * point_;
0121 
0122     /// the corresponding bin id
0123     bit_container<parameter_hash_bits> * bin_id_;
0124 
0125     /// flags for variables to be sampled
0126     std::vector<bool> sampled_variables_;
0127 
0128     /// the random number generator
0129     Random rnd_gen_;
0130 
0131     /// wether or not compensation is needed
0132     bool compensate_;
0133 
0134   };
0135 
0136   /// \brief accessor returning the integral of a cell
0137   struct integral_accessor {    
0138 
0139     /// update and return the value
0140     double& set(cell& node) const {
0141       return node.integral();
0142     }
0143 
0144     /// get the value
0145     double get(const cell& node, bool) const {
0146       return node.integral();
0147     }
0148 
0149   };
0150 
0151   /// \brief accessor returning the number of missing events
0152   struct missing_accessor {    
0153 
0154     /// update and return the value
0155     int& set(cell& node) const {
0156       return node.missing_events();
0157     }
0158 
0159     /// get the value
0160     int get(const cell& node, bool) const {
0161       return node.missing_events();
0162     }
0163 
0164   };
0165 
0166   /// \brief accessor returning the number of missing events
0167   /// for given parameter bin id
0168   struct parametric_missing_accessor {    
0169 
0170     /// the default constructor
0171     parametric_missing_accessor ()
0172       : id_() {}
0173 
0174     /// construct from subtree hash to consider
0175     explicit parametric_missing_accessor (bit_container<parameter_hash_bits>* id)
0176       : id_ (id) {}
0177 
0178     /// update and return the value
0179     int& set(cell& node) const {
0180       return node.missing_events();
0181     }
0182 
0183     /// get the value
0184     int get(const cell& node, bool isleaf) const {
0185       if (isleaf)
0186     return node.info().parametric_missing(*id_);
0187       return node.missing_events();
0188     }
0189 
0190   private:
0191 
0192     /// the subtree hash to consider
0193     bit_container<parameter_hash_bits>* id_;
0194 
0195   };
0196 
0197 }
0198 
0199 #include "selectors.icc"
0200 
0201 #endif // EXSAMPLE_selectors_h_included