CMS 3D CMS Logo

AlpgenHeader.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iostream>
3 #include <sstream>
4 #include <fstream>
5 #include <string>
6 #include <memory>
7 #include <map>
8 
9 #include <boost/algorithm/string/classification.hpp>
10 #include <boost/algorithm/string/split.hpp>
11 #include <boost/algorithm/string/trim.hpp>
12 
14 
16 
17 namespace {
18  struct AlpgenParTokens {
19  unsigned int index;
20  std::vector<double> values;
21  std::vector<std::string> comments;
22 
23  bool parse(const std::string &line, bool withIndex);
24  };
25 } // namespace
26 
27 bool AlpgenParTokens::parse(const std::string &line, bool withIndex) {
28  std::string::size_type pos = line.find('!');
29  if (pos == std::string::npos)
30  return false;
31 
32  std::string tmp = boost::trim_copy(line.substr(0, pos));
33  boost::split(comments, tmp, boost::algorithm::is_space(), boost::token_compress_on);
34  if (comments.empty())
35  return false;
36 
37  unsigned int i = 0, n = comments.size();
38  if (withIndex) {
39  std::istringstream ss(comments[i++]);
40  ss >> index;
41  if (ss.bad() || ss.peek() != std::istringstream::traits_type::eof())
42  return false;
43  }
44 
45  values.clear();
46  while (i < n) {
47  std::istringstream ss(comments[i++]);
48  double value;
49  ss >> value;
50  if (ss.bad() || ss.peek() != std::istringstream::traits_type::eof())
51  return false;
52 
53  values.push_back(value);
54  }
55 
56  tmp = boost::trim_copy(line.substr(pos + 1));
57  boost::split(comments, tmp, boost::algorithm::is_space(), boost::token_compress_on);
58 
59  return true;
60 }
61 
62 bool AlpgenHeader::parse(const std::vector<std::string>::const_iterator &begin,
63  const std::vector<std::string>::const_iterator &end) {
64  std::vector<std::string>::const_iterator line = begin;
65 
66  // Mimicking Alpgen - read the _unw.par file until you find the "****".
67  while (line != end)
68  if ((line++)->find("****") != std::string::npos)
69  break;
70 
71  AlpgenParTokens tokens;
72 
73  // hard process code
74  if (line == end || !tokens.parse(*line++, true) || !tokens.values.empty())
75  return false;
76  ihrd = tokens.index;
77 
78  // mc,mb,mt,mw,mz,mh
79  if (line == end || !tokens.parse(*line++, false) || tokens.values.size() < 6)
80  return false;
81 
82  std::copy(tokens.values.begin(), tokens.values.begin() + 6, masses);
83 
84  // key - value pairs
85  params.clear();
86  while (line != end && line->find("****") == std::string::npos) {
87  if (!tokens.parse(*line++, true) || tokens.values.size() != 1)
88  return false;
89  params[(Parameter)tokens.index] = tokens.values[0];
90  }
91  if (line == end)
92  return false;
93  else
94  line++;
95 
96  // cross-section
97  if (line == end || !tokens.parse(*line++, false) || tokens.values.size() != 2)
98  return false;
99 
100  xsec = tokens.values[0];
101  xsecErr = tokens.values[1];
102 
103  // unweighted events, luminosity
104  if (line == end || !tokens.parse(*line++, true) || tokens.values.size() != 1)
105  return false;
106 
107  nEvents = tokens.index;
108  lumi = tokens.values[0];
109 
110  return true;
111 }
112 
113 // create human-readable representation for all Alpgen parameter indices
114 
115 #define DEFINE_ALPGEN_PARAMETER(x) \
116  { AlpgenHeader::x, #x }
117 
118 namespace {
119  struct AlpgenParameterName {
121  const char *name;
122 
123  inline bool operator==(AlpgenHeader::Parameter index) const { return this->index == index; }
124  }
125 
126  const alpgenParameterNames[] = {
140  DEFINE_ALPGEN_PARAMETER(iseed4)};
141 } // anonymous namespace
142 
144  static const unsigned int size = sizeof alpgenParameterNames / sizeof alpgenParameterNames[0];
145 
146  const AlpgenParameterName *pos = std::find(alpgenParameterNames, alpgenParameterNames + size, index);
147 
148  if (pos != alpgenParameterNames + size)
149  return pos->name;
150 
151  std::ostringstream ss;
152  ss << "unknown " << (int)index;
153  return ss.str();
154 }
size
Write out results.
std::vector< std::string_view > split(std::string_view, const char *)
#define DEFINE_ALPGEN_PARAMETER(x)
bool parse(const std::vector< std::string >::const_iterator &begin, const std::vector< std::string >::const_iterator &end)
Definition: AlpgenHeader.cc:62
static std::string parameterName(Parameter index)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
uint16_t size_type
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
#define end
Definition: vmac.h:39
def parse(path, config)
Definition: dumpparser.py:13
#define begin
Definition: vmac.h:32
UInt_t nEvents
Definition: hcalCalib.cc:41
tmp
align.sh
Definition: createJobs.py:716