00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef THEPEG_XSecStat_H
00010 #define THEPEG_XSecStat_H
00011
00012
00013
00014
00015 #include "ThePEG/Config/ThePEG.h"
00016
00017 namespace ThePEG {
00018
00036 class XSecStat {
00037
00038 public:
00039
00045 XSecStat()
00046 : theMaxXSec(ZERO), theAttempts(0), theAccepted(0),
00047 theSumWeights(0.0), theSumWeights2(0.0) {}
00048
00053 XSecStat(CrossSection xsecmax)
00054 : theMaxXSec(xsecmax), theAttempts(0), theAccepted(0),
00055 theSumWeights(0.0), theSumWeights2(0.0) {}
00056
00060 XSecStat & operator=(const XSecStat & x) {
00061 theMaxXSec = x.theMaxXSec;
00062 theAttempts = x.theAttempts;
00063 theAccepted = x.theAccepted;
00064 theSumWeights = x.theSumWeights;
00065 theSumWeights2 = x.theSumWeights2;
00066 return *this;
00067 }
00068
00072 XSecStat & operator+=(const XSecStat & x) {
00073 theMaxXSec += x.theMaxXSec;
00074 theAttempts += x.theAttempts;
00075 theAccepted += x.theAccepted;
00076 theSumWeights += x.theSumWeights;
00077 theSumWeights2 += x.theSumWeights2;
00078 return *this;
00079 }
00080
00084 void reset() {
00085 theAttempts = theAccepted = 0;
00086 theSumWeights = theSumWeights2 = 0.0;
00087 }
00088
00090
00091 public:
00092
00095
00100 void accept() { ++theAccepted; }
00101
00106 void select(double weight) {
00107 ++theAttempts;
00108 theSumWeights += weight;
00109 theSumWeights2 += sqr(weight);
00110 }
00111
00120 void reject(double weight = 1.0) {
00121 theSumWeights -= weight;
00122 theSumWeights2 -= sqr(weight);
00123 --theAccepted;
00124 }
00125
00131 CrossSection xSec() const {
00132 return attempts() ? maxXSec()*sumWeights()/attempts() : maxXSec();
00133 }
00134
00135
00141 CrossSection xSecErr() const {
00142 return attempts() ? maxXSec()*sqrt(sumWeights2())/attempts() : maxXSec();
00143 }
00144
00148 CrossSection maxXSec() const { return theMaxXSec; }
00149
00153 double sumWeights() const { return theSumWeights; }
00154
00158 double sumWeights2() const { return theSumWeights2; }
00159
00163 long attempts() const { return theAttempts; }
00164
00168 long accepted() const { return theAccepted; }
00169
00173 void maxXSec(CrossSection x) { theMaxXSec = x; }
00175
00176 public:
00177
00183 void output(PersistentOStream & os) const;
00184
00188 void input(PersistentIStream & is);
00190
00191 private:
00192
00196 CrossSection theMaxXSec;
00197
00201 long theAttempts;
00202
00206 long theAccepted;
00207
00211 double theSumWeights;
00212
00216 double theSumWeights2;
00217
00218 };
00219
00221 PersistentOStream & operator<<(PersistentOStream &, const XSecStat &);
00222
00224 PersistentIStream & operator>>(PersistentIStream &, XSecStat &);
00225
00227 inline XSecStat operator+(const XSecStat & x1, const XSecStat & x2) {
00228 XSecStat x = x1;
00229 return x += x2;
00230 }
00231
00232 }
00233
00234 #endif