ATLAS Offline Software
Loading...
Searching...
No Matches
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
18using namespace MuonGMR4;
19using namespace CxxUtils;
20
21namespace {
22 constexpr double tolerance = 10. * Gaudi::Units::micrometer;
23}
24
25// construction/destruction
26namespace MuonG4R4 {
27
28
29G4bool 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
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(),
47 if (!etaHitID.is_valid()) {
48 ATH_MSG_VERBOSE("No valid hit found");
49 return true;
50 }
52 const Amg::Transform3D toGasGap{readOutEle->globalToLocalTransform(gctx, etaHitID)};
53 propagateAndSaveStrip(etaHitID, toGasGap, aStep);
54 return true;
55}
56
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->globalToLocalTransform(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}
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,
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}
#define ATH_MSG_VERBOSE(x)
bool is_valid() const
Check if id is in a valid state.
const MuonGMR4::MuonDetectorManager * m_detMgr
Pointer to the underlying detector manager.
xAOD::MuonSimHit * propagateAndSaveStrip(const Identifier &hitId, const Amg::Transform3D &toGasGap, const G4Step *hitStep)
bool processStep(const G4Step *step) const
Checks whether the current step shall be processed at all.
ActsTrk::GeometryContext getGeoContext() const
Returns the current geometry context in the event.
const MuonGMR4::sTgcReadoutElement * getReadoutElement(const ActsTrk::GeometryContext &gctx, const G4TouchableHistory *touchHist) const
Retrieves the matching readout element to a G4 hit.
Identifier getIdentifier(const ActsTrk::GeometryContext &gctx, const MuonGMR4::sTgcReadoutElement *readOutEle, const Amg::Vector3D &hitAtGapPlane, sTgcIdHelper::sTgcChannelTypes chType) const
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override final
member functions
Amg::Transform3D globalToLocalTransform(const ActsTrk::GeometryContext &ctx) const
Returns the transformation from the global ATLAS coordinate system into the local coordinate system o...
Amg::Vector3D center(const ActsTrk::GeometryContext &ctx) const
Returns the geometrical center point of the readout element.
Identifier identify() const override final
Return the ATLAS identifier.
int multilayer() const
Returns the multilayer of the sTgcReadoutElement.
double gasGapPitch() const
Distance between 2 gas gaps.
int stationNameIndex(const std::string &name) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType, int channel) const
Identifier multilayerID(const Identifier &channeldID) const
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
std::vector< std::string > tokenize(const std::string &the_str, std::string_view delimiters)
Splits the string into smaller substrings.
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Include the common definitions from the MuonReadoutGeometry.
Amg::Transform3D getTransform(const G4VTouchable *history, unsigned int level)
Extracts the local -> global transformation from a TouchableHistory at a given level.
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10