ATLAS Offline Software
Loading...
Searching...
No Matches
MuonG4R4::MdtSensitiveDetector Class Reference

#include <MdtSensitiveDetector.h>

Inheritance diagram for MuonG4R4::MdtSensitiveDetector:
Collaboration diagram for MuonG4R4::MdtSensitiveDetector:

Public Member Functions

 ~MdtSensitiveDetector ()=default
 Default destructor.
virtual G4bool ProcessHits (G4Step *aStep, G4TouchableHistory *ROhist) override final
 MuonSensitiveDetector (const std::string &name, const std::string &output_key, const std::string &trf_storeKey, const MuonGMR4::MuonDetectorManager *detMgr)
 Recylce the constructor from the MuonSensitiveDetector.
virtual void Initialize (G4HCofThisEvent *HCE) override final
 Create the output container at the beginning of the event.
bool msgLvl (const MSG::Level lvl) const
 Test the output level.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.
void setLevel (MSG::Level lvl)
 Change the current logging level.

Protected Member Functions

xAOD::MuonSimHitlastSnapShot (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.
const EventContext & eventContext () const
 Returns the current event context recorded in the G4 event info.
ActsTrk::GeometryContext getGeoContext () const
 Returns the current geometry context in the event.
HepMcParticleLink genParticleLink (const G4Track *track) const
 Generates a HepMcParticleLink for the Geant4 track using the current event store.
xAOD::MuonSimHitpropagateAndSaveStrip (const Identifier &hitId, const Amg::Transform3D &toGasGap, const G4Step *hitStep)
 Records the G4Step in the sim hit.
xAOD::MuonSimHitsaveHit (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.

Protected Attributes

const MuonGMR4::MuonDetectorManagerm_detMgr {nullptr}
 Pointer to the underlying detector manager.

Private Member Functions

const MuonGMR4::MdtReadoutElementgetReadoutElement (const G4TouchableHistory *touchHist) const
 Retrieves the MuonReadoutElement associated to the multilayer in which the energy deposit is taking place.
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.
AtlasG4EventUserInfoeventInfo () const
 Returns the event user info for the current G4 event, if available.
xAOD::MuonSimHitlastSnapShot (const Identifier &gasGapId, const G4Step *hitStep, const HepMcParticleLink &particleLink)
 Returns the last snap shot matching an already generated HepMcParticleLink.
void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

std::string m_writeKey {}
 Key under which the output container is stored in the G4 event.
xAOD::MuonSimHitContainerm_outContainer {}
 Pointer to the MuonSimHit output container.
AtlasG4EventUserInfom_g4UserEventInfo {}
 G4 event user information holding the current event store/context.
SG::ReadHandleKey< ActsTrk::DetectorAlignStorem_trfCacheKey
 ReadHandleKey to the DetectorAlignmentStore caching the relevant transformations needed in this event.
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

Definition at line 44 of file MdtSensitiveDetector.h.

Constructor & Destructor Documentation

◆ ~MdtSensitiveDetector()

MuonG4R4::MdtSensitiveDetector::~MdtSensitiveDetector ( )
default

Default destructor.

Member Function Documentation

◆ eventContext()

const EventContext & MuonG4R4::MuonSensitiveDetector::eventContext ( ) const
protectedinherited

Returns the current event context recorded in the G4 event info.

Definition at line 54 of file MuonSensitiveDetector.cxx.

54 {
55 AtlasG4EventUserInfo* g4EventInfo = eventInfo();
56 if (!g4EventInfo) {
57 THROW_EXCEPTION("No AtlasG4EventUserInfo available");
58 }
59 return g4EventInfo->GetEventContext();
60 }
const EventContext & GetEventContext() const
AtlasG4EventUserInfo * eventInfo() const
Returns the event user info for the current G4 event, if available.
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10

◆ eventInfo()

AtlasG4EventUserInfo * MuonG4R4::MuonSensitiveDetector::eventInfo ( ) const
privateinherited

Returns the event user info for the current G4 event, if available.

Definition at line 51 of file MuonSensitiveDetector.cxx.

51 {
53 }
static AtlasG4EventUserInfo * GetEventUserInfo()
AtlasG4EventUserInfo * m_g4UserEventInfo
G4 event user information holding the current event store/context.

◆ genParticleLink()

HepMcParticleLink MuonG4R4::MuonSensitiveDetector::genParticleLink ( const G4Track * track) const
protectedinherited

Generates a HepMcParticleLink for the Geant4 track using the current event store.

Parameters
trackthe track for which particle link should be created

Definition at line 87 of file MuonSensitiveDetector.cxx.

87 {
88 TrackHelper trHelper{track};
89 AtlasG4EventUserInfo* g4EventInfo = eventInfo();
90 return trHelper.GenerateParticleLink(g4EventInfo ? g4EventInfo->GetEventStore() : nullptr);
91 }
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
Definition TrackHelper.h:52

◆ getGeoContext()

ActsTrk::GeometryContext MuonG4R4::MuonSensitiveDetector::getGeoContext ( ) const
protectedinherited

Returns the current geometry context in the event.

Definition at line 61 of file MuonSensitiveDetector.cxx.

61 {
62 ActsTrk::GeometryContext gctx{};
63 const ActsTrk::DetectorAlignStore* alignment{nullptr};
64 if (!SG::get(alignment, m_trfCacheKey, eventContext()).isSuccess()) {
65 THROW_EXCEPTION("Failed to retrieve "<<m_trfCacheKey.fullKey()<<".");
66 }
67 gctx.setStore(std::make_unique<DetectorAlignStore>(*alignment));
68 return gctx;
69 }
void setStore(AlignmentStorePtr store)
Adds the store to the Geometry context.
const EventContext & eventContext() const
Returns the current event context recorded in the G4 event info.
SG::ReadHandleKey< ActsTrk::DetectorAlignStore > m_trfCacheKey
ReadHandleKey to the DetectorAlignmentStore caching the relevant transformations needed in this event...
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.

◆ getIdentifier()

Identifier MuonG4R4::MdtSensitiveDetector::getIdentifier ( const ActsTrk::GeometryContext & gctx,
const MuonGMR4::MdtReadoutElement * reElement,
const G4TouchableHistory * touchHist ) const
private

Constructs the identifier of the actual tube where the energy deposit is taking place.

@gctx: Geometry context to access the local -> global transform of the readout element

Parameters
reElementThe readout element associated with the multi layer
touchHistTouchable history of the G4 track to fetch the transform of the G4 volume

The Geant transform takes a hit global -> local --> inverse goes back to the global system Compose this one with the global to local transformation of the first tube in the layer -->

equilateral triangle

Update the reference tube position to be in the proper layer

It can happen that the tube is assigned to zero by numerical precision Catch these cases if the layer is fine

Definition at line 106 of file MdtSensitiveDetector.cxx.

108 {
109 const Amg::Transform3D localToGlobal{getTransform(touchHist, 0)};
112 Amg::Vector3D refTubePos = (readOutEle->globalToLocalTransform(gctx, readOutEle->measurementHash(1,1)) * localToGlobal).translation();
113 ATH_MSG_VERBOSE("Position of the tube wire w.r.t. the first tube in the multi layer "<<Amg::toString(refTubePos, 2));
115 static const double layerPitch = 1./ std::sin(60*Gaudi::Units::deg);
116 const int layer = std::round(refTubePos.x() * layerPitch / readOutEle->tubePitch()) +1;
117 if (layer <= 0) {
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 "
121 <<m_detMgr->idHelperSvc()->toStringDetEl(readOutEle->identify())<<". ");
122 }
124 refTubePos = (readOutEle->globalToLocalTransform(gctx, readOutEle->measurementHash(layer,1)) * localToGlobal).translation();
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));
130 const Amg::Transform3D closureCheck{readOutEle->globalToLocalTransform(gctx,
131 readOutEle->measurementHash(layer, tube))*localToGlobal};
132 if (!Amg::isIdentity(closureCheck)) {
133 ATH_MSG_WARNING("Correction needed "<<layer<<","<<tube<<" "<<Amg::toString(closureCheck));
134 if (closureCheck.translation().y() > 0) ++tube;
135 else --tube;
136 }
137
138 const IdentifierHash tubeHash = readOutEle->measurementHash(layer, tube);
139 const Identifier tubeId = readOutEle->measurementId(tubeHash);
140 {
141 const Amg::Transform3D closureCheck{readOutEle->globalToLocalTransform(gctx, tubeHash)*localToGlobal};
142 if (!Amg::isIdentity(closureCheck)) {
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 "
146 <<m_detMgr->idHelperSvc()->toStringDetEl(readOutEle->identify())<<". "
147 <<"Layer: "<<layer<<", tube: "<<tube<<" "
148 <<Amg::toString(closureCheck)
149 <<"tube volume : "<<touchHist->GetVolume(0)->GetName()
150 <<" mdt chamber: "<<touchHist->GetVolume(2)->GetName());
151 }
152 }
153 ATH_MSG_VERBOSE("Tube & layer number candidate "<<tube<<", "<<layer<<" back and forth transformation "
154 <<Amg::toString(closureCheck));
155 return tubeId;
156}
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
const MuonGMR4::MuonDetectorManager * m_detMgr
Pointer to the underlying detector manager.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
bool isIdentity(const Amg::Transform3D &trans)
Checks whether the transformation is the Identity transformation.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Amg::Transform3D getTransform(const G4VTouchable *history, unsigned int level)
Extracts the local -> global transformation from a TouchableHistory at a given level.
@ layer
Definition HitInfo.h:79

◆ getReadoutElement()

const MuonGMR4::MdtReadoutElement * MuonG4R4::MdtSensitiveDetector::getReadoutElement ( const G4TouchableHistory * touchHist) const
private

Retrieves the MuonReadoutElement associated to the multilayer in which the energy deposit is taking place.

Parameters
touchHistTouchable history of the G4 track to find the proper volume name from which the re element can be deduced

The third volume in the history is the volume corresponding to the Muon multilayer

Find the Detector element from the Identifier

Build first the Identifier to find the detector element

Then retrieve the Detector element

Definition at line 22 of file MdtSensitiveDetector.cxx.

22 {
24 const std::string stationVolume = touchHist->GetVolume(2)->GetName();
25 using namespace MuonGMR4;
26 const std::vector<std::string> volumeTokens = tokenize(stationVolume, "_");
27 ATH_MSG_VERBOSE("Name of the station volume is "<<stationVolume);
28 if (volumeTokens.size() != 5) {
29 THROW_EXCEPTION(" Cannot deduce the station name from "<<stationVolume);
30 }
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]);
36 const MdtIdHelper& idHelper{m_detMgr->idHelperSvc()->mdtIdHelper()};
38 const Identifier detElId = idHelper.multilayerID(idHelper.elementID(stName,stationEta, stationPhi), multiLayer);
40 const MdtReadoutElement* readOutEle = m_detMgr->getMdtReadoutElement(detElId);
41 if (!readOutEle) {
42 THROW_EXCEPTION(" Failed to retrieve a valid detector element from "
43 <<m_detMgr->idHelperSvc()->toStringDetEl(detElId)<<" "<<stationVolume);
44 }
45 return readOutEle;
46}
Identifier multilayerID(const Identifier &channeldID) const
Identifier elementID(int stationName, int stationEta, int stationPhi) const
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...
const std::string & stName(StIndex index)
convert StIndex into a string
constexpr uint8_t stationPhi
station Phi 1 to 8

◆ Initialize()

void MuonG4R4::MuonSensitiveDetector::Initialize ( G4HCofThisEvent * HCE)
finaloverridevirtualinherited

Create the output container at the beginning of the event.

Definition at line 38 of file MuonSensitiveDetector.cxx.

38 {
41 auto* hitVec = m_g4UserEventInfo->GetHitCollectionMap()->Find<MuonSimHitsVec>(m_writeKey);
42 if (!hitVec) {
43 THROW_EXCEPTION("The event does not contain a MuonSimHit container called '"<<m_writeKey<<"'");
44 }
45 m_outContainer = hitVec->container.get();
46 ATH_MSG_DEBUG(__func__<<"() "<<__LINE__<<" - Retrieved '"<<m_writeKey<<"'.");
47 } else {
48 m_outContainer = nullptr;
49 }
50 }
#define ATH_MSG_DEBUG(x)
std::string m_writeKey
Key under which the output container is stored in the G4 event.
xAOD::MuonSimHitContainer * m_outContainer
Pointer to the MuonSimHit output container.
AthHitVec::AuxStoreHitCollection< xAOD::MuonSimHitContainer, xAOD::MuonSimHitAuxContainer > MuonSimHitsVec
Helper type which can be filled into the HitCollectionMap storing the event content in the event.

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ lastSnapShot() [1/2]

xAOD::MuonSimHit * MuonG4R4::MuonSensitiveDetector::lastSnapShot ( const Identifier & gasGapId,
const G4Step * hitStep )
protectedinherited

Returns the last snap shot of the traversing particle.

The G4 track must have stepped through the same volume. Otherwise, a nullptr is returned

Parameters
gasGapIdIdentifier of the gasGap to consider
hitStepPointer to the current step

Definition at line 167 of file MuonSensitiveDetector.cxx.

168 {
169 const HepMcParticleLink particleLink{genParticleLink(hitStep->GetTrack())};
170 return lastSnapShot(hitId, hitStep, particleLink);
171 }
HepMcParticleLink genParticleLink(const G4Track *track) const
Generates a HepMcParticleLink for the Geant4 track using the current event store.
xAOD::MuonSimHit * lastSnapShot(const Identifier &gasGapId, const G4Step *hitStep, const HepMcParticleLink &particleLink)
Returns the last snap shot matching an already generated HepMcParticleLink.

◆ lastSnapShot() [2/2]

xAOD::MuonSimHit * MuonG4R4::MuonSensitiveDetector::lastSnapShot ( const Identifier & gasGapId,
const G4Step * hitStep,
const HepMcParticleLink & particleLink )
privateinherited

Returns the last snap shot matching an already generated HepMcParticleLink.

Parameters
gasGapIdIdentifier of the gasGap to consider
hitStepPointer to the current step .
particleLinkthe existing particle link for the G4Track

There's only a snapshot if the last saved hit has the same Identifier & the same particle Link + G4Track Id

Definition at line 172 of file MuonSensitiveDetector.cxx.

174 {
177 if (m_outContainer->empty() ||
178 m_outContainer->back()->identify() != hitId ||
179 particleLink != m_outContainer->back()->genParticleLink() ||
180 dec_G4TrkId(*m_outContainer->back()) != hitStep->GetTrack()->GetTrackID()) {
181 return nullptr;
182 }
183 return m_outContainer->back();
184 }

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 167 of file AthMessaging.h.

168{
169 MsgStream* ms = m_msg_tls.get();
170 if (!ms) {
171 if (!m_initialized.test_and_set()) initMessaging();
172 ms = new MsgStream(m_imsg,m_nm);
173 m_msg_tls.reset( ms );
174 }
175
176 ms->setLevel (m_lvl);
177 return *ms;
178}
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels).
void initMessaging() const
Initialize our message level and MessageSvc.

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 182 of file AthMessaging.h.

183{ return msg() << lvl; }
MsgStream & msg() const
The standard message stream.

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152{
153 // If user did not set explicit message level we have to initialize
154 // the messaging and retrieve the default via the MessageSvc.
155 if (m_lvl==MSG::NIL && !m_initialized.test_and_set()) initMessaging();
156
157 if (m_lvl <= lvl) {
158 msg() << lvl;
159 return true;
160 } else {
161 return false;
162 }
163}

◆ MuonSensitiveDetector()

MuonG4R4::MuonSensitiveDetector::MuonSensitiveDetector ( const std::string & name,
const std::string & output_key,
const std::string & trf_storeKey,
const MuonGMR4::MuonDetectorManager * detMgr )

Recylce the constructor from the MuonSensitiveDetector.

Definition at line 42 of file MuonSensitiveDetector.cxx.

30 :
31 G4VSensitiveDetector{name},
33 m_writeKey{output_key},
34 m_trfCacheKey{trfStore_key},
35 m_detMgr{detMgr} {
36 m_trfCacheKey.initialize().ignore();
37 }
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.

◆ ProcessHits()

G4bool MuonG4R4::MdtSensitiveDetector::ProcessHits ( G4Step * aStep,
G4TouchableHistory * ROhist )
finaloverridevirtual

Check whether the detector is sensitive to the traversing particle

Calculate the closest approach of the track w.r.t. the wire. We're starting with the post step position and if, there's a closer approach to the wire from that, the propagation distance will be always less than zero. Otherwise one would need to go forward along the trajectory

Closest approach of the step

Definition at line 48 of file MdtSensitiveDetector.cxx.

48 {
49
51 if (!processStep(aStep)) {
52 return true;
53 }
54 G4Track* currentTrack = aStep->GetTrack();
55 const G4StepPoint* preStep = aStep->GetPreStepPoint();
56 const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(preStep->GetTouchable());
57 const MdtReadoutElement* reEle{getReadoutElement(touchHist)};
58
59 const ActsTrk::GeometryContext gctx{getGeoContext()};
60
61 const Identifier HitID = getIdentifier(gctx, reEle, touchHist);
62 if (!HitID.is_valid()) {
63 ATH_MSG_VERBOSE("No valid hit found");
64 return true;
65 }
66
67 const Amg::Transform3D globalToLocal{reEle->globalToLocalTransform(gctx, reEle->measurementHash(HitID))};
68
69 // transform pre and post step positions to local positions
70 const Amg::Vector3D prePosition{Amg::Hep3VectorToEigen(preStep->GetPosition())};
71 const Amg::Vector3D postPosition{Amg::Hep3VectorToEigen(aStep->GetPostStepPoint()->GetPosition())};
72
73 const Amg::Vector3D trackDirection{(postPosition - prePosition).unit()};
74
75 const Amg::Vector3D trackLocPos{globalToLocal * prePosition};
76 const Amg::Vector3D trackLocDir{globalToLocal.linear()* trackDirection};
77
81 double lambda = Amg::intersect<3>(Amg::Vector3D::Zero(), Amg::Vector3D::UnitZ(),
82 trackLocPos, trackLocDir).value_or(0);
83 if (std::abs(currentTrack->GetDefinition()->GetPDGEncoding()) == 11) {
84 lambda = std::clamp(lambda, 0., aStep->GetStepLength());
85 }
87 const Amg::Vector3D driftHit{trackLocPos + lambda * trackLocDir};
88
89
90 const double globalTime{preStep->GetGlobalTime() + lambda / currentTrack->GetVelocity()};
91
92 if (std::abs(currentTrack->GetDefinition()->GetPDGEncoding()) == 11) {
93 const xAOD::MuonSimHit* lastRecord = lastSnapShot(HitID, aStep);
94 if (lastRecord && lastRecord->localPosition().perp() < driftHit.perp()) {
95 return true;
96 }
97 }
98
99 ATH_MSG_VERBOSE(" Dumping of hit "<<m_detMgr->idHelperSvc()->toString(HitID)
100 <<", barcode: "<<genParticleLink(currentTrack).barcode()
101 <<", "<<(*currentTrack) <<", driftCircle: "<<Amg::toString(driftHit, 4)
102 <<", direction "<<Amg::toString(trackLocDir, 4) <<" to SimHit container ahead. ");
103 saveHit(HitID, driftHit, trackLocDir, globalTime, aStep);
104 return true;
105}
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
int HitID
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...
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.
static IdentifierHash measurementHash(unsigned layerNumber, unsigned tubeNumber)
Constructs a Measurement hash from layer && tube number.
Amg::Transform3D globalToLocalTransform(const ActsTrk::GeometryContext &ctx) const
Returns the transformation from the global ATLAS coordinate system into the local coordinate system o...
ConstVectorMap< 3 > localPosition() const
Returns the local postion of the traversing particle.
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.
Amg::Vector3D Hep3VectorToEigen(const CLHEP::Hep3Vector &CLHEPvector)
Converts a CLHEP-based CLHEP::Hep3Vector into an Eigen-based Amg::Vector3D.
int barcode(const T *p)
Definition Barcode.h:16
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12

◆ processStep()

bool MuonG4R4::MuonSensitiveDetector::processStep ( const G4Step * step) const
protectedinherited

Checks whether the current step shall be processed at all.

I.e. the particle needs to be charged, there's a minimum velocity needed and the step length must not vanish

Parameters
stepG4 step to consider

Reject secondary particles

Sensitive detector is only sensitive to charged particles or Geantinos

Definition at line 70 of file MuonSensitiveDetector.cxx.

70 {
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) {
76 ATH_MSG_VERBOSE("Step length is too short ");
77 return false;
78 }
80 if (currentTrack->GetDefinition()->GetPDGCharge() == 0.0) {
81 ATH_MSG_VERBOSE("Particle is neutral");
82 return currentTrack->GetDefinition() == G4Geantino::GeantinoDefinition() ||
83 currentTrack->GetDefinition() == G4ChargedGeantino::ChargedGeantinoDefinition();
84 }
85 return true;
86 }

◆ propagateAndSaveStrip()

xAOD::MuonSimHit * MuonG4R4::MuonSensitiveDetector::propagateAndSaveStrip ( const Identifier & hitId,
const Amg::Transform3D & toGasGap,
const G4Step * hitStep )
protectedinherited

Records the G4Step in the sim hit.

Hits are usually expressed at the center point of the step. Except for low-energy electrons where the endpoint of the random walk path is just extended

Parameters
hitIdIdentifier of the gas gap or the tube in which the hit is recorded
toGaGapTransform from the ATLAS global coordinates into the sensitive volume
hitStepStep from which the particle's information and the pre and post step positions are fetched

Fetch the step end-points

Hit direction as the momentum direction

Electrons randomly work through the gas instead of drifting through the gas -> take the prestep of the first snap shop inside the gas as pre step point

Definition at line 92 of file MuonSensitiveDetector.cxx.

94 {
95
96 const G4Track* currentTrack = aStep->GetTrack();
98 const Amg::Vector3D locPostStep{toGasGap*Amg::Hep3VectorToEigen(aStep->GetPostStepPoint()->GetPosition())};
99 Amg::Vector3D locPreStep{toGasGap*Amg::Hep3VectorToEigen(aStep->GetPreStepPoint()->GetPosition())};
100
102 Amg::Vector3D locHitDir = toGasGap.linear() * Amg::Hep3VectorToEigen(currentTrack->GetMomentumDirection());
103
106 xAOD::MuonSimHit* prevHit = lastSnapShot(hitID, aStep);
107 if (std::abs(currentTrack->GetParticleDefinition()->GetPDGEncoding()) == 11 && prevHit) {
108 locPreStep = xAOD::toEigen(prevHit->localPosition()) - 0.5* prevHit->stepLength() *
109 xAOD::toEigen(prevHit->localDirection());
110
111 locHitDir = (locPostStep - locPreStep).unit();
112 }
113 const Amg::Vector3D locHitPos = 0.5* (locPreStep + locPostStep);
114 ATH_MSG_VERBOSE( m_detMgr->idHelperSvc()->toStringGasGap(hitID)<<" - track: "<<(*currentTrack)
115 <<", deposit: "<<aStep->GetTotalEnergyDeposit()<<", -- local coords: "
116 <<"prestep: "<<Amg::toString(locPreStep)<<", post step: "<<Amg::toString(locPostStep)
117 <<" mid point: "<< Amg::toString(locHitPos)<<", direction: "<<Amg::toString(locHitDir)
118 <<", deposit: "<<aStep->GetTotalEnergyDeposit());
119
120 const double globalTime = currentTrack->GetGlobalTime() + locHitDir.dot(locPostStep - locHitPos) / currentTrack->GetVelocity();
121
122 xAOD::MuonSimHit* newHit = saveHit(hitID, locHitPos, locHitDir, globalTime, aStep);
123 if (prevHit) {
124 newHit->setStepLength((locPostStep - locPreStep).mag());
125 }
126 return newHit;
127 }
Scalar mag() const
mag method
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.

◆ saveHit()

xAOD::MuonSimHit * MuonG4R4::MuonSensitiveDetector::saveHit ( const Identifier & hitId,
const Amg::Vector3D & hitPos,
const Amg::Vector3D & hitDir,
const double globTime,
const G4Step * hitStep )
protectedinherited

Saves the current Step as a xAOD::MuonSimHit snapshot.

Parameters
hitIdIdentifier of the gasGap/ tube where the hit was deposited
hitPosLocal position of the hit expressed w.r.t gas gap coordinate system
hitDirLocal direction of the hit expressed w.r.t gas gap coordinate system
globTimeGlobal time of the hit
hitStepPointer to the step from which the hit information was derived.

Definition at line 128 of file MuonSensitiveDetector.cxx.

132 {
133 const G4Track* currentTrack = aStep->GetTrack();
134 const HepMcParticleLink particleLink{genParticleLink(currentTrack)};
135 // If Geant4 propagates the same track through the same volume just update the last hit and don't write a new one
136 xAOD::MuonSimHit* hit = lastSnapShot(hitId, aStep, particleLink);
137 bool newHit{false};
138 if (!hit) {
139 if (!m_outContainer) {
140 THROW_EXCEPTION("Cannot find container '"<<m_writeKey<<"'.");
141 }
142 hit = m_outContainer->push_back(std::make_unique<xAOD::MuonSimHit>());
143 newHit = true;
144 }
145 dec_G4TrkId(*hit) = currentTrack->GetTrackID();
146 hit->setIdentifier(hitId);
147 hit->setLocalPosition(xAOD::toStorage(hitPos));
149 hit->setMass(currentTrack->GetDefinition()->GetPDGMass());
150 hit->setGlobalTime(globTime);
151 hit->setPdgId(currentTrack->GetDefinition()->GetPDGEncoding());
152 hit->setEnergyDeposit(aStep->GetTotalEnergyDeposit() + (newHit ? 0. : hit->energyDeposit()));
153 hit->setKineticEnergy(currentTrack->GetKineticEnergy());
154 hit->setGenParticleLink(particleLink);
155 hit->setStepLength(aStep->GetStepLength());
156
157 ATH_MSG_VERBOSE("Save new hit "<<m_detMgr->idHelperSvc()->toString(hitId)
158 <<", pdgId: "<<hit->pdgId()
159 <<", "<<particleLink
160 <<", trackId: "<<currentTrack->GetTrackID()<<", "
161 <<", "<<particleLink.cptr()<<std::endl
162 <<"pos: "<<Amg::toString(hitPos)<<", dir: "<<Amg::toString(hitDir)<<", time: "<<globTime
163 <<", energy: "<<hit->kineticEnergy()<<", stepLength: "<<hit->stepLength()<<", "
164 <<", deposit energy: "<<hit->energyDeposit());
165 return hit;
166 }
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
int pdgId() const
Returns the pdgID of the traversing particle.
void setIdentifier(const Identifier &id)
Sets the global ATLAS identifier.
float energyDeposit() const
Returns the energy deposited by the traversing particle inside the gas volume.
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.
MeasVector< N > toStorage(const AmgVector(N)&amgVec)
Converts the double precision of the AmgVector into the floating point storage precision of the MeasV...

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_detMgr

const MuonGMR4::MuonDetectorManager* MuonG4R4::MuonSensitiveDetector::m_detMgr {nullptr}
protectedinherited

Pointer to the underlying detector manager.

Definition at line 123 of file MuonSensitiveDetector.h.

123{nullptr};

◆ m_g4UserEventInfo

AtlasG4EventUserInfo* MuonG4R4::MuonSensitiveDetector::m_g4UserEventInfo {}
privateinherited

G4 event user information holding the current event store/context.

Definition at line 58 of file MuonSensitiveDetector.h.

58{};

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_outContainer

xAOD::MuonSimHitContainer* MuonG4R4::MuonSensitiveDetector::m_outContainer {}
privateinherited

Pointer to the MuonSimHit output container.

Definition at line 56 of file MuonSensitiveDetector.h.

56{};

◆ m_trfCacheKey

SG::ReadHandleKey<ActsTrk::DetectorAlignStore> MuonG4R4::MuonSensitiveDetector::m_trfCacheKey
privateinherited

ReadHandleKey to the DetectorAlignmentStore caching the relevant transformations needed in this event.

Definition at line 61 of file MuonSensitiveDetector.h.

◆ m_writeKey

std::string MuonG4R4::MuonSensitiveDetector::m_writeKey {}
privateinherited

Key under which the output container is stored in the G4 event.

Definition at line 54 of file MuonSensitiveDetector.h.

54{};

The documentation for this class was generated from the following files: