Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // 27 /// \file UserMoleculeGun.cc 28 /// \brief Implementation of the UserMoleculeGun class 29 30 #include "UserMoleculeGun.hh" 31 #include "UserMolecule.hh" 32 33 #include "G4MoleculeTable.hh" 34 #include "G4SystemOfUnits.hh" 35 #include "G4VITTrackHolder.hh" 36 #include "G4H2O.hh" 37 #include "G4Track.hh" 38 39 UserMoleculeShoot::UserMoleculeShoot() : 40 G4enable_shared_from_this<UserMoleculeShoot>() 41 { 42 fMoleculeName = ""; 43 fTime = 0; 44 fNumber = 1; 45 fBoxSize = 0; 46 fCopyNumber = -1; 47 fStrand = -1; 48 } 49 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 52 UserMoleculeShoot::~UserMoleculeShoot() 53 { 54 if(fBoxSize) delete fBoxSize; 55 } 56 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 59 template<> 60 void TUserMoleculeShoot<G4Track>::ShootAtRandomPosition(UserMoleculeGun* gun) 61 { 62 G4ThreeVector positionInLocalCoordinate; 63 64 for(int i = 0; i < fNumber; ++i) 65 { 66 RandomPosInBox(*fBoxSize, positionInLocalCoordinate); 67 if(fStrand<=0) 68 gun->BuildAndPushTrack(fMoleculeName, 69 fPosition + positionInLocalCoordinate, 70 fTime); 71 else 72 gun->BuildAndPushTrack(fMoleculeName, 73 fPosition + positionInLocalCoordinate, 74 fTime,fCopyNumber,fStrand); 75 } 76 } 77 78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 80 template<> 81 void TUserMoleculeShoot<G4Track>::ShootAtFixedPosition(UserMoleculeGun* gun) 82 { 83 for(int i = 0; i < fNumber; ++i) 84 { 85 if(fStrand<=0) 86 gun->BuildAndPushTrack(fMoleculeName, fPosition, fTime); 87 else 88 gun->BuildAndPushTrack(fMoleculeName,fPosition,fTime,fCopyNumber,fStrand); 89 } 90 } 91 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 93 94 template<> 95 void TUserMoleculeShoot<G4Track>::MyShoot(UserMoleculeGun* gun) 96 { 97 if(fBoxSize) ShootAtRandomPosition(gun); 98 else ShootAtFixedPosition(gun); 99 } 100 101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 102 103 void UserMoleculeGun::DefineTracks() 104 { 105 for (size_t i = 0; i < fShoots.size(); i++) 106 { 107 fShoots[i]->MyShoot(this); 108 } 109 } 110 111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 112 113 void UserMoleculeGun::AddMolecule(const G4String& name, 114 const G4ThreeVector& position, 115 G4double time, 116 G4int copyNumber, 117 G4int strand) 118 { 119 G4shared_ptr<UserMoleculeShoot> shoot(new TUserMoleculeShoot<G4Track>()); 120 shoot->fMoleculeName = name; 121 shoot->fPosition = position; 122 shoot->fTime = time; 123 shoot->fCopyNumber = copyNumber; 124 shoot->fStrand = strand; 125 fShoots.push_back(shoot); 126 } 127 128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 129 130 void UserMoleculeGun::AddWaterMolecule(const G4ThreeVector& position, 131 G4int trackId, 132 ElectronicModification elecModif, 133 G4int electronicLevel) 134 { 135 UserMolecule * H2O = new UserMolecule (G4H2O::Definition() ); 136 switch (elecModif) 137 { 138 case eDissociativeAttachment: 139 H2O -> AddElectron(5,1); 140 break; 141 case eExcitedMolecule : 142 H2O -> ExciteMolecule(electronicLevel); 143 break; 144 case eIonizedMolecule : 145 H2O -> IonizeMolecule(electronicLevel); 146 break; 147 } 148 149 G4Track * H2OTrack = H2O->BuildTrack(1*picosecond, position); 150 H2OTrack->SetParentID(trackId); 151 H2OTrack->SetTrackStatus(fStopButAlive); 152 H2OTrack->SetKineticEnergy(0.); 153 G4VITTrackHolder::Instance()->Push(H2OTrack); 154 } 155 156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 157 158 void UserMoleculeGun::BuildAndPushTrack(const G4String& name, 159 const G4ThreeVector& position, 160 G4double time) 161 { 162 G4MolecularConfiguration* conf = 163 G4MoleculeTable::Instance()->GetConfiguration(name); 164 assert(conf != 0); 165 UserMolecule* molecule = new UserMolecule(conf); 166 PushTrack(molecule->BuildTrack(time, position)); 167 } 168 169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 170 171 void UserMoleculeGun::BuildAndPushTrack(const G4String& name, 172 const G4ThreeVector& position, 173 G4double time, 174 G4int copyNumber, 175 G4int strand) 176 { 177 G4MoleculeDefinition* def = G4MoleculeTable::Instance()->GetMoleculeDefinition(name); 178 assert(def != 0); 179 UserMolecule* molecule = new UserMolecule(def); 180 molecule->SetCopyNumber(copyNumber); 181 molecule->SetStrand(strand); 182 183 PushTrack(molecule->BuildTrack(time, position)); 184 } 185 186 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 187