CMS 3D CMS Logo

LumiDetails.cc
Go to the documentation of this file.
3 
4 #include <cassert>
5 #include <iomanip>
6 #include <ostream>
7 
8 std::vector<std::string> const LumiDetails::m_algoNames = {
9  // If in the future additional algorithm names are added,
10  // it is important that they be added at the end of the list.
11  // The Algos enum in LumiDetails.h also would need to be
12  // updated to keep the list of names in sync.
13  {"OCC1"},
14  {"OCC2"},
15  {"ET"},
16  {"PLT"}};
17 
18 static std::vector<std::string> const s_dipalgoNames = {{"DIP"}};
19 
21  : m_lumiVersion("-1"),
22  m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
23  m_allValues(),
24  m_allErrors(),
25  m_allQualities(),
26  m_beam1Intensities(),
27  m_beam2Intensities() {}
28 
30  : m_lumiVersion(lumiVersion),
31  m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
32  m_allValues(),
33  m_allErrors(),
34  m_allQualities(),
35  m_beam1Intensities(),
36  m_beam2Intensities() {}
37 
39 
41 
43 
44 bool LumiDetails::isValid() const { return !m_allValues.empty(); }
45 
47  std::vector<float> const& values,
48  std::vector<float> const& errors,
49  std::vector<short> const& qualities) {
50  checkAlgo(algo);
51  if (values.size() != errors.size() || values.size() != qualities.size() ||
53  throw edm::Exception(edm::errors::LogicError) << "Illegal input values passed to LumiDetails::fill.\n"
54  << "The current implementation of LumiDetails only allows filling\n"
55  << "vectors for each algorithm once and the input vectors must\n"
56  << "all be the same size.\n";
57  }
58  m_allValues.insert(m_allValues.begin() + m_algoToFirstIndex[algo], values.begin(), values.end());
59  m_allErrors.insert(m_allErrors.begin() + m_algoToFirstIndex[algo], errors.begin(), errors.end());
60  m_allQualities.insert(m_allQualities.begin() + m_algoToFirstIndex[algo], qualities.begin(), qualities.end());
61  for (unsigned i = algo + 1U; i <= kMaxNumAlgos; ++i) {
62  m_algoToFirstIndex[i] += values.size();
63  }
64 }
65 
66 void LumiDetails::fillBeamIntensities(std::vector<float> const& beam1Intensities,
67  std::vector<float> const& beam2Intensities) {
68  m_beam1Intensities = beam1Intensities;
69  m_beam2Intensities = beam2Intensities;
70 }
71 
72 float LumiDetails::lumiValue(AlgoType algo, unsigned int bx) const {
75 }
76 
77 float LumiDetails::lumiError(AlgoType algo, unsigned int bx) const {
80 }
81 
82 short LumiDetails::lumiQuality(AlgoType algo, unsigned int bx) const {
85 }
86 
87 float LumiDetails::lumiBeam1Intensity(unsigned int bx) const { return m_beam1Intensities.at(bx); }
88 
89 float LumiDetails::lumiBeam2Intensity(unsigned int bx) const { return m_beam2Intensities.at(bx); }
90 
92  checkAlgo(algo);
94  m_allValues.begin() + m_algoToFirstIndex[algo + 1U]);
95 }
96 
98  checkAlgo(algo);
100  m_allErrors.begin() + m_algoToFirstIndex[algo + 1U]);
101 }
102 
104  checkAlgo(algo);
106  m_allQualities.begin() + m_algoToFirstIndex[algo + 1U]);
107 }
108 
109 std::vector<float> const& LumiDetails::lumiBeam1Intensities() const { return m_beam1Intensities; }
110 
111 std::vector<float> const& LumiDetails::lumiBeam2Intensities() const { return m_beam2Intensities; }
112 
113 std::vector<std::string> const& LumiDetails::algoNames() {
114  assert(m_algoNames.size() == kMaxNumAlgos);
115  return m_algoNames;
116 }
117 
118 std::vector<std::string> const& LumiDetails::dipalgoNames() { return s_dipalgoNames; }
119 bool LumiDetails::isProductEqual(LumiDetails const& lumiDetails) const {
120  if (m_lumiVersion == lumiDetails.m_lumiVersion && m_algoToFirstIndex == lumiDetails.m_algoToFirstIndex &&
121  m_allValues == lumiDetails.m_allValues && m_allErrors == lumiDetails.m_allErrors &&
122  m_allQualities == lumiDetails.m_allQualities && m_beam1Intensities == lumiDetails.m_beam1Intensities &&
123  m_beam2Intensities == lumiDetails.m_beam2Intensities) {
124  return true;
125  }
126  return false;
127 }
128 
130  if (algo >= kMaxNumAlgos) {
132  << "Algorithm type argument out of range in a call to a function in LumiDetails\n";
133  }
134 }
135 
136 void LumiDetails::checkAlgoAndBX(AlgoType algo, unsigned int bx) const {
137  checkAlgo(algo);
140  << "Branch crossing argument out of range in call to a function in LumiDetails\n";
141  }
142 }
143 
144 std::ostream& operator<<(std::ostream& s, LumiDetails const& lumiDetails) {
145  s << "\nDumping LumiDetails\n";
146  s << std::setw(12) << "lumi version " << lumiDetails.lumiVersion() << "\n";
147  std::vector<std::string>::const_iterator algo;
148  std::vector<std::string>::const_iterator algoEnd;
149  if (lumiDetails.lumiVersion() != std::string("DIP")) {
150  algo = lumiDetails.algoNames().begin();
151  algoEnd = lumiDetails.algoNames().end();
152  } else {
153  algo = lumiDetails.dipalgoNames().begin();
154  algoEnd = lumiDetails.dipalgoNames().end();
155  }
157 
158  for (; algo != algoEnd; ++algo, ++i) {
159  std::vector<float>::const_iterator value = lumiDetails.lumiValuesForAlgo(i).first;
160  std::vector<float>::const_iterator valueEnd = lumiDetails.lumiValuesForAlgo(i).second;
161  std::vector<float>::const_iterator error = lumiDetails.lumiErrorsForAlgo(i).first;
162  std::vector<short>::const_iterator quality = lumiDetails.lumiQualitiesForAlgo(i).first;
163 
164  s << "algorithm: " << *algo << "\n";
165  s << std::setw(12) << "value" << std::setw(12) << "error" << std::setw(12) << "quality"
166  << "\n";
167 
168  for (; value != valueEnd; ++value, ++error, ++quality) {
169  s << std::setw(12) << *value << std::setw(12) << *error << std::setw(12) << *quality << "\n";
170  }
171  s << "\n";
172  }
173  s << "beam 1 intensities:\n";
174  std::vector<float> const& beam1Intensities = lumiDetails.lumiBeam1Intensities();
175  for (std::vector<float>::const_iterator intensity = beam1Intensities.begin(), iEnd = beam1Intensities.end();
176  intensity != iEnd;
177  ++intensity) {
178  s << *intensity << "\n";
179  }
180  s << "\nbeam 2 intensities:\n";
181  std::vector<float> const& beam2Intensities = lumiDetails.lumiBeam2Intensities();
182  for (std::vector<float>::const_iterator intensity = beam2Intensities.begin(), iEnd = beam2Intensities.end();
183  intensity != iEnd;
184  ++intensity) {
185  s << *intensity << "\n";
186  }
187  s << "\n";
188  return s;
189 }
static std::vector< std::string > const & algoNames()
Definition: LumiDetails.cc:113
float lumiBeam2Intensity(unsigned int bx) const
Definition: LumiDetails.cc:89
std::pair< std::vector< float >::const_iterator, std::vector< float >::const_iterator > ValueRange
Definition: LumiDetails.h:28
void checkAlgo(AlgoType algo) const
Definition: LumiDetails.cc:129
std::vector< float > m_allErrors
Definition: LumiDetails.h:85
std::pair< std::vector< float >::const_iterator, std::vector< float >::const_iterator > ErrorRange
Definition: LumiDetails.h:29
bool isProductEqual(LumiDetails const &lumiDetails) const
Definition: LumiDetails.cc:119
float lumiBeam1Intensity(unsigned int bx) const
Definition: LumiDetails.cc:87
ValueRange lumiValuesForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:91
assert(be >=bs)
std::vector< float > const & lumiBeam2Intensities() const
Definition: LumiDetails.cc:111
std::vector< float > m_beam2Intensities
Definition: LumiDetails.h:88
static std::vector< std::string > const m_algoNames
Definition: LumiDetails.h:72
void setLumiVersion(std::string const &lumiVersion)
Definition: LumiDetails.cc:40
std::string m_lumiVersion
Definition: LumiDetails.h:74
std::pair< std::vector< short >::const_iterator, std::vector< short >::const_iterator > QualityRange
Definition: LumiDetails.h:30
void fill(AlgoType algo, std::vector< float > const &values, std::vector< float > const &errors, std::vector< short > const &qualities)
Definition: LumiDetails.cc:46
std::string const & lumiVersion() const
Definition: LumiDetails.cc:42
static std::vector< std::string > const s_dipalgoNames
Definition: LumiDetails.cc:18
bool isValid() const
Definition: LumiDetails.cc:44
std::vector< float > m_allValues
Definition: LumiDetails.h:84
Definition: value.py:1
float lumiValue(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:72
const char * qualities[3]
ErrorRange lumiErrorsForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:97
float lumiError(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:77
unsigned int AlgoType
Definition: LumiDetails.h:27
std::vector< float > const & lumiBeam1Intensities() const
Definition: LumiDetails.cc:109
void checkAlgoAndBX(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:136
std::vector< unsigned int > m_algoToFirstIndex
Definition: LumiDetails.h:83
QualityRange lumiQualitiesForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:103
static std::vector< std::string > const & dipalgoNames()
Definition: LumiDetails.cc:118
short lumiQuality(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:82
std::vector< short > m_allQualities
Definition: LumiDetails.h:86
void fillBeamIntensities(std::vector< float > const &beam1Intensities, std::vector< float > const &beam2Intensities)
Definition: LumiDetails.cc:66
Definition: errors.py:1
string quality
std::ostream & operator<<(std::ostream &s, LumiDetails const &lumiDetails)
Definition: LumiDetails.cc:144
std::vector< float > m_beam1Intensities
Definition: LumiDetails.h:87