Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-26 22:25:17

0001 #include "Geometry/HGCalCommonData/interface/HGCalGeomRotation.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 void HGCalGeomRotation::uvMappingFromSector0(WaferCentring waferCentring,
0006                                              int& moduleU,
0007                                              int& moduleV,
0008                                              unsigned sector) const {
0009   if (sector == 0) {
0010     return;
0011   }
0012 
0013   if (sectorType_ == SectorType::Sector60Degrees) {
0014     uvMappingFrom60DegreeSector0(waferCentring, moduleU, moduleV, sector);
0015   } else if (sectorType_ == SectorType::Sector120Degrees) {
0016     uvMappingFrom120DegreeSector0(waferCentring, moduleU, moduleV, sector);
0017   }
0018 }
0019 
0020 unsigned HGCalGeomRotation::uvMappingToSector0(WaferCentring waferCentring, int& moduleU, int& moduleV) const {
0021   unsigned sector = 0;
0022 
0023   if (sectorType_ == SectorType::Sector60Degrees) {
0024     sector = uvMappingTo60DegreeSector0(waferCentring, moduleU, moduleV);
0025   } else if (sectorType_ == SectorType::Sector120Degrees) {
0026     sector = uvMappingTo120DegreeSector0(waferCentring, moduleU, moduleV);
0027   }
0028 
0029   return sector;
0030 }
0031 
0032 void HGCalGeomRotation::uvMappingFrom60DegreeSector0(WaferCentring waferCentring,
0033                                                      int& moduleU,
0034                                                      int& moduleV,
0035                                                      unsigned sector) const {
0036   if (waferCentring != WaferCentring::WaferCentred) {
0037     edm::LogError("HGCalGeomRotation")
0038         << "HGCalGeomRotation: 60 degree sector defintion selected, but not WaferCentred centring. This is "
0039            "incompatible, assuming WaferCentred centring";
0040   }
0041 
0042   if (sector > 5) {
0043     throw cms::Exception("RotationException") << "HGCalGeomRotation: desired sector must be either 0, 1, 2, 3, 4, or 5";
0044   }
0045   for (unsigned rot = 0; rot < sector; rot++) {
0046     RotateModule60DegreesAnticlockwise(moduleU, moduleV);
0047   }
0048 }
0049 
0050 void HGCalGeomRotation::uvMappingFrom120DegreeSector0(WaferCentring waferCentring,
0051                                                       int& moduleU,
0052                                                       int& moduleV,
0053                                                       unsigned sector) const {
0054   int offset;
0055 
0056   if (waferCentring == WaferCentring::WaferCentred) {
0057     offset = 0;
0058   } else if (waferCentring == WaferCentring::CornerCentredY) {
0059     offset = -1;
0060   } else if (waferCentring == WaferCentring::CornerCentredMercedes) {
0061     offset = 1;
0062   } else {
0063     throw cms::Exception("RotationException")
0064         << "HGCalGeomRotation: WaferCentring must be one of: WaferCentred, CornerCentredY or CornerCentredMercedes";
0065   }
0066 
0067   if (sector > 2) {
0068     edm::LogError("RotationException") << "HGCalGeomRotation: desired sector must be either 0, 1 or 2";
0069     return;
0070   }
0071   for (unsigned rot = 0; rot < sector; rot++) {
0072     RotateModule120DegreesAnticlockwise(moduleU, moduleV, offset);
0073   }
0074 }
0075 
0076 unsigned HGCalGeomRotation::uvMappingTo120DegreeSector0(WaferCentring waferCentring, int& moduleU, int& moduleV) const {
0077   unsigned sector = 0;
0078   int offset;
0079 
0080   if (waferCentring == WaferCentring::WaferCentred) {
0081     if (moduleU > 0 && moduleV >= 0)
0082       return sector;
0083 
0084     offset = 0;
0085     if (moduleU >= moduleV && moduleV < 0)
0086       sector = 2;
0087     else
0088       sector = 1;
0089 
0090   } else if (waferCentring == WaferCentring::CornerCentredY) {
0091     if (moduleU >= 0 && moduleV >= 0)
0092       return sector;
0093 
0094     offset = -1;
0095     if (moduleU > moduleV && moduleV < 0)
0096       sector = 2;
0097     else
0098       sector = 1;
0099 
0100   } else if (waferCentring == WaferCentring::CornerCentredMercedes) {
0101     if (moduleU >= 1 && moduleV >= 1)
0102       return sector;
0103 
0104     offset = 1;
0105     if (moduleU >= moduleV && moduleV < 1)
0106       sector = 2;
0107     else
0108       sector = 1;
0109   } else {
0110     throw cms::Exception("RotationException")
0111         << "HGCalGeomRotation: WaferCentring must be one of: WaferCentred, CornerCentredY or CornerCentredMercedes";
0112   }
0113 
0114   for (unsigned rot = 0; rot < sector; rot++) {
0115     RotateModule120DegreesClockwise(moduleU, moduleV, offset);
0116   }
0117 
0118   return sector;
0119 }
0120 
0121 unsigned HGCalGeomRotation::uvMappingTo60DegreeSector0(WaferCentring waferCentring, int& moduleU, int& moduleV) const {
0122   unsigned sector = 0;
0123 
0124   if (waferCentring != WaferCentring::WaferCentred) {
0125     edm::LogError("HGCalGeomRotation")
0126         << "HGCalGeomRotation: 60 degree sector defintion selected, but not WaferCentred centring. This is "
0127            "incompatible, assuming WaferCentred centring";
0128   }
0129 
0130   if (moduleU > 0 && moduleV >= 0) {
0131     if (moduleV < moduleU) {
0132       return sector;
0133     } else {
0134       sector = 1;
0135     }
0136   } else if (moduleU >= moduleV && moduleV < 0) {
0137     if (moduleU >= 0) {
0138       sector = 5;
0139     } else {
0140       sector = 4;
0141     }
0142   } else {
0143     if (moduleV > 0) {
0144       sector = 2;
0145     } else {
0146       sector = 3;
0147     }
0148   }
0149 
0150   for (unsigned rot = 0; rot < sector; rot++) {
0151     RotateModule60DegreesClockwise(moduleU, moduleV);
0152   }
0153 
0154   return sector;
0155 }
0156 
0157 void HGCalGeomRotation::RotateModule60DegreesAnticlockwise(int& moduleU, int& moduleV) const {
0158   int moduleURotated, moduleVRotated;
0159   moduleURotated = moduleU - moduleV;
0160   moduleVRotated = moduleU;
0161 
0162   moduleU = moduleURotated;
0163   moduleV = moduleVRotated;
0164 }
0165 
0166 void HGCalGeomRotation::RotateModule60DegreesClockwise(int& moduleU, int& moduleV) const {
0167   int moduleURotated, moduleVRotated;
0168   moduleURotated = moduleV;
0169   moduleVRotated = moduleV - moduleU;
0170 
0171   moduleU = moduleURotated;
0172   moduleV = moduleVRotated;
0173 }
0174 
0175 void HGCalGeomRotation::RotateModule120DegreesAnticlockwise(int& moduleU, int& moduleV, int offset) const {
0176   int moduleURotated, moduleVRotated;
0177 
0178   moduleURotated = -moduleV + offset;
0179   moduleVRotated = moduleU - moduleV + offset;
0180 
0181   moduleU = moduleURotated;
0182   moduleV = moduleVRotated;
0183 }
0184 
0185 void HGCalGeomRotation::RotateModule120DegreesClockwise(int& moduleU, int& moduleV, int offset) const {
0186   int moduleURotated, moduleVRotated;
0187 
0188   moduleURotated = moduleV - moduleU;
0189   moduleVRotated = -moduleU + offset;
0190 
0191   moduleU = moduleURotated;
0192   moduleV = moduleVRotated;
0193 }