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