ATLAS Offline Software
Loading...
Searching...
No Matches
TgcSensitiveDetector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
6
7#include "G4ThreeVector.hh"
8
10#include <sstream>
11
13#include "GaudiKernel/SystemOfUnits.h"
14#include "GeoModelKernel/throwExcept.h"
15
16using namespace ActsTrk;
17
18// construction/destruction
19namespace MuonG4R4 {
20
21G4bool TgcSensitiveDetector::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
22
23 if (!processStep(aStep)) {
24 return true;
25 }
26
27 const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
28
29 const MuonGMR4::TgcReadoutElement* readOutEle = getReadoutElement(touchHist);
30 if (!readOutEle) {
31 return false;
32 }
34
35 const Amg::Transform3D localToGlobal = getTransform(touchHist, 0);
36 ATH_MSG_VERBOSE(" Track is inside volume "
37 <<touchHist->GetHistory()->GetTopVolume()->GetName()
38 <<" transformation: "<<Amg::toString(localToGlobal));
39
40 const Identifier etaHitID = getIdentifier(gctx, readOutEle, localToGlobal.translation(), false);
41 if (!etaHitID.is_valid()) {
42 ATH_MSG_VERBOSE("No valid hit found");
43 return true;
44 }
46 const Amg::Transform3D toGasGap{readOutEle->globalToLocalTrans(gctx, etaHitID)};
47 propagateAndSaveStrip(etaHitID, toGasGap, aStep);
48 return true;
49}
50const MuonGMR4::TgcReadoutElement* TgcSensitiveDetector::getReadoutElement(const G4TouchableHistory* touchHist) const {
52 const std::string stationVolume = touchHist->GetVolume(2)->GetName();
53 const std::vector<std::string> volumeTokens = CxxUtils::tokenize(stationVolume, "_");
57 const size_t nTokens{volumeTokens.size()};
58 const TgcIdHelper& idHelper{m_detMgr->idHelperSvc()->tgcIdHelper()};
59 const std::string stationName{volumeTokens[nTokens-4].substr(0,3)};
60 const int stationEta = CxxUtils::atoi(volumeTokens[nTokens-2]);
61 const int stationPhi = CxxUtils::atoi(volumeTokens[nTokens-1]);
62 bool isValid{false};
63 const Identifier stationId = idHelper.elementID(stationName, stationEta, stationPhi, isValid);
64 if (!isValid) {
65 THROW_EXCEPTION("Failed to deduce station name from "+stationVolume);
66 }
67 return m_detMgr->getTgcReadoutElement(stationId);
68}
69
71 const MuonGMR4::TgcReadoutElement* readOutEle,
72 const Amg::Vector3D& hitAtGapPlane, bool phiGap) const {
73 const TgcIdHelper& idHelper{m_detMgr->idHelperSvc()->tgcIdHelper()};
74 const Identifier firstChan = idHelper.channelID(readOutEle->identify(), 1, phiGap, 1);
75
76 const Amg::Vector3D locHitPos{readOutEle->globalToLocalTrans(gctx, firstChan) * hitAtGapPlane};
77
78 const int gasGap = std::round(std::abs(locHitPos.z()) / readOutEle->gasGapPitch()) + 1;
79 ATH_MSG_VERBOSE("Detector element: "<<m_detMgr->idHelperSvc()->toStringDetEl(firstChan)
80 <<" locPos: "<<Amg::toString(locHitPos, 2)
81 <<" gap thickness: "<<readOutEle->gasGapPitch()
82 <<" gasGap: "<<gasGap);
83
84 return idHelper.channelID(readOutEle->identify(), gasGap, phiGap, 1);
85}
86
87}
#define ATH_MSG_VERBOSE(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
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::TgcReadoutElement * getReadoutElement(const G4TouchableHistory *touchHist) const
Retrieves the readout element that's associates with the TouchableHistory.
Identifier getIdentifier(const ActsTrk::GeometryContext &gctx, const MuonGMR4::TgcReadoutElement *readOutEle, const Amg::Vector3D &hitAtGapPlane, bool phiGap) const
Constructs the Identifier of the gasGap using the readoutElement and the hit expressed in it's local ...
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override final
Identifier identify() const override final
Return the athena identifier.
Amg::Transform3D globalToLocalTrans(const ActsTrk::GeometryContext &ctx) const
Transformations to translate between local <-> global coordinates.
double gasGapPitch() const
Returns the thickness of the gasGap.
Identifier elementID(int stationName, int stationEta, int stationPhi) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int gasGap, int isStrip, int channel) const
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
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.
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10