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