CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes

lhef::LHERunInfo Class Reference

#include <LHERunInfo.h>

List of all members.

Classes

struct  Counter
class  Header
struct  Process
struct  XSec

Public Types

enum  CountMode { kTried = 0, kSelected, kKilled, kAccepted }

Public Member Functions

void addComment (const std::string &line)
void addHeader (const Header &header)
void count (int process, CountMode count, double eventWeight=1.0, double brWeight=1.0, double matchWeight=1.0)
std::vector< std::string > findHeader (const std::string &tag) const
const std::vector< std::string > & getComments () const
const std::vector< Header > & getHeaders () const
const HEPRUPgetHEPRUP () const
 LHERunInfo (const HEPRUP &heprup)
 LHERunInfo (const LHERunInfoProduct &product)
 LHERunInfo (const HEPRUP &heprup, const std::vector< LHERunInfoProduct::Header > &headers, const std::vector< std::string > &comments)
 LHERunInfo (std::istream &in)
bool operator!= (const LHERunInfo &other) const
bool operator== (const LHERunInfo &other) const
std::pair< int, int > pdfSetTranslation () const
void statistics () const
XSec xsec () const
 ~LHERunInfo ()

Private Member Functions

void init ()

Private Attributes

std::vector< std::string > comments
std::vector< Headerheaders
HEPRUP heprup
std::vector< Processprocesses

Detailed Description

Definition at line 25 of file LHERunInfo.h.


Member Enumeration Documentation

Enumerator:
kTried 
kSelected 
kKilled 
kAccepted 

Definition at line 66 of file LHERunInfo.h.


Constructor & Destructor Documentation

lhef::LHERunInfo::LHERunInfo ( std::istream &  in)

Definition at line 41 of file LHERunInfo.cc.

References comments, lhef::HEPRUP::EBMUP, heprup, i, lhef::HEPRUP::IDBMUP, lhef::HEPRUP::IDWTUP, init(), geometryCSVtoXML::line, lhef::HEPRUP::LPRUP, lhef::HEPRUP::NPRUP, lhef::HEPRUP::PDFGUP, lhef::HEPRUP::PDFSUP, lhef::HEPRUP::resize(), skipWhitespace(), lhef::HEPRUP::XERRUP, lhef::HEPRUP::XMAXUP, and lhef::HEPRUP::XSECUP.

{
        in >> heprup.IDBMUP.first >> heprup.IDBMUP.second
           >> heprup.EBMUP.first >> heprup.EBMUP.second
           >> heprup.PDFGUP.first >> heprup.PDFGUP.second
           >> heprup.PDFSUP.first >> heprup.PDFSUP.second
           >> heprup.IDWTUP >> heprup.NPRUP;
        if (!in.good())
                throw cms::Exception("InvalidFormat")
                        << "Les Houches file contained invalid"
                           " header in init section." << std::endl;

        heprup.resize();

        for(int i = 0; i < heprup.NPRUP; i++) {
                in >> heprup.XSECUP[i] >> heprup.XERRUP[i]
                   >> heprup.XMAXUP[i] >> heprup.LPRUP[i];
                if (!in.good())
                        throw cms::Exception("InvalidFormat")
                                << "Les Houches file contained invalid data"
                                   " in header payload line " << (i + 1)
                                << "." << std::endl;
        }

        while(skipWhitespace(in) == '#') {
                std::string line;
                std::getline(in, line);
                comments.push_back(line + "\n");
        }

        if (!in.eof())
                edm::LogWarning("Generator|LHEInterface")
                        << "Les Houches file contained spurious"
                           " content after the regular data." << std::endl;

        init();
}
lhef::LHERunInfo::LHERunInfo ( const HEPRUP heprup)

Definition at line 79 of file LHERunInfo.cc.

References init().

                                           :
        heprup(heprup)
{
        init();
}
lhef::LHERunInfo::LHERunInfo ( const HEPRUP heprup,
const std::vector< LHERunInfoProduct::Header > &  headers,
const std::vector< std::string > &  comments 
)

Definition at line 85 of file LHERunInfo.cc.

References filterCSVwithJSON::copy, and init().

                                                             :
        heprup(heprup)
{
        std::copy(headers.begin(), headers.end(),
                  std::back_inserter(this->headers));
        std::copy(comments.begin(), comments.end(),
                  std::back_inserter(this->comments));

        init();
}
lhef::LHERunInfo::LHERunInfo ( const LHERunInfoProduct product)
lhef::LHERunInfo::~LHERunInfo ( )

Definition at line 109 of file LHERunInfo.cc.

{
}

Member Function Documentation

void lhef::LHERunInfo::addComment ( const std::string &  line) [inline]

Definition at line 64 of file LHERunInfo.h.

{ comments.push_back(line); }
void lhef::LHERunInfo::addHeader ( const Header header) [inline]

Definition at line 63 of file LHERunInfo.h.

Referenced by lhef::LHEReader::next().

{ headers.push_back(header); }
void lhef::LHERunInfo::count ( int  process,
CountMode  count,
double  eventWeight = 1.0,
double  brWeight = 1.0,
double  matchWeight = 1.0 
)

Definition at line 132 of file LHERunInfo.cc.

References kAccepted, kKilled, kSelected, kTried, proc, align_tpl::process, and processes.

{
        std::vector<Process>::iterator proc =
                std::lower_bound(processes.begin(), processes.end(), process);
        if (proc == processes.end() || proc->process != process)
                return;

        switch(mode) {
            case kAccepted:
                proc->acceptedBr.add(eventWeight * brWeight * matchWeight);
                proc->accepted.add(eventWeight * matchWeight);
            case kKilled:
                proc->killed.add(eventWeight * matchWeight);
            case kSelected:
                proc->selected.add(eventWeight);
            case kTried:
                proc->tried.add(eventWeight);
        }
}
std::vector< std::string > lhef::LHERunInfo::findHeader ( const std::string &  tag) const

Definition at line 390 of file LHERunInfo.cc.

References lhef::domToLines(), headers, dbtoconf::root, and GlobalPosition_Frontier_DevDB_cff::tag.

Referenced by gen::JetMatchingAlpgen::init(), gen::JetMatchingMadgraph::init(), Herwig6Hadronizer::initialize(), and gen::Pythia6Hadronizer::initializeForExternalPartons().

{
        const LHERunInfo::Header *header = 0;
        for(std::vector<Header>::const_iterator iter = headers.begin();
            iter != headers.end(); ++iter) {
                if (iter->tag() == tag)
                        return std::vector<std::string>(iter->begin(),
                                                        iter->end());
                if (iter->tag() == "header")
                        header = &*iter;
        }

        if (!header)
                return std::vector<std::string>();

        const DOMNode *root = header->getXMLNode();
        if (!root)
                return std::vector<std::string>();

        for(const DOMNode *iter = root->getFirstChild();
            iter; iter = iter->getNextSibling()) {
                if (iter->getNodeType() != DOMNode::ELEMENT_NODE)
                        continue;
                if (tag == (const char*)XMLSimpleStr(iter->getNodeName()))
                        return domToLines(iter);
        }

        return std::vector<std::string>();
}
const std::vector<std::string>& lhef::LHERunInfo::getComments ( ) const [inline]

Definition at line 59 of file LHERunInfo.h.

References comments.

{ return comments; }
const std::vector<Header>& lhef::LHERunInfo::getHeaders ( ) const [inline]

Definition at line 58 of file LHERunInfo.h.

References headers.

Referenced by Herwig6Hadronizer::upInit().

{ return headers; }
const HEPRUP* lhef::LHERunInfo::getHEPRUP ( ) const [inline]

Definition at line 52 of file LHERunInfo.h.

References heprup.

Referenced by gen::FortranCallback::fillHeader(), and ThePEG::LesHouchesInterface::open().

{ return &heprup; } 
void lhef::LHERunInfo::init ( void  ) [private]

Definition at line 113 of file LHERunInfo.cc.

References heprup, lhef::LHERunInfo::Process::heprupIndex, i, lhef::HEPRUP::LPRUP, lhef::HEPRUP::NPRUP, proc, lhef::LHERunInfo::Process::process, processes, and python::multivaluedict::sort().

Referenced by LHERunInfo().

{
        for(int i = 0; i < heprup.NPRUP; i++) {
                Process proc;

                proc.process = heprup.LPRUP[i];
                proc.heprupIndex = (unsigned int)i;

                processes.push_back(proc);
        }

        std::sort(processes.begin(), processes.end());
}
bool lhef::LHERunInfo::operator!= ( const LHERunInfo other) const [inline]

Definition at line 55 of file LHERunInfo.h.

        { return !(*this == other); }
bool lhef::LHERunInfo::operator== ( const LHERunInfo other) const

Definition at line 127 of file LHERunInfo.cc.

References heprup.

{
        return heprup == other.heprup;
}
std::pair< int, int > lhef::LHERunInfo::pdfSetTranslation ( ) const

Definition at line 502 of file LHERunInfo.cc.

References heprup, lhef::HEPRUP::PDFGUP, and lhef::HEPRUP::PDFSUP.

Referenced by Herwig6Hadronizer::initialize().

{
        int pdfA = -1, pdfB = -1;

        if (heprup.PDFGUP.first >= 0) {
                pdfA = heprup.PDFSUP.first;
        }

        if (heprup.PDFGUP.second >= 0) {
                pdfB = heprup.PDFSUP.second;
        }

        return std::make_pair(pdfA, pdfB);
}
void lhef::LHERunInfo::statistics ( ) const

Definition at line 228 of file LHERunInfo.cc.

References abs, gather_cfg::cout, heprup, lhef::HEPRUP::IDWTUP, proc, processes, mathSSE::sqrt(), lhef::HEPRUP::XERRUP, xsec(), and lhef::HEPRUP::XSECUP.

Referenced by edm::HadronizerFilter< HAD, DEC >::endRun().

{
        double sigSelSum = 0.0;
        double sigSum = 0.0;
        double sigBrSum = 0.0;
        double err2Sum = 0.0;
        double errBr2Sum = 0.0;
        unsigned long nAccepted = 0;
        unsigned long nTried = 0;

        std::cout << std::endl;
        std::cout << "Process and cross-section statistics" << std::endl;
        std::cout << "------------------------------------" << std::endl;
        std::cout << "Process\tevents\ttried\txsec [pb]\t\taccepted [%]"
                  << std::endl;

        for(std::vector<Process>::const_iterator proc = processes.begin();
            proc != processes.end(); ++proc) {
                unsigned int idx = proc->heprupIndex;

                double sigmaSum, sigma2Sum, sigma2Err, xsec;
                switch(std::abs(heprup.IDWTUP)) {
                    case 2:
                        sigmaSum = proc->tried.sum * heprup.XSECUP[idx];
                        sigma2Sum = proc->tried.sum2 * heprup.XSECUP[idx]
                                                     * heprup.XSECUP[idx];
                        sigma2Err = proc->tried.sum2 * heprup.XERRUP[idx]
                                                     * heprup.XERRUP[idx];
                        break;
                    case 3:
                        sigmaSum = proc->tried.n * heprup.XSECUP[idx];
                        sigma2Sum = sigmaSum * heprup.XSECUP[idx];
                        sigma2Err = proc->tried.n * heprup.XERRUP[idx]
                                                  * heprup.XERRUP[idx];
                        break;
                    default:
                        xsec = proc->tried.sum / proc->tried.n;
                        sigmaSum = proc->tried.sum * xsec;
                        sigma2Sum = proc->tried.sum2 * xsec * xsec;
                        sigma2Err = 0.0;
                }

                if (!proc->selected.n) {
                        std::cout << proc->process << "\t0\t0\tn/a\t\t\tn/a"
                                  << std::endl;
                        continue;
                }

                double sigmaAvg = sigmaSum / proc->tried.sum;
                double fracAcc = proc->killed.sum / proc->selected.sum;
                double fracBr = proc->accepted.sum > 0.0 ?
                                proc->acceptedBr.sum / proc->accepted.sum : 1;
                double sigmaFin = sigmaAvg * fracAcc;
                double sigmaFinBr = sigmaFin * fracBr;

                double relErr = 1.0;
                if (proc->killed.n > 1) {
                        double sigmaAvg2 = sigmaAvg * sigmaAvg;
                        double delta2Sig =
                                (sigma2Sum / proc->tried.n - sigmaAvg2) /
                                (proc->tried.n * sigmaAvg2);
                        double delta2Veto =
                                ((double)proc->selected.n - proc->killed.n) /
                                ((double)proc->selected.n * proc->killed.n);
                        double delta2Sum = delta2Sig + delta2Veto
                                           + sigma2Err / sigma2Sum;
                        relErr = (delta2Sum > 0.0 ?
                                        std::sqrt(delta2Sum) : 0.0);
                }
                double deltaFin = sigmaFin * relErr;
                double deltaFinBr = sigmaFinBr * relErr;

                std::cout << proc->process << "\t"
                          << proc->accepted.n << "\t"
                          << proc->tried.n << "\t"
                          << std::scientific << std::setprecision(3)
                          << sigmaFinBr << " +/- "
                          << deltaFinBr << "\t"
                          << std::fixed << std::setprecision(1)
                          << (fracAcc * 100) << std::endl;

                nAccepted += proc->accepted.n;
                nTried += proc->tried.n;
                sigSelSum += sigmaAvg;
                sigSum += sigmaFin;
                sigBrSum += sigmaFinBr;
                err2Sum += deltaFin * deltaFin;
                errBr2Sum += deltaFinBr * deltaFinBr;
        }

        std::cout << "Total\t"
                  << nAccepted << "\t"
                  << nTried << "\t"
                  << std::scientific << std::setprecision(3)
                  << sigBrSum << " +/- "
                  << std::sqrt(errBr2Sum) << "\t"
                  << std::fixed << std::setprecision(1)
                  << (sigSum / sigSelSum * 100) << std::endl;
}
LHERunInfo::XSec lhef::LHERunInfo::xsec ( ) const

Definition at line 153 of file LHERunInfo.cc.

References abs, lhef::LHERunInfo::XSec::error, heprup, lhef::HEPRUP::IDWTUP, proc, processes, query::result, mathSSE::sqrt(), lhef::LHERunInfo::XSec::value, lhef::HEPRUP::XERRUP, and lhef::HEPRUP::XSECUP.

Referenced by edm::HadronizerFilter< HAD, DEC >::endRun(), and statistics().

{
        double sigSelSum = 0.0;
        double sigSum = 0.0;
        double sigBrSum = 0.0;
        double err2Sum = 0.0;
        double errBr2Sum = 0.0;

        for(std::vector<Process>::const_iterator proc = processes.begin();
            proc != processes.end(); ++proc) {
                unsigned int idx = proc->heprupIndex;

                double sigmaSum, sigma2Sum, sigma2Err, xsec;
                switch(std::abs(heprup.IDWTUP)) {
                    case 2:
                        sigmaSum = proc->tried.sum * heprup.XSECUP[idx];
                        sigma2Sum = proc->tried.sum2 * heprup.XSECUP[idx]
                                                     * heprup.XSECUP[idx];
                        sigma2Err = proc->tried.sum2 * heprup.XERRUP[idx]
                                                     * heprup.XERRUP[idx];
                        break;
                    case 3:
                        sigmaSum = proc->tried.n * heprup.XSECUP[idx];
                        sigma2Sum = sigmaSum * heprup.XSECUP[idx];
                        sigma2Err = proc->tried.n * heprup.XERRUP[idx]
                                                  * heprup.XERRUP[idx];
                        break;
                    default:
                        xsec = proc->tried.sum / proc->tried.n;
                        sigmaSum = proc->tried.sum * xsec;
                        sigma2Sum = proc->tried.sum2 * xsec * xsec;
                        sigma2Err = 0.0;
                }

                if (!proc->killed.n)
                        continue;

                double sigmaAvg = sigmaSum / proc->tried.sum;
                double fracAcc = proc->killed.sum / proc->selected.sum;
                double fracBr = proc->accepted.sum > 0.0 ?
                                proc->acceptedBr.sum / proc->accepted.sum : 1;
                double sigmaFin = sigmaAvg * fracAcc * fracBr;
                double sigmaFinBr = sigmaFin * fracBr;

                double relErr = 1.0;
                if (proc->killed.n > 1) {
                        double sigmaAvg2 = sigmaAvg * sigmaAvg;
                        double delta2Sig =
                                (sigma2Sum / proc->tried.n - sigmaAvg2) /
                                (proc->tried.n * sigmaAvg2);
                        double delta2Veto =
                                ((double)proc->selected.n - proc->killed.n) /
                                ((double)proc->selected.n * proc->killed.n);
                        double delta2Sum = delta2Sig + delta2Veto
                                           + sigma2Err / sigma2Sum;
                        relErr = (delta2Sum > 0.0 ?
                                        std::sqrt(delta2Sum) : 0.0);
                }
                double deltaFin = sigmaFin * relErr;
                double deltaFinBr = sigmaFinBr * relErr;

                sigSelSum += sigmaAvg;
                sigSum += sigmaFin;
                sigBrSum += sigmaFinBr;
                err2Sum += deltaFin * deltaFin;
                errBr2Sum += deltaFinBr * deltaFinBr;
        }

        XSec result;
        result.value = sigBrSum;
        result.error = std::sqrt(errBr2Sum);

        return result;
}

Member Data Documentation

std::vector<std::string> lhef::LHERunInfo::comments [private]

Definition at line 125 of file LHERunInfo.h.

Referenced by getComments(), and LHERunInfo().

std::vector<Header> lhef::LHERunInfo::headers [private]

Definition at line 124 of file LHERunInfo.h.

Referenced by findHeader(), getHeaders(), and LHERunInfo().

Definition at line 122 of file LHERunInfo.h.

Referenced by getHEPRUP(), init(), LHERunInfo(), operator==(), pdfSetTranslation(), statistics(), and xsec().

std::vector<Process> lhef::LHERunInfo::processes [private]

Definition at line 123 of file LHERunInfo.h.

Referenced by count(), init(), statistics(), and xsec().