Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:14

0001 #include "Geometry/HGCalTBCommonData/interface/HGCalTBParameters.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 #include <array>
0005 
0006 //#define EDM_ML_DEBUG
0007 
0008 HGCalTBParameters::HGCalTBParameters(const std::string& nam) : name_(nam), nCells_(0) {
0009 #ifdef EDM_ML_DEBUG
0010   edm::LogVerbatim("HGCalGeom") << "Construct HGCalTBParameters for " << name_;
0011 #endif
0012 }
0013 
0014 void HGCalTBParameters::fillModule(const HGCalTBParameters::hgtrap& mytr, bool reco) {
0015   if (reco) {
0016     moduleLayR_.emplace_back(mytr.lay);
0017     moduleBlR_.emplace_back(mytr.bl);
0018     moduleTlR_.emplace_back(mytr.tl);
0019     moduleHR_.emplace_back(mytr.h);
0020     moduleDzR_.emplace_back(mytr.dz);
0021     moduleAlphaR_.emplace_back(mytr.alpha);
0022     moduleCellR_.emplace_back(mytr.cellSize);
0023   } else {
0024     moduleLayS_.emplace_back(mytr.lay);
0025     moduleBlS_.emplace_back(mytr.bl);
0026     moduleTlS_.emplace_back(mytr.tl);
0027     moduleHS_.emplace_back(mytr.h);
0028     moduleDzS_.emplace_back(mytr.dz);
0029     moduleAlphaS_.emplace_back(mytr.alpha);
0030     moduleCellS_.emplace_back(mytr.cellSize);
0031   }
0032 }
0033 
0034 HGCalTBParameters::hgtrap HGCalTBParameters::getModule(unsigned int k, bool reco) const {
0035   HGCalTBParameters::hgtrap mytr;
0036   if (reco) {
0037     if (k < moduleLayR_.size()) {
0038       mytr.lay = moduleLayR_[k];
0039       mytr.bl = moduleBlR_[k];
0040       mytr.tl = moduleTlR_[k];
0041       mytr.h = moduleHR_[k];
0042       mytr.dz = moduleDzR_[k];
0043       mytr.alpha = moduleAlphaR_[k];
0044       mytr.cellSize = moduleCellR_[k];
0045     } else {
0046       mytr.lay = -1;
0047       mytr.bl = mytr.tl = mytr.h = mytr.dz = mytr.alpha = mytr.cellSize = 0;
0048     }
0049   } else {
0050     if (k < moduleLayS_.size()) {
0051       mytr.lay = moduleLayS_[k];
0052       mytr.bl = moduleBlS_[k];
0053       mytr.tl = moduleTlS_[k];
0054       mytr.h = moduleHS_[k];
0055       mytr.dz = moduleDzS_[k];
0056       mytr.alpha = moduleAlphaS_[k];
0057       mytr.cellSize = moduleCellS_[k];
0058     } else {
0059       mytr.lay = -1;
0060       mytr.bl = mytr.tl = mytr.h = mytr.dz = mytr.alpha = mytr.cellSize = 0;
0061     }
0062   }
0063   return mytr;
0064 }
0065 
0066 void HGCalTBParameters::fillTrForm(const HGCalTBParameters::hgtrform& mytr) {
0067   int zp = (mytr.zp == 1) ? 1 : 0;
0068   uint32_t indx = ((zp & kMaskZside) << kShiftZside);
0069   indx |= ((mytr.lay & kMaskLayer) << kShiftLayer);
0070   indx |= ((mytr.sec & kMaskSector) << kShiftSector);
0071   indx |= ((mytr.subsec & kMaskSubSec) << kShiftSubSec);
0072 #ifdef EDM_ML_DEBUG
0073   edm::LogVerbatim("HGCalGeom") << "ZP " << zp << ":" << kMaskZside << ":" << kShiftZside
0074                                 << ((zp & kMaskZside) << kShiftZside) << " Lay " << mytr.lay << ":" << kMaskLayer << ":"
0075                                 << kShiftLayer << ":" << ((mytr.lay & kMaskLayer) << kShiftLayer) << " Sector "
0076                                 << mytr.sec << ":" << kMaskSector << ":" << kShiftSector << ":"
0077                                 << ((mytr.sec & kMaskSector) << kShiftSector) << " SubSec " << mytr.subsec << ":"
0078                                 << kMaskSubSec << ":" << kShiftSubSec << ":"
0079                                 << ((mytr.subsec & kMaskSubSec) << kShiftSubSec) << " Index " << std::hex << indx
0080                                 << std::dec;
0081 #endif
0082   trformIndex_.emplace_back(indx);
0083   trformTranX_.emplace_back(mytr.h3v.x());
0084   trformTranY_.emplace_back(mytr.h3v.y());
0085   trformTranZ_.emplace_back(mytr.h3v.z());
0086   trformRotXX_.emplace_back((std::abs(mytr.hr.xx()) > tol) ? mytr.hr.xx() : 0);
0087   trformRotYX_.emplace_back((std::abs(mytr.hr.yx()) > tol) ? mytr.hr.yx() : 0);
0088   trformRotZX_.emplace_back((std::abs(mytr.hr.zx()) > tol) ? mytr.hr.zx() : 0);
0089   trformRotXY_.emplace_back((std::abs(mytr.hr.xy()) > tol) ? mytr.hr.xy() : 0);
0090   trformRotYY_.emplace_back((std::abs(mytr.hr.yy()) > tol) ? mytr.hr.yy() : 0);
0091   trformRotZY_.emplace_back((std::abs(mytr.hr.zy()) > tol) ? mytr.hr.zy() : 0);
0092   trformRotXZ_.emplace_back((std::abs(mytr.hr.xz()) > tol) ? mytr.hr.xz() : 0);
0093   trformRotYZ_.emplace_back((std::abs(mytr.hr.yz()) > tol) ? mytr.hr.yz() : 0);
0094   trformRotZZ_.emplace_back((std::abs(mytr.hr.zz()) > tol) ? mytr.hr.zz() : 0);
0095 #ifdef EDM_ML_DEBUG
0096   unsigned int k = trformIndex_.size() - 1;
0097   edm::LogVerbatim("HGCalGeom") << "HGCalTBParameters[" << k << "] Index " << std::hex << trformIndex_[k] << std::dec
0098                                 << " (" << mytr.zp << ", " << mytr.lay << ", " << mytr.sec << ", " << mytr.subsec
0099                                 << ") Translation (" << trformTranX_[k] << ", " << trformTranY_[k] << ", "
0100                                 << trformTranZ_[k] << ") Rotation (" << trformRotXX_[k] << ", " << trformRotYX_[k]
0101                                 << ", " << trformRotZX_[k] << ", " << trformRotXY_[k] << ", " << trformRotYY_[k] << ", "
0102                                 << trformRotZY_[k] << ", " << trformRotXZ_[k] << ", " << trformRotYZ_[k] << ", "
0103                                 << trformRotZZ_[k];
0104 #endif
0105 }
0106 
0107 HGCalTBParameters::hgtrform HGCalTBParameters::getTrForm(unsigned int k) const {
0108   HGCalTBParameters::hgtrform mytr;
0109   if (k < trformIndex_.size()) {
0110     const auto& id = getID(k);
0111     mytr.zp = id[0];
0112     mytr.lay = id[1];
0113     mytr.sec = id[2];
0114     mytr.subsec = id[3];
0115     mytr.h3v = CLHEP::Hep3Vector(trformTranX_[k], trformTranY_[k], trformTranZ_[k]);
0116     const CLHEP::HepRep3x3 rotation(trformRotXX_[k],
0117                                     trformRotXY_[k],
0118                                     trformRotXZ_[k],
0119                                     trformRotYX_[k],
0120                                     trformRotYY_[k],
0121                                     trformRotYZ_[k],
0122                                     trformRotZX_[k],
0123                                     trformRotZY_[k],
0124                                     trformRotZZ_[k]);
0125     mytr.hr = CLHEP::HepRotation(rotation);
0126   } else {
0127     mytr.zp = mytr.lay = mytr.sec = mytr.subsec = 0;
0128   }
0129 #ifdef EDM_ML_DEBUG
0130   edm::LogVerbatim("HGCalGeom") << "HGCalTBParameters[" << k << "] Index " << std::hex << trformIndex_[k] << std::dec
0131                                 << " (" << mytr.zp << ", " << mytr.lay << ", " << mytr.sec << ", " << mytr.subsec
0132                                 << ") Translation (" << mytr.h3v.x() << ", " << mytr.h3v.y() << ", " << mytr.h3v.z()
0133                                 << ") Rotation (" << mytr.hr.xx() << ", " << mytr.hr.yx() << ", " << mytr.hr.zx()
0134                                 << ", " << mytr.hr.xy() << ", " << mytr.hr.yy() << ", " << mytr.hr.zy() << ", "
0135                                 << mytr.hr.xz() << ", " << mytr.hr.yz() << ", " << mytr.hr.zz();
0136 #endif
0137   return mytr;
0138 }
0139 
0140 void HGCalTBParameters::addTrForm(const CLHEP::Hep3Vector& h3v) {
0141   unsigned int k = trformTranX_.size();
0142   if (k > 0) {
0143     trformTranX_[k - 1] += h3v.x();
0144     trformTranY_[k - 1] += h3v.y();
0145     trformTranZ_[k - 1] += h3v.z();
0146   }
0147 }
0148 
0149 void HGCalTBParameters::scaleTrForm(double scale) {
0150   unsigned int k = trformTranX_.size();
0151   if (k > 0) {
0152     trformTranX_[k - 1] *= scale;
0153     trformTranY_[k - 1] *= scale;
0154     trformTranZ_[k - 1] *= scale;
0155   }
0156 }
0157 
0158 std::array<int, 4> HGCalTBParameters::getID(unsigned int k) const {
0159   int zp = ((trformIndex_[k] >> kShiftZside) & kMaskZside);
0160   if (zp != 1)
0161     zp = -1;
0162   int lay = ((trformIndex_[k] >> kShiftLayer) & kMaskLayer);
0163   int sec = ((trformIndex_[k] >> kShiftSector) & kMaskSector);
0164   int subsec = ((trformIndex_[k] >> kShiftSubSec) & kMaskSubSec);
0165   return std::array<int, 4>{{zp, lay, sec, subsec}};
0166 }
0167 
0168 #include "FWCore/Utilities/interface/typelookup.h"
0169 
0170 TYPELOOKUP_DATA_REG(HGCalTBParameters);