Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-27 06:43:56

0001 #include "CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include <iostream>
0006 #include <iomanip>  // std::setw
0007 
0008 //****************************************************************************//
0009 namespace AlignPCLThresholdsHGImpl {
0010   template <typename T>
0011   const T &getParam(const std::vector<T> &params, size_t index) {
0012     if (index >= params.size())
0013       throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
0014     return params[index];
0015   }
0016 
0017   template <typename T>
0018   void setParam(std::vector<T> &params, size_t index, const T &value) {
0019     if (index >= params.size())
0020       throw std::out_of_range("Parameter with index " + std::to_string(index) + " is out of range.");
0021     params[index] = value;
0022   }
0023 
0024 }  //namespace AlignPCLThresholdsHGImpl
0025 
0026 //****************************************************************************//
0027 void AlignPCLThresholdsHG::setFloatMap(const std::unordered_map<std::string, std::vector<float>> &floatMap) {
0028   floatMap_ = floatMap;
0029 }
0030 
0031 //****************************************************************************//
0032 const std::vector<float> &AlignPCLThresholdsHG::getFloatVec(const std::string &AlignableId) const {
0033   const auto &it = floatMap_.find(AlignableId);
0034 
0035   if (it != floatMap_.end()) {
0036     return it->second;
0037   } else {
0038     throw cms::Exception("AlignPCLThresholdsHG") << "No float vector defined for Alignable id " << AlignableId << "\n";
0039   }
0040 }
0041 
0042 //****************************************************************************//
0043 void AlignPCLThresholdsHG::setFractionCut(const std::string &AlignableId, const coordType &type, const float &cut) {
0044   // Set entry in map if not yet available
0045   const auto &it = floatMap_.find(AlignableId);
0046   if (it == floatMap_.end())
0047     floatMap_[AlignableId] = std::vector<float>(FSIZE, -1.);
0048 
0049   switch (type) {
0050     case X:
0051       return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_X, cut);
0052     case Y:
0053       return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_Y, cut);
0054     case Z:
0055       return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_Z, cut);
0056     case theta_X:
0057       return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_TX, cut);
0058     case theta_Y:
0059       return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_TY, cut);
0060     case theta_Z:
0061       return AlignPCLThresholdsHGImpl::setParam(floatMap_[AlignableId], FRACTION_CUT_TZ, cut);
0062     default:
0063       throw cms::Exception("AlignPCLThresholdsHG")
0064           << "Requested setting fraction threshold for undefined coordinate" << type << "\n";
0065   }
0066 }
0067 
0068 //****************************************************************************//
0069 std::array<float, 6> AlignPCLThresholdsHG::getFractionCut(const std::string &AlignableId) const {
0070   const std::vector<float> vec = getFloatVec(AlignableId);
0071   return {{AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_X),
0072            AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_Y),
0073            AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_Z),
0074            AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TX),
0075            AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TY),
0076            AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TZ)}};
0077 }
0078 
0079 //****************************************************************************//
0080 float AlignPCLThresholdsHG::getFractionCut(const std::string &AlignableId, const coordType &type) const {
0081   const std::vector<float> vec = getFloatVec(AlignableId);
0082   switch (type) {
0083     case X:
0084       return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_X);
0085     case Y:
0086       return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_Y);
0087     case Z:
0088       return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_Z);
0089     case theta_X:
0090       return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TX);
0091     case theta_Y:
0092       return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TY);
0093     case theta_Z:
0094       return AlignPCLThresholdsHGImpl::getParam(vec, FRACTION_CUT_TZ);
0095     default:
0096       throw cms::Exception("AlignPCLThresholdsHG")
0097           << "Requested fraction threshold for undefined coordinate" << type << "\n";
0098   }
0099 }
0100 
0101 //****************************************************************************//
0102 const bool AlignPCLThresholdsHG::hasFloatMap(const std::string &AlignableId) const {
0103   const auto &it = floatMap_.find(AlignableId);
0104   return (it != floatMap_.end());
0105 }
0106 
0107 //****************************************************************************//
0108 const int AlignPCLThresholdsHG::payloadVersion() const {
0109   switch (FSIZE + ISIZE + SSIZE) {
0110     case 6:
0111       return 1;
0112     default:
0113       throw cms::Exception("AlignPCLThresholdsHG")
0114           << "Payload version with parameter size equal to " << FSIZE + ISIZE + SSIZE << " is not defined.\n";
0115   }
0116 }
0117 
0118 //****************************************************************************//
0119 void AlignPCLThresholdsHG::printAll() const {
0120   edm::LogVerbatim out("AlignPCLThresholdsHG");
0121 
0122   out << "AlignPCLThresholdsHG::printAll()\n";
0123   out << "============================================================================================================="
0124          "======\n";
0125   out << "N records cut: " << this->getNrecords() << "\n";
0126   for (auto it = m_thresholds.begin(); it != m_thresholds.end(); ++it) {
0127     out << "==========================================================================================================="
0128            "========\n";
0129 
0130     std::stringstream ss;
0131 
0132     ss << "key : " << it->first << " \n"
0133        << "- Xcut             : " << std::setw(4) << (it->second).getXcut() << std::setw(5) << "   um"
0134        << "| sigXcut          : " << std::setw(4) << (it->second).getSigXcut() << std::setw(1) << " "
0135        << "| maxMoveXcut      : " << std::setw(4) << (it->second).getMaxMoveXcut() << std::setw(5) << "   um"
0136        << "| ErrorXcut        : " << std::setw(4) << (it->second).getErrorXcut() << std::setw(5) << "   um";
0137 
0138     if (floatMap_.find(it->first) != floatMap_.end()) {
0139       ss << "| X_fractionCut      : " << std::setw(4) << getFractionCut(it->first, X) << std::setw(5) << "\n";
0140     } else {
0141       ss << "\n";
0142     }
0143 
0144     ss << "- thetaXcut        : " << std::setw(4) << (it->second).getThetaXcut() << std::setw(5) << " urad"
0145        << "| sigThetaXcut     : " << std::setw(4) << (it->second).getSigThetaXcut() << std::setw(1) << " "
0146        << "| maxMoveThetaXcut : " << std::setw(4) << (it->second).getMaxMoveThetaXcut() << std::setw(5) << " urad"
0147        << "| ErrorThetaXcut   : " << std::setw(4) << (it->second).getErrorThetaXcut() << std::setw(5) << " urad";
0148 
0149     if (floatMap_.find(it->first) != floatMap_.end()) {
0150       ss << "| thetaX_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_X) << std::setw(5) << "\n";
0151     } else {
0152       ss << "\n";
0153     }
0154 
0155     ss << "- Ycut             : " << std::setw(4) << (it->second).getYcut() << std::setw(5) << "   um"
0156        << "| sigYcut          : " << std::setw(4) << (it->second).getSigXcut() << std::setw(1) << " "
0157        << "| maxMoveYcut      : " << std::setw(4) << (it->second).getMaxMoveYcut() << std::setw(5) << "   um"
0158        << "| ErrorYcut        : " << std::setw(4) << (it->second).getErrorYcut() << std::setw(5) << "   um";
0159 
0160     if (floatMap_.find(it->first) != floatMap_.end()) {
0161       ss << "| Y_fractionCut      : " << std::setw(4) << getFractionCut(it->first, Y) << std::setw(5) << "\n";
0162     } else {
0163       ss << "\n";
0164     }
0165 
0166     ss << "- thetaYcut        : " << std::setw(4) << (it->second).getThetaYcut() << std::setw(5) << " urad"
0167        << "| sigThetaYcut     : " << std::setw(4) << (it->second).getSigThetaYcut() << std::setw(1) << " "
0168        << "| maxMoveThetaYcut : " << std::setw(4) << (it->second).getMaxMoveThetaYcut() << std::setw(5) << " urad"
0169        << "| ErrorThetaYcut   : " << std::setw(4) << (it->second).getErrorThetaYcut() << std::setw(5) << " urad";
0170 
0171     if (floatMap_.find(it->first) != floatMap_.end()) {
0172       ss << "| thetaY_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_Y) << std::setw(5) << "\n";
0173     } else {
0174       ss << "\n";
0175     }
0176 
0177     ss << "- Zcut             : " << std::setw(4) << (it->second).getZcut() << std::setw(5) << "   um"
0178        << "| sigZcut          : " << std::setw(4) << (it->second).getSigZcut() << std::setw(1) << " "
0179        << "| maxMoveZcut      : " << std::setw(4) << (it->second).getMaxMoveZcut() << std::setw(5) << "   um"
0180        << "| ErrorZcut        : " << std::setw(4) << (it->second).getErrorZcut() << std::setw(5) << "   um";
0181 
0182     if (floatMap_.find(it->first) != floatMap_.end()) {
0183       ss << "| Z_fractionCut      : " << std::setw(4) << getFractionCut(it->first, Z) << std::setw(5) << "\n";
0184     } else {
0185       ss << "\n";
0186     }
0187 
0188     ss << "- thetaZcut        : " << std::setw(4) << (it->second).getThetaZcut() << std::setw(5) << " urad"
0189        << "| sigThetaZcut     : " << std::setw(4) << (it->second).getSigThetaZcut() << std::setw(1) << " "
0190        << "| maxMoveThetaZcut : " << std::setw(4) << (it->second).getMaxMoveThetaZcut() << std::setw(5) << " urad"
0191        << "| ErrorThetaZcut   : " << std::setw(4) << (it->second).getErrorThetaZcut() << std::setw(5) << " urad";
0192 
0193     if (floatMap_.find(it->first) != floatMap_.end()) {
0194       ss << "| thetaZ_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_Z) << std::setw(5) << "\n";
0195     } else {
0196       ss << "\n";
0197     }
0198 
0199     out << ss.str() << std::endl;
0200 
0201     if ((it->second).hasExtraDOF()) {
0202       for (unsigned int j = 0; j < (it->second).extraDOFSize(); j++) {
0203         std::array<float, 4> extraDOFCuts = getExtraDOFCutsForAlignable(it->first, j);
0204 
0205         out << "Extra DOF " << j << " with label: " << getExtraDOFLabelForAlignable(it->first, j);
0206         out << "- cut              : " << std::setw(4) << extraDOFCuts.at(0) << std::setw(5) << "    "
0207             << "| sigCut           : " << std::setw(4) << extraDOFCuts.at(1) << std::setw(1) << " "
0208             << "| maxMoveCut       : " << std::setw(4) << extraDOFCuts.at(2) << std::setw(5) << "    "
0209             << "| maxErrorCut      : " << std::setw(4) << extraDOFCuts.at(3) << std::setw(5) << "    ";
0210       }
0211     }
0212   }
0213 }