File indexing completed on 2026-09-20 08:30:34
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 #include "MoleculeInserter.hh"
0038
0039 #include "G4ITTrackHolder.hh"
0040 #include "G4MolecularConfiguration.hh"
0041 #include "G4Molecule.hh"
0042 #include "G4MoleculeTable.hh"
0043 #include "G4PhysicalVolumeStore.hh"
0044 #include "G4Track.hh"
0045 #include "G4VPhysicalVolume.hh"
0046 #include "Randomize.hh"
0047
0048 #include <cassert>
0049
0050
0051
0052 MoleculeInserter::MoleculeInserter() : fSaveTrackID(false) {}
0053
0054
0055
0056 MoleculeInserter::MoleculeInserter(G4bool save) : fSaveTrackID(save) {}
0057
0058
0059
0060 void MoleculeShoot::Shoot(MoleculeInserter* gun)
0061 {
0062 for (int i = 0; i < fNumber; ++i) {
0063 G4MolecularConfiguration* conf = G4MoleculeTable::Instance()->GetConfiguration(fMoleculeName);
0064
0065 if (conf == 0) {
0066 G4String msg = "Chemistry Error: Molecule " + fMoleculeName + " don't exists.";
0067 G4Exception("MoleculeInserter::Shoot()", "Invalid_Value", FatalException, msg);
0068 }
0069
0070 G4Molecule* molecule = new G4Molecule(conf);
0071 gun->PushToChemistry(molecule, fTime, fPosition);
0072 }
0073 }
0074
0075
0076
0077 void MoleculeInserter::CreateMolecule(G4Molecule* molecule, G4double time, G4ThreeVector pos)
0078 {
0079 G4Track* MolTrack = molecule->BuildTrack(time, pos);
0080 PushTrack(MolTrack);
0081 }
0082
0083
0084
0085 void MoleculeInserter::CreateMolecule(G4String molecule, G4double time, G4ThreeVector pos)
0086 {
0087 G4MolecularConfiguration* conf = G4MoleculeTable::Instance()->GetConfiguration(molecule);
0088
0089 if (conf == 0) {
0090 G4String msg = "Chemistry Error: Molecule " + molecule + " don't exists.";
0091 G4Exception("MoleculeInserter::CreateMolecule()", "Invalid_Value", FatalException, msg);
0092 }
0093
0094 G4Molecule* gmolecule = new G4Molecule(conf);
0095 G4Track* MolTrack = gmolecule->BuildTrack(time, pos);
0096 PushTrack(MolTrack);
0097 }
0098
0099
0100
0101 void MoleculeInserter::PushToChemistry(G4Molecule* mol, G4double time, G4ThreeVector position)
0102 {
0103 G4Track* MolTrack = mol->BuildTrack(time, position);
0104 PushTrack(MolTrack);
0105
0106 if (fSaveTrackID) {
0107 fInsertedTracks.push_back(MolTrack);
0108 }
0109 }
0110
0111
0112
0113 void MoleculeInserter::DefineTracks()
0114 {
0115 if (fInsertedTracks.size() != 0) {
0116 fInsertedTracks.clear();
0117 }
0118
0119 for (size_t i = 0; i < fShoots.size(); i++) {
0120 fShoots[i].Shoot(this);
0121 }
0122 }
0123
0124
0125
0126 void MoleculeInserter::AddMolecule(const G4String& name, const G4ThreeVector& position, double time)
0127 {
0128 MoleculeShoot shoot;
0129 shoot.fMoleculeName = name;
0130 shoot.fPosition = position;
0131 shoot.fTime = time;
0132 fShoots.push_back(shoot);
0133 }
0134
0135
0136
0137 MoleculeShoot::MoleculeShoot()
0138 {
0139 fMoleculeName = "";
0140 fTime = 0;
0141 fNumber = 1;
0142 }
0143
0144
0145
0146 void MoleculeInserter::Clean()
0147 {
0148 if (fShoots.size() != 0) fShoots.clear();
0149
0150 if (fInsertedTracks.size() != 0) fInsertedTracks.clear();
0151 }
0152
0153