CMS 3D CMS Logo

GenLumiInfoProduct.h
Go to the documentation of this file.
1 #ifndef SimDataFormats_GeneratorProducts_GenLumiInfoProduct_h
2 #define SimDataFormats_GeneratorProducts_GenLumiInfoProduct_h
3 
4 #include <vector>
5 #include <cmath>
6 
12 public:
13  // a few forward declarations
14  struct XSec;
15  struct ProcessInfo;
16 
17  // constructors, destructors
19  GenLumiInfoProduct(const int id);
20  virtual ~GenLumiInfoProduct();
21 
22  // getters
23 
24  const int getHEPIDWTUP() const { return hepidwtup_; }
25  const std::vector<ProcessInfo> &getProcessInfos() const { return internalProcesses_; }
26 
27  // setters
28 
29  void setHEPIDWTUP(const int id) { hepidwtup_ = id; }
30  void setProcessInfo(const std::vector<ProcessInfo> &processes) { internalProcesses_ = processes; }
31 
32  // Struct- definitions
33  struct XSec {
34  public:
35  XSec() : value_(-1.), error_(-1.) {}
36  XSec(double v, double e = -1.) : value_(v), error_(e) {}
37 
38  double value() const { return value_; }
39  double error() const { return error_; }
40 
41  bool isSet() const { return value_ >= 0.; }
42  bool hasError() const { return error_ >= 0.; }
43 
44  operator double() const { return value_; }
45  operator bool() const { return isSet(); }
46 
47  bool operator==(const XSec &other) const { return value_ == other.value_ && error_ == other.error_; }
48  bool operator!=(const XSec &other) const { return !(*this == other); }
49 
50  private:
51  double value_, error_;
52  };
53 
54  struct FinalStat {
55  public:
56  FinalStat() : n_(0), sum_(0.0), sum2_(0.0) {}
57  FinalStat(unsigned int n1, double sum1, double sum21) : n_(n1), sum_(sum1), sum2_(sum21) {}
58 
59  unsigned int n() const { return n_; }
60  double sum() const { return sum_; }
61  double sum2() const { return sum2_; }
62 
63  void add(const FinalStat &other) {
64  //Hadronizers treat 0, -1., -1. to mean the value is not present
65  if (other.n() != 0 and other.sum_ != -1. and other.sum2() != -1.) {
66  n_ += other.n();
67  sum_ += other.sum();
68  sum2_ += other.sum2();
69  }
70  }
71 
72  bool operator==(const FinalStat &other) const {
73  return n_ == other.n_ && sum_ == other.sum_ && sum2_ == other.sum2_;
74  }
75  bool operator!=(const FinalStat &other) const { return !(*this == other); }
76 
77  private:
78  unsigned int n_;
79  double sum_;
80  double sum2_;
81  };
82 
83  struct ProcessInfo {
84  public:
87 
88  // accessors
89  int process() const { return process_; }
90  XSec const &lheXSec() const { return lheXSec_; }
91 
92  unsigned int nPassPos() const { return nPassPos_; }
93  unsigned int nPassNeg() const { return nPassNeg_; }
94  unsigned int nTotalPos() const { return nTotalPos_; }
95  unsigned int nTotalNeg() const { return nTotalNeg_; }
96 
97  FinalStat const &tried() const { return tried_; }
98  FinalStat const &selected() const { return selected_; }
99  FinalStat const &killed() const { return killed_; }
100  FinalStat const &accepted() const { return accepted_; }
101  FinalStat const &acceptedBr() const { return acceptedBr_; }
102 
103  // setters
104  void addOthers(const ProcessInfo &other) {
105  mergeXSec(other.lheXSec(), other.selected().sum());
106  nPassPos_ += other.nPassPos();
107  nPassNeg_ += other.nPassNeg();
108  nTotalPos_ += other.nTotalPos();
109  nTotalNeg_ += other.nTotalNeg();
110  tried_.add(other.tried());
111  selected_.add(other.selected());
112  killed_.add(other.killed());
113  accepted_.add(other.accepted());
114  acceptedBr_.add(other.acceptedBr());
115  }
116  void setProcess(int id) { process_ = id; }
117  void setLheXSec(double value, double err) { lheXSec_ = XSec(value, err); }
118  void setNPassPos(unsigned int n) { nPassPos_ = n; }
119  void setNPassNeg(unsigned int n) { nPassNeg_ = n; }
120  void setNTotalPos(unsigned int n) { nTotalPos_ = n; }
121  void setNTotalNeg(unsigned int n) { nTotalNeg_ = n; }
122  void setTried(unsigned int n, double sum, double sum2) { tried_ = FinalStat(n, sum, sum2); }
123  void setSelected(unsigned int n, double sum, double sum2) { selected_ = FinalStat(n, sum, sum2); }
124  void setKilled(unsigned int n, double sum, double sum2) { killed_ = FinalStat(n, sum, sum2); }
125  void setAccepted(unsigned int n, double sum, double sum2) { accepted_ = FinalStat(n, sum, sum2); }
126  void setAcceptedBr(unsigned int n, double sum, double sum2) { acceptedBr_ = FinalStat(n, sum, sum2); }
127 
128  private:
129  void mergeXSec(XSec const &iXSec, double iWeight) {
130  if (iWeight <= 0.) {
131  return;
132  }
133  if (lheXSec_.value() <= 0.) {
134  lheXSec_ = iXSec;
135  } else {
136  bool useWeights = (lheXSec_.error() <= 0. || iXSec.error() <= 0.);
137  double wgt1 = useWeights ? selected().sum() : 1. / (lheXSec_.error() * lheXSec_.error());
138  double wgt2 = useWeights ? iWeight : 1. / (iXSec.error() * iXSec.error());
139  double xsec = (wgt1 * lheXSec_.value() + wgt2 * iXSec.value()) / (wgt1 + wgt2);
140  double err = useWeights ? 0. : 1.0 / std::sqrt(wgt1 + wgt2);
141  lheXSec_ = XSec(xsec, err);
142  }
143  }
144  int process_;
146  unsigned int nPassPos_;
147  unsigned int nPassNeg_;
148  unsigned int nTotalPos_;
149  unsigned int nTotalNeg_;
155  };
156 
157  // methods used by EDM
158  virtual bool mergeProduct(const GenLumiInfoProduct &other);
160  virtual bool isProductEqual(const GenLumiInfoProduct &other) const;
161 
162 private:
163  // cross sections
165  std::vector<ProcessInfo> internalProcesses_;
166 };
167 
168 #endif // SimDataFormats_GeneratorProducts_GenLumiInfoProduct_h
void add(const FinalStat &other)
void setTried(unsigned int n, double sum, double sum2)
bool operator!=(const XSec &other) const
void setSelected(unsigned int n, double sum, double sum2)
void mergeXSec(XSec const &iXSec, double iWeight)
void setKilled(unsigned int n, double sum, double sum2)
void swap(GenLumiInfoProduct &other)
virtual bool isProductEqual(const GenLumiInfoProduct &other) const
FinalStat const & acceptedBr() const
FinalStat const & selected() const
void setAccepted(unsigned int n, double sum, double sum2)
const std::vector< ProcessInfo > & getProcessInfos() const
FinalStat(unsigned int n1, double sum1, double sum21)
void setAcceptedBr(unsigned int n, double sum, double sum2)
XSec(double v, double e=-1.)
FinalStat const & killed() const
T sqrt(T t)
Definition: SSEVec.h:23
FinalStat const & accepted() const
Definition: value.py:1
const int getHEPIDWTUP() const
bool operator==(const XSec &other) const
virtual bool mergeProduct(const GenLumiInfoProduct &other)
void setLheXSec(double value, double err)
FinalStat const & tried() const
void setHEPIDWTUP(const int id)
bool operator!=(const FinalStat &other) const
bool operator==(const FinalStat &other) const
void addOthers(const ProcessInfo &other)
void setProcessInfo(const std::vector< ProcessInfo > &processes)
std::vector< ProcessInfo > internalProcesses_