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