Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 /// \file PrimaryGeneratorSourceGRASCSV.cc 28 /// \brief Primary Generator source class impl 29 /// for Molecular DNA simulation 30 31 #include "PrimaryGeneratorSourceGRASCSV.hh" 32 33 //....oooOO0OOooo........oooOO0OOooo........oo 34 35 PrimaryGeneratorSourceGRASCSV::PrimaryGenerato 36 { 37 // set a default buffer size 38 fEndOfFile = false; 39 40 // open file 41 fInputFile.open(filename); 42 if (fInputFile.is_open()) { 43 G4cout << "*** Opening particle source fil 44 // find the starting particle source box 45 G4String line = ""; 46 G4int totalevents = 0; 47 while (std::getline(fInputFile, line)) { 48 if (line.find("TOTAL_EVENTS") != std::st 49 // Create a stringstream of the curren 50 std::stringstream ss(line); 51 G4String tmp = ""; 52 ss >> tmp >> tmp >> totalevents; 53 } 54 if (line.find 55 ("TWO-STAGE PARTICLE PHASE SPACE OUT 56 != std::string::npos) 57 { 58 for (G4int i = 0; i < 18; i++) { 59 std::getline(fInputFile, line); 60 // Print the header information 61 G4cout << line << G4endl; 62 } 63 break; 64 } 65 } 66 // set the number of particles 67 fnParticles = totalevents; 68 } 69 else { 70 G4cout << "*** Warning: can't open particl 71 } 72 } 73 74 //....oooOO0OOooo........oooOO0OOooo........oo 75 76 PrimaryGeneratorSourceGRASCSV::~PrimaryGenerat 77 { 78 // close file and clear structures 79 if (fInputFile.is_open()) { 80 fInputFile.close(); 81 } 82 fPrimaryList.clear(); 83 } 84 85 //....oooOO0OOooo........oooOO0OOooo........oo 86 87 G4double PrimaryGeneratorSourceGRASCSV::Recomp 88 { 89 // to be implemented 90 // the variable in CSV has to be recomputed 91 return fnParticles; 92 } 93 94 //....oooOO0OOooo........oooOO0OOooo........oo 95 96 Primary* PrimaryGeneratorSourceGRASCSV::GetPri 97 { 98 if (fInputFile.peek() == EOF || fEndOfFile = 99 // Read in primaries if the primary list is 100 if (fPrimaryList.size() == 0) { 101 // Read 100 primaries at a time 102 G4int num = fBufferSize; 103 if (num > fnParticles) { 104 num = fnParticles; 105 } 106 107 for (G4int i = 0; i < num; i++) { 108 if (fInputFile.peek() == EOF) { 109 // End of file 110 fEndOfFile = true; 111 break; 112 } 113 G4String line = ""; 114 std::getline(fInputFile, line); 115 if (line.find 116 ("TWO-STAGE PARTICLE PHASE SPACE OUT 117 != std::string::npos) 118 { 119 const G4int lines = 18; 120 for (G4int j = 0; j < lines; j++) { 121 std::getline(fInputFile, line); 122 } 123 i--; 124 continue; 125 } 126 if (line.find("Block") != std::string::n 127 || line.find("End") != std::string:: 128 { 129 // End of Block, skip 130 i--; 131 continue; 132 } 133 std::stringstream ss(line); 134 std::vector<G4String> tempVect; 135 G4String tempString = ""; 136 while (ss >> tempString) 137 tempVect.push_back(tempString); 138 139 try { 140 // Define position and momentum direct 141 G4ThreeVector pos = G4ThreeVector(std: 142 std: 143 std: 144 G4ThreeVector momDir = G4ThreeVector(s 145 s 146 s 147 G4int PDGEncoding = std::stoi(tempVect 148 G4double KE = 0; 149 KE = std::stod(tempVect.at(8)); 150 151 // Generate primary particle 152 auto* primary = new Primary(); 153 primary->SetName(PDGEncoding); 154 primary->SetPosition(pos); 155 primary->SetMomentumDirection(momDir); 156 primary->SetEnergy(KE); 157 158 // Populate the primaries list 159 fPrimaryList.push_back(primary); 160 } 161 catch (const std::invalid_argument&) { 162 G4cerr << "Phase Space reading error: 163 } 164 catch (const std::out_of_range&) { 165 G4cerr << "Phase Space reading error: 166 } 167 } 168 } 169 170 // Get first element and delete it so it's n 171 Primary* primary = nullptr; 172 if (fPrimaryList.size() > 0) { 173 primary = fPrimaryList.front(); 174 fPrimaryList.pop_front(); 175 } 176 return primary; 177 } 178