Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-12-20 03:22:23

0001 #ifndef SimDataFormats_GeneratorProducts_GenLumiInfoProduct_h
0002 #define SimDataFormats_GeneratorProducts_GenLumiInfoProduct_h
0003 
0004 #include <vector>
0005 #include <cmath>
0006 
0007 /** \class GenLumiInfoProduct
0008  *
0009  */
0010 
0011 class GenLumiInfoProduct {
0012 public:
0013   // a few forward declarations
0014   struct XSec;
0015   struct ProcessInfo;
0016 
0017   // constructors, destructors
0018   GenLumiInfoProduct();
0019   GenLumiInfoProduct(const int id);
0020   virtual ~GenLumiInfoProduct();
0021 
0022   // getters
0023 
0024   const int getHEPIDWTUP() const { return hepidwtup_; }
0025   const std::vector<ProcessInfo> &getProcessInfos() const { return internalProcesses_; }
0026 
0027   // setters
0028 
0029   void setHEPIDWTUP(const int id) { hepidwtup_ = id; }
0030   void setProcessInfo(const std::vector<ProcessInfo> &processes) { internalProcesses_ = processes; }
0031 
0032   // Struct- definitions
0033   struct XSec {
0034   public:
0035     XSec() : value_(-1.), error_(-1.) {}
0036     XSec(double v, double e = -1.) : value_(v), error_(e) {}
0037 
0038     double value() const { return value_; }
0039     double error() const { return error_; }
0040 
0041     bool isSet() const { return value_ >= 0.; }
0042     bool hasError() const { return error_ >= 0.; }
0043 
0044     operator double() const { return value_; }
0045     operator bool() const { return isSet(); }
0046 
0047     bool operator==(const XSec &other) const { return value_ == other.value_ && error_ == other.error_; }
0048     bool operator!=(const XSec &other) const { return !(*this == other); }
0049 
0050   private:
0051     double value_, error_;
0052   };
0053 
0054   struct FinalStat {
0055   public:
0056     FinalStat() : n_(0), sum_(0.0), sum2_(0.0) {}
0057     FinalStat(unsigned int n1, double sum1, double sum21) : n_(n1), sum_(sum1), sum2_(sum21) {}
0058 
0059     unsigned int n() const { return n_; }
0060     double sum() const { return sum_; }
0061     double sum2() const { return sum2_; }
0062 
0063     void add(const FinalStat &other) {
0064       //Hadronizers treat 0, -1., -1. to mean the value is not present
0065       if (other.n() != 0 and other.sum_ != -1. and other.sum2() != -1.) {
0066         n_ += other.n();
0067         sum_ += other.sum();
0068         sum2_ += other.sum2();
0069       }
0070     }
0071 
0072     bool operator==(const FinalStat &other) const {
0073       return n_ == other.n_ && sum_ == other.sum_ && sum2_ == other.sum2_;
0074     }
0075     bool operator!=(const FinalStat &other) const { return !(*this == other); }
0076 
0077   private:
0078     unsigned int n_;
0079     double sum_;
0080     double sum2_;
0081   };
0082 
0083   struct ProcessInfo {
0084   public:
0085     ProcessInfo() : process_(-1), nPassPos_(0), nPassNeg_(0), nTotalPos_(0), nTotalNeg_(0) {}
0086     ProcessInfo(int id) : process_(id), nPassPos_(0), nPassNeg_(0), nTotalPos_(0), nTotalNeg_(0) {}
0087 
0088     // accessors
0089     int process() const { return process_; }
0090     XSec const &lheXSec() const { return lheXSec_; }
0091 
0092     unsigned int nPassPos() const { return nPassPos_; }
0093     unsigned int nPassNeg() const { return nPassNeg_; }
0094     unsigned int nTotalPos() const { return nTotalPos_; }
0095     unsigned int nTotalNeg() const { return nTotalNeg_; }
0096 
0097     FinalStat const &tried() const { return tried_; }
0098     FinalStat const &selected() const { return selected_; }
0099     FinalStat const &killed() const { return killed_; }
0100     FinalStat const &accepted() const { return accepted_; }
0101     FinalStat const &acceptedBr() const { return acceptedBr_; }
0102 
0103     // setters
0104     void addOthers(const ProcessInfo &other) {
0105       mergeXSec(other.lheXSec(), other.selected().sum());
0106       nPassPos_ += other.nPassPos();
0107       nPassNeg_ += other.nPassNeg();
0108       nTotalPos_ += other.nTotalPos();
0109       nTotalNeg_ += other.nTotalNeg();
0110       tried_.add(other.tried());
0111       selected_.add(other.selected());
0112       killed_.add(other.killed());
0113       accepted_.add(other.accepted());
0114       acceptedBr_.add(other.acceptedBr());
0115     }
0116     void setProcess(int id) { process_ = id; }
0117     void setLheXSec(double value, double err) { lheXSec_ = XSec(value, err); }
0118     void setNPassPos(unsigned int n) { nPassPos_ = n; }
0119     void setNPassNeg(unsigned int n) { nPassNeg_ = n; }
0120     void setNTotalPos(unsigned int n) { nTotalPos_ = n; }
0121     void setNTotalNeg(unsigned int n) { nTotalNeg_ = n; }
0122     void setTried(unsigned int n, double sum, double sum2) { tried_ = FinalStat(n, sum, sum2); }
0123     void setSelected(unsigned int n, double sum, double sum2) { selected_ = FinalStat(n, sum, sum2); }
0124     void setKilled(unsigned int n, double sum, double sum2) { killed_ = FinalStat(n, sum, sum2); }
0125     void setAccepted(unsigned int n, double sum, double sum2) { accepted_ = FinalStat(n, sum, sum2); }
0126     void setAcceptedBr(unsigned int n, double sum, double sum2) { acceptedBr_ = FinalStat(n, sum, sum2); }
0127 
0128   private:
0129     void mergeXSec(XSec const &iXSec, double iWeight) {
0130       if (iWeight <= 0.) {
0131         return;
0132       }
0133       if (lheXSec_.value() <= 0.) {
0134         lheXSec_ = iXSec;
0135       } else {
0136         bool useWeights = (lheXSec_.error() <= 0. || iXSec.error() <= 0.);
0137         double wgt1 = useWeights ? selected().sum() : 1. / (lheXSec_.error() * lheXSec_.error());
0138         double wgt2 = useWeights ? iWeight : 1. / (iXSec.error() * iXSec.error());
0139         double xsec = (wgt1 * lheXSec_.value() + wgt2 * iXSec.value()) / (wgt1 + wgt2);
0140         double err = useWeights ? 0. : 1.0 / std::sqrt(wgt1 + wgt2);
0141         lheXSec_ = XSec(xsec, err);
0142       }
0143     }
0144     int process_;
0145     XSec lheXSec_;
0146     unsigned int nPassPos_;
0147     unsigned int nPassNeg_;
0148     unsigned int nTotalPos_;
0149     unsigned int nTotalNeg_;
0150     FinalStat tried_;
0151     FinalStat selected_;
0152     FinalStat killed_;
0153     FinalStat accepted_;
0154     FinalStat acceptedBr_;
0155   };
0156 
0157   // methods used by EDM
0158   virtual bool mergeProduct(const GenLumiInfoProduct &other);
0159   void swap(GenLumiInfoProduct &other);
0160   virtual bool isProductEqual(const GenLumiInfoProduct &other) const;
0161 
0162 private:
0163   // cross sections
0164   int hepidwtup_;
0165   std::vector<ProcessInfo> internalProcesses_;
0166 };
0167 
0168 #endif  // SimDataFormats_GeneratorProducts_GenLumiInfoProduct_h