Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-11 04:36:42

0001 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
0002 
0003 #include <algorithm>
0004 
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0007 
0008 struct AlignableObjectId::entry {
0009   align::StructureType type;
0010   const char *name;
0011 };
0012 
0013 namespace {
0014 
0015   constexpr AlignableObjectId::entry entries_RunI[]{{align::invalid, "invalid"},
0016                                                     {align::AlignableDetUnit, "DetUnit"},
0017                                                     {align::AlignableDet, "Det"},
0018 
0019                                                     {align::TPBModule, "TPBModule"},
0020                                                     {align::TPBLadder, "TPBLadder"},
0021                                                     {align::TPBLayer, "TPBLayer"},
0022                                                     {align::TPBHalfBarrel, "TPBHalfBarrel"},
0023                                                     {align::TPBBarrel, "TPBBarrel"},
0024 
0025                                                     {align::TPEModule, "TPEModule"},
0026                                                     {align::TPEPanel, "TPEPanel"},
0027                                                     {align::TPEBlade, "TPEBlade"},
0028                                                     {align::TPEHalfDisk, "TPEHalfDisk"},
0029                                                     {align::TPEHalfCylinder, "TPEHalfCylinder"},
0030                                                     {align::TPEEndcap, "TPEEndcap"},
0031 
0032                                                     {align::TIBModule, "TIBModule"},
0033                                                     {align::TIBString, "TIBString"},
0034                                                     {align::TIBSurface, "TIBSurface"},
0035                                                     {align::TIBHalfShell, "TIBHalfShell"},
0036                                                     {align::TIBLayer, "TIBLayer"},
0037                                                     {align::TIBHalfBarrel, "TIBHalfBarrel"},
0038                                                     {align::TIBBarrel, "TIBBarrel"},
0039 
0040                                                     {align::TIDModule, "TIDModule"},
0041                                                     {align::TIDSide, "TIDSide"},
0042                                                     {align::TIDRing, "TIDRing"},
0043                                                     {align::TIDDisk, "TIDDisk"},
0044                                                     {align::TIDEndcap, "TIDEndcap"},
0045 
0046                                                     {align::TOBModule, "TOBModule"},
0047                                                     {align::TOBRod, "TOBRod"},
0048                                                     {align::TOBLayer, "TOBLayer"},
0049                                                     {align::TOBHalfBarrel, "TOBHalfBarrel"},
0050                                                     {align::TOBBarrel, "TOBBarrel"},
0051 
0052                                                     {align::TECModule, "TECModule"},
0053                                                     {align::TECRing, "TECRing"},
0054                                                     {align::TECPetal, "TECPetal"},
0055                                                     {align::TECSide, "TECSide"},
0056                                                     {align::TECDisk, "TECDisk"},
0057                                                     {align::TECEndcap, "TECEndcap"},
0058 
0059                                                     {align::Pixel, "Pixel"},
0060                                                     {align::Strip, "Strip"},
0061                                                     {align::Tracker, "Tracker"},
0062 
0063                                                     {align::AlignableDTBarrel, "DTBarrel"},
0064                                                     {align::AlignableDTWheel, "DTWheel"},
0065                                                     {align::AlignableDTStation, "DTStation"},
0066                                                     {align::AlignableDTChamber, "DTChamber"},
0067                                                     {align::AlignableDTSuperLayer, "DTSuperLayer"},
0068                                                     {align::AlignableDTLayer, "DTLayer"},
0069                                                     {align::AlignableCSCEndcap, "CSCEndcap"},
0070                                                     {align::AlignableCSCStation, "CSCStation"},
0071                                                     {align::AlignableCSCRing, "CSCRing"},
0072                                                     {align::AlignableCSCChamber, "CSCChamber"},
0073                                                     {align::AlignableCSCLayer, "CSCLayer"},
0074                                                     {align::AlignableMuon, "Muon"},
0075 
0076                                                     {align::BeamSpot, "BeamSpot"},
0077                                                     {align::notfound, nullptr}};
0078 
0079   constexpr AlignableObjectId::entry entries_PhaseI[]{{align::invalid, "invalid"},
0080                                                       {align::AlignableDetUnit, "DetUnit"},
0081                                                       {align::AlignableDet, "Det"},
0082 
0083                                                       {align::TPBModule, "P1PXBModule"},
0084                                                       {align::TPBLadder, "P1PXBLadder"},
0085                                                       {align::TPBLayer, "P1PXBLayer"},
0086                                                       {align::TPBHalfBarrel, "P1PXBHalfBarrel"},
0087                                                       {align::TPBBarrel, "P1PXBBarrel"},
0088 
0089                                                       {align::TPEModule, "P1PXECModule"},
0090                                                       {align::TPEPanel, "P1PXECPanel"},
0091                                                       {align::TPEBlade, "P1PXECBlade"},
0092                                                       {align::TPEHalfDisk, "P1PXECHalfDisk"},
0093                                                       {align::TPEHalfCylinder, "P1PXECHalfCylinder"},
0094                                                       {align::TPEEndcap, "P1PXECEndcap"},
0095 
0096                                                       {align::TIBModule, "TIBModule"},
0097                                                       {align::TIBString, "TIBString"},
0098                                                       {align::TIBSurface, "TIBSurface"},
0099                                                       {align::TIBHalfShell, "TIBHalfShell"},
0100                                                       {align::TIBLayer, "TIBLayer"},
0101                                                       {align::TIBHalfBarrel, "TIBHalfBarrel"},
0102                                                       {align::TIBBarrel, "TIBBarrel"},
0103 
0104                                                       {align::TIDModule, "TIDModule"},
0105                                                       {align::TIDSide, "TIDSide"},
0106                                                       {align::TIDRing, "TIDRing"},
0107                                                       {align::TIDDisk, "TIDDisk"},
0108                                                       {align::TIDEndcap, "TIDEndcap"},
0109 
0110                                                       {align::TOBModule, "TOBModule"},
0111                                                       {align::TOBRod, "TOBRod"},
0112                                                       {align::TOBLayer, "TOBLayer"},
0113                                                       {align::TOBHalfBarrel, "TOBHalfBarrel"},
0114                                                       {align::TOBBarrel, "TOBBarrel"},
0115 
0116                                                       {align::TECModule, "TECModule"},
0117                                                       {align::TECRing, "TECRing"},
0118                                                       {align::TECPetal, "TECPetal"},
0119                                                       {align::TECSide, "TECSide"},
0120                                                       {align::TECDisk, "TECDisk"},
0121                                                       {align::TECEndcap, "TECEndcap"},
0122 
0123                                                       {align::Pixel, "Pixel"},
0124                                                       {align::Strip, "Strip"},
0125                                                       {align::Tracker, "Tracker"},
0126 
0127                                                       {align::AlignableDTBarrel, "DTBarrel"},
0128                                                       {align::AlignableDTWheel, "DTWheel"},
0129                                                       {align::AlignableDTStation, "DTStation"},
0130                                                       {align::AlignableDTChamber, "DTChamber"},
0131                                                       {align::AlignableDTSuperLayer, "DTSuperLayer"},
0132                                                       {align::AlignableDTLayer, "DTLayer"},
0133                                                       {align::AlignableCSCEndcap, "CSCEndcap"},
0134                                                       {align::AlignableCSCStation, "CSCStation"},
0135                                                       {align::AlignableCSCRing, "CSCRing"},
0136                                                       {align::AlignableCSCChamber, "CSCChamber"},
0137                                                       {align::AlignableCSCLayer, "CSCLayer"},
0138                                                       {align::AlignableGEMEndcap, "GEMEndcap"},
0139                                                       {align::AlignableGEMStation, "GEMStation"},
0140                                                       {align::AlignableGEMRing, "GEMRing"},
0141                                                       {align::AlignableGEMSuperChamber, "GEMSuperChamber"},
0142                                                       {align::AlignableGEMChamber, "GEMChamber"},
0143                                                       {align::AlignableGEMEtaPartition, "GEMEtaPartition"},
0144                                                       {align::AlignableMuon, "Muon"},
0145 
0146                                                       {align::BeamSpot, "BeamSpot"},
0147                                                       {align::notfound, nullptr}};
0148 
0149   constexpr AlignableObjectId::entry entries_PhaseII[]{{align::invalid, "invalid"},
0150                                                        {align::AlignableDetUnit, "DetUnit"},
0151                                                        {align::AlignableDet, "Det"},
0152 
0153                                                        {align::TPBModule, "P2PXBModule"},
0154                                                        {align::TPBLadder, "P2PXBLadder"},
0155                                                        {align::TPBLayer, "P2PXBLayer"},
0156                                                        {align::TPBHalfBarrel, "P2PXBHalfBarrel"},
0157                                                        {align::TPBBarrel, "P2PXBBarrel"},
0158 
0159                                                        {align::TPEModule, "P2PXECModule"},
0160                                                        {align::TPEPanel, "P2PXECPanel"},
0161                                                        {align::TPEBlade, "P2PXECBlade"},
0162                                                        {align::TPEHalfDisk, "P2PXECHalfDisk"},
0163                                                        {align::TPEHalfCylinder, "P2PXECHalfCylinder"},
0164                                                        {align::TPEEndcap, "P2PXECEndcap"},
0165 
0166                                                        // TIB doesn't exit in PhaseII
0167                                                        {align::TIBModule, "TIBModule-INVALID"},
0168                                                        {align::TIBString, "TIBString-INVALID"},
0169                                                        {align::TIBSurface, "TIBSurface-INVALID"},
0170                                                        {align::TIBHalfShell, "TIBHalfShell-INVALID"},
0171                                                        {align::TIBLayer, "TIBLayer-INVALID"},
0172                                                        {align::TIBHalfBarrel, "TIBHalfBarrel-INVALID"},
0173                                                        {align::TIBBarrel, "TIBBarrel-INVALID"},
0174 
0175                                                        {align::TIDModule, "P2OTECModule"},
0176                                                        {align::TIDSide, "P2OTECSide"},
0177                                                        {align::TIDRing, "P2OTECRing"},
0178                                                        {align::TIDDisk, "P2OTECDisk"},
0179                                                        {align::TIDEndcap, "P2OTECEndcap"},
0180 
0181                                                        {align::TOBModule, "P2OTBModule"},
0182                                                        {align::TOBRod, "P2OTBRod"},
0183                                                        {align::TOBLayer, "P2OTBLayer"},
0184                                                        {align::TOBHalfBarrel, "P2OTBHalfBarrel"},
0185                                                        {align::TOBBarrel, "P2OTBBarrel"},
0186 
0187                                                        // TEC doesn't exit in PhaseII
0188                                                        {align::TECModule, "TECModule-INVALID"},
0189                                                        {align::TECRing, "TECRing-INVALID"},
0190                                                        {align::TECPetal, "TECPetal-INVALID"},
0191                                                        {align::TECSide, "TECSide-INVALID"},
0192                                                        {align::TECDisk, "TECDisk-INVALID"},
0193                                                        {align::TECEndcap, "TECEndcap-INVALID"},
0194 
0195                                                        {align::Pixel, "Pixel"},
0196                                                        {align::Strip, "Strip"},
0197                                                        {align::Tracker, "Tracker"},
0198 
0199                                                        {align::AlignableDTBarrel, "DTBarrel"},
0200                                                        {align::AlignableDTWheel, "DTWheel"},
0201                                                        {align::AlignableDTStation, "DTStation"},
0202                                                        {align::AlignableDTChamber, "DTChamber"},
0203                                                        {align::AlignableDTSuperLayer, "DTSuperLayer"},
0204                                                        {align::AlignableDTLayer, "DTLayer"},
0205                                                        {align::AlignableCSCEndcap, "CSCEndcap"},
0206                                                        {align::AlignableCSCStation, "CSCStation"},
0207                                                        {align::AlignableCSCRing, "CSCRing"},
0208                                                        {align::AlignableCSCChamber, "CSCChamber"},
0209                                                        {align::AlignableCSCLayer, "CSCLayer"},
0210                                                        {align::AlignableGEMEndcap, "GEMEndcap"},
0211                                                        {align::AlignableGEMStation, "GEMStation"},
0212                                                        {align::AlignableGEMRing, "GEMRing"},
0213                                                        {align::AlignableGEMSuperChamber, "GEMSuperChamber"},
0214                                                        {align::AlignableGEMChamber, "GEMChamber"},
0215                                                        {align::AlignableGEMEtaPartition, "GEMEtaPartition"},
0216                                                        {align::AlignableMuon, "Muon"},
0217 
0218                                                        {align::BeamSpot, "BeamSpot"},
0219                                                        {align::notfound, nullptr}};
0220 
0221   constexpr bool same(char const *x, char const *y) { return !*x && !*y ? true : (*x == *y && same(x + 1, y + 1)); }
0222 
0223   constexpr char const *objectIdToString(align::StructureType type, AlignableObjectId::entry const *entries) {
0224     return !entries->name ? nullptr : entries->type == type ? entries->name : objectIdToString(type, entries + 1);
0225   }
0226 
0227   constexpr enum align::StructureType stringToObjectId(char const *name, AlignableObjectId::entry const *entries) {
0228     return !entries->name              ? align::invalid
0229            : same(entries->name, name) ? entries->type
0230                                        : stringToObjectId(name, entries + 1);
0231   }
0232 }  // namespace
0233 
0234 //_____________________________________________________________________________
0235 AlignableObjectId ::AlignableObjectId(AlignableObjectId::Geometry geometry) : geometry_(geometry) {
0236   switch (geometry) {
0237     case AlignableObjectId::Geometry::RunI:
0238       entries_ = entries_RunI;
0239       break;
0240     case AlignableObjectId::Geometry::PhaseI:
0241       entries_ = entries_PhaseI;
0242       break;
0243     case AlignableObjectId::Geometry::PhaseII:
0244       entries_ = entries_PhaseII;
0245       break;
0246     case AlignableObjectId::Geometry::General:
0247       entries_ = entries_RunI;
0248       break;
0249     case AlignableObjectId::Geometry::Unspecified:
0250       entries_ = nullptr;
0251       break;
0252   }
0253   if (!entries_) {
0254     throw cms::Exception("LogicError") << "@SUB=AlignableObjectId::ctor\n"
0255                                        << "trying to create AlignableObjectId with unspecified geometry";
0256   }
0257 }
0258 
0259 //_____________________________________________________________________________
0260 AlignableObjectId ::AlignableObjectId(const TrackerGeometry *tracker,
0261                                       const DTGeometry *muonDt,
0262                                       const CSCGeometry *muonCsc,
0263                                       const GEMGeometry *muonGem)
0264     : AlignableObjectId(commonGeometry(trackerGeometry(tracker), muonGeometry(muonDt, muonCsc, muonGem))) {}
0265 
0266 //_____________________________________________________________________________
0267 align::StructureType AlignableObjectId::nameToType(const std::string &name) const { return stringToId(name.c_str()); }
0268 
0269 //_____________________________________________________________________________
0270 std::string AlignableObjectId::typeToName(align::StructureType type) const { return idToString(type); }
0271 
0272 //_____________________________________________________________________________
0273 const char *AlignableObjectId::idToString(align::StructureType type) const {
0274   const char *result = objectIdToString(type, entries_);
0275 
0276   if (result == nullptr) {
0277     throw cms::Exception("AlignableObjectIdError") << "Unknown alignableObjectId " << type;
0278   }
0279 
0280   return result;
0281 }
0282 
0283 //_____________________________________________________________________________
0284 align::StructureType AlignableObjectId::stringToId(const char *name) const {
0285   auto result = stringToObjectId(name, entries_);
0286   if (result == -1) {
0287     throw cms::Exception("AlignableObjectIdError") << "Unknown alignableObjectId " << name;
0288   }
0289 
0290   return result;
0291 }
0292 
0293 //______________________________________________________________________________
0294 AlignableObjectId::Geometry AlignableObjectId ::trackerGeometry(const TrackerGeometry *geometry) {
0295   if (!geometry)
0296     return Geometry::General;
0297 
0298   if (geometry->isThere(GeomDetEnumerators::P2PXEC)) {
0299     // use structure-type <-> name translation for PhaseII geometry
0300     return Geometry::PhaseII;
0301 
0302   } else if (geometry->isThere(GeomDetEnumerators::P1PXEC)) {
0303     // use structure-type <-> name translation for PhaseI geometry
0304     return Geometry::PhaseI;
0305 
0306   } else if (geometry->isThere(GeomDetEnumerators::PixelEndcap)) {
0307     // use structure-type <-> name translation for RunI geometry
0308     return Geometry::RunI;
0309 
0310   } else {
0311     throw cms::Exception("AlignableObjectIdError") << "@SUB=AlignableObjectId::trackerGeometry\n"
0312                                                    << "unknown version of TrackerGeometry";
0313   }
0314 }
0315 
0316 AlignableObjectId::Geometry AlignableObjectId ::muonGeometry(const DTGeometry *,
0317                                                              const CSCGeometry *,
0318                                                              const GEMGeometry *) {
0319   // muon alignment structure types are identical for all kinds of geometries
0320   return Geometry::General;
0321 }
0322 
0323 AlignableObjectId::Geometry AlignableObjectId ::commonGeometry(Geometry first, Geometry second) {
0324   if (first == Geometry::General)
0325     return second;
0326   if (second == Geometry::General)
0327     return first;
0328   if (first == second)
0329     return first;
0330 
0331   throw cms::Exception("AlignableObjectIdError") << "@SUB=AlignableObjectId::commonGeometry\n"
0332                                                  << "impossible to find common geometry because the two geometries are "
0333                                                  << "different and none of them is 'General'";
0334 }
0335 
0336 AlignableObjectId AlignableObjectId ::commonObjectIdProvider(const AlignableObjectId &first,
0337                                                              const AlignableObjectId &second) {
0338   return AlignableObjectId{commonGeometry(first.geometry(), second.geometry())};
0339 }