Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // ------------------------------------------- 27 // ------------------------------------------------------------------- 28 // 28 // 29 // GEANT4 Class file 29 // GEANT4 Class file 30 // 30 // 31 // File name: G4EmDataHandler 31 // File name: G4EmDataHandler 32 // 32 // 33 // Author: V. Ivanchenko 33 // Author: V. Ivanchenko 34 // 34 // 35 // Creation date: 16 August 2017 35 // Creation date: 16 August 2017 36 // 36 // 37 // Modifications: 37 // Modifications: 38 // 38 // 39 // ------------------------------------------- 39 // ------------------------------------------------------------------- 40 // 40 // 41 // 41 // 42 42 43 #include "G4EmDataHandler.hh" 43 #include "G4EmDataHandler.hh" 44 #include "G4EmDataRegistry.hh" << 45 #include "G4ParticleDefinition.hh" 44 #include "G4ParticleDefinition.hh" 46 #include "G4EmParameters.hh" 45 #include "G4EmParameters.hh" 47 #include "G4PhysicsTableHelper.hh" 46 #include "G4PhysicsTableHelper.hh" 48 #include "G4VEmProcess.hh" 47 #include "G4VEmProcess.hh" 49 #include "G4VEnergyLossProcess.hh" << 50 48 51 //....oooOO0OOooo........oooOO0OOooo........oo 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 50 53 G4EmDataHandler::G4EmDataHandler(std::size_t n << 51 G4EmDataHandler::G4EmDataHandler(size_t n) : tLength(n) 54 : tLength(n), fName(nam) << 55 { 52 { 56 data.resize(n, nullptr); 53 data.resize(n, nullptr); 57 fMaxXS = new std::vector<G4double>; << 58 fXSpeaks = new std::vector<G4TwoPeaksXS*>; << 59 G4EmDataRegistry::Instance()->Register(this) << 60 } 54 } 61 55 62 //....oooOO0OOooo........oooOO0OOooo........oo 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 57 64 G4EmDataHandler::~G4EmDataHandler() 58 G4EmDataHandler::~G4EmDataHandler() 65 { 59 { 66 if (!fUseBaseParticleTable) { << 60 //std::cout << "G4EmDataHandler::~G4EmDataHandler " 67 for (std::size_t i=0; i<tLength; ++i) { << 61 // << tLength << " " << this << std::endl; 68 CleanTable(i); << 62 for(size_t i=0; i<tLength; ++i) { CleanTable(i); } 69 } << 70 delete fMaxXS; << 71 delete fXSpeaks; << 72 } << 73 if (!fElemSelectors.empty()) { << 74 for (auto const & ptr : fElemSelectors) { << 75 if (nullptr != ptr) { << 76 for (auto const & p : *ptr) { delete p; } << 77 } << 78 } << 79 } << 80 << 81 } 63 } 82 64 83 //....oooOO0OOooo........oooOO0OOooo........oo 65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 84 66 85 std::size_t G4EmDataHandler::SetTable(G4Physic << 67 size_t G4EmDataHandler::SetTable(G4PhysicsTable* ptr) 86 { 68 { 87 for (std::size_t i=0; i<tLength; ++i) { << 88 if (ptr == data[i]) { return i; } << 89 } << 90 data.push_back(ptr); 69 data.push_back(ptr); 91 ++tLength; 70 ++tLength; 92 return tLength-1; 71 return tLength-1; 93 } 72 } 94 73 95 //....oooOO0OOooo........oooOO0OOooo........oo 74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 96 75 97 void G4EmDataHandler::UpdateTable(G4PhysicsTab << 76 G4PhysicsTable* G4EmDataHandler::MakeTable(size_t i) 98 { << 99 // update table pointer but not delete previ << 100 if (idx < tLength) { << 101 if (ptr != data[idx]) { data[idx] = ptr; } << 102 data[idx] = G4PhysicsTableHelper::PrepareP << 103 } else { << 104 G4cout << "### G4EmDataHandler::UpdateTabl << 105 << " length=" << tLength << G4endl; << 106 } << 107 } << 108 << 109 //....oooOO0OOooo........oooOO0OOooo........oo << 110 << 111 void G4EmDataHandler::SaveTable(G4PhysicsTable << 112 { << 113 if (idx < tLength) { << 114 data[idx] = ptr; << 115 } << 116 } << 117 << 118 //....oooOO0OOooo........oooOO0OOooo........oo << 119 << 120 G4PhysicsTable* G4EmDataHandler::MakeTable(std << 121 { 77 { 122 std::size_t idx = i; << 78 G4PhysicsTable* table = nullptr; 123 if (idx >= tLength) { << 124 data.push_back(nullptr); << 125 idx = tLength; << 126 ++tLength; << 127 } << 128 data[idx] = G4PhysicsTableHelper::PreparePhy << 129 return data[idx]; << 130 } << 131 << 132 //....oooOO0OOooo........oooOO0OOooo........oo << 133 << 134 G4PhysicsTable* G4EmDataHandler::MakeTable(G4P << 135 { << 136 std::size_t idx = i; << 137 // create new table only if index correspond 79 // create new table only if index corresponds to the 138 // position in the vector 80 // position in the vector 139 if (idx < tLength) { << 81 if(i <= tLength) { 140 if (ptr != data[idx]) { << 82 if(i < tLength) { table = data[i]; } 141 CleanTable(idx); << 83 table = G4PhysicsTableHelper::PreparePhysicsTable(table); 142 data[idx] = ptr; << 84 if(i == tLength) { 143 } << 85 data.push_back(table); 144 } else { << 86 ++tLength; 145 data.push_back(ptr); << 87 } else { data[i] = table; } 146 idx = tLength; << 147 ++tLength; << 148 } 88 } 149 data[idx] = G4PhysicsTableHelper::PreparePhy << 89 return table; 150 return data[idx]; << 151 } 90 } 152 91 153 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 154 93 155 void G4EmDataHandler::CleanTable(std::size_t i << 94 void G4EmDataHandler::CleanTable(size_t i) 156 { 95 { 157 if (i < tLength && nullptr != data[i]) { << 96 //std::cout << i << " " << data[i] << std::endl; 158 auto ptr = data[i]; << 97 if(i < tLength && data[i]) { 159 ptr->clearAndDestroy(); << 98 data[i]->clearAndDestroy(); 160 delete ptr; << 99 delete data[i]; 161 for (std::size_t j=0; j<tLength; ++j) { << 100 data[i] = nullptr; 162 if (ptr == data[j]) { data[j] = nullptr; << 163 } << 164 } 101 } 165 } 102 } 166 103 167 //....oooOO0OOooo........oooOO0OOooo........oo 104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168 105 169 G4bool G4EmDataHandler::StorePhysicsTable(std: << 106 G4bool G4EmDataHandler::StorePhysicsTable(size_t idx, 170 const G4ParticleDef 107 const G4ParticleDefinition* part, 171 const G4String& fname, 108 const G4String& fname, 172 G4bool ascii) 109 G4bool ascii) 173 { 110 { 174 G4bool yes = true; 111 G4bool yes = true; 175 if(nullptr != data[idx]) { << 112 if(data[idx]) { 176 yes = data[idx]->StorePhysicsTable(fname, 113 yes = data[idx]->StorePhysicsTable(fname, ascii); 177 114 178 if ( yes ) { 115 if ( yes ) { 179 G4cout << "### Physics table is stored f << 116 G4cout << "Physics table is stored for " 180 << part->GetParticleName() 117 << part->GetParticleName() 181 << " <" << fname << "> " << G4end 118 << " <" << fname << "> " << G4endl; 182 } else { 119 } else { 183 G4cout << "### Fail to store Physics Tab << 120 G4cout << "Fail to store Physics Table for " 184 << part->GetParticleName() 121 << part->GetParticleName() 185 << " <" << fname << "> " << G4end 122 << " <" << fname << "> " << G4endl; 186 } 123 } 187 } 124 } 188 return yes; 125 return yes; 189 } 126 } 190 127 191 //....oooOO0OOooo........oooOO0OOooo........oo 128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 192 129 193 G4bool G4EmDataHandler::RetrievePhysicsTable(s << 130 G4bool G4EmDataHandler::RetrievePhysicsTable(size_t idx, 194 const G4ParticleDef 131 const G4ParticleDefinition* part, 195 const G4String& fname, 132 const G4String& fname, 196 G4bool ascii, G4bool spline) << 133 G4bool ascii) 197 { 134 { 198 G4PhysicsTable* table = Table(idx); << 135 G4bool yes = 199 G4bool yes = G4PhysicsTableHelper::RetrieveP << 136 G4PhysicsTableHelper::RetrievePhysicsTable(data[idx], fname, ascii); 200 G4EmParameters* param = G4EmParameters::Inst 137 G4EmParameters* param = G4EmParameters::Instance(); 201 if ( yes ) { 138 if ( yes ) { 202 if (0 < param->Verbose()) { 139 if (0 < param->Verbose()) { 203 G4cout << "### Physics table " << idx << << 140 G4cout << "Physics table " << idx << " for " 204 << part->GetParticleName() 141 << part->GetParticleName() 205 << " is retrieved from <" << fname << " 142 << " is retrieved from <" << fname << ">" 206 << G4endl; 143 << G4endl; 207 } 144 } >> 145 if(param->Spline()) { >> 146 G4PhysicsTable* table = data[idx]; >> 147 size_t n = table->length(); >> 148 for(size_t i=0; i<n; ++i) { >> 149 if((*table)[i]) { (*table)[i]->SetSpline(true); } >> 150 } >> 151 } 208 } else if (1 < param->Verbose()) { 152 } else if (1 < param->Verbose()) { 209 G4cout << "### Fail to retrieve physics ta << 153 G4cout << "Fail to retrieve physics table " << idx << " for " 210 << part->GetParticleName() << " from <" 154 << part->GetParticleName() << " from <" 211 << fname << ">" << G4endl; 155 << fname << ">" << G4endl; 212 } 156 } 213 return yes; 157 return yes; 214 } 158 } 215 159 216 //....oooOO0OOooo........oooOO0OOooo........oo 160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 217 161 218 void G4EmDataHandler::SetMasterProcess(const G 162 void G4EmDataHandler::SetMasterProcess(const G4VEmProcess* ptr) 219 { 163 { 220 masterProcess.push_back(ptr); 164 masterProcess.push_back(ptr); 221 } 165 } 222 166 223 //....oooOO0OOooo........oooOO0OOooo........oo 167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 224 168 225 const G4VEmProcess* G4EmDataHandler::GetMaster << 169 const G4VEmProcess* G4EmDataHandler::GetMasterProcess(size_t idx) const 226 { 170 { 227 return (idx < masterProcess.size()) ? master << 171 const G4VEmProcess* ptr = 228 } << 172 (idx < masterProcess.size()) ? masterProcess[idx] : nullptr; 229 << 173 return ptr; 230 //....oooOO0OOooo........oooOO0OOooo........oo << 231 << 232 void G4EmDataHandler::SetElementSelectors(std: << 233 std::size_t i) << 234 { << 235 if (i < eLength) { << 236 if (fElemSelectors[i] != p) { << 237 delete fElemSelectors[i]; << 238 } << 239 fElemSelectors[i] = p; << 240 } else { << 241 fElemSelectors.push_back(p); << 242 ++eLength; << 243 } << 244 } 174 } 245 175 246 //....oooOO0OOooo........oooOO0OOooo........oo 176 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 247 177