Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-28 08:56:23

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/EventData/MuonSpacePoint.hpp"
0010 
0011 #include "Acts/Utilities/StringHelpers.hpp"
0012 
0013 #include <cassert>
0014 #include <format>
0015 
0016 namespace {
0017 constexpr std::uint32_t oneBit = 1;
0018 constexpr std::uint32_t threeBit = 0x7;
0019 constexpr std::uint32_t fourBit = 0xF;
0020 constexpr std::uint32_t sixBit = 0x3F;
0021 }  // namespace
0022 
0023 namespace ActsExamples {
0024 
0025 std::ostream& operator<<(std::ostream& ostr,
0026                          const ActsExamples::MuonSpacePoint::MuonId& id) {
0027   ostr << id.toString();
0028   return ostr;
0029 }
0030 std::ostream& operator<<(std::ostream& ostr,
0031                          const ActsExamples::MuonSpacePoint& sp) {
0032   ostr << std::format(
0033       "Muon-ID: {}, position: {}, orientation (d/n/o): {}/{}/{}, covariance: "
0034       "({:.2f}, {:.2f}, {:.2f})",
0035       sp.id().toString(), Acts::toString(sp.localPosition()),
0036       Acts::toString(sp.sensorDirection()), Acts::toString(sp.toNextSensor()),
0037       Acts::toString(sp.planeNormal()), sp.covariance()[0], sp.covariance()[1],
0038       sp.covariance()[2]);
0039   return ostr;
0040 }
0041 
0042 using TechField = MuonSpacePoint::MuonId::TechField;
0043 using StationName = MuonSpacePoint::MuonId::StationName;
0044 using DetSide = MuonSpacePoint::MuonId::DetSide;
0045 
0046 std::string MuonSpacePoint::MuonId::toString(const StationName st) {
0047   switch (st) {
0048     case StationName::BIS:
0049       return "BIS";
0050     case StationName::BIL:
0051       return "BIL";
0052     case StationName::BMS:
0053       return "BMS";
0054     case StationName::BML:
0055       return "BML";
0056     case StationName::BOS:
0057       return "BOS";
0058     case StationName::BOL:
0059       return "BOL";
0060     case StationName::BEE:
0061       return "BEE";
0062     case StationName::EIL:
0063       return "EIL";
0064     case StationName::EIS:
0065       return "EIS";
0066     case StationName::EMS:
0067       return "EMS";
0068     case StationName::EML:
0069       return "EML";
0070     case StationName::EOS:
0071       return "EOS";
0072     case StationName::EOL:
0073       return "EOL";
0074     case StationName::EES:
0075       return "EES";
0076     case StationName::EEL:
0077       return "EEL";
0078     default:
0079       return "Unknown";
0080   }
0081 }
0082 std::string MuonSpacePoint::MuonId::toString(const TechField tech) {
0083   switch (tech) {
0084     case TechField::Mdt:
0085       return "Mdt";
0086     case TechField::Tgc:
0087       return "Tgc";
0088     case TechField::Rpc:
0089       return "Rpc";
0090     case TechField::sTgc:
0091       return "sTgc";
0092     case TechField::Mm:
0093       return "Mm";
0094     default:
0095       return "Unknown";
0096   }
0097 }
0098 std::string MuonSpacePoint::MuonId::toString(const DetSide side) {
0099   switch (side) {
0100     case DetSide::A:
0101       return "A-side";
0102     case DetSide::C:
0103       return "C-side";
0104     default:
0105       return "Unknown";
0106   }
0107 }
0108 
0109 /// Bit layout
0110 /// StationName 0-14 -> 4 bits
0111 /// Detector side 0-1 -> 1 bit
0112 /// Technology 0-5 -> 3 bis
0113 /// Sector 1-64 -> 6 bits
0114 /// Layer 1-16 -> 4 bits
0115 /// measuresLoc0 -> 1 bit
0116 /// measuresLoc1 -> 1 bit
0117 MuonSpacePoint::MuonId::MuonId(std::uint32_t rawRep) : MuonId{} {
0118   m_stName = static_cast<StationName>(rawRep & fourBit);
0119   if (((rawRep >> 4) & oneBit) != 0u) {
0120     m_side = DetSide::A;
0121   } else {
0122     m_side = DetSide::C;
0123   }
0124   m_tech = static_cast<TechField>((rawRep >> 5) & threeBit);
0125   m_sector = ((rawRep >> 8) & sixBit) + 1u;
0126   m_measEta = ((rawRep >> 14) & oneBit) == 1u;
0127   m_measPhi = ((rawRep >> 15) & oneBit) == 1u;
0128   m_measTime = ((rawRep >> 16) & oneBit) == 1u;
0129   m_layer = ((rawRep >> 17) & fourBit) + 1u;
0130   m_channel = (rawRep >> 21) + 1u;
0131 }
0132 
0133 std::uint32_t MuonSpacePoint::MuonId::toInt() const {
0134   std::uint32_t rawRep{0};
0135   rawRep |= (static_cast<std::uint32_t>(m_stName) & fourBit);
0136   if (m_side == DetSide::A) {
0137     rawRep |= (1u << 4);
0138   }
0139   rawRep |= ((static_cast<std::uint32_t>(m_tech) & threeBit) << 5);
0140   rawRep |= ((static_cast<std::uint32_t>(m_sector - 1u) & sixBit) << 8);
0141   rawRep |= (static_cast<std::uint32_t>(m_measEta) << 14);
0142   rawRep |= (static_cast<std::uint32_t>(m_measPhi) << 15);
0143   rawRep |= (static_cast<std::uint32_t>(m_measTime) << 16);
0144   rawRep |= ((static_cast<std::uint32_t>(m_layer - 1u) & fourBit) << 17);
0145   rawRep |= (static_cast<std::uint32_t>(m_channel - 1u) << 21);
0146   return rawRep;
0147 }
0148 
0149 std::string MuonSpacePoint::MuonId::toString() const {
0150   return std::format("{:} in {:2d} on {:}", toString(msStation()), sector(),
0151                      toString(side()));
0152 }
0153 void MuonSpacePoint::MuonId::setChamber(StationName stName, DetSide side,
0154                                         std::uint16_t sector, TechField tech) {
0155   m_stName = stName;
0156   m_side = side;
0157   m_sector = sector;
0158   m_tech = tech;
0159   assert(sector > 0);
0160 }
0161 void MuonSpacePoint::MuonId::setLayAndCh(std::uint8_t layer, std::uint16_t ch) {
0162   m_layer = layer;
0163   m_channel = ch;
0164   assert(layer > 0);
0165   assert(ch > 0);
0166 }
0167 void MuonSpacePoint::MuonId::setCoordFlags(bool measEta, bool measPhi,
0168                                            bool measTime) {
0169   m_measEta = measEta;
0170   m_measPhi = measPhi;
0171   m_measTime = measTime;
0172 }
0173 void MuonSpacePoint::defineCoordinates(Acts::Vector3&& pos,
0174                                        Acts::Vector3&& sensorDir,
0175                                        Acts::Vector3&& toNextSensor) {
0176   m_pos = std::move(pos);
0177   m_dir = std::move(sensorDir);
0178   m_toNext = std::move(toNextSensor);
0179   m_norm = m_dir.cross(m_toNext).normalized();
0180 }
0181 void MuonSpacePoint::setRadius(const double r) {
0182   m_radius = r;
0183 }
0184 void MuonSpacePoint::setTime(const double t) {
0185   m_time = t;
0186 }
0187 void MuonSpacePoint::setCovariance(const double covX, const double covY,
0188                                    const double covT) {
0189   m_cov[0] = covX;
0190   m_cov[1] = covY;
0191   m_cov[2] = covT;
0192 }
0193 void MuonSpacePoint::setId(const MuonId& id) {
0194   m_id = id;
0195 }
0196 void MuonSpacePoint::setGeometryId(const Acts::GeometryIdentifier& geoId) {
0197   m_geoId = geoId;
0198 }
0199 }  // namespace ActsExamples