Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:14

0001 #ifndef GeneratorInterface_LHEInterface_LHERunInfo_h
0002 #define GeneratorInterface_LHEInterface_LHERunInfo_h
0003 
0004 #include <iostream>
0005 #include <memory>
0006 #include <vector>
0007 #include <string>
0008 
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 
0011 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
0012 #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
0013 
0014 #ifndef XERCES_CPP_NAMESPACE_QUALIFIER
0015 #define UNDEF_XERCES_CPP_NAMESPACE_QUALIFIER
0016 #define XERCES_CPP_NAMESPACE_QUALIFIER dummy::
0017 namespace dummy {
0018   class DOMNode;
0019   class DOMDocument;
0020 }  // namespace dummy
0021 #endif
0022 
0023 namespace lhef {
0024 
0025   class LHERunInfo {
0026   public:
0027     LHERunInfo(std::istream &in);
0028     LHERunInfo(const HEPRUP &heprup);
0029     LHERunInfo(const HEPRUP &heprup,
0030                const std::vector<LHERunInfoProduct::Header> &headers,
0031                const std::vector<std::string> &comments);
0032     LHERunInfo(const LHERunInfoProduct &product);
0033     ~LHERunInfo();
0034 
0035     class Header : public LHERunInfoProduct::Header {
0036     public:
0037       Header();
0038       Header(const std::string &tag);
0039       Header(const Header &orig);
0040       Header(const LHERunInfoProduct::Header &orig);
0041       ~Header();
0042 
0043 #ifndef UNDEF_XERCES_CPP_NAMESPACE_QUALIFIER
0044       const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *getXMLNode() const;
0045 #endif
0046 
0047     private:
0048       mutable XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *xmlDoc;
0049     };
0050 
0051     const HEPRUP *getHEPRUP() const { return &heprup; }
0052 
0053     bool operator==(const LHERunInfo &other) const;
0054     inline bool operator!=(const LHERunInfo &other) const { return !(*this == other); }
0055 
0056     const std::vector<Header> &getHeaders() const { return headers; }
0057     const std::vector<std::string> &getComments() const { return comments; }
0058 
0059     std::vector<std::string> findHeader(const std::string &tag) const;
0060 
0061     void addHeader(const Header &header) { headers.push_back(header); }
0062     void addComment(const std::string &line) { comments.push_back(line); }
0063 
0064     enum CountMode { kTried = 0, kSelected, kKilled, kAccepted };
0065 
0066     struct XSec {
0067     public:
0068       XSec() : value_(0.0), error_(0.0) {}
0069       XSec(double v, double e) : value_(v), error_(e) {}
0070       double value() { return value_; }
0071       double error() { return error_; }
0072 
0073     private:
0074       double value_;
0075       double error_;
0076     };
0077 
0078     void count(int process, CountMode count, double eventWeight = 1.0, double brWeight = 1.0, double matchWeight = 1.0);
0079     XSec xsec() const;
0080     void statistics() const;
0081 
0082     std::pair<int, int> pdfSetTranslation() const;
0083 
0084     struct Counter {
0085     public:
0086       Counter() : n_(0), sum_(0.0), sum2_(0.0) {}
0087       Counter(unsigned int n1, double sum1, double sum21) : n_(n1), sum_(sum1), sum2_(sum21) {}
0088       inline void add(double weight) {
0089         n_++;
0090         sum_ += weight;
0091         sum2_ += weight * weight;
0092       }
0093       unsigned int n() const { return n_; }
0094       double sum() const { return sum_; }
0095       double sum2() const { return sum2_; }
0096 
0097     private:
0098       unsigned int n_;
0099       double sum_;
0100       double sum2_;
0101     };
0102 
0103     struct Process {
0104     public:
0105       Process() : process_(-1), heprupIndex_(-1), nPassPos_(0), nPassNeg_(0), nTotalPos_(0), nTotalNeg_(0) {}
0106       Process(int id) : process_(id), heprupIndex_(-1), nPassPos_(0), nPassNeg_(0), nTotalPos_(0), nTotalNeg_(0) {}
0107       // accessors
0108       int process() const { return process_; }
0109       unsigned int heprupIndex() const { return heprupIndex_; }
0110       XSec getLHEXSec() const { return lheXSec_; }
0111 
0112       unsigned int nPassPos() const { return nPassPos_; }
0113       unsigned int nPassNeg() const { return nPassNeg_; }
0114       unsigned int nTotalPos() const { return nTotalPos_; }
0115       unsigned int nTotalNeg() const { return nTotalNeg_; }
0116 
0117       Counter tried() const { return tried_; }
0118       Counter selected() const { return selected_; }
0119       Counter killed() const { return killed_; }
0120       Counter accepted() const { return accepted_; }
0121       Counter acceptedBr() const { return acceptedBr_; }
0122 
0123       // setters
0124       void setProcess(int id) { process_ = id; }
0125       void setHepRupIndex(int id) { heprupIndex_ = id; }
0126       void setLHEXSec(double value, double error) { lheXSec_ = XSec(value, error); }
0127 
0128       void addNPassPos(unsigned int n = 1) { nPassPos_ += n; }
0129       void addNPassNeg(unsigned int n = 1) { nPassNeg_ += n; }
0130       void addNTotalPos(unsigned int n = 1) { nTotalPos_ += n; }
0131       void addNTotalNeg(unsigned int n = 1) { nTotalNeg_ += n; }
0132 
0133       void addTried(double w) { tried_.add(w); }
0134       void addSelected(double w) { selected_.add(w); }
0135       void addKilled(double w) { killed_.add(w); }
0136       void addAccepted(double w) { accepted_.add(w); }
0137       void addAcceptedBr(double w) { acceptedBr_.add(w); }
0138 
0139     private:
0140       int process_;
0141       XSec lheXSec_;
0142       unsigned int heprupIndex_;
0143       unsigned int nPassPos_;
0144       unsigned int nPassNeg_;
0145       unsigned int nTotalPos_;
0146       unsigned int nTotalNeg_;
0147       Counter tried_;
0148       Counter selected_;
0149       Counter killed_;
0150       Counter accepted_;
0151       Counter acceptedBr_;
0152     };
0153 
0154   private:
0155     void init();
0156 
0157     HEPRUP heprup;
0158     std::vector<Process> processes;
0159     std::vector<Header> headers;
0160     std::vector<std::string> comments;
0161 
0162   public:
0163     const std::vector<Process> &getLumiProcesses() const { return processesLumi; }
0164     const int getHEPIDWTUP() const { return heprup.IDWTUP; }
0165     void initLumi();
0166 
0167   private:
0168     std::vector<Process> processesLumi;
0169   };
0170 
0171 }  // namespace lhef
0172 
0173 #ifdef UNDEF_XERCES_CPP_NAMESPACE_QUALIFIER
0174 #undef XERCES_CPP_NAMESPACE_QUALIFIER
0175 #endif
0176 
0177 #endif  // GeneratorRunInfo_LHEInterface_LHERunInfo_h