10#include <GeoModelKernel/throwExcept.h>
13#include <G4Geantino.hh>
14#include <G4ChargedGeantino.hh>
28 const std::string& output_key,
29 const std::string& trfStore_key,
31 G4VSensitiveDetector{name},
67 gctx.
setStore(std::make_unique<DetectorAlignStore>(*alignment));
71 const G4Track* currentTrack = aStep->GetTrack();
72 ATH_MSG_VERBOSE(
"Check whether step pdgId: "<<(*currentTrack)<<
" will be processed.");
74 constexpr double velCutOff = 10.*Gaudi::Units::micrometer / Gaudi::Units::second;
75 if (aStep->GetStepLength() < std::numeric_limits<float>::epsilon() || currentTrack->GetVelocity() < velCutOff) {
80 if (currentTrack->GetDefinition()->GetPDGCharge() == 0.0) {
82 return currentTrack->GetDefinition() == G4Geantino::GeantinoDefinition() ||
83 currentTrack->GetDefinition() == G4ChargedGeantino::ChargedGeantinoDefinition();
94 const G4Step* aStep) {
96 const G4Track* currentTrack = aStep->GetTrack();
107 if (std::abs(currentTrack->GetParticleDefinition()->GetPDGEncoding()) == 11 && prevHit) {
111 locHitDir = (locPostStep - locPreStep).
unit();
113 const Amg::Vector3D locHitPos = 0.5* (locPreStep + locPostStep);
115 <<
", deposit: "<<aStep->GetTotalEnergyDeposit()<<
", -- local coords: "
118 <<
", deposit: "<<aStep->GetTotalEnergyDeposit());
120 const double globalTime = currentTrack->GetGlobalTime() + locHitDir.dot(locPostStep - locHitPos) / currentTrack->GetVelocity();
131 const double globTime,
132 const G4Step* aStep) {
133 const G4Track* currentTrack = aStep->GetTrack();
142 hit =
m_outContainer->push_back(std::make_unique<xAOD::MuonSimHit>());
145 dec_G4TrkId(*hit) = currentTrack->GetTrackID();
149 hit->
setMass(currentTrack->GetDefinition()->GetPDGMass());
151 hit->
setPdgId(currentTrack->GetDefinition()->GetPDGEncoding());
158 <<
", pdgId: "<<hit->
pdgId()
160 <<
", trackId: "<<currentTrack->GetTrackID()<<
", "
161 <<
", "<<particleLink.
cptr()<<std::endl
168 const G4Step* hitStep) {
173 const G4Step* hitStep,
180 dec_G4TrkId(*
m_outContainer->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)
Utility helpers used by Run-4 muon sensitive detector implementations.
void setStore(AlignmentStorePtr store)
Adds the store to the Geometry context.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
This class is attached to G4Event objects as UserInformation.
static AtlasG4EventUserInfo * GetEventUserInfo()
IProxyDict * GetEventStore()
const EventContext & GetEventContext() const
const T * get(size_type n) const
Access an element, as an rvalue.
a link optimized in size for a GenParticle in a McEventCollection
HepMC::ConstGenParticlePtr cptr() const
Dereference.
const MuonGMR4::MuonDetectorManager * m_detMgr
Pointer to the underlying detector manager.
AtlasG4EventUserInfo * eventInfo() const
Returns the event user info for the current G4 event, if available.
const EventContext & eventContext() const
Returns the current event context recorded in the G4 event info.
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...
HepMcParticleLink genParticleLink(const G4Track *track) const
Generates a HepMcParticleLink for the Geant4 track using the current event store.
xAOD::MuonSimHit * propagateAndSaveStrip(const Identifier &hitId, const Amg::Transform3D &toGasGap, const G4Step *hitStep)
Records the G4Step in the sim hit.
bool processStep(const G4Step *step) const
Checks whether the current step shall be processed at all.
AtlasG4EventUserInfo * m_g4UserEventInfo
G4 event user information holding the current event store/context.
std::string m_writeKey
Key under which the output container is stored in the G4 event.
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::MuonSimHitContainer * m_outContainer
Pointer to the MuonSimHit output container.
xAOD::MuonSimHit * lastSnapShot(const Identifier &gasGapId, const G4Step *hitStep, const HepMcParticleLink &particleLink)
Returns the last snap shot matching an already generated HepMcParticleLink.
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.
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.
AthHitVec::AuxStoreHitCollection< xAOD::MuonSimHitContainer, xAOD::MuonSimHitAuxContainer > MuonSimHitsVec
Helper type which can be filled into the HitCollectionMap storing the event content in the event.
SG::Decorator< T, ALLOC > Decorator
Helper class to provide type-safe access to aux data, specialized for JaggedVecElt.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
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)