Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:40

0001 #include "DataFormats/Luminosity/interface/LumiDetails.h"
0002 #include "FWCore/Utilities/interface/EDMException.h"
0003 
0004 #include <cassert>
0005 #include <iomanip>
0006 #include <ostream>
0007 
0008 std::vector<std::string> const LumiDetails::m_algoNames = {
0009     // If in the future additional algorithm names are added,
0010     // it is important that they be added at the end of the list.
0011     // The Algos enum in LumiDetails.h also would need to be
0012     // updated to keep the list of names in sync.
0013     {"OCC1"},
0014     {"OCC2"},
0015     {"ET"},
0016     {"PLT"}};
0017 
0018 static std::vector<std::string> const s_dipalgoNames = {{"DIP"}};
0019 
0020 LumiDetails::LumiDetails()
0021     : m_lumiVersion("-1"),
0022       m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
0023       m_allValues(),
0024       m_allErrors(),
0025       m_allQualities(),
0026       m_beam1Intensities(),
0027       m_beam2Intensities() {}
0028 
0029 LumiDetails::LumiDetails(std::string const& lumiVersion)
0030     : m_lumiVersion(lumiVersion),
0031       m_algoToFirstIndex(kMaxNumAlgos + 1, 0),
0032       m_allValues(),
0033       m_allErrors(),
0034       m_allQualities(),
0035       m_beam1Intensities(),
0036       m_beam2Intensities() {}
0037 
0038 LumiDetails::~LumiDetails() {}
0039 
0040 void LumiDetails::setLumiVersion(std::string const& lumiVersion) { m_lumiVersion = lumiVersion; }
0041 
0042 std::string const& LumiDetails::lumiVersion() const { return m_lumiVersion; }
0043 
0044 bool LumiDetails::isValid() const { return !m_allValues.empty(); }
0045 
0046 void LumiDetails::fill(AlgoType algo,
0047                        std::vector<float> const& values,
0048                        std::vector<float> const& errors,
0049                        std::vector<short> const& qualities) {
0050   checkAlgo(algo);
0051   if (values.size() != errors.size() || values.size() != qualities.size() ||
0052       m_algoToFirstIndex[algo] != m_algoToFirstIndex[algo + 1U]) {
0053     throw edm::Exception(edm::errors::LogicError) << "Illegal input values passed to LumiDetails::fill.\n"
0054                                                   << "The current implementation of LumiDetails only allows filling\n"
0055                                                   << "vectors for each algorithm once and the input vectors must\n"
0056                                                   << "all be the same size.\n";
0057   }
0058   m_allValues.insert(m_allValues.begin() + m_algoToFirstIndex[algo], values.begin(), values.end());
0059   m_allErrors.insert(m_allErrors.begin() + m_algoToFirstIndex[algo], errors.begin(), errors.end());
0060   m_allQualities.insert(m_allQualities.begin() + m_algoToFirstIndex[algo], qualities.begin(), qualities.end());
0061   for (unsigned i = algo + 1U; i <= kMaxNumAlgos; ++i) {
0062     m_algoToFirstIndex[i] += values.size();
0063   }
0064 }
0065 
0066 void LumiDetails::fillBeamIntensities(std::vector<float> const& beam1Intensities,
0067                                       std::vector<float> const& beam2Intensities) {
0068   m_beam1Intensities = beam1Intensities;
0069   m_beam2Intensities = beam2Intensities;
0070 }
0071 
0072 float LumiDetails::lumiValue(AlgoType algo, unsigned int bx) const {
0073   checkAlgoAndBX(algo, bx);
0074   return m_allValues[m_algoToFirstIndex[algo] + bx];
0075 }
0076 
0077 float LumiDetails::lumiError(AlgoType algo, unsigned int bx) const {
0078   checkAlgoAndBX(algo, bx);
0079   return m_allErrors[m_algoToFirstIndex[algo] + bx];
0080 }
0081 
0082 short LumiDetails::lumiQuality(AlgoType algo, unsigned int bx) const {
0083   checkAlgoAndBX(algo, bx);
0084   return m_allQualities[m_algoToFirstIndex[algo] + bx];
0085 }
0086 
0087 float LumiDetails::lumiBeam1Intensity(unsigned int bx) const { return m_beam1Intensities.at(bx); }
0088 
0089 float LumiDetails::lumiBeam2Intensity(unsigned int bx) const { return m_beam2Intensities.at(bx); }
0090 
0091 LumiDetails::ValueRange LumiDetails::lumiValuesForAlgo(AlgoType algo) const {
0092   checkAlgo(algo);
0093   return ValueRange(m_allValues.begin() + m_algoToFirstIndex[algo],
0094                     m_allValues.begin() + m_algoToFirstIndex[algo + 1U]);
0095 }
0096 
0097 LumiDetails::ErrorRange LumiDetails::lumiErrorsForAlgo(AlgoType algo) const {
0098   checkAlgo(algo);
0099   return ErrorRange(m_allErrors.begin() + m_algoToFirstIndex[algo],
0100                     m_allErrors.begin() + m_algoToFirstIndex[algo + 1U]);
0101 }
0102 
0103 LumiDetails::QualityRange LumiDetails::lumiQualitiesForAlgo(AlgoType algo) const {
0104   checkAlgo(algo);
0105   return QualityRange(m_allQualities.begin() + m_algoToFirstIndex[algo],
0106                       m_allQualities.begin() + m_algoToFirstIndex[algo + 1U]);
0107 }
0108 
0109 std::vector<float> const& LumiDetails::lumiBeam1Intensities() const { return m_beam1Intensities; }
0110 
0111 std::vector<float> const& LumiDetails::lumiBeam2Intensities() const { return m_beam2Intensities; }
0112 
0113 std::vector<std::string> const& LumiDetails::algoNames() {
0114   assert(m_algoNames.size() == kMaxNumAlgos);
0115   return m_algoNames;
0116 }
0117 
0118 std::vector<std::string> const& LumiDetails::dipalgoNames() { return s_dipalgoNames; }
0119 bool LumiDetails::isProductEqual(LumiDetails const& lumiDetails) const {
0120   if (m_lumiVersion == lumiDetails.m_lumiVersion && m_algoToFirstIndex == lumiDetails.m_algoToFirstIndex &&
0121       m_allValues == lumiDetails.m_allValues && m_allErrors == lumiDetails.m_allErrors &&
0122       m_allQualities == lumiDetails.m_allQualities && m_beam1Intensities == lumiDetails.m_beam1Intensities &&
0123       m_beam2Intensities == lumiDetails.m_beam2Intensities) {
0124     return true;
0125   }
0126   return false;
0127 }
0128 
0129 void LumiDetails::checkAlgo(AlgoType algo) const {
0130   if (algo >= kMaxNumAlgos) {
0131     throw edm::Exception(edm::errors::LogicError)
0132         << "Algorithm type argument out of range in a call to a function in LumiDetails\n";
0133   }
0134 }
0135 
0136 void LumiDetails::checkAlgoAndBX(AlgoType algo, unsigned int bx) const {
0137   checkAlgo(algo);
0138   if (bx >= (m_algoToFirstIndex[algo + 1U] - m_algoToFirstIndex[algo])) {
0139     throw edm::Exception(edm::errors::LogicError)
0140         << "Branch crossing argument out of range in call to a function in LumiDetails\n";
0141   }
0142 }
0143 
0144 std::ostream& operator<<(std::ostream& s, LumiDetails const& lumiDetails) {
0145   s << "\nDumping LumiDetails\n";
0146   s << std::setw(12) << "lumi version " << lumiDetails.lumiVersion() << "\n";
0147   std::vector<std::string>::const_iterator algo;
0148   std::vector<std::string>::const_iterator algoEnd;
0149   if (lumiDetails.lumiVersion() != std::string("DIP")) {
0150     algo = lumiDetails.algoNames().begin();
0151     algoEnd = lumiDetails.algoNames().end();
0152   } else {
0153     algo = lumiDetails.dipalgoNames().begin();
0154     algoEnd = lumiDetails.dipalgoNames().end();
0155   }
0156   LumiDetails::AlgoType i = 0;
0157 
0158   for (; algo != algoEnd; ++algo, ++i) {
0159     std::vector<float>::const_iterator value = lumiDetails.lumiValuesForAlgo(i).first;
0160     std::vector<float>::const_iterator valueEnd = lumiDetails.lumiValuesForAlgo(i).second;
0161     std::vector<float>::const_iterator error = lumiDetails.lumiErrorsForAlgo(i).first;
0162     std::vector<short>::const_iterator quality = lumiDetails.lumiQualitiesForAlgo(i).first;
0163 
0164     s << "algorithm: " << *algo << "\n";
0165     s << std::setw(12) << "value" << std::setw(12) << "error" << std::setw(12) << "quality"
0166       << "\n";
0167 
0168     for (; value != valueEnd; ++value, ++error, ++quality) {
0169       s << std::setw(12) << *value << std::setw(12) << *error << std::setw(12) << *quality << "\n";
0170     }
0171     s << "\n";
0172   }
0173   s << "beam 1 intensities:\n";
0174   std::vector<float> const& beam1Intensities = lumiDetails.lumiBeam1Intensities();
0175   for (std::vector<float>::const_iterator intensity = beam1Intensities.begin(), iEnd = beam1Intensities.end();
0176        intensity != iEnd;
0177        ++intensity) {
0178     s << *intensity << "\n";
0179   }
0180   s << "\nbeam 2 intensities:\n";
0181   std::vector<float> const& beam2Intensities = lumiDetails.lumiBeam2Intensities();
0182   for (std::vector<float>::const_iterator intensity = beam2Intensities.begin(), iEnd = beam2Intensities.end();
0183        intensity != iEnd;
0184        ++intensity) {
0185     s << *intensity << "\n";
0186   }
0187   s << "\n";
0188   return s;
0189 }