Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // statistics.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_statistics_h_included
0012 #define EXSAMPLE_statistics_h_included
0013 
0014 #include "utility.h"
0015 
0016 namespace exsample {
0017 
0018   /// \brief statistics is a helper class for keeping track of event
0019   /// generation statistics.
0020   class statistics {
0021 
0022   public:
0023 
0024     /// default constructor
0025     statistics();
0026 
0027     /// update the statistics for a weight encountered during
0028     /// presampling
0029     void presampled(double weight);
0030 
0031     /// indicate that a weight has been selected; optionally preven
0032     /// the weight from entering the caluclation of the integral
0033     void select(double weight,
0034         bool calculate_integral = true);
0035 
0036     /// indicate that a point has been accepted
0037     void accept(double weight) {
0038       ++accepted_;
0039       if (weight < 0) ++accepted_negative_;
0040     }
0041 
0042     /// reject a prviously accepted event
0043     void reject(double weight) {
0044       --accepted_;
0045       if (weight < 0) --accepted_negative_;
0046     }
0047 
0048     /// reset the statistics object
0049     void reset();
0050 
0051     /// return the integral's estimate and its uncertainty at the
0052     /// currently accumulated statistics
0053     std::pair<double,double> current() const;
0054 
0055     /// the average weight
0056     double average_weight() const { 
0057       return (n_iterations_ == 0 ? 0. : average_weight_/n_iterations_);
0058     }
0059     
0060     /// the average absolute weight
0061     double average_abs_weight() const { 
0062       return (n_iterations_ == 0 ? 0. : average_abs_weight_/n_iterations_);
0063     }
0064     
0065     /// the variance of the weight
0066     double average_weight_variance() const { 
0067       return (n_iterations_ == 0 ? 0. : average_weight_variance_/n_iterations_);
0068     }
0069 
0070     /// the number of points in this iteration
0071     unsigned long iteration_points() const { return iteration_points_; }
0072 
0073     /// the number of iterations
0074     unsigned long n_iterations() const { return n_iterations_; }
0075     
0076     /// the total number of attempted in this bin
0077     unsigned long attempted() const { return attempted_; }
0078     
0079     /// the total number of finally accepted events in this bin
0080     unsigned long accepted() const { return accepted_; }
0081     
0082     /// the total number of acceptet events with negative weights
0083     unsigned long accepted_negative() const { return accepted_negative_; }
0084     
0085     /// the sum of weights
0086     double sum_weights() const { return sum_weights_; }
0087     
0088     /// the sum of absolute values of the weights
0089     double sum_abs_weights() const { return sum_abs_weights_; }
0090     
0091     /// the sum of weights squared
0092     double sum_weights_squared() const { return sum_weights_squared_; }
0093     
0094     /// the maximum weight
0095     double max_weight() const { return max_weight_; }
0096 
0097   public:
0098 
0099     /// put ostream
0100     template<class OStream>
0101     void put(OStream& os) const;
0102 
0103     /// get from istream
0104     template<class IStream>
0105     void get(IStream& is);
0106 
0107   private:
0108 
0109     /// the average weight
0110     double average_weight_;
0111     
0112     /// the average absolute weight
0113     double average_abs_weight_;
0114     
0115     /// the variance of the weight
0116     double average_weight_variance_;
0117 
0118     /// the number of points in this iteration
0119     unsigned long iteration_points_;
0120     
0121     /// the total number of attempted in this bin
0122     unsigned long attempted_;
0123     
0124     /// the total number of finally accepted events in this bin
0125     unsigned long accepted_;
0126     
0127     /// the total number of acceptet events with negative weights
0128     unsigned long accepted_negative_;
0129     
0130     /// the sum of weights
0131     double sum_weights_;
0132     
0133     /// the sum of absolute values of the weights
0134     double sum_abs_weights_;
0135     
0136     /// the sum of weights squared
0137     double sum_weights_squared_;
0138     
0139     /// the maximum weight
0140     double max_weight_;
0141 
0142     /// the number of iterations used to calculate the integral
0143     unsigned long n_iterations_;
0144     
0145   };
0146 
0147 }
0148 
0149 #include "statistics.icc"
0150 
0151 #endif // EXSAMPLE_statistics_h_included