10#include <GeoModelKernel/throwExcept.h>
14#include <G4Geantino.hh>
15#include <G4ChargedGeantino.hh>
27 const std::string& output_key,
28 const std::string& trfStore_key,
30 G4VSensitiveDetector{name},
42 if (!
m_writeHandle.recordNonConst(std::make_unique<xAOD::MuonSimHitContainer>(),
43 std::make_unique<xAOD::MuonSimHitAuxContainer>()).isSuccess()) {
51 if (!trfStoreHandle.
isValid()) {
54 gctx.
setStore(std::make_unique<DetectorAlignStore>(*trfStoreHandle));
58 const G4Track* currentTrack = aStep->GetTrack();
59 ATH_MSG_VERBOSE(
"Check whether step pdgId: "<<(*currentTrack)<<
" will be processed.");
61 constexpr double velCutOff = 10.*Gaudi::Units::micrometer / Gaudi::Units::second;
62 if (aStep->GetStepLength() < std::numeric_limits<float>::epsilon() || currentTrack->GetVelocity() < velCutOff) {
67 if (currentTrack->GetDefinition()->GetPDGCharge() == 0.0) {
69 return currentTrack->GetDefinition() == G4Geantino::GeantinoDefinition() ||
70 currentTrack->GetDefinition() == G4ChargedGeantino::ChargedGeantinoDefinition();
76 const G4Step* aStep) {
78 const G4Track* currentTrack = aStep->GetTrack();
89 if (std::abs(currentTrack->GetParticleDefinition()->GetPDGEncoding()) == 11 && prevHit) {
93 locHitDir = (locPostStep - locPreStep).
unit();
95 const Amg::Vector3D locHitPos = 0.5* (locPreStep + locPostStep);
97 <<
", deposit: "<<aStep->GetTotalEnergyDeposit()<<
", -- local coords: "
100 <<
", deposit: "<<aStep->GetTotalEnergyDeposit());
102 const double globalTime = currentTrack->GetGlobalTime() + locHitDir.dot(locPostStep - locHitPos) / currentTrack->GetVelocity();
113 const double globTime,
114 const G4Step* aStep) {
115 const G4Track* currentTrack = aStep->GetTrack();
121 hit =
m_writeHandle->push_back(std::make_unique<xAOD::MuonSimHit>());
124 dec_G4TrkId(*hit) = currentTrack->GetTrackID();
128 hit->
setMass(currentTrack->GetDefinition()->GetPDGMass());
130 hit->
setPdgId(currentTrack->GetDefinition()->GetPDGEncoding());
137 <<
", pdgId: "<<hit->
pdgId()
139 <<
", trackId: "<<currentTrack->GetTrackID()<<
", "
147 const G4Step* hitStep) {
154 dec_G4TrkId(*
m_writeHandle->back()) != hitStep->GetTrack()->GetTrackID()) {
Scalar mag() const
mag method
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
#define ATH_MSG_VERBOSE(x)
void setStore(AlignmentStorePtr store)
Adds the store to the Geometry context.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
HepMC::ConstGenParticlePtr cptr() const
Dereference.
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.
SG::WriteHandle< xAOD::MuonSimHitContainer > m_writeHandle
virtual void Initialize(G4HCofThisEvent *HCE) override final
Create the output container at the beginning of the event.
MuonSensitiveDetector(const std::string &name, const std::string &output_key, const std::string &trf_storeKey, const MuonGMR4::MuonDetectorManager *detMgr)
Constructor.
SG::ReadHandleKey< ActsTrk::DetectorAlignStore > m_trfCacheKey
ReadHandleKey to the DetectorAlignmentStore caching the relevant transformations needed in this event...
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.
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.
Helper class to provide type-safe access to aux data.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
void setGenParticleLink(const HepMcParticleLink &link)
Sets the link to the HepMC particle producing this hit.
void setGlobalTime(const float time)
Sets the time of the traversing particle.
void setLocalDirection(MeasVector< 3 > vec)
Sets the local direction of the traversing particle.
void setEnergyDeposit(const float deposit)
Sets the energy deposited by the traversing particle inside the gas volume.
void setMass(const float m)
set the rest-mass of the traversing particle
ConstVectorMap< 3 > localDirection() const
Returns the local direction of the traversing particle.
int pdgId() const
Returns the pdgID of the traversing particle.
void setIdentifier(const Identifier &id)
Sets the global ATLAS identifier.
float stepLength() const
Returns the path length of the G4 step.
void setStepLength(const float length)
Set the path length of the G4 step.
float energyDeposit() const
Returns the energy deposited by the traversing particle inside the gas volume.
ConstVectorMap< 3 > localPosition() const
Returns the local postion of the traversing particle.
void setKineticEnergy(const float energy)
Sets the kinetic energy of the traversing particle.
const HepMcParticleLink & genParticleLink() const
Returns the link to the HepMC particle producing this hit.
void setLocalPosition(MeasVector< 3 > vec)
Sets the local position of the traversing particle.
void setPdgId(int id)
Sets the pdgID of the traversing particle.
float kineticEnergy() const
Returns the kinetic energy of the traversing particle.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
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
Include the common definitions from the MuonReadoutGeometry.
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
MeasVector< N > toStorage(const AmgVector(N)&amgVec)
Converts the double precision of the AmgVector into the floating point storage precision of the MeasV...
#define THROW_EXCEPTION(MESSAGE)