File indexing completed on 2024-09-08 23:51:45
0001 #include <algorithm>
0002 #include <iostream>
0003 #include <sstream>
0004 #include <fstream>
0005 #include <string>
0006 #include <memory>
0007 #include <map>
0008
0009 #include <boost/algorithm/string/classification.hpp>
0010 #include <boost/algorithm/string/split.hpp>
0011 #include <boost/algorithm/string/trim.hpp>
0012
0013 #include "FWCore/Utilities/interface/Exception.h"
0014
0015 #include "GeneratorInterface/AlpgenInterface/interface/AlpgenHeader.h"
0016
0017 namespace {
0018 struct AlpgenParTokens {
0019 unsigned int index;
0020 std::vector<double> values;
0021 std::vector<std::string> comments;
0022
0023 bool parse(const std::string &line, bool withIndex);
0024 };
0025 }
0026
0027 bool AlpgenParTokens::parse(const std::string &line, bool withIndex) {
0028 std::string::size_type pos = line.find('!');
0029 if (pos == std::string::npos)
0030 return false;
0031
0032 std::string tmp = boost::trim_copy(line.substr(0, pos));
0033 boost::split(comments, tmp, boost::algorithm::is_space(), boost::token_compress_on);
0034 if (comments.empty())
0035 return false;
0036
0037 unsigned int i = 0, n = comments.size();
0038 if (withIndex) {
0039 std::istringstream ss(comments[i++]);
0040 ss >> index;
0041 if (ss.bad() || ss.peek() != std::istringstream::traits_type::eof())
0042 return false;
0043 }
0044
0045 values.clear();
0046 while (i < n) {
0047 std::istringstream ss(comments[i++]);
0048 double value;
0049 ss >> value;
0050 if (ss.bad() || ss.peek() != std::istringstream::traits_type::eof())
0051 return false;
0052
0053 values.push_back(value);
0054 }
0055
0056 tmp = boost::trim_copy(line.substr(pos + 1));
0057 boost::split(comments, tmp, boost::algorithm::is_space(), boost::token_compress_on);
0058
0059 return true;
0060 }
0061
0062 bool AlpgenHeader::parse(const std::vector<std::string>::const_iterator &begin,
0063 const std::vector<std::string>::const_iterator &end) {
0064 std::vector<std::string>::const_iterator line = begin;
0065
0066
0067 while (line != end)
0068 if ((line++)->find("****") != std::string::npos)
0069 break;
0070
0071 AlpgenParTokens tokens;
0072
0073
0074 if (line == end || !tokens.parse(*line++, true) || !tokens.values.empty())
0075 return false;
0076 ihrd = tokens.index;
0077
0078
0079 if (line == end || !tokens.parse(*line++, false) || tokens.values.size() < 6)
0080 return false;
0081
0082 std::copy(tokens.values.begin(), tokens.values.begin() + 6, masses);
0083
0084
0085 params.clear();
0086 while (line != end && line->find("****") == std::string::npos) {
0087 if (!tokens.parse(*line++, true) || tokens.values.size() != 1)
0088 return false;
0089 params[(Parameter)tokens.index] = tokens.values[0];
0090 }
0091 if (line == end)
0092 return false;
0093 else
0094 line++;
0095
0096
0097 if (line == end || !tokens.parse(*line++, false) || tokens.values.size() != 2)
0098 return false;
0099
0100 xsec = tokens.values[0];
0101 xsecErr = tokens.values[1];
0102
0103
0104 if (line == end || !tokens.parse(*line++, true) || tokens.values.size() != 1)
0105 return false;
0106
0107 nEvents = tokens.index;
0108 lumi = tokens.values[0];
0109
0110 return true;
0111 }
0112
0113
0114
0115 #define DEFINE_ALPGEN_PARAMETER(x) {AlpgenHeader::x, #x}
0116
0117 namespace {
0118 struct AlpgenParameterName {
0119 AlpgenHeader::Parameter index;
0120 const char *name;
0121
0122 inline bool operator==(AlpgenHeader::Parameter index) const { return this->index == index; }
0123 }
0124
0125 const alpgenParameterNames[] = {
0126 DEFINE_ALPGEN_PARAMETER(ih2), DEFINE_ALPGEN_PARAMETER(ebeam), DEFINE_ALPGEN_PARAMETER(ndns),
0127 DEFINE_ALPGEN_PARAMETER(iqopt), DEFINE_ALPGEN_PARAMETER(qfac), DEFINE_ALPGEN_PARAMETER(ickkw),
0128 DEFINE_ALPGEN_PARAMETER(ktfac), DEFINE_ALPGEN_PARAMETER(njets), DEFINE_ALPGEN_PARAMETER(ihvy),
0129 DEFINE_ALPGEN_PARAMETER(ihvy2), DEFINE_ALPGEN_PARAMETER(nw), DEFINE_ALPGEN_PARAMETER(nz),
0130 DEFINE_ALPGEN_PARAMETER(nh), DEFINE_ALPGEN_PARAMETER(nph), DEFINE_ALPGEN_PARAMETER(ptjmin),
0131 DEFINE_ALPGEN_PARAMETER(ptbmin), DEFINE_ALPGEN_PARAMETER(ptcmin), DEFINE_ALPGEN_PARAMETER(ptlmin),
0132 DEFINE_ALPGEN_PARAMETER(metmin), DEFINE_ALPGEN_PARAMETER(ptphmin), DEFINE_ALPGEN_PARAMETER(etajmax),
0133 DEFINE_ALPGEN_PARAMETER(etabmax), DEFINE_ALPGEN_PARAMETER(etacmax), DEFINE_ALPGEN_PARAMETER(etalmax),
0134 DEFINE_ALPGEN_PARAMETER(etaphmax), DEFINE_ALPGEN_PARAMETER(drjmin), DEFINE_ALPGEN_PARAMETER(drbmin),
0135 DEFINE_ALPGEN_PARAMETER(drcmin), DEFINE_ALPGEN_PARAMETER(drlmin), DEFINE_ALPGEN_PARAMETER(drphjmin),
0136 DEFINE_ALPGEN_PARAMETER(drphlmin), DEFINE_ALPGEN_PARAMETER(drphmin), DEFINE_ALPGEN_PARAMETER(mllmin),
0137 DEFINE_ALPGEN_PARAMETER(mllmax), DEFINE_ALPGEN_PARAMETER(iseed1), DEFINE_ALPGEN_PARAMETER(iseed2),
0138 DEFINE_ALPGEN_PARAMETER(itopprc), DEFINE_ALPGEN_PARAMETER(cluopt), DEFINE_ALPGEN_PARAMETER(iseed3),
0139 DEFINE_ALPGEN_PARAMETER(iseed4)};
0140 }
0141
0142 std::string AlpgenHeader::parameterName(Parameter index) {
0143 static const unsigned int size = sizeof alpgenParameterNames / sizeof alpgenParameterNames[0];
0144
0145 const AlpgenParameterName *pos = std::find(alpgenParameterNames, alpgenParameterNames + size, index);
0146
0147 if (pos != alpgenParameterNames + size)
0148 return pos->name;
0149
0150 std::ostringstream ss;
0151 ss << "unknown " << (int)index;
0152 return ss.str();
0153 }