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