15#include <GeoModelKernel/throwExcept.h>
16#include <GaudiKernel/SystemOfUnits.h>
26 const std::string stationVolume = touchHist->GetVolume(2)->GetName();
28 const std::vector<std::string> volumeTokens =
tokenize(stationVolume,
"_");
30 if (volumeTokens.size() != 5) {
31 THROW_EXCEPTION(
" Cannot deduce the station name from "<<stationVolume);
34 const std::string stName = volumeTokens[0].substr(0,3);
35 const int stationEta =
atoi(volumeTokens[2]);
36 const int stationPhi =
atoi(volumeTokens[3]);
37 const int multiLayer =
atoi(volumeTokens[4]);
45 <<
m_detMgr->idHelperSvc()->toStringDetEl(detElId)<<
" "<<stationVolume);
56 G4Track* currentTrack = aStep->GetTrack();
57 const G4StepPoint* preStep = aStep->GetPreStepPoint();
58 const G4TouchableHistory* touchHist =
static_cast<const G4TouchableHistory*
>(preStep->GetTouchable());
65 if (!
HitID.is_valid()) {
79 const Amg::Vector3D trackLocDir{globalToLocal.linear()* trackDirection};
85 trackLocPos, trackLocDir).value_or(0);
86 if (std::abs(currentTrack->GetDefinition()->GetPDGEncoding()) == 11) {
87 lambda = std::clamp(lambda, 0., aStep->GetStepLength());
90 const Amg::Vector3D driftHit{trackLocPos + lambda * trackLocDir};
93 const double globalTime{preStep->GetGlobalTime() + lambda / currentTrack->GetVelocity()};
95 if (std::abs(currentTrack->GetDefinition()->GetPDGEncoding()) == 11) {
97 if (lastRecord && lastRecord->
localPosition().perp() < driftHit.perp()) {
106 <<
", "<<(*currentTrack) <<
", driftCircle: "<<
Amg::toString(driftHit, 4)
107 <<
", direction "<<
Amg::toString(trackLocDir, 4) <<
" to SimHit container ahead. ");
108 saveHit(
HitID, driftHit, trackLocDir, globalTime, aStep);
113 const G4TouchableHistory* touchHist)
const {
120 static const double layerPitch = 1./ std::sin(60*Gaudi::Units::deg);
121 const int layer = std::round(refTubePos.x() * layerPitch / readOutEle->
tubePitch()) +1;
123 THROW_EXCEPTION(
"Tube hit in nirvana -- It seems that the tube position "
124 <<
Amg::toString(refTubePos, 2)<<
", perp: "<<refTubePos.perp()
125 <<
" is outside of the volume envelope "
130 const double tubePitches = refTubePos.y() / readOutEle->
tubePitch();
131 unsigned int tube = std::round(tubePitches) + 1;
132 tube = std::max(1u, std::min(readOutEle->
numTubesInLay(), tube));
139 if (closureCheck.translation().y() > 0) ++tube;
148 THROW_EXCEPTION(
"Tube hit in Nirvana -- It seems that the tube position "
149 <<
Amg::toString(refTubePos, 2)<<
", perp: "<<refTubePos.perp()
150 <<
" is outside of the volume envelope "
152 <<
"Layer: "<<layer<<
", tube: "<<tube<<
" "
154 <<
"tube volume : "<<touchHist->GetVolume(0)->GetName()
155 <<
" mdt chamber: "<<touchHist->GetVolume(2)->GetName());
158 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)
Handle class for reading from StoreGate.
int barcode() const
Return the barcode of the target particle.
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
Retrieves from the Readoutelement & the touchable history the Identifier.
const MuonGMR4::MdtReadoutElement * getReadoutElement(const G4TouchableHistory *touchHist) const
Retrieves the matching readout element to a G4 hit.
const MuonGMR4::MuonDetectorManager * m_detMgr
Pointer to the underlying detector manager.
xAOD::MuonSimHit * lastSnapShot(const Identifier &gasGapId, const G4Step *hitStep)
Returns the last snap shot of the traversing particle.
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.
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.
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
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(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...
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
#define THROW_EXCEPTION(MESSAGE)