Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /****************************************************************************
0002 *
0003 * This is a part of TOTEM offline software.
0004 * Authors:
0005 *  Jan Kaspar (jan.kaspar@gmail.com)
0006 *
0007 ****************************************************************************/
0008 
0009 #include "Geometry/VeryForwardGeometryBuilder/interface/CTPPSGeometry.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include <regex>
0012 
0013 //----------------------------------------------------------------------------------------------------
0014 
0015 void CTPPSGeometry::build(const DetGeomDesc* gD, unsigned int verbosity) {
0016   // reset
0017   sensors_map_.clear();
0018   rps_map_.clear();
0019   stations_in_arm_.clear();
0020   rps_in_station_.clear();
0021   dets_in_rp_.clear();
0022 
0023   // propagate through the GeometricalDet structure and add all detectors to 'sensors_map_'
0024   std::deque<const DetGeomDesc*> buffer;
0025   buffer.emplace_back(gD);
0026   while (!buffer.empty()) {
0027     const DetGeomDesc* d = buffer.front();
0028     buffer.pop_front();
0029 
0030     // verbosity printout
0031     if (verbosity == 2) {
0032       d->print();
0033     }
0034 
0035     // check if it is a sensor
0036     if (d->name() == DDD_TOTEM_RP_SENSOR_NAME ||
0037         std::regex_match(d->name(), std::regex(DDD_TOTEM_TIMING_SENSOR_TMPL)) ||
0038         d->name() == DDD_CTPPS_DIAMONDS_SEGMENT_NAME || d->name() == DDD_CTPPS_UFSD_SEGMENT_NAME ||
0039         d->name() == DDD_CTPPS_PIXELS_SENSOR_NAME || d->name() == DDD_CTPPS_PIXELS_SENSOR_NAME_2x2)
0040       addSensor(d->geographicalID(), d);
0041 
0042     // check if it is a RP
0043     if (d->name() == DDD_TOTEM_RP_RP_NAME || d->name() == DDD_TOTEM_TIMING_RP_NAME ||
0044         d->name() == DDD_CTPPS_DIAMONDS_RP_NAME || d->name() == DDD_CTPPS_PIXELS_RP_NAME)
0045       addRP(d->geographicalID(), d);
0046 
0047     for (const auto& comp : d->components())
0048       buffer.emplace_back(comp);
0049   }
0050 
0051   // verbosity printout
0052   if (verbosity) {
0053     edm::LogVerbatim("CTPPSGeometry::build")
0054         << "sensors_map_.size() = " << sensors_map_.size() << ", rps_map_.size() = " << rps_map_.size() << std::endl;
0055   }
0056 
0057   // build sets
0058   for (const auto& it : sensors_map_) {
0059     const CTPPSDetId detId(it.first);
0060     const CTPPSDetId rpId = detId.rpId();
0061     const CTPPSDetId stId = detId.stationId();
0062     const CTPPSDetId armId = detId.armId();
0063 
0064     stations_in_arm_[armId].insert(armId);
0065     rps_in_station_[stId].insert(rpId);
0066     dets_in_rp_[rpId].insert(detId);
0067   }
0068 }
0069 
0070 //----------------------------------------------------------------------------------------------------
0071 
0072 bool CTPPSGeometry::addSensor(unsigned int id, const DetGeomDesc*& gD) {
0073   if (sensors_map_.find(id) != sensors_map_.end())
0074     return false;
0075 
0076   sensors_map_[id] = gD;
0077   return true;
0078 }
0079 
0080 //----------------------------------------------------------------------------------------------------
0081 
0082 bool CTPPSGeometry::addRP(unsigned int id, const DetGeomDesc*& gD) {
0083   if (rps_map_.find(id) != rps_map_.end())
0084     return false;
0085 
0086   rps_map_[id] = gD;
0087   return true;
0088 }
0089 
0090 //----------------------------------------------------------------------------------------------------
0091 
0092 const DetGeomDesc* CTPPSGeometry::sensor(unsigned int id) const {
0093   auto g = sensorNoThrow(id);
0094   if (nullptr == g) {
0095     throw cms::Exception("CTPPSGeometry") << "Not found detector with ID " << id << ", i.e. " << CTPPSDetId(id);
0096   }
0097   return g;
0098 }
0099 
0100 //----------------------------------------------------------------------------------------------------
0101 
0102 const DetGeomDesc* CTPPSGeometry::sensorNoThrow(unsigned int id) const noexcept {
0103   auto it = sensors_map_.find(id);
0104   if (it == sensors_map_.end()) {
0105     return nullptr;
0106   }
0107   return it->second;
0108 }
0109 
0110 //----------------------------------------------------------------------------------------------------
0111 
0112 const DetGeomDesc* CTPPSGeometry::rp(unsigned int id) const {
0113   auto rp = rpNoThrow(id);
0114   if (nullptr == rp) {
0115     throw cms::Exception("CTPPSGeometry") << "Not found RP device with ID " << id << ", i.e. " << CTPPSDetId(id);
0116   }
0117   return rp;
0118 }
0119 
0120 //----------------------------------------------------------------------------------------------------
0121 
0122 const DetGeomDesc* CTPPSGeometry::rpNoThrow(unsigned int id) const noexcept {
0123   auto it = rps_map_.find(id);
0124   if (it == rps_map_.end()) {
0125     return nullptr;
0126   }
0127 
0128   return it->second;
0129 }
0130 
0131 //----------------------------------------------------------------------------------------------------
0132 const std::set<unsigned int>& CTPPSGeometry::stationsInArm(unsigned int id) const {
0133   auto it = stations_in_arm_.find(id);
0134   if (it == stations_in_arm_.end())
0135     throw cms::Exception("CTPPSGeometry") << "Arm with ID " << id << " not found.";
0136   return it->second;
0137 }
0138 
0139 //----------------------------------------------------------------------------------------------------
0140 
0141 const std::set<unsigned int>& CTPPSGeometry::rpsInStation(unsigned int id) const {
0142   auto it = rps_in_station_.find(id);
0143   if (it == rps_in_station_.end())
0144     throw cms::Exception("CTPPSGeometry") << "Station with ID " << id << " not found.";
0145   return it->second;
0146 }
0147 
0148 //----------------------------------------------------------------------------------------------------
0149 
0150 const std::set<unsigned int>& CTPPSGeometry::sensorsInRP(unsigned int id) const {
0151   auto it = dets_in_rp_.find(id);
0152   if (it == dets_in_rp_.end())
0153     throw cms::Exception("CTPPSGeometry") << "RP with ID " << id << " not found.";
0154   return it->second;
0155 }
0156 
0157 //----------------------------------------------------------------------------------------------------
0158 
0159 CTPPSGeometry::Vector CTPPSGeometry::localToGlobal(const DetGeomDesc* gd, const CTPPSGeometry::Vector& r) const {
0160   return gd->rotation() * r + gd->translation();
0161 }
0162 
0163 //----------------------------------------------------------------------------------------------------
0164 
0165 CTPPSGeometry::Vector CTPPSGeometry::localToGlobal(unsigned int id, const CTPPSGeometry::Vector& r) const {
0166   return localToGlobal(sensor(id), r);
0167 }
0168 
0169 //----------------------------------------------------------------------------------------------------
0170 
0171 CTPPSGeometry::Vector CTPPSGeometry::globalToLocal(const DetGeomDesc* gd, const CTPPSGeometry::Vector& r) const {
0172   return gd->rotation().Inverse() * (r - gd->translation());
0173 }
0174 
0175 //----------------------------------------------------------------------------------------------------
0176 
0177 CTPPSGeometry::Vector CTPPSGeometry::globalToLocal(unsigned int id, const CTPPSGeometry::Vector& r) const {
0178   return globalToLocal(sensor(id), r);
0179 }
0180 
0181 //----------------------------------------------------------------------------------------------------
0182 
0183 CTPPSGeometry::Vector CTPPSGeometry::localToGlobalDirection(unsigned int id, const CTPPSGeometry::Vector& dir) const {
0184   return sensor(id)->rotation() * dir;
0185 }
0186 
0187 //----------------------------------------------------------------------------------------------------
0188 
0189 CTPPSGeometry::Vector CTPPSGeometry::globalToLocalDirection(unsigned int id, const CTPPSGeometry::Vector& dir) const {
0190   return sensor(id)->rotation().Inverse() * dir;
0191 }
0192 
0193 //----------------------------------------------------------------------------------------------------
0194 
0195 CTPPSGeometry::Vector CTPPSGeometry::sensorTranslation(unsigned int id) const {
0196   auto gd = sensor(id);
0197   return gd->translation();
0198 }
0199 
0200 //----------------------------------------------------------------------------------------------------
0201 
0202 CTPPSGeometry::Vector CTPPSGeometry::rpTranslation(unsigned int id) const {
0203   auto gd = rp(id);
0204   return gd->translation();
0205 }