ATLAS Offline Software
sTgcSensitiveDetector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include "G4ThreeVector.hh"
9 
10 #include "MCTruth/TrackHelper.h"
11 #include <sstream>
12 
14 #include "GaudiKernel/SystemOfUnits.h"
15 #include "GeoModelKernel/throwExcept.h"
16 
17 
18 using namespace MuonGMR4;
19 using namespace CxxUtils;
20 
21 namespace {
22  constexpr double tolerance = 10. * Gaudi::Units::micrometer;
23 }
24 
25 // construction/destruction
26 namespace MuonG4R4 {
27 
28 
29 G4bool sTgcSensitiveDetector::ProcessHits(G4Step* aStep,G4TouchableHistory*) {
30  if (!processStep(aStep)) {
31  return false;
32  }
33 
34  const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
35 
36  const ActsGeometryContext gctx{getGeoContext()};
37 
38  const MuonGMR4::sTgcReadoutElement* readOutEle = getReadoutElement(gctx, touchHist);
39 
40  const Amg::Transform3D localToGlobal = getTransform(touchHist, 0);
41  ATH_MSG_VERBOSE(" Track is inside volume "
42  <<touchHist->GetHistory()->GetTopVolume()->GetName()
43  <<" transformation: "<<Amg::toString(localToGlobal));
44 
45  const Identifier etaHitID = getIdentifier(gctx, readOutEle, localToGlobal.translation(),
46  sTgcIdHelper::sTgcChannelTypes::Strip);
47  if (!etaHitID.is_valid()) {
48  ATH_MSG_VERBOSE("No valid hit found");
49  return true;
50  }
52  const Amg::Transform3D toGasGap{readOutEle->globalToLocalTrans(gctx, etaHitID)};
53  propagateAndSaveStrip(etaHitID, toGasGap, aStep);
54  return true;
55 }
56 
57 Identifier sTgcSensitiveDetector::getIdentifier(const ActsGeometryContext& gctx,
58  const MuonGMR4::sTgcReadoutElement* readOutEle,
59  const Amg::Vector3D& hitAtGapPlane,
61 
62  const sTgcIdHelper& idHelper{m_detMgr->idHelperSvc()->stgcIdHelper()};
63  const Identifier firstChan = idHelper.channelID(readOutEle->identify(),
64  readOutEle->multilayer(), 1, chType, 1);
65 
66  const Amg::Vector3D locHitPos{readOutEle->globalToLocalTrans(gctx, firstChan) * hitAtGapPlane};
67  ATH_MSG_VERBOSE("Detector element: "<<m_detMgr->idHelperSvc()->toStringDetEl(firstChan)
68  <<" locPos: "<<Amg::toString(locHitPos, 2)
69  <<" gap thickness "<<readOutEle->gasGapPitch()
70  <<" gasGap: "<< (std::abs(locHitPos.z()) / readOutEle->gasGapPitch()) + 1);
71 
72  const int gasGap = std::round(std::abs(locHitPos.z()) / readOutEle->gasGapPitch()) + 1;
73  return idHelper.channelID(readOutEle->identify(),readOutEle->multilayer(), gasGap, chType, 1);
74 }
75 const MuonGMR4::sTgcReadoutElement* sTgcSensitiveDetector::getReadoutElement(const ActsGeometryContext& gctx,
76  const G4TouchableHistory* touchHist) const {
77 
78 
80  const std::string& stationVolume = touchHist->GetVolume(3)->GetName();
82  const std::vector<std::string> volumeTokens = tokenize(stationVolume.substr(stationVolume.rfind("Q")), "_");
83  ATH_MSG_VERBOSE("Name of the station volume is "<<volumeTokens);
84  if (volumeTokens.size() != 4) {
85  THROW_EXCEPTION("Cannot deduce the station name from "<<stationVolume);
86  }
88  const std::string stName = volumeTokens[0][1] == 'S' ? "STS" : "STL";
89  const int stationEta = atoi(volumeTokens[2]);
90  const int stationPhi = atoi(volumeTokens[3]);
91 
92  const sTgcIdHelper& idHelper{m_detMgr->idHelperSvc()->stgcIdHelper()};
93  const Identifier detElIdMl1 = idHelper.channelID(idHelper.stationNameIndex(stName), stationEta, stationPhi, 1, 1,
94  sTgcIdHelper::sTgcChannelTypes::Strip, 1);
95  const Identifier detElIdMl2 = idHelper.multilayerID(detElIdMl1, 2);
96  const sTgcReadoutElement* readOutElemMl1 = m_detMgr->getsTgcReadoutElement(detElIdMl1);
97  const sTgcReadoutElement* readOutElemMl2 = m_detMgr->getsTgcReadoutElement(detElIdMl2);
98  if (!readOutElemMl1 || !readOutElemMl2) {
99  THROW_EXCEPTION("Failed to retrieve a valid detector element from "
100  <<m_detMgr->idHelperSvc()->toStringDetEl(detElIdMl1)<<" "<<stationVolume);
101  }
103  const Amg::Vector3D transformCenter = getTransform(touchHist, 0).translation();
106  const Amg::Vector3D centerMl2 = readOutElemMl2->center(gctx, detElIdMl2);
107  return std::abs(centerMl2.z()) - tolerance <= std::abs(transformCenter.z()) ? readOutElemMl2 : readOutElemMl1;
108 }
109 }
MuonGMR4::sTgcReadoutElement::multilayer
int multilayer() const
Returns the multilayer of the sTgcReadoutElement.
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
CxxUtils::tokenize
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
Definition: Control/CxxUtils/Root/StringUtils.cxx:15
TrackHelper.h
MuonGMR4::sTgcReadoutElement::gasGapPitch
double gasGapPitch() const
Distance between 2 gas gaps.
Muon::MuonStationIndex::stName
const std::string & stName(StIndex index)
convert StIndex into a string
Definition: MuonStationIndex.cxx:104
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
MuonGMR4::MuonReadoutElement::globalToLocalTrans
Amg::Transform3D globalToLocalTrans(const ActsGeometryContext &ctx) const
Transformations to translate between local <-> global coordinates.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:78
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
sTgcIdHelper::sTgcChannelTypes
sTgcChannelTypes
Definition: sTgcIdHelper.h:190
MuonG4R4
Include the common definitions from the MuonReadoutGeometry.
Definition: MuonSpectrometer/MuonPhaseII/MuonG4/MuonSensitiveDetectorsR4/MuonSensitiveDetectorsR4/Utils.h:14
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
MuonGMR4
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
Definition: MdtCalibInput.h:19
POOLtoEI_tf.getTransform
def getTransform()
Definition: POOLtoEI_tf.py:103
python.SystemOfUnits.micrometer
float micrometer
Definition: SystemOfUnits.py:80
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
CxxUtils
Definition: aligned_vector.h:29
MuonGMR4::MuonReadoutElement::center
Amg::Vector3D center(const ActsGeometryContext &ctx) const
Returns the detector center (Which is the same as the detector center of the first measurement layer)
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
CLHEPtoEigenConverter.h
tolerance
Definition: suep_shower.h:17
Utils.h
sTgcIdHelper
Definition: sTgcIdHelper.h:55
MuonGMR4::MuonReadoutElement::identify
Identifier identify() const override final
Return the athena identifier.
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
THROW_EXCEPTION
#define THROW_EXCEPTION(MESSAGE)
Definition: throwExcept.h:10
MuonGMR4::sTgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/sTgcReadoutElement.h:20
sTgcSensitiveDetector.h
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
Identifier
Definition: IdentifierFieldParser.cxx:14