Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-02 22:46:14

0001 #ifndef ALIGNMENT_MILLEPEDEALIGNMENTALGORITHM_INTERFACE_MILLEPEDEFILEREADER_H_
0002 #define ALIGNMENT_MILLEPEDEALIGNMENTALGORITHM_INTERFACE_MILLEPEDEFILEREADER_H_
0003 
0004 /*** system includes ***/
0005 #include <array>
0006 #include <string>
0007 #include <iostream>
0008 
0009 /*** core framework functionality ***/
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 /*** Alignment ***/
0014 #include "Alignment/MillePedeAlignmentAlgorithm/interface/PedeLabelerBase.h"
0015 #include "CondFormats/PCLConfig/interface/AlignPCLThresholdsHG.h"
0016 #include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyMap.h"
0017 
0018 struct mpPCLresults {
0019 private:
0020   bool m_isHG;
0021   bool m_isDBUpdated;
0022   bool m_isDBUpdateVetoed;
0023   int m_nRecords;
0024   int m_exitCode;
0025   std::string m_exitMessage;
0026   std::bitset<4> m_updateBits;
0027 
0028 public:
0029   mpPCLresults(bool isDBUpdated,
0030                bool isDBUpdateVetoed,
0031                int nRecords,
0032                int exitCode,
0033                std::string exitMessage,
0034                std::bitset<4> updateBits,
0035                bool isHG)
0036       : m_isHG(isHG),
0037         m_isDBUpdated(isDBUpdated),
0038         m_isDBUpdateVetoed(isDBUpdateVetoed),
0039         m_nRecords(nRecords),
0040         m_exitCode(exitCode),
0041         m_exitMessage(exitMessage),
0042         m_updateBits(updateBits) {}
0043 
0044   const bool isHighGranularity() { return m_isHG; }
0045   const bool getDBUpdated() { return m_isDBUpdated; }
0046   const bool getDBVetoed() { return m_isDBUpdateVetoed; }
0047   const bool exceedsThresholds() { return m_updateBits.test(0); }
0048   const bool exceedsCutoffs() { return m_updateBits.test(1); }
0049   const bool exceedsMaxError() { return m_updateBits.test(2); }
0050   const bool belowSignificance() { return m_updateBits.test(3); }
0051   const int getNRecords() { return m_nRecords; }
0052   const int getExitCode() { return m_exitCode; }
0053   const std::string getExitMessage() { return m_exitMessage; }
0054 
0055   void print() {
0056     edm::LogInfo("MillePedeFileReader") << " is DB updated: " << m_isDBUpdated
0057                                         << " is DB update vetoed: " << m_isDBUpdateVetoed << " nRecords: " << m_nRecords
0058                                         << " exitCode: " << m_exitCode << " (" << m_exitMessage << ")" << std::endl;
0059   }
0060 };
0061 
0062 class MillePedeFileReader {
0063   //========================== PUBLIC METHODS ==================================
0064 public:  //====================================================================
0065   explicit MillePedeFileReader(const edm::ParameterSet&,
0066                                const std::shared_ptr<const PedeLabelerBase>&,
0067                                const std::shared_ptr<const AlignPCLThresholdsHG>&,
0068                                const std::shared_ptr<const PixelTopologyMap>&);
0069 
0070   virtual ~MillePedeFileReader() = default;
0071 
0072   void read();
0073   bool storeAlignments();
0074 
0075   enum { SIZE_LG_STRUCTS = 6, SIZE_HG_STRUCTS = 820 };
0076 
0077   const std::array<double, SIZE_LG_STRUCTS>& getXobs() const { return Xobs_; }
0078   const std::array<double, SIZE_LG_STRUCTS>& getXobsErr() const { return XobsErr_; }
0079   const std::array<double, SIZE_LG_STRUCTS>& getTXobs() const { return tXobs_; }
0080   const std::array<double, SIZE_LG_STRUCTS>& getTXobsErr() const { return tXobsErr_; }
0081 
0082   const std::array<double, SIZE_LG_STRUCTS>& getYobs() const { return Yobs_; }
0083   const std::array<double, SIZE_LG_STRUCTS>& getYobsErr() const { return YobsErr_; }
0084   const std::array<double, SIZE_LG_STRUCTS>& getTYobs() const { return tYobs_; }
0085   const std::array<double, SIZE_LG_STRUCTS>& getTYobsErr() const { return tYobsErr_; }
0086 
0087   const std::array<double, SIZE_LG_STRUCTS>& getZobs() const { return Zobs_; }
0088   const std::array<double, SIZE_LG_STRUCTS>& getZobsErr() const { return ZobsErr_; }
0089   const std::array<double, SIZE_LG_STRUCTS>& getTZobs() const { return tZobs_; }
0090   const std::array<double, SIZE_LG_STRUCTS>& getTZobsErr() const { return tZobsErr_; }
0091 
0092   const std::array<double, SIZE_HG_STRUCTS>& getXobs_HG() const { return Xobs_HG_; }
0093   const std::array<double, SIZE_HG_STRUCTS>& getXobsErr_HG() const { return XobsErr_HG_; }
0094   const std::array<double, SIZE_HG_STRUCTS>& getTXobs_HG() const { return tXobs_HG_; }
0095   const std::array<double, SIZE_HG_STRUCTS>& getTXobsErr_HG() const { return tXobsErr_HG_; }
0096 
0097   const std::array<double, SIZE_HG_STRUCTS>& getYobs_HG() const { return Yobs_HG_; }
0098   const std::array<double, SIZE_HG_STRUCTS>& getYobsErr_HG() const { return YobsErr_HG_; }
0099   const std::array<double, SIZE_HG_STRUCTS>& getTYobs_HG() const { return tYobs_HG_; }
0100   const std::array<double, SIZE_HG_STRUCTS>& getTYobsErr_HG() const { return tYobsErr_HG_; }
0101 
0102   const std::array<double, SIZE_HG_STRUCTS>& getZobs_HG() const { return Zobs_HG_; }
0103   const std::array<double, SIZE_HG_STRUCTS>& getZobsErr_HG() const { return ZobsErr_HG_; }
0104   const std::array<double, SIZE_HG_STRUCTS>& getTZobs_HG() const { return tZobs_HG_; }
0105   const std::array<double, SIZE_HG_STRUCTS>& getTZobsErr_HG() const { return tZobsErr_HG_; }
0106 
0107   const AlignPCLThresholdsHG::threshold_map getThresholdMap() const { return theThresholds_.get()->getThreshold_Map(); }
0108 
0109   const int binariesAmount() const { return binariesAmount_; }
0110 
0111   const mpPCLresults getResults() const {
0112     return mpPCLresults(updateDB_, vetoUpdateDB_, Nrec_, exitCode_, exitMessage_, updateBits_, isHG_);
0113   }
0114 
0115   const std::map<std::string, std::array<bool, 6>>& getResultsHG() const { return fractionExceeded_; }
0116 
0117 private:
0118   //========================= PRIVATE ENUMS ====================================
0119   //============================================================================
0120 
0121   enum class PclHLS : int {
0122     NotInPCL = -1,
0123     TPEHalfCylinderXplusZminus = 0,
0124     TPEHalfCylinderXminusZminus = 1,
0125     TPBHalfBarrelXplus = 2,
0126     TPBHalfBarrelXminus = 3,
0127     TPEHalfCylinderXplusZplus = 4,
0128     TPEHalfCylinderXminusZplus = 5,
0129     TPBLadderLayer1 = 6,
0130     TPBLadderLayer2 = 7,
0131     TPBLadderLayer3 = 8,
0132     TPBLadderLayer4 = 9,
0133     TPEPanelDisk1 = 10,
0134     TPEPanelDisk2 = 11,
0135     TPEPanelDisk3 = 12,
0136     TPEPanelDiskM1 = 13,
0137     TPEPanelDiskM2 = 14,
0138     TPEPanelDiskM3 = 15,
0139   };
0140 
0141   //========================= PRIVATE METHODS ==================================
0142   //============================================================================
0143 
0144   void readMillePedeEndFile();
0145   void readMillePedeLogFile();
0146   void readMillePedeResultFile();
0147   PclHLS getHLS(const Alignable*);
0148   std::string getStringFromHLS(PclHLS HLS);
0149   int getIndexForHG(align::ID id, PclHLS HLS);
0150   void initializeIndexHelper();
0151 
0152   //========================== PRIVATE DATA ====================================
0153   //============================================================================
0154 
0155   // pede labeler plugin
0156   const std::shared_ptr<const PedeLabelerBase> pedeLabeler_;
0157 
0158   // thresholds from DB
0159   const std::shared_ptr<const AlignPCLThresholdsHG> theThresholds_;
0160 
0161   // PixelTopologyMap
0162   const std::shared_ptr<const PixelTopologyMap> pixelTopologyMap_;
0163 
0164   // input directory name
0165   std::string dirName_;
0166 
0167   // file-names
0168   const std::string millePedeEndFile_;
0169   const std::string millePedeLogFile_;
0170   const std::string millePedeResFile_;
0171 
0172   // conversion factors: cm to um & rad to urad
0173   static constexpr std::array<double, 6> multiplier_ = {{10000.,      // X
0174                                                          10000.,      // Y
0175                                                          10000.,      // Z
0176                                                          1000000.,    // tX
0177                                                          1000000.,    // tY
0178                                                          1000000.}};  // tZ
0179 
0180   bool updateDB_{false};
0181   bool vetoUpdateDB_{false};
0182   const bool isHG_;
0183 
0184   // stores in a compact format the 4 decisions:
0185   // 1st bit: exceeds maximum thresholds
0186   // 2nd bit: exceeds cutoffs (significant movement)
0187   // 3rd bit: exceeds maximum errors
0188   // 4th bit: is below the significance
0189   std::bitset<4> updateBits_;
0190 
0191   // pede binaries available
0192   int binariesAmount_{0};
0193 
0194   // Fraction threshold booleans for HG alignment
0195   std::map<std::string, std::array<bool, 6>> fractionExceeded_;
0196 
0197   int Nrec_{0};
0198   int exitCode_{-1};
0199   std::string exitMessage_{""};
0200 
0201   std::array<double, SIZE_LG_STRUCTS> Xobs_ = std::array<double, SIZE_LG_STRUCTS>();
0202   std::array<double, SIZE_LG_STRUCTS> XobsErr_ = std::array<double, SIZE_LG_STRUCTS>();
0203   std::array<double, SIZE_LG_STRUCTS> tXobs_ = std::array<double, SIZE_LG_STRUCTS>();
0204   std::array<double, SIZE_LG_STRUCTS> tXobsErr_ = std::array<double, SIZE_LG_STRUCTS>();
0205 
0206   std::array<double, SIZE_LG_STRUCTS> Yobs_ = std::array<double, SIZE_LG_STRUCTS>();
0207   std::array<double, SIZE_LG_STRUCTS> YobsErr_ = std::array<double, SIZE_LG_STRUCTS>();
0208   std::array<double, SIZE_LG_STRUCTS> tYobs_ = std::array<double, SIZE_LG_STRUCTS>();
0209   std::array<double, SIZE_LG_STRUCTS> tYobsErr_ = std::array<double, SIZE_LG_STRUCTS>();
0210 
0211   std::array<double, SIZE_LG_STRUCTS> Zobs_ = std::array<double, SIZE_LG_STRUCTS>();
0212   std::array<double, SIZE_LG_STRUCTS> ZobsErr_ = std::array<double, SIZE_LG_STRUCTS>();
0213   std::array<double, SIZE_LG_STRUCTS> tZobs_ = std::array<double, SIZE_LG_STRUCTS>();
0214   std::array<double, SIZE_LG_STRUCTS> tZobsErr_ = std::array<double, SIZE_LG_STRUCTS>();
0215 
0216   std::array<double, SIZE_HG_STRUCTS> Xobs_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0217   std::array<double, SIZE_HG_STRUCTS> XobsErr_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0218   std::array<double, SIZE_HG_STRUCTS> tXobs_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0219   std::array<double, SIZE_HG_STRUCTS> tXobsErr_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0220 
0221   std::array<double, SIZE_HG_STRUCTS> Yobs_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0222   std::array<double, SIZE_HG_STRUCTS> YobsErr_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0223   std::array<double, SIZE_HG_STRUCTS> tYobs_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0224   std::array<double, SIZE_HG_STRUCTS> tYobsErr_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0225 
0226   std::array<double, SIZE_HG_STRUCTS> Zobs_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0227   std::array<double, SIZE_HG_STRUCTS> ZobsErr_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0228   std::array<double, SIZE_HG_STRUCTS> tZobs_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0229   std::array<double, SIZE_HG_STRUCTS> tZobsErr_HG_ = std::array<double, SIZE_HG_STRUCTS>();
0230 
0231   std::unordered_map<PclHLS, std::pair<int, int>> indexHelper;
0232 };
0233 
0234 const std::array<std::string, 8> coord_str = {{"X", "Y", "Z", "theta_X", "theta_Y", "theta_Z", "extra_DOF", "none"}};
0235 inline std::ostream& operator<<(std::ostream& os, const AlignPCLThresholdsHG::coordType& c) {
0236   if (c >= AlignPCLThresholdsHG::endOfTypes || c < AlignPCLThresholdsHG::X)
0237     return os << "unrecongnized coordinate";
0238   return os << coord_str[c];
0239 }
0240 
0241 #endif /* ALIGNMENT_MILLEPEDEALIGNMENTALGORITHM_INTERFACE_MILLEPEDEFILEREADER_H_ */