File indexing completed on 2025-10-13 08:27:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #include <memory>
0040
0041 #include "MoleculeCounter.hh"
0042
0043 #include "G4Event.hh"
0044 #include "G4EventManager.hh"
0045 #include "G4MolecularConfiguration.hh"
0046 #include "G4Molecule.hh"
0047 #include "G4MoleculeLocator.hh"
0048 #include "G4Navigator.hh"
0049 #include "G4Scheduler.hh"
0050 #include "G4UIcommand.hh"
0051 #include "G4UnitsTable.hh"
0052
0053 using G4VMoleculeCounterIndex = G4VMoleculeCounter::G4VMoleculeCounterIndex;
0054
0055 G4ThreadLocal std::unique_ptr<G4Navigator> MoleculeCounter::fNavigator = nullptr;
0056
0057 MoleculeCounter::MoleculeCounter(G4String name)
0058 : G4VUserMoleculeCounter(name, G4VMoleculeCounter::MoleculeCounterType::Other),
0059 fIgnoreMoleculePosition(false),
0060 fIgnoreCopyNumbers(true)
0061 {}
0062
0063
0064 void MoleculeCounter::InitializeUser() {}
0065
0066
0067 std::unique_ptr<G4VMoleculeCounterIndex> MoleculeCounter::BuildIndex(const G4Track* aTrack) const
0068 {
0069 if (fVerbose > 1) {
0070 G4cout << "MoleculeCounter::BuildIndex(" << aTrack->GetTrackID() << " : "
0071 << GetMolecule(aTrack)->GetName() << ")" << G4endl;
0072 }
0073 if (fIgnoreMoleculePosition) {
0074 return std::make_unique<MoleculeCounterIndex>(
0075 GetMolecule(aTrack)->GetMolecularConfiguration(), nullptr);
0076 }
0077 else {
0078 const G4VTouchable* touchable = aTrack->GetNextTouchable();
0079 G4TouchableHistory* touchableHistory = nullptr;
0080
0081 if (touchable == nullptr) touchable = aTrack->GetTouchable();
0082 if (touchable == nullptr) {
0083 auto touchableHandle = G4MoleculeLocator::Instance()->LocateMoleculeTrack(aTrack);
0084 touchable = touchableHandle();
0085 }
0086 if (touchable == nullptr) {
0087 G4ExceptionDescription errMsg;
0088 errMsg << "Molecule scorer requires a valid volume pointer."
0089 << " G4Track->GetVolume: " << aTrack->GetVolume()
0090 << " G4Navigator->LocateGlobalPointAndUpdateTouchable: nullptr" << G4endl;
0091 G4Exception("MoleculeCounter::BuildIndex", "VOL_NOT_FOUND", FatalException, errMsg);
0092 }
0093
0094 auto index = std::make_unique<MoleculeCounterIndex>(
0095 GetMolecule(aTrack)->GetMolecularConfiguration(), touchable);
0096
0097 delete touchableHistory;
0098 return index;
0099 }
0100 }
0101
0102
0103 std::unique_ptr<G4VMoleculeCounterIndex>
0104 MoleculeCounter::BuildIndex(const G4Track* aTrack, const G4StepPoint* aStepPoint) const
0105 {
0106 return std::make_unique<MoleculeCounterIndex>(
0107 GetMolecule(aTrack)->GetMolecularConfiguration(), aStepPoint->GetTouchable());
0108 }
0109
0110
0111 std::unique_ptr<G4VMoleculeCounterIndex>
0112 MoleculeCounter::BuildSimpleIndex(const G4MolecularConfiguration* configuration) const
0113 {
0114 return std::make_unique<MoleculeCounterIndex>(
0115 configuration, nullptr);
0116 }
0117
0118
0119 G4bool MoleculeCounter::GetIgnoreMoleculePosition() const
0120 {
0121 return fIgnoreMoleculePosition;
0122 }
0123
0124 void MoleculeCounter::SetIgnoreMoleculePosition(G4bool flag)
0125 {
0126 fIgnoreMoleculePosition = flag;
0127 }
0128
0129 void MoleculeCounter::SetNegativeCountsAreFatal(G4bool flag)
0130 {
0131 G4VMoleculeCounter::SetNegativeCountsAreFatal(flag);
0132
0133 }
0134