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 }
mps_fire.i
i
Definition: mps_fire.py:428
DEFINE_ALPGEN_PARAMETER
#define DEFINE_ALPGEN_PARAMETER(x)
Definition: AlpgenHeader.cc:115
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
AlpgenHeader::xsec
double xsec
Definition: AlpgenHeader.h:67
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
pos
Definition: PixelAliasList.h:18
AlpgenHeader::xsecErr
double xsecErr
Definition: AlpgenHeader.h:68
AlpgenHeader.h
AlpgenHeader::parameterName
static std::string parameterName(Parameter index)
Definition: AlpgenHeader.cc:143
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
AlpgenHeader::params
std::map< Parameter, double > params
Definition: AlpgenHeader.h:65
AlpgenHeader::ihrd
unsigned int ihrd
Definition: AlpgenHeader.h:66
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
cms::cuda::nh
uint32_t nh
Definition: HistoContainer.h:23
mps_fire.end
end
Definition: mps_fire.py:242
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
operator==
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
Definition: QGLikelihoodObject.h:49
dumpparser.parse
def parse(path, config)
Definition: dumpparser.py:13
indexGen.comments
comments
Definition: indexGen.py:75
createfilelist.int
int
Definition: createfilelist.py:10
value
Definition: value.py:1
AlpgenHeader::nEvents
double nEvents
Definition: AlpgenHeader.h:69
BTaggingMonitoring_cff.njets
njets
Definition: BTaggingMonitoring_cff.py:10
relativeConstraints.value
value
Definition: relativeConstraints.py:53
AlpgenHeader::Parameter
Parameter
Definition: AlpgenHeader.h:11
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
AlpgenHeader::masses
double masses[MASS_MAX]
Definition: AlpgenHeader.h:71
mps_splice.line
line
Definition: mps_splice.py:76
lumi
Definition: LumiSectionData.h:20
AlpgenHeader::parse
bool parse(const std::vector< std::string >::const_iterator &begin, const std::vector< std::string >::const_iterator &end)
Definition: AlpgenHeader.cc:62
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443