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.) :
38  value_(v), error_(e) {}
39  XSec(const XSec &other) :
40  value_(other.value_), error_(other.error_) {}
41 
42  double value() const { return value_; }
43  double error() const { return error_; }
44 
45  bool isSet() const { return value_ >= 0.; }
46  bool hasError() const { return error_ >= 0.; }
47 
48  operator double() const { return value_; }
49  operator bool() const { return isSet(); }
50 
51  bool operator == (const XSec &other) const
52  { return value_ == other.value_ && error_ == other.error_; }
53  bool operator != (const XSec &other) const { return !(*this == other); }
54 
55  private:
56  double value_, error_;
57  };
58 
59 
60  struct FinalStat {
61  public:
62  FinalStat() : n_(0), sum_(0.0), sum2_(0.0) {}
63  FinalStat(unsigned int n1, double sum1, double sum21) :
64  n_(n1), sum_(sum1), sum2_(sum21) {}
65  FinalStat(const FinalStat &other) :
66  n_(other.n_), sum_(other.sum_), sum2_(other.sum2_) {}
67 
68  unsigned int n() const { return n_; }
69  double sum() const { return sum_; }
70  double sum2() const{ return sum2_; }
71 
72  void add(const FinalStat& other) {
73  if (other.n() != 0 and other.sum_ != -1. and other.sum2() != -1.) {
74  n_ += other.n();
75  sum_ += other.sum();
76  sum2_ += other.sum2();
77  }
78  }
79 
80  bool operator == (const FinalStat &other) const
81  { return n_ == other.n_ && sum_ == other.sum_ && sum2_ == other.sum2_; }
82  bool operator != (const FinalStat &other) const { return !(*this == other); }
83  private:
84  unsigned int n_;
85  double sum_;
86  double sum2_;
87  };
88 
89 
90  struct ProcessInfo {
91  public:
92  ProcessInfo():process_(-1),nPassPos_(0),nPassNeg_(0),nTotalPos_(0),nTotalNeg_(0){}
93  ProcessInfo(int id):process_(id),nPassPos_(0),nPassNeg_(0),nTotalPos_(0),nTotalNeg_(0){}
94 
95  // accessors
96  int process() const {return process_;}
97  XSec const &lheXSec() const {return lheXSec_;}
98 
99  unsigned int nPassPos() const {return nPassPos_;}
100  unsigned int nPassNeg() const {return nPassNeg_;}
101  unsigned int nTotalPos() const {return nTotalPos_;}
102  unsigned int nTotalNeg() const {return nTotalNeg_;}
103 
104  FinalStat const &tried() const {return tried_;}
105  FinalStat const &selected() const {return selected_;}
106  FinalStat const &killed() const {return killed_;}
107  FinalStat const &accepted() const {return accepted_;}
108  FinalStat const &acceptedBr() const {return acceptedBr_;}
109 
110  // setters
111  void addOthers(const ProcessInfo& other){
112  mergeXSec(other.lheXSec(), other.selected().sum());
113  nPassPos_ += other.nPassPos();
114  nPassNeg_ += other.nPassNeg();
115  nTotalPos_ += other.nTotalPos();
116  nTotalNeg_ += other.nTotalNeg();
117  tried_.add(other.tried());
118  selected_.add(other.selected());
119  killed_.add(other.killed());
120  accepted_.add(other.accepted());
121  acceptedBr_.add(other.acceptedBr());
122  }
123  void setProcess(int id) { process_ = id; }
124  void setLheXSec(double value, double err) { lheXSec_ = XSec(value,err); }
125  void setNPassPos(unsigned int n) { nPassPos_ = n; }
126  void setNPassNeg(unsigned int n) { nPassNeg_ = n; }
127  void setNTotalPos(unsigned int n) { nTotalPos_ = n; }
128  void setNTotalNeg(unsigned int n) { nTotalNeg_ = n; }
129  void setTried(unsigned int n, double sum, double sum2) { tried_ = FinalStat(n,sum,sum2); }
130  void setSelected(unsigned int n, double sum, double sum2) { selected_ = FinalStat(n,sum,sum2); }
131  void setKilled(unsigned int n, double sum, double sum2) { killed_ = FinalStat(n,sum,sum2); }
132  void setAccepted(unsigned int n, double sum, double sum2) { accepted_ = FinalStat(n,sum,sum2); }
133  void setAcceptedBr(unsigned int n, double sum, double sum2) { acceptedBr_ = FinalStat(n,sum,sum2); }
134 
135  private:
136  void mergeXSec(XSec const &iXSec, double iWeight) {
137  if (iWeight <= 0.) {
138  return;
139  }
140  if (lheXSec_.value() <= 0.) {
141  lheXSec_ = iXSec;
142  } else {
143  bool useWeights = (lheXSec_.error() <= 0. || iXSec.error() <= 0.);
144  double wgt1 = useWeights ? selected().sum() : 1. / (lheXSec_.error() * lheXSec_.error());
145  double wgt2 = useWeights ? iWeight : 1. / (iXSec.error() * iXSec.error());
146  double xsec = (wgt1 * lheXSec_.value() + wgt2 * iXSec.value()) / (wgt1 + wgt2);
147  double err = useWeights ? 0. : 1.0 / std::sqrt(wgt1 + wgt2);
148  lheXSec_ = XSec(xsec, err);
149  }
150  }
151  int process_;
153  unsigned int nPassPos_;
154  unsigned int nPassNeg_;
155  unsigned int nTotalPos_;
156  unsigned int nTotalNeg_;
162 
163  };
164 
165 
166 
167  // methods used by EDM
168  virtual bool mergeProduct(const GenLumiInfoProduct &other);
169  void swap(GenLumiInfoProduct& other);
170  virtual bool isProductEqual(const GenLumiInfoProduct &other) const;
171  private:
172  // cross sections
174  std::vector<ProcessInfo> internalProcesses_;
175 
176 
177 };
178 
179 #endif // SimDataFormats_GeneratorProducts_GenLumiInfoProduct_h
const std::vector< ProcessInfo > & getProcessInfos() const
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)
FinalStat const & tried() const
void setAccepted(unsigned int n, double sum, double sum2)
FinalStat(unsigned int n1, double sum1, double sum21)
void setAcceptedBr(unsigned int n, double sum, double sum2)
XSec(double v, double e=-1.)
T sqrt(T t)
Definition: SSEVec.h:18
Definition: value.py:1
virtual bool isProductEqual(const GenLumiInfoProduct &other) const
FinalStat const & killed() const
virtual bool mergeProduct(const GenLumiInfoProduct &other)
void setLheXSec(double value, double err)
void setHEPIDWTUP(const int id)
bool operator==(const XSec &other) const
FinalStat const & accepted() const
FinalStat const & acceptedBr() const
void addOthers(const ProcessInfo &other)
FinalStat(const FinalStat &other)
void setProcessInfo(const std::vector< ProcessInfo > &processes)
std::vector< ProcessInfo > internalProcesses_
const int getHEPIDWTUP() const
FinalStat const & selected() const