CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
19 static std::vector<std::string> const s_dipalgoNames = { {"DIP"} };
20 
22  m_lumiVersion("-1"),
23  m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
24  m_allValues(),
25  m_allErrors(),
26  m_allQualities(),
27  m_beam1Intensities(),
28  m_beam2Intensities()
29 {
30 }
31 
33  m_lumiVersion(lumiVersion),
34  m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
35  m_allValues(),
36  m_allErrors(),
37  m_allQualities(),
38  m_beam1Intensities(),
39  m_beam2Intensities()
40 {
41 }
42 
44 }
45 
46 void
49 }
50 
51 std::string const&
53  return m_lumiVersion;
54 }
55 
56 bool
58  return m_allValues.size()!=0;
59 }
60 
61 void
63  std::vector<float> const& values,
64  std::vector<float> const& errors,
65  std::vector<short> const& qualities) {
66  checkAlgo(algo);
67  if (values.size() != errors.size() ||
68  values.size() != qualities.size() ||
71  << "Illegal input values passed to LumiDetails::fill.\n"
72  << "The current implementation of LumiDetails only allows filling\n"
73  << "vectors for each algorithm once and the input vectors must\n"
74  << "all be the same size.\n";
75  }
76  m_allValues.insert(m_allValues.begin() + m_algoToFirstIndex[algo], values.begin(), values.end());
77  m_allErrors.insert(m_allErrors.begin() + m_algoToFirstIndex[algo], errors.begin(), errors.end());
78  m_allQualities.insert(m_allQualities.begin() + m_algoToFirstIndex[algo], qualities.begin(), qualities.end());
79  for (unsigned i = algo + 1U; i <= kMaxNumAlgos; ++i) {
80  m_algoToFirstIndex[i] += values.size();
81  }
82 }
83 
84 void
85 LumiDetails::fillBeamIntensities(std::vector<float> const& beam1Intensities,
86  std::vector<float> const& beam2Intensities) {
87  m_beam1Intensities = beam1Intensities;
88  m_beam2Intensities = beam2Intensities;
89 }
90 
91 float
92 LumiDetails::lumiValue(AlgoType algo, unsigned int bx) const {
93  checkAlgoAndBX(algo, bx);
94  return m_allValues[m_algoToFirstIndex[algo] + bx];
95 }
96 
97 float
98 LumiDetails::lumiError(AlgoType algo, unsigned int bx) const {
99  checkAlgoAndBX(algo, bx);
100  return m_allErrors[m_algoToFirstIndex[algo] + bx];
101 }
102 
103 short
104 LumiDetails::lumiQuality(AlgoType algo, unsigned int bx) const {
105  checkAlgoAndBX(algo, bx);
106  return m_allQualities[m_algoToFirstIndex[algo] + bx];
107 }
108 
109 float
110 LumiDetails::lumiBeam1Intensity(unsigned int bx) const {
111  return m_beam1Intensities.at(bx);
112 }
113 
114 float
115 LumiDetails::lumiBeam2Intensity(unsigned int bx) const {
116  return m_beam2Intensities.at(bx);
117 }
118 
121  checkAlgo(algo);
122  return ValueRange(m_allValues.begin() + m_algoToFirstIndex[algo],
123  m_allValues.begin() + m_algoToFirstIndex[algo + 1U]);
124 }
125 
128  checkAlgo(algo);
129  return ErrorRange(m_allErrors.begin() + m_algoToFirstIndex[algo],
130  m_allErrors.begin() + m_algoToFirstIndex[algo + 1U]);
131 }
132 
135  checkAlgo(algo);
137  m_allQualities.begin() + m_algoToFirstIndex[algo + 1U]);
138 }
139 
140 std::vector<float> const&
142  return m_beam1Intensities;
143 }
144 
145 std::vector<float> const&
147  return m_beam2Intensities;
148 }
149 
150 std::vector<std::string> const&
152  assert(m_algoNames.size() == kMaxNumAlgos);
153  return m_algoNames;
154 }
155 
156 std::vector<std::string> const&
158  return s_dipalgoNames;
159 }
160 bool
161 LumiDetails::isProductEqual(LumiDetails const& lumiDetails) const {
162 
163  if (m_lumiVersion == lumiDetails.m_lumiVersion &&
164  m_algoToFirstIndex == lumiDetails.m_algoToFirstIndex &&
165  m_allValues == lumiDetails.m_allValues &&
166  m_allErrors == lumiDetails.m_allErrors &&
167  m_allQualities == lumiDetails.m_allQualities &&
168  m_beam1Intensities == lumiDetails.m_beam1Intensities &&
169  m_beam2Intensities == lumiDetails.m_beam2Intensities) {
170  return true;
171  }
172  return false;
173 }
174 
175 void
177  if (algo >= kMaxNumAlgos) {
179  << "Algorithm type argument out of range in a call to a function in LumiDetails\n";
180  }
181 }
182 
183 void
184 LumiDetails::checkAlgoAndBX(AlgoType algo, unsigned int bx) const {
185  checkAlgo(algo);
186  if (bx >= (m_algoToFirstIndex[algo + 1U] - m_algoToFirstIndex[algo])) {
188  << "Branch crossing argument out of range in call to a function in LumiDetails\n";
189  }
190 }
191 
192 std::ostream& operator<<(std::ostream& s, LumiDetails const& lumiDetails) {
193 
194  s << "\nDumping LumiDetails\n";
195  s << std::setw(12) << "lumi version " << lumiDetails.lumiVersion() << "\n";
196  std::vector<std::string>::const_iterator algo;
197  std::vector<std::string>::const_iterator algoEnd;
198  if(lumiDetails.lumiVersion()!=std::string("DIP")){
199  algo = lumiDetails.algoNames().begin();
200  algoEnd = lumiDetails.algoNames().end();
201  }else{
202  algo = lumiDetails.dipalgoNames().begin();
203  algoEnd = lumiDetails.dipalgoNames().end();
204  }
206 
207  for( ; algo != algoEnd; ++algo, ++i) {
208 
209  std::vector<float>::const_iterator value = lumiDetails.lumiValuesForAlgo(i).first;
210  std::vector<float>::const_iterator valueEnd = lumiDetails.lumiValuesForAlgo(i).second;
211  std::vector<float>::const_iterator error = lumiDetails.lumiErrorsForAlgo(i).first;
212  std::vector<short>::const_iterator quality = lumiDetails.lumiQualitiesForAlgo(i).first;
213 
214  s << "algorithm: " << *algo << "\n";
215  s << std::setw(12) << "value"
216  << std::setw(12) << "error"
217  << std::setw(12) << "quality" << "\n";
218 
219  for( ; value != valueEnd; ++value, ++error, ++quality){
220  s << std::setw(12) << *value
221  << std::setw(12) << *error
222  << std::setw(12) << *quality << "\n";
223  }
224  s << "\n";
225  }
226  s << "beam 1 intensities:\n";
227  std::vector<float> const& beam1Intensities = lumiDetails.lumiBeam1Intensities();
228  for (std::vector<float>::const_iterator intensity = beam1Intensities.begin(),
229  iEnd = beam1Intensities.end();
230  intensity != iEnd; ++intensity) {
231  s << *intensity << "\n";
232  }
233  s << "\nbeam 2 intensities:\n";
234  std::vector<float> const& beam2Intensities = lumiDetails.lumiBeam2Intensities();
235  for (std::vector<float>::const_iterator intensity = beam2Intensities.begin(),
236  iEnd = beam2Intensities.end();
237  intensity != iEnd; ++intensity) {
238  s << *intensity << "\n";
239  }
240  s << "\n";
241  return s;
242 }
int i
Definition: DBlmapReader.cc:9
float lumiBeam2Intensity(unsigned int bx) const
Definition: LumiDetails.cc:115
std::vector< float > const & lumiBeam2Intensities() const
Definition: LumiDetails.cc:146
std::pair< std::vector< float >::const_iterator, std::vector< float >::const_iterator > ValueRange
Definition: LumiDetails.h:35
ValueRange lumiValuesForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:120
assert(m_qm.get())
bool isValid() const
Definition: LumiDetails.cc:57
void checkAlgoAndBX(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:184
std::vector< float > m_allErrors
Definition: LumiDetails.h:94
std::pair< std::vector< float >::const_iterator, std::vector< float >::const_iterator > ErrorRange
Definition: LumiDetails.h:36
std::vector< float > const & lumiBeam1Intensities() const
Definition: LumiDetails.cc:141
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:188
float lumiValue(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:92
std::vector< float > m_beam2Intensities
Definition: LumiDetails.h:97
float lumiBeam1Intensity(unsigned int bx) const
Definition: LumiDetails.cc:110
static std::vector< std::string > const m_algoNames
Definition: LumiDetails.h:81
short lumiQuality(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:104
void setLumiVersion(std::string const &lumiVersion)
Definition: LumiDetails.cc:47
std::string m_lumiVersion
Definition: LumiDetails.h:83
std::pair< std::vector< short >::const_iterator, std::vector< short >::const_iterator > QualityRange
Definition: LumiDetails.h:37
ErrorRange lumiErrorsForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:127
void fill(AlgoType algo, std::vector< float > const &values, std::vector< float > const &errors, std::vector< short > const &qualities)
Definition: LumiDetails.cc:62
static std::vector< std::string > const s_dipalgoNames
Definition: LumiDetails.cc:19
static std::vector< std::string > const & dipalgoNames()
Definition: LumiDetails.cc:157
std::vector< float > m_allValues
Definition: LumiDetails.h:93
static std::vector< std::string > const & algoNames()
Definition: LumiDetails.cc:151
unsigned int AlgoType
Definition: LumiDetails.h:34
void checkAlgo(AlgoType algo) const
Definition: LumiDetails.cc:176
std::vector< unsigned int > m_algoToFirstIndex
Definition: LumiDetails.h:92
QualityRange lumiQualitiesForAlgo(AlgoType algo) const
Definition: LumiDetails.cc:134
float lumiError(AlgoType algo, unsigned int bx) const
Definition: LumiDetails.cc:98
std::vector< short > m_allQualities
Definition: LumiDetails.h:95
void fillBeamIntensities(std::vector< float > const &beam1Intensities, std::vector< float > const &beam2Intensities)
Definition: LumiDetails.cc:85
std::string const & lumiVersion() const
Definition: LumiDetails.cc:52
bool isProductEqual(LumiDetails const &lumiDetails) const
Definition: LumiDetails.cc:161
std::vector< float > m_beam1Intensities
Definition: LumiDetails.h:96