14#include <GeoModelKernel/throwExcept.h>
15#include <GaudiKernel/SystemOfUnits.h>
24 const std::string stationVolume = touchHist->GetVolume(2)->GetName();
26 const std::vector<std::string> volumeTokens =
tokenize(stationVolume,
"_");
28 if (volumeTokens.size() != 5) {
29 THROW_EXCEPTION(
" Cannot deduce the station name from "<<stationVolume);
32 const std::string stName = volumeTokens[0].substr(0,3);
33 const int stationEta =
atoi(volumeTokens[2]);
34 const int stationPhi =
atoi(volumeTokens[3]);
35 const int multiLayer =
atoi(volumeTokens[4]);
43 <<
m_detMgr->idHelperSvc()->toStringDetEl(detElId)<<
" "<<stationVolume);
54 G4Track* currentTrack = aStep->GetTrack();
55 const G4StepPoint* preStep = aStep->GetPreStepPoint();
56 const G4TouchableHistory* touchHist =
static_cast<const G4TouchableHistory*
>(preStep->GetTouchable());
62 if (!
HitID.is_valid()) {
76 const Amg::Vector3D trackLocDir{globalToLocal.linear()* trackDirection};
82 trackLocPos, trackLocDir).value_or(0);
83 if (std::abs(currentTrack->GetDefinition()->GetPDGEncoding()) == 11) {
84 lambda = std::clamp(lambda, 0., aStep->GetStepLength());
87 const Amg::Vector3D driftHit{trackLocPos + lambda * trackLocDir};
90 const double globalTime{preStep->GetGlobalTime() + lambda / currentTrack->GetVelocity()};
92 if (std::abs(currentTrack->GetDefinition()->GetPDGEncoding()) == 11) {
94 if (lastRecord && lastRecord->
localPosition().perp() < driftHit.perp()) {
101 <<
", "<<(*currentTrack) <<
", driftCircle: "<<
Amg::toString(driftHit, 4)
102 <<
", direction "<<
Amg::toString(trackLocDir, 4) <<
" to SimHit container ahead. ");
103 saveHit(
HitID, driftHit, trackLocDir, globalTime, aStep);
108 const G4TouchableHistory* touchHist)
const {
115 static const double layerPitch = 1./ std::sin(60*Gaudi::Units::deg);
116 const int layer = std::round(refTubePos.x() * layerPitch / readOutEle->
tubePitch()) +1;
118 THROW_EXCEPTION(
"Tube hit in nirvana -- It seems that the tube position "
119 <<
Amg::toString(refTubePos, 2)<<
", perp: "<<refTubePos.perp()
120 <<
" is outside of the volume envelope "
125 const double tubePitches = refTubePos.y() / readOutEle->
tubePitch();
126 unsigned int tube = std::round(tubePitches) + 1;
127 tube = std::max(1u, std::min(readOutEle->
numTubesInLay(), tube));
134 if (closureCheck.translation().y() > 0) ++tube;
143 THROW_EXCEPTION(
"Tube hit in Nirvana -- It seems that the tube position "
144 <<
Amg::toString(refTubePos, 2)<<
", perp: "<<refTubePos.perp()
145 <<
" is outside of the volume envelope "
147 <<
"Layer: "<<layer<<
", tube: "<<tube<<
" "
149 <<
"tube volume : "<<touchHist->GetVolume(0)->GetName()
150 <<
" mdt chamber: "<<touchHist->GetVolume(2)->GetName());
153 ATH_MSG_VERBOSE(
"Tube & layer number candidate "<<tube<<
", "<<layer<<
" back and forth transformation "
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Utility helpers used by Run-4 muon sensitive detector implementations.
This is a "hash" representation of an Identifier.
Identifier multilayerID(const Identifier &channeldID) const
Identifier elementID(int stationName, int stationEta, int stationPhi) const
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override final
Identifier getIdentifier(const ActsTrk::GeometryContext &gctx, const MuonGMR4::MdtReadoutElement *reElement, const G4TouchableHistory *touchHist) const
Constructs the identifier of the actual tube where the energy deposit is taking place.
const MuonGMR4::MdtReadoutElement * getReadoutElement(const G4TouchableHistory *touchHist) const
Retrieves the MuonReadoutElement associated to the multilayer in which the energy deposit is taking p...
const MuonGMR4::MuonDetectorManager * m_detMgr
Pointer to the underlying detector manager.
HepMcParticleLink genParticleLink(const G4Track *track) const
Generates a HepMcParticleLink for the Geant4 track using the current event store.
bool processStep(const G4Step *step) const
Checks whether the current step shall be processed at all.
xAOD::MuonSimHit * saveHit(const Identifier &hitId, const Amg::Vector3D &hitPos, const Amg::Vector3D &hitDir, const double globTime, const G4Step *hitStep)
Saves the current Step as a xAOD::MuonSimHit snapshot.
ActsTrk::GeometryContext getGeoContext() const
Returns the current geometry context in the event.
xAOD::MuonSimHit * lastSnapShot(const Identifier &gasGapId, const G4Step *hitStep, const HepMcParticleLink &particleLink)
Returns the last snap shot matching an already generated HepMcParticleLink.
Readout element to describe the Monitored Drift Tube (Mdt) chambers Mdt chambers usually comrpise out...
unsigned numTubesInLay() const
Returns the number of tubes in a layer.
static IdentifierHash measurementHash(unsigned layerNumber, unsigned tubeNumber)
Constructs a Measurement hash from layer && tube number.
Identifier measurementId(const IdentifierHash &measHash) const override final
Back conversion of the measurement hash towards a full identifier Tube & layer number are extracted f...
double tubePitch() const
Returns the pitch between 2 tubes in a layer.
Amg::Transform3D globalToLocalTransform(const ActsTrk::GeometryContext &ctx) const
Returns the transformation from the global ATLAS coordinate system into the local coordinate system o...
Identifier identify() const override final
Return the ATLAS identifier.
ConstVectorMap< 3 > localPosition() const
Returns the local postion of the traversing particle.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the point B' along the line B that's closest to a second line A.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
bool isIdentity(const Amg::Transform3D &trans)
Checks whether the transformation is the Identity transformation.
Amg::Vector3D Hep3VectorToEigen(const CLHEP::Hep3Vector &CLHEPvector)
Converts a CLHEP-based CLHEP::Hep3Vector into an Eigen-based Amg::Vector3D.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
std::vector< std::string > tokenize(std::string_view 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...
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
#define THROW_EXCEPTION(MESSAGE)