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 }
26 
27 bool AlpgenParTokens::parse(const std::string &line, bool withIndex)
28 {
29  std::string::size_type pos = line.find('!');
30  if (pos == std::string::npos)
31  return false;
32 
33  std::string tmp = boost::trim_copy(line.substr(0, pos));
34  boost::split(comments, tmp, boost::algorithm::is_space(),
35  boost::token_compress_on);
36  if (comments.empty())
37  return false;
38 
39  unsigned int i = 0, n = comments.size();
40  if (withIndex) {
41  std::istringstream ss(comments[i++]);
42  ss >> index;
43  if (ss.bad() ||
44  ss.peek() != std::istringstream::traits_type::eof())
45  return false;
46  }
47 
48  values.clear();
49  while(i < n) {
50  std::istringstream ss(comments[i++]);
51  double value;
52  ss >> value;
53  if (ss.bad() ||
54  ss.peek() != std::istringstream::traits_type::eof())
55  return false;
56 
57  values.push_back(value);
58  }
59 
60  tmp = boost::trim_copy(line.substr(pos + 1));
61  boost::split(comments, tmp, boost::algorithm::is_space(),
62  boost::token_compress_on);
63 
64  return true;
65 }
66 
67 bool AlpgenHeader::parse(const std::vector<std::string>::const_iterator &begin,
68  const std::vector<std::string>::const_iterator &end)
69 {
70  std::vector<std::string>::const_iterator line = begin;
71 
72  // Mimicking Alpgen - read the _unw.par file until you find the "****".
73  while(line != end)
74  if ((line++)->find("****") != std::string::npos)
75  break;
76 
77  AlpgenParTokens tokens;
78 
79  // hard process code
80  if (line == end || !tokens.parse(*line++, true) ||
81  !tokens.values.empty())
82  return false;
83  ihrd = tokens.index;
84 
85  // mc,mb,mt,mw,mz,mh
86  if (line == end || !tokens.parse(*line++, false) ||
87  tokens.values.size() < 6)
88  return false;
89 
90  std::copy(tokens.values.begin(), tokens.values.begin() + 6, masses);
91 
92  // key - value pairs
93  params.clear();
94  while(line != end && line->find("****") == std::string::npos) {
95  if (!tokens.parse(*line++, true) ||
96  tokens.values.size() != 1)
97  return false;
98  params[(Parameter)tokens.index] = tokens.values[0];
99  }
100  if (line == end)
101  return false;
102  else
103  line++;
104 
105  // cross-section
106  if (line == end || !tokens.parse(*line++, false) ||
107  tokens.values.size() != 2)
108  return false;
109 
110  xsec = tokens.values[0];
111  xsecErr = tokens.values[1];
112 
113  // unweighted events, luminosity
114  if (line == end || !tokens.parse(*line++, true) ||
115  tokens.values.size() != 1)
116  return false;
117 
118  nEvents = tokens.index;
119  lumi = tokens.values[0];
120 
121  return true;
122 }
123 
124 // create human-readable representation for all Alpgen parameter indices
125 
126 #define DEFINE_ALPGEN_PARAMETER(x) { AlpgenHeader::x, #x }
127 
128 namespace {
129  struct AlpgenParameterName {
131  const char* name;
132 
133  inline bool operator == (AlpgenHeader::Parameter index) const
134  { return this->index == index; }
135  }
136 
137  static const alpgenParameterNames[] = {
152  DEFINE_ALPGEN_PARAMETER(ptjmin),
153  DEFINE_ALPGEN_PARAMETER(ptbmin),
154  DEFINE_ALPGEN_PARAMETER(ptcmin),
155  DEFINE_ALPGEN_PARAMETER(ptlmin),
156  DEFINE_ALPGEN_PARAMETER(metmin),
157  DEFINE_ALPGEN_PARAMETER(ptphmin),
158  DEFINE_ALPGEN_PARAMETER(etajmax),
159  DEFINE_ALPGEN_PARAMETER(etabmax),
160  DEFINE_ALPGEN_PARAMETER(etacmax),
161  DEFINE_ALPGEN_PARAMETER(etalmax),
162  DEFINE_ALPGEN_PARAMETER(etaphmax),
163  DEFINE_ALPGEN_PARAMETER(drjmin),
164  DEFINE_ALPGEN_PARAMETER(drbmin),
165  DEFINE_ALPGEN_PARAMETER(drcmin),
166  DEFINE_ALPGEN_PARAMETER(drlmin),
167  DEFINE_ALPGEN_PARAMETER(drphjmin),
168  DEFINE_ALPGEN_PARAMETER(drphlmin),
169  DEFINE_ALPGEN_PARAMETER(drphmin),
170  DEFINE_ALPGEN_PARAMETER(mllmin),
171  DEFINE_ALPGEN_PARAMETER(mllmax),
172  DEFINE_ALPGEN_PARAMETER(iseed1),
173  DEFINE_ALPGEN_PARAMETER(iseed2),
174  DEFINE_ALPGEN_PARAMETER(itopprc),
175  DEFINE_ALPGEN_PARAMETER(cluopt),
176  DEFINE_ALPGEN_PARAMETER(iseed3),
178  };
179 } // anonymous namespace
180 
182 {
183  static const unsigned int size = sizeof alpgenParameterNames /
184  sizeof alpgenParameterNames[0];
185 
186  const AlpgenParameterName *pos =
187  std::find(alpgenParameterNames,
188  alpgenParameterNames + size, index);
189 
190  if (pos != alpgenParameterNames + size)
191  return pos->name;
192 
193  std::ostringstream ss;
194  ss << "unknown " << (int)index;
195  return ss.str();
196 }
size
Write out results.
#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:67
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:20
uint16_t size_type
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
#define end
Definition: vmac.h:37
def parse(path, config)
Definition: dumpparser.py:13
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
#define begin
Definition: vmac.h:30
UInt_t nEvents
Definition: hcalCalib.cc:42
double split
Definition: MVATrainer.cc:139