Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-29 23:12:32

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 (static_cast<int>(FSIZE) + static_cast<int>(ISIZE) + static_cast<int>(SSIZE)) {
0110     case 6:
0111       return 1;
0112     default:
0113       throw cms::Exception("AlignPCLThresholdsHG")
0114           << "Payload version with parameter size equal to "
0115           << static_cast<int>(FSIZE) + static_cast<int>(ISIZE) + static_cast<int>(SSIZE) << " is not defined.\n";
0116   }
0117 }
0118 
0119 //****************************************************************************//
0120 void AlignPCLThresholdsHG::printAll() const {
0121   edm::LogVerbatim out("AlignPCLThresholdsHG");
0122 
0123   out << "AlignPCLThresholdsHG::printAll()\n";
0124   out << "============================================================================================================="
0125          "======\n";
0126   out << "N records cut: " << this->getNrecords() << "\n";
0127   for (auto it = m_thresholds.begin(); it != m_thresholds.end(); ++it) {
0128     out << "==========================================================================================================="
0129            "========\n";
0130 
0131     std::stringstream ss;
0132 
0133     ss << "key : " << it->first << " \n"
0134        << "- Xcut             : " << std::setw(4) << (it->second).getXcut() << std::setw(5) << "   um"
0135        << "| sigXcut          : " << std::setw(4) << (it->second).getSigXcut() << std::setw(1) << " "
0136        << "| maxMoveXcut      : " << std::setw(4) << (it->second).getMaxMoveXcut() << std::setw(5) << "   um"
0137        << "| ErrorXcut        : " << std::setw(4) << (it->second).getErrorXcut() << std::setw(5) << "   um";
0138 
0139     if (floatMap_.find(it->first) != floatMap_.end()) {
0140       ss << "| X_fractionCut      : " << std::setw(4) << getFractionCut(it->first, X) << std::setw(5) << "\n";
0141     } else {
0142       ss << "\n";
0143     }
0144 
0145     ss << "- thetaXcut        : " << std::setw(4) << (it->second).getThetaXcut() << std::setw(5) << " urad"
0146        << "| sigThetaXcut     : " << std::setw(4) << (it->second).getSigThetaXcut() << std::setw(1) << " "
0147        << "| maxMoveThetaXcut : " << std::setw(4) << (it->second).getMaxMoveThetaXcut() << std::setw(5) << " urad"
0148        << "| ErrorThetaXcut   : " << std::setw(4) << (it->second).getErrorThetaXcut() << std::setw(5) << " urad";
0149 
0150     if (floatMap_.find(it->first) != floatMap_.end()) {
0151       ss << "| thetaX_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_X) << std::setw(5) << "\n";
0152     } else {
0153       ss << "\n";
0154     }
0155 
0156     ss << "- Ycut             : " << std::setw(4) << (it->second).getYcut() << std::setw(5) << "   um"
0157        << "| sigYcut          : " << std::setw(4) << (it->second).getSigXcut() << std::setw(1) << " "
0158        << "| maxMoveYcut      : " << std::setw(4) << (it->second).getMaxMoveYcut() << std::setw(5) << "   um"
0159        << "| ErrorYcut        : " << std::setw(4) << (it->second).getErrorYcut() << std::setw(5) << "   um";
0160 
0161     if (floatMap_.find(it->first) != floatMap_.end()) {
0162       ss << "| Y_fractionCut      : " << std::setw(4) << getFractionCut(it->first, Y) << std::setw(5) << "\n";
0163     } else {
0164       ss << "\n";
0165     }
0166 
0167     ss << "- thetaYcut        : " << std::setw(4) << (it->second).getThetaYcut() << std::setw(5) << " urad"
0168        << "| sigThetaYcut     : " << std::setw(4) << (it->second).getSigThetaYcut() << std::setw(1) << " "
0169        << "| maxMoveThetaYcut : " << std::setw(4) << (it->second).getMaxMoveThetaYcut() << std::setw(5) << " urad"
0170        << "| ErrorThetaYcut   : " << std::setw(4) << (it->second).getErrorThetaYcut() << std::setw(5) << " urad";
0171 
0172     if (floatMap_.find(it->first) != floatMap_.end()) {
0173       ss << "| thetaY_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_Y) << std::setw(5) << "\n";
0174     } else {
0175       ss << "\n";
0176     }
0177 
0178     ss << "- Zcut             : " << std::setw(4) << (it->second).getZcut() << std::setw(5) << "   um"
0179        << "| sigZcut          : " << std::setw(4) << (it->second).getSigZcut() << std::setw(1) << " "
0180        << "| maxMoveZcut      : " << std::setw(4) << (it->second).getMaxMoveZcut() << std::setw(5) << "   um"
0181        << "| ErrorZcut        : " << std::setw(4) << (it->second).getErrorZcut() << std::setw(5) << "   um";
0182 
0183     if (floatMap_.find(it->first) != floatMap_.end()) {
0184       ss << "| Z_fractionCut      : " << std::setw(4) << getFractionCut(it->first, Z) << std::setw(5) << "\n";
0185     } else {
0186       ss << "\n";
0187     }
0188 
0189     ss << "- thetaZcut        : " << std::setw(4) << (it->second).getThetaZcut() << std::setw(5) << " urad"
0190        << "| sigThetaZcut     : " << std::setw(4) << (it->second).getSigThetaZcut() << std::setw(1) << " "
0191        << "| maxMoveThetaZcut : " << std::setw(4) << (it->second).getMaxMoveThetaZcut() << std::setw(5) << " urad"
0192        << "| ErrorThetaZcut   : " << std::setw(4) << (it->second).getErrorThetaZcut() << std::setw(5) << " urad";
0193 
0194     if (floatMap_.find(it->first) != floatMap_.end()) {
0195       ss << "| thetaZ_fractionCut : " << std::setw(4) << getFractionCut(it->first, theta_Z) << std::setw(5) << "\n";
0196     } else {
0197       ss << "\n";
0198     }
0199 
0200     out << ss.str() << std::endl;
0201 
0202     if ((it->second).hasExtraDOF()) {
0203       for (unsigned int j = 0; j < (it->second).extraDOFSize(); j++) {
0204         std::array<float, 4> extraDOFCuts = getExtraDOFCutsForAlignable(it->first, j);
0205 
0206         out << "Extra DOF " << j << " with label: " << getExtraDOFLabelForAlignable(it->first, j);
0207         out << "- cut              : " << std::setw(4) << extraDOFCuts.at(0) << std::setw(5) << "    "
0208             << "| sigCut           : " << std::setw(4) << extraDOFCuts.at(1) << std::setw(1) << " "
0209             << "| maxMoveCut       : " << std::setw(4) << extraDOFCuts.at(2) << std::setw(5) << "    "
0210             << "| maxErrorCut      : " << std::setw(4) << extraDOFCuts.at(3) << std::setw(5) << "    ";
0211       }
0212     }
0213   }
0214 }