CMS 3D CMS Logo

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

LHERunInfoProduct Class Reference

#include <LHERunInfoProduct.h>

List of all members.

Classes

class  const_iterator
class  Header

Public Types

typedef std::vector
< std::string >
::const_iterator 
comments_const_iterator
typedef std::vector< Header >
::const_iterator 
headers_const_iterator
typedef std::vector< Header >
::size_type 
size_type

Public Member Functions

void addComment (const std::string &line)
void addHeader (const Header &header)
const_iterator begin () const
comments_const_iterator comments_begin () const
comments_const_iterator comments_end () const
size_type comments_size () const
const_iterator end () const
headers_const_iterator headers_begin () const
headers_const_iterator headers_end () const
size_type headers_size () const
const lhef::HEPRUPheprup () const
const_iterator init () const
bool isProductEqual (const LHERunInfoProduct &other) const
 LHERunInfoProduct (const lhef::HEPRUP &heprup)
 LHERunInfoProduct ()
bool mergeProduct (const LHERunInfoProduct &other)
bool operator!= (const LHERunInfoProduct &other) const
bool operator== (const LHERunInfoProduct &other) const
 ~LHERunInfoProduct ()

Static Public Member Functions

static const std::string & endOfFile ()

Private Attributes

std::vector< std::string > comments_
std::vector< Headerheaders_
lhef::HEPRUP heprup_

Detailed Description

Definition at line 13 of file LHERunInfoProduct.h.


Member Typedef Documentation

Definition at line 45 of file LHERunInfoProduct.h.

Definition at line 43 of file LHERunInfoProduct.h.

Definition at line 42 of file LHERunInfoProduct.h.


Constructor & Destructor Documentation

LHERunInfoProduct::LHERunInfoProduct ( ) [inline]

Definition at line 47 of file LHERunInfoProduct.h.

{}
LHERunInfoProduct::LHERunInfoProduct ( const lhef::HEPRUP heprup) [inline]

Definition at line 48 of file LHERunInfoProduct.h.

: heprup_(heprup) {}
LHERunInfoProduct::~LHERunInfoProduct ( ) [inline]

Definition at line 49 of file LHERunInfoProduct.h.

{}

Member Function Documentation

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

Definition at line 52 of file LHERunInfoProduct.h.

References comments_.

Referenced by LHESource::beginRun(), and LHESource::produce().

{ comments_.push_back(line); }
void LHERunInfoProduct::addHeader ( const Header header) [inline]

Definition at line 51 of file LHERunInfoProduct.h.

References headers_.

Referenced by LHESource::beginRun(), mergeProduct(), and LHESource::produce().

{ headers_.push_back(header); }
LHERunInfoProduct::const_iterator LHERunInfoProduct::begin ( void  ) const
comments_const_iterator LHERunInfoProduct::comments_begin ( ) const [inline]

Definition at line 61 of file LHERunInfoProduct.h.

References comments_.

Referenced by lhef::LHERunInfo::LHERunInfo(), and LHERunInfoProduct::const_iterator::next().

{ return comments_.begin(); }
comments_const_iterator LHERunInfoProduct::comments_end ( ) const [inline]

Definition at line 62 of file LHERunInfoProduct.h.

References comments_.

Referenced by lhef::LHERunInfo::LHERunInfo().

{ return comments_.end(); }
size_type LHERunInfoProduct::comments_size ( ) const [inline]

Definition at line 60 of file LHERunInfoProduct.h.

References comments_.

Referenced by LHERunInfoProduct::const_iterator::next().

{ return comments_.size(); }
const_iterator LHERunInfoProduct::end ( void  ) const [inline]

Definition at line 110 of file LHERunInfoProduct.h.

{ return const_iterator(); }
const std::string & LHERunInfoProduct::endOfFile ( ) [static]

Definition at line 163 of file LHERunInfoProduct.cc.

Referenced by LHEWriter::endRun().

{
        static const std::string theEnd("</LesHouchesEvents>\n");

        return theEnd;
}
headers_const_iterator LHERunInfoProduct::headers_begin ( ) const [inline]

Definition at line 57 of file LHERunInfoProduct.h.

References headers_.

Referenced by begin(), lhef::LHERunInfo::LHERunInfo(), and mergeProduct().

{ return headers_.begin(); }
headers_const_iterator LHERunInfoProduct::headers_end ( ) const [inline]

Definition at line 58 of file LHERunInfoProduct.h.

References headers_.

Referenced by lhef::LHERunInfo::LHERunInfo(), mergeProduct(), and LHERunInfoProduct::const_iterator::next().

{ return headers_.end(); }
size_type LHERunInfoProduct::headers_size ( ) const [inline]

Definition at line 56 of file LHERunInfoProduct.h.

References headers_.

{ return headers_.size(); }
const lhef::HEPRUP& LHERunInfoProduct::heprup ( ) const [inline]

Definition at line 54 of file LHERunInfoProduct.h.

References heprup_.

Referenced by LHERunInfoProduct::const_iterator::next().

{ return heprup_; }
LHERunInfoProduct::const_iterator LHERunInfoProduct::init ( void  ) const
bool LHERunInfoProduct::isProductEqual ( const LHERunInfoProduct other) const [inline]

Definition at line 120 of file LHERunInfoProduct.h.

        { return *this == other; }
bool LHERunInfoProduct::mergeProduct ( const LHERunInfoProduct other)

Definition at line 208 of file LHERunInfoProduct.cc.

References addHeader(), filterCSVwithJSON::copy, lhef::HEPRUP::EBMUP, Exception, MultipleCompare::header, headers_, headers_begin(), headers_end(), heprup_, i, lhef::HEPRUP::IDBMUP, lhef::HEPRUP::IDWTUP, lhef::HEPRUP::LPRUP, max(), lhef::HEPRUP::NPRUP, lhef::HEPRUP::PDFGUP, lhef::HEPRUP::PDFSUP, lhef::HEPRUP::resize(), mathSSE::sqrt(), x, lhef::HEPRUP::XERRUP, lhef::HEPRUP::XMAXUP, and lhef::HEPRUP::XSECUP.

{
        if (heprup_.IDBMUP != other.heprup_.IDBMUP ||
            heprup_.EBMUP != other.heprup_.EBMUP ||
            heprup_.PDFGUP != other.heprup_.PDFGUP ||
            heprup_.PDFSUP != other.heprup_.PDFSUP ||
            heprup_.IDWTUP != other.heprup_.IDWTUP) {
                throw cms::Exception("ProductsNotMergeable")
                        << "Error in LHERunInfoProduct: LHE headers differ. "
                           "Cannot merge products." << std::endl;
        }

        bool compatibleHeaders = headers_ == other.headers_;

        // try to merge different, but compatible headers
        while(!compatibleHeaders) {
                // okay, something is different.
                // Let's try to merge, but don't duplicate identical headers
                // and test the rest against a whitelist

                std::set<Header, HeaderLess> headers;
                std::copy(headers_begin(), headers_end(),
                          std::inserter(headers, headers.begin()));

                bool failed = false;
                for(std::vector<LHERunInfoProduct::Header>::const_iterator
                                        header = other.headers_begin();
                    header != other.headers_end(); ++header) {
                        if (headers.count(*header))
                                continue;

                        if (header->tag() == "" ||
                            header->tag().find("Alpgen") == 0 ||
                            header->tag() == "MGGridCard" ||
                            header->tag() == "MGGenerationInfo") {
                                addHeader(*header);     
                                headers.insert(*header);
                        } else
                                failed = true;
                }
                if (failed)
                        break;

                compatibleHeaders = true;
        }

        // still not compatible after fixups
        if (!compatibleHeaders) {
                throw cms::Exception("ProductsNotMergeable")
                        << "Error in LHERunInfoProduct: LHE headers differ. "
                           "Cannot merge products." << std::endl;
        }

        // it is exactly the same, so merge
        if (heprup_ == other.heprup_)
                return true;

        // the input files are different ones, presumably generation
        // of the same process in different runs with identical run number
        // attempt merge of processes and cross-sections

        std::map<int, XSec> processes;

        for(int i = 0; i < heprup_.NPRUP; i++) {
                int id = heprup_.LPRUP[i];
                XSec &x = processes[id];
                x.xsec = heprup_.XSECUP[i];
                x.err = heprup_.XERRUP[i];
                x.max = heprup_.XMAXUP[i];
        }

        for(int i = 0; i < other.heprup_.NPRUP; i++) {
                int id = other.heprup_.LPRUP[i];
                XSec &x = processes[id];
                if (x.xsec) {
                        double wgt1 = 1.0 / (x.err * x.err);
                        double wgt2 = 1.0 / (other.heprup_.XERRUP[i] *
                                             other.heprup_.XERRUP[i]);
                        x.xsec = (wgt1 * x.xsec +
                                  wgt2 * other.heprup_.XSECUP[i]) /
                                 (wgt1 + wgt2);
                        x.err = 1.0 / std::sqrt(wgt1 + wgt2);
                        x.max = std::max(x.max, other.heprup_.XMAXUP[i]);
                } else {
                        x.xsec = other.heprup_.XSECUP[i];
                        x.err = other.heprup_.XERRUP[i];
                        x.max = other.heprup_.XMAXUP[i];
                }
        }

        heprup_.resize(processes.size());
        unsigned int i = 0;
        for(std::map<int, XSec>::const_iterator iter = processes.begin();
            iter != processes.end(); ++iter, i++) {
                heprup_.LPRUP[i] = iter->first;
                heprup_.XSECUP[i] = iter->second.xsec;
                heprup_.XERRUP[i] = iter->second.err;
                heprup_.XMAXUP[i] = iter->second.max;
        }

        return true;
}
bool LHERunInfoProduct::operator!= ( const LHERunInfoProduct other) const [inline]

Definition at line 116 of file LHERunInfoProduct.h.

        { return !(*this == other); }
bool LHERunInfoProduct::operator== ( const LHERunInfoProduct other) const [inline]

Definition at line 114 of file LHERunInfoProduct.h.

References comments_, headers_, and heprup_.

        { return heprup_ == other.heprup_ && headers_ == other.headers_ && comments_ == other.comments_; }

Member Data Documentation

std::vector<std::string> LHERunInfoProduct::comments_ [private]
std::vector<Header> LHERunInfoProduct::headers_ [private]

Definition at line 124 of file LHERunInfoProduct.h.

Referenced by heprup(), mergeProduct(), and operator==().