ATLAS Offline Software
TgcSensitiveDetector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "TgcSensitiveDetector.h"
6 
7 #include "G4ThreeVector.hh"
8 
9 #include "MCTruth/TrackHelper.h"
10 #include <sstream>
11 
13 #include "GaudiKernel/SystemOfUnits.h"
14 #include "GeoModelKernel/throwExcept.h"
15 
16 using namespace ActsTrk;
17 
18 // construction/destruction
19 namespace MuonG4R4 {
20 
21 G4bool 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  }
33  const ActsGeometryContext gctx{getGeoContext()};
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 }
50 const 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 
70 Identifier TgcSensitiveDetector::getIdentifier(const ActsGeometryContext& gctx,
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 }
dumpTgcDigiDeadChambers.gasGap
list gasGap
Definition: dumpTgcDigiDeadChambers.py:33
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
TgcIdHelper
Definition: TgcIdHelper.h:50
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
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
isValid
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition: AtlasPID.h:867
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
POOLtoEI_tf.getTransform
def getTransform()
Definition: POOLtoEI_tf.py:103
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonGMR4::TgcReadoutElement::gasGapPitch
double gasGapPitch() const
Returns the thickness of the gasGap.
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
CLHEPtoEigenConverter.h
Utils.h
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
TgcSensitiveDetector.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
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MSTrackingVolumeBuilder.cxx:24
MuonGMR4::TgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:19
Identifier
Definition: IdentifierFieldParser.cxx:14