10#include "GeoModelKernel/throwExcept.h"
14#include "G4Geantino.hh"
15#include "G4ChargedGeantino.hh"
30 const std::string& output_key,
31 const std::string& trfStore_key,
33 G4VSensitiveDetector{name},
69 gctx.
setStore(std::make_unique<DetectorAlignStore>(*alignment));
73 const G4Track* currentTrack = aStep->GetTrack();
74 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Check whether step pdgId: "<<(*currentTrack)<<
" will be processed.");
76 constexpr double velCutOff = 10.*Gaudi::Units::micrometer / Gaudi::Units::second;
77 if (aStep->GetStepLength() < std::numeric_limits<float>::epsilon() || currentTrack->GetVelocity() < velCutOff) {
78 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Step length is too short ");
82 if (currentTrack->GetDefinition()->GetPDGCharge() == 0.0) {
84 return currentTrack->GetDefinition() == G4Geantino::GeantinoDefinition() ||
85 currentTrack->GetDefinition() == G4ChargedGeantino::ChargedGeantinoDefinition();
95 const Acts::Transform3& toGasGap,
96 const G4Step* aStep) {
98 const G4Track* currentTrack = aStep->GetTrack();
109 if (
MC::isElectron(currentTrack->GetParticleDefinition()->GetPDGEncoding()) && prevHit) {
113 locHitDir = (locPostStep - locPreStep).
unit();
115 const Amg::Vector3D locHitPos = 0.5* (locPreStep + locPostStep);
117 <<
" - track: "<<(*currentTrack) <<
", deposit: "<<aStep->GetTotalEnergyDeposit()
118 <<
", -- local coords -- prestep: "<<
Amg::toString(locPreStep)
121 <<
", deposit: "<<aStep->GetTotalEnergyDeposit());
123 const double globalTime = currentTrack->GetGlobalTime() + locHitDir.dot(locPostStep - locHitPos) / currentTrack->GetVelocity();
126 if (newHit && prevHit) {
134 const double globTime,
135 const G4Step* aStep) {
136 const G4Track* currentTrack = aStep->GetTrack();
148 dec_G4TrkId(*
hit) = currentTrack->GetTrackID();
149 hit->setIdentifier(hitId);
152 hit->setMass(currentTrack->GetDefinition()->GetPDGMass());
153 hit->setGlobalTime(globTime);
154 int pdgId = currentTrack->GetDefinition()->GetPDGEncoding();
157 if (currentTrack->GetDefinition() == G4ChargedGeantino::ChargedGeantinoDefinition()){
158 pdgId = std::copysign(
MC::GEANTINOPLUS, currentTrack->GetDynamicParticle()->GetCharge());
159 }
else if (currentTrack->GetDefinition() == G4Geantino::GeantinoDefinition()) {
162 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - The track has an undefined pdgId "<<aStep);
167 hit->setPdgId(pdgId);
168 hit->setEnergyDeposit(aStep->GetTotalEnergyDeposit() + (newHit ? 0. :
hit->energyDeposit()));
169 hit->setKineticEnergy(currentTrack->GetKineticEnergy());
170 hit->setGenParticleLink(particleLink);
171 hit->setStepLength(aStep->GetStepLength());
174 <<
", pdgId: "<<
hit->pdgId()<<
", "<<particleLink
175 <<
", trackId: "<<currentTrack->GetTrackID()
176 <<
", "<<particleLink.
cptr()<<std::endl
178 <<
", energy: "<<
hit->kineticEnergy()<<
", stepLength: "<<
hit->stepLength()<<
", "
179 <<
", deposit energy: "<<
hit->energyDeposit());
183 const G4Step* hitStep) {
188 const G4Step* hitStep,
195 dec_G4TrkId(*
m_outContainer->back()) != hitStep->GetTrack()->GetTrackID()) {
Scalar mag() const
mag method
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
detray::unit< scalar_t > unit
ATLAS-specific HepMC functions.
Utility helpers used by Run-4 muon sensitive detector implementations.
Handle class for reading from StoreGate.
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
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.
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.
xAOD::MuonSimHit * propagateAndSaveStrip(const Identifier &hitId, const Acts::Transform3 &toGasGap, const G4Step *hitStep)
Records the G4Step in the sim hit.
HepMcParticleLink GenerateParticleLink()
Generates a new HepMcParticleLink object on the stack based on the generation-zero unique id,...
ConstVectorMap< 3 > localDirection() const
Returns the local direction of the traversing particle.
float stepLength() const
Returns the path length of the G4 step.
void setStepLength(const float length)
Set the path length of the G4 step.
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::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::Matrix< double, 3, 1 > Vector3D
static const int GEANTINOPLUS
PDG rule 10: Codes 81–100 are reserved for generator-specific pseudoparticles and concepts.
bool isElectron(const T &p)
static const int GEANTINO0
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)