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 // GEANT4 Class file 28 // GEANT4 Class file 29 // 29 // 30 // 30 // 31 // File name: G4LossTableBuilder 31 // File name: G4LossTableBuilder 32 // 32 // 33 // Author: Vladimir Ivanchenko 33 // Author: Vladimir Ivanchenko 34 // 34 // 35 // Creation date: 03.01.2002 35 // Creation date: 03.01.2002 36 // 36 // 37 // Modifications: 37 // Modifications: 38 // 38 // 39 // 23-01-03 V.Ivanchenko Cut per region 39 // 23-01-03 V.Ivanchenko Cut per region 40 // 21-07-04 V.Ivanchenko Fix problem of range 40 // 21-07-04 V.Ivanchenko Fix problem of range for dedx=0 41 // 08-11-04 Migration to new interface of Stor 41 // 08-11-04 Migration to new interface of Store/Retrieve tables (V.Ivanchenko) 42 // 07-12-04 Fix of BuildDEDX table (V.Ivanchen 42 // 07-12-04 Fix of BuildDEDX table (V.Ivanchenko) 43 // 27-03-06 Add bool options isIonisation (V.I 43 // 27-03-06 Add bool options isIonisation (V.Ivanchenko) 44 // 16-01-07 Fill new (not old) DEDX table (V.I 44 // 16-01-07 Fill new (not old) DEDX table (V.Ivanchenko) 45 // 12-02-07 Use G4LPhysicsFreeVector for the i 45 // 12-02-07 Use G4LPhysicsFreeVector for the inverse range table (V.Ivanchenko) 46 // 24-06-09 Removed hidden bin in G4PhysicsVec 46 // 24-06-09 Removed hidden bin in G4PhysicsVector (V.Ivanchenko) 47 // 47 // 48 // Class Description: 48 // Class Description: 49 // 49 // 50 // ------------------------------------------- 50 // ------------------------------------------------------------------- 51 // 51 // 52 //....oooOO0OOooo........oooOO0OOooo........oo 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 53 //....oooOO0OOooo........oooOO0OOooo........oo 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 54 54 55 #include "G4LossTableBuilder.hh" 55 #include "G4LossTableBuilder.hh" 56 #include "G4SystemOfUnits.hh" 56 #include "G4SystemOfUnits.hh" 57 #include "G4PhysicsTable.hh" 57 #include "G4PhysicsTable.hh" 58 #include "G4PhysicsLogVector.hh" 58 #include "G4PhysicsLogVector.hh" 59 #include "G4PhysicsTableHelper.hh" 59 #include "G4PhysicsTableHelper.hh" 60 #include "G4PhysicsFreeVector.hh" 60 #include "G4PhysicsFreeVector.hh" 61 #include "G4ProductionCutsTable.hh" 61 #include "G4ProductionCutsTable.hh" 62 #include "G4MaterialCutsCouple.hh" 62 #include "G4MaterialCutsCouple.hh" 63 #include "G4Material.hh" 63 #include "G4Material.hh" 64 #include "G4VEmModel.hh" 64 #include "G4VEmModel.hh" 65 #include "G4ParticleDefinition.hh" 65 #include "G4ParticleDefinition.hh" 66 #include "G4LossTableManager.hh" 66 #include "G4LossTableManager.hh" 67 #include "G4EmParameters.hh" 67 #include "G4EmParameters.hh" 68 68 69 G4bool G4LossTableBuilder::baseMatFlag = false << 70 std::vector<G4double>* G4LossTableBuilder::the 69 std::vector<G4double>* G4LossTableBuilder::theDensityFactor = nullptr; 71 std::vector<G4int>* G4LossTableBuilder::the 70 std::vector<G4int>* G4LossTableBuilder::theDensityIdx = nullptr; 72 std::vector<G4bool>* G4LossTableBuilder::the 71 std::vector<G4bool>* G4LossTableBuilder::theFlag = nullptr; 73 72 74 //....oooOO0OOooo........oooOO0OOooo........oo 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 75 74 76 G4LossTableBuilder::G4LossTableBuilder(G4bool 75 G4LossTableBuilder::G4LossTableBuilder(G4bool master) 77 : isInitializer(master) << 78 { 76 { 79 theParameters = G4EmParameters::Instance(); 77 theParameters = G4EmParameters::Instance(); 80 if (nullptr == theFlag) { 78 if (nullptr == theFlag) { >> 79 if (!master) { >> 80 G4ExceptionDescription ed; >> 81 ed << "The table builder is instantiated in a worker thread "; >> 82 G4Exception("G4LossTableBuilder::G4LossTableBuilder ", "em0001", >> 83 JustWarning, ed); >> 84 } 81 theDensityFactor = new std::vector<G4doubl 85 theDensityFactor = new std::vector<G4double>; 82 theDensityIdx = new std::vector<G4int>; 86 theDensityIdx = new std::vector<G4int>; 83 theFlag = new std::vector<G4bool>; 87 theFlag = new std::vector<G4bool>; >> 88 isInitializer = true; 84 } 89 } 85 } 90 } 86 91 87 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 88 93 89 G4LossTableBuilder::~G4LossTableBuilder() 94 G4LossTableBuilder::~G4LossTableBuilder() 90 { 95 { 91 if (isInitializer) { 96 if (isInitializer) { 92 delete theDensityFactor; 97 delete theDensityFactor; 93 delete theDensityIdx; 98 delete theDensityIdx; 94 delete theFlag; 99 delete theFlag; 95 theDensityFactor = nullptr; 100 theDensityFactor = nullptr; 96 theDensityIdx = nullptr; 101 theDensityIdx = nullptr; 97 theFlag = nullptr; 102 theFlag = nullptr; 98 } 103 } 99 } 104 } 100 105 101 //....oooOO0OOooo........oooOO0OOooo........oo 106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 102 107 103 const std::vector<G4int>* G4LossTableBuilder:: << 108 const std::vector<G4int>* G4LossTableBuilder::GetCoupleIndexes() const 104 { 109 { 105 return theDensityIdx; 110 return theDensityIdx; 106 } 111 } 107 112 108 //....oooOO0OOooo........oooOO0OOooo........oo 113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 109 114 110 const std::vector<G4double>* G4LossTableBuilde << 115 const std::vector<G4double>* G4LossTableBuilder::GetDensityFactors() const 111 { 116 { 112 return theDensityFactor; 117 return theDensityFactor; 113 } 118 } 114 119 115 //....oooOO0OOooo........oooOO0OOooo........oo 120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 116 121 117 G4bool G4LossTableBuilder::GetFlag(std::size_t 122 G4bool G4LossTableBuilder::GetFlag(std::size_t idx) 118 { 123 { >> 124 if (theFlag->empty()) { InitialiseBaseMaterials(); } 119 return (idx < theFlag->size()) ? (*theFlag)[ 125 return (idx < theFlag->size()) ? (*theFlag)[idx] : false; 120 } 126 } 121 127 122 //....oooOO0OOooo........oooOO0OOooo........oo 128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 123 129 124 G4bool G4LossTableBuilder::GetBaseMaterialFlag 130 G4bool G4LossTableBuilder::GetBaseMaterialFlag() 125 { 131 { >> 132 if (theFlag->empty()) { InitialiseBaseMaterials(); } 126 return baseMatFlag; 133 return baseMatFlag; 127 } 134 } 128 135 129 //....oooOO0OOooo........oooOO0OOooo........oo 136 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 130 137 131 void 138 void 132 G4LossTableBuilder::BuildDEDXTable(G4PhysicsTa 139 G4LossTableBuilder::BuildDEDXTable(G4PhysicsTable* dedxTable, 133 const std:: 140 const std::vector<G4PhysicsTable*>& list) 134 { 141 { 135 InitialiseBaseMaterials(dedxTable); 142 InitialiseBaseMaterials(dedxTable); 136 std::size_t n_processes = list.size(); 143 std::size_t n_processes = list.size(); 137 if(1 >= n_processes) { return; } 144 if(1 >= n_processes) { return; } 138 145 139 std::size_t nCouples = dedxTable->size(); 146 std::size_t nCouples = dedxTable->size(); 140 //G4cout << "Nproc= " << n_processes << " nC 147 //G4cout << "Nproc= " << n_processes << " nCouples=" << nCouples << " Nv= " 141 // << dedxTable->size() << G4endl; 148 // << dedxTable->size() << G4endl; 142 if(0 >= nCouples) { return; } 149 if(0 >= nCouples) { return; } 143 150 144 for (std::size_t i=0; i<nCouples; ++i) { 151 for (std::size_t i=0; i<nCouples; ++i) { 145 auto pv0 = static_cast<G4PhysicsLogVector* 152 auto pv0 = static_cast<G4PhysicsLogVector*>((*(list[0]))[i]); 146 //if (0 == i) G4cout << i << ". pv0=" << p << 147 if(pv0 == nullptr) { continue; } 153 if(pv0 == nullptr) { continue; } 148 std::size_t npoints = pv0->GetVectorLength 154 std::size_t npoints = pv0->GetVectorLength(); 149 auto pv = new G4PhysicsLogVector(*pv0); 155 auto pv = new G4PhysicsLogVector(*pv0); 150 for (std::size_t j=0; j<npoints; ++j) { 156 for (std::size_t j=0; j<npoints; ++j) { 151 G4double dedx = 0.0; 157 G4double dedx = 0.0; 152 for (std::size_t k=0; k<n_processes; ++k 158 for (std::size_t k=0; k<n_processes; ++k) { 153 const G4PhysicsVector* pv1 = (*(list[k]))[i] 159 const G4PhysicsVector* pv1 = (*(list[k]))[i]; 154 //if (0 == i) G4cout << " " << k << ". p << 155 dedx += (*pv1)[j]; 160 dedx += (*pv1)[j]; 156 } 161 } 157 pv->PutValue(j, dedx); 162 pv->PutValue(j, dedx); 158 } 163 } 159 if(splineFlag) { pv->FillSecondDerivatives 164 if(splineFlag) { pv->FillSecondDerivatives(); } 160 G4PhysicsTableHelper::SetPhysicsVector(ded 165 G4PhysicsTableHelper::SetPhysicsVector(dedxTable, i, pv); 161 } 166 } 162 //G4cout << "### G4LossTableBuilder::BuildDE 167 //G4cout << "### G4LossTableBuilder::BuildDEDXTable " << G4endl; 163 //G4cout << *dedxTable << G4endl; 168 //G4cout << *dedxTable << G4endl; 164 } 169 } 165 170 166 //....oooOO0OOooo........oooOO0OOooo........oo 171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 167 172 168 void G4LossTableBuilder::BuildRangeTable(const 173 void G4LossTableBuilder::BuildRangeTable(const G4PhysicsTable* dedxTable, 169 G4Phy 174 G4PhysicsTable* rangeTable) 170 // Build range table from the energy loss tabl 175 // Build range table from the energy loss table 171 { 176 { 172 //G4cout << "### G4LossTableBuilder::BuildRa 177 //G4cout << "### G4LossTableBuilder::BuildRangeTable: DEDX table" << G4endl; 173 //G4cout << *const_cast<G4PhysicsTable*>(ded 178 //G4cout << *const_cast<G4PhysicsTable*>(dedxTable) << G4endl; 174 const std::size_t nCouples = dedxTable->size 179 const std::size_t nCouples = dedxTable->size(); 175 if(0 >= nCouples) { return; } 180 if(0 >= nCouples) { return; } 176 181 177 const std::size_t n = 100; 182 const std::size_t n = 100; 178 const G4double del = 1.0/(G4double)n; 183 const G4double del = 1.0/(G4double)n; 179 184 180 for (std::size_t i=0; i<nCouples; ++i) { 185 for (std::size_t i=0; i<nCouples; ++i) { 181 auto pv = static_cast<G4PhysicsLogVector*> 186 auto pv = static_cast<G4PhysicsLogVector*>((*dedxTable)[i]); 182 if((pv == nullptr) || (isBaseMatActive && 187 if((pv == nullptr) || (isBaseMatActive && !(*theFlag)[i])) { continue; } 183 std::size_t npoints = pv->GetVectorLength( 188 std::size_t npoints = pv->GetVectorLength(); 184 std::size_t bin0 = 0; 189 std::size_t bin0 = 0; 185 G4double elow = pv->Energy(0); 190 G4double elow = pv->Energy(0); 186 G4double ehigh = pv->Energy(npoints-1); 191 G4double ehigh = pv->Energy(npoints-1); 187 G4double dedx1 = (*pv)[0]; 192 G4double dedx1 = (*pv)[0]; 188 193 189 // protection for specific cases dedx=0 194 // protection for specific cases dedx=0 190 if(dedx1 == 0.0) { 195 if(dedx1 == 0.0) { 191 for (std::size_t k=1; k<npoints; ++k) { 196 for (std::size_t k=1; k<npoints; ++k) { 192 ++bin0; 197 ++bin0; 193 elow = pv->Energy(k); 198 elow = pv->Energy(k); 194 dedx1 = (*pv)[k]; 199 dedx1 = (*pv)[k]; 195 if(dedx1 > 0.0) { break; } 200 if(dedx1 > 0.0) { break; } 196 } 201 } 197 npoints -= bin0; 202 npoints -= bin0; 198 } 203 } 199 204 200 // initialisation of a new vector 205 // initialisation of a new vector 201 if(npoints < 3) { npoints = 3; } 206 if(npoints < 3) { npoints = 3; } 202 207 203 delete (*rangeTable)[i]; 208 delete (*rangeTable)[i]; 204 G4PhysicsLogVector* v; 209 G4PhysicsLogVector* v; 205 if(0 == bin0) { v = new G4PhysicsLogVector 210 if(0 == bin0) { v = new G4PhysicsLogVector(*pv); } 206 else { v = new G4PhysicsLogVector(elow, eh 211 else { v = new G4PhysicsLogVector(elow, ehigh, npoints-1, splineFlag); } 207 212 208 // assumed dedx proportional to beta 213 // assumed dedx proportional to beta 209 G4double energy1 = v->Energy(0); 214 G4double energy1 = v->Energy(0); 210 G4double range = 2.*energy1/dedx1; 215 G4double range = 2.*energy1/dedx1; 211 /* 216 /* 212 G4cout << "New Range vector Npoints=" << v 217 G4cout << "New Range vector Npoints=" << v->GetVectorLength() 213 << " coupleIdx=" << i << " spline=" << v- 218 << " coupleIdx=" << i << " spline=" << v->GetSpline() 214 << " Elow=" << v->GetMinEnergy() <<" Ehig 219 << " Elow=" << v->GetMinEnergy() <<" Ehigh=" << v->GetMinEnergy() 215 << " DEDX(Elow)=" << dedx1 << " R(Elow)=" 220 << " DEDX(Elow)=" << dedx1 << " R(Elow)=" << range << G4endl; 216 */ 221 */ 217 v->PutValue(0,range); 222 v->PutValue(0,range); 218 223 219 for (std::size_t j=1; j<npoints; ++j) { 224 for (std::size_t j=1; j<npoints; ++j) { 220 225 221 G4double energy2 = v->Energy(j); 226 G4double energy2 = v->Energy(j); 222 G4double de = (energy2 - energy1) * 227 G4double de = (energy2 - energy1) * del; 223 G4double energy = energy2 + de*0.5; 228 G4double energy = energy2 + de*0.5; 224 G4double sum = 0.0; 229 G4double sum = 0.0; 225 std::size_t idx = j - 1; 230 std::size_t idx = j - 1; 226 for (std::size_t k=0; k<n; ++k) { 231 for (std::size_t k=0; k<n; ++k) { 227 energy -= de; 232 energy -= de; 228 dedx1 = pv->Value(energy, idx); 233 dedx1 = pv->Value(energy, idx); 229 if(dedx1 > 0.0) { sum += de/dedx1; } 234 if(dedx1 > 0.0) { sum += de/dedx1; } 230 } 235 } 231 range += sum; 236 range += sum; 232 /* 237 /* 233 if(energy < 10.) 238 if(energy < 10.) 234 G4cout << "j= " << j << " e1= " << energy1 < 239 G4cout << "j= " << j << " e1= " << energy1 << " e2= " << energy2 235 << " n= " << n << " range=" << range< 240 << " n= " << n << " range=" << range<< G4endl; 236 */ 241 */ 237 v->PutValue(j,range); 242 v->PutValue(j,range); 238 energy1 = energy2; 243 energy1 = energy2; 239 } 244 } 240 if(splineFlag) { v->FillSecondDerivatives( 245 if(splineFlag) { v->FillSecondDerivatives(); } 241 G4PhysicsTableHelper::SetPhysicsVector(ran 246 G4PhysicsTableHelper::SetPhysicsVector(rangeTable, i, v); 242 } 247 } 243 //G4cout << "### Range table" << G4endl; 248 //G4cout << "### Range table" << G4endl; 244 //G4cout << *rangeTable << G4endl; 249 //G4cout << *rangeTable << G4endl; 245 } 250 } 246 251 247 //....oooOO0OOooo........oooOO0OOooo........oo 252 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 248 253 249 void 254 void 250 G4LossTableBuilder::BuildInverseRangeTable(con 255 G4LossTableBuilder::BuildInverseRangeTable(const G4PhysicsTable* rangeTable, 251 G4P 256 G4PhysicsTable* invRangeTable) 252 // Build inverse range table from the energy l 257 // Build inverse range table from the energy loss table 253 { 258 { 254 std::size_t nCouples = rangeTable->size(); 259 std::size_t nCouples = rangeTable->size(); 255 if(0 >= nCouples) { return; } 260 if(0 >= nCouples) { return; } 256 261 257 for (std::size_t i=0; i<nCouples; ++i) { 262 for (std::size_t i=0; i<nCouples; ++i) { 258 G4PhysicsVector* pv = (*rangeTable)[i]; 263 G4PhysicsVector* pv = (*rangeTable)[i]; 259 if((pv == nullptr) || (isBaseMatActive && 264 if((pv == nullptr) || (isBaseMatActive && !(*theFlag)[i])) { continue; } 260 std::size_t npoints = pv->GetVectorLength( 265 std::size_t npoints = pv->GetVectorLength(); 261 266 262 delete (*invRangeTable)[i]; 267 delete (*invRangeTable)[i]; 263 auto v = new G4PhysicsFreeVector(npoints, 268 auto v = new G4PhysicsFreeVector(npoints, splineFlag); 264 269 265 for (std::size_t j=0; j<npoints; ++j) { 270 for (std::size_t j=0; j<npoints; ++j) { 266 G4double e = pv->Energy(j); 271 G4double e = pv->Energy(j); 267 G4double r = (*pv)[j]; 272 G4double r = (*pv)[j]; 268 v->PutValues(j,r,e); 273 v->PutValues(j,r,e); 269 } 274 } 270 if (splineFlag) { v->FillSecondDerivatives 275 if (splineFlag) { v->FillSecondDerivatives(); } 271 v->EnableLogBinSearch(theParameters->Numbe 276 v->EnableLogBinSearch(theParameters->NumberForFreeVector()); 272 277 273 G4PhysicsTableHelper::SetPhysicsVector(inv 278 G4PhysicsTableHelper::SetPhysicsVector(invRangeTable, i, v); 274 } 279 } 275 //G4cout << "### Inverse range table" << G4e 280 //G4cout << "### Inverse range table" << G4endl; 276 //G4cout << *invRangeTable << G4endl; 281 //G4cout << *invRangeTable << G4endl; 277 } 282 } 278 283 279 //....oooOO0OOooo........oooOO0OOooo........oo 284 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 280 285 281 void G4LossTableBuilder::InitialiseBaseMateria 286 void G4LossTableBuilder::InitialiseBaseMaterials(const G4PhysicsTable* table) 282 { 287 { 283 if(!isInitializer) { return; } 288 if(!isInitializer) { return; } 284 const G4ProductionCutsTable* theCoupleTable= 289 const G4ProductionCutsTable* theCoupleTable= 285 G4ProductionCutsTable::GetProductionCutsTa 290 G4ProductionCutsTable::GetProductionCutsTable(); 286 std::size_t nCouples = theCoupleTable->GetTa 291 std::size_t nCouples = theCoupleTable->GetTableSize(); 287 std::size_t nFlags = theFlag->size(); 292 std::size_t nFlags = theFlag->size(); 288 /* 293 /* 289 G4cout << "### InitialiseBaseMaterials: nCou 294 G4cout << "### InitialiseBaseMaterials: nCouples=" << nCouples 290 << " nFlags=" << nFlags << " isInit:" << is 295 << " nFlags=" << nFlags << " isInit:" << isInitialized 291 << " baseMat:" << baseMatFlag << G4endl; 296 << " baseMat:" << baseMatFlag << G4endl; 292 */ 297 */ 293 // define base material flag 298 // define base material flag 294 if(isBaseMatActive && !baseMatFlag) { 299 if(isBaseMatActive && !baseMatFlag) { 295 for(G4int i=0; i<(G4int)nCouples; ++i) { 300 for(G4int i=0; i<(G4int)nCouples; ++i) { 296 if(nullptr != theCoupleTable->GetMateria 301 if(nullptr != theCoupleTable->GetMaterialCutsCouple(i)->GetMaterial()->GetBaseMaterial()) { 297 baseMatFlag = true; 302 baseMatFlag = true; 298 isInitialized = false; 303 isInitialized = false; 299 break; 304 break; 300 } 305 } 301 } 306 } 302 } 307 } 303 308 304 if(nFlags != nCouples) { isInitialized = fal 309 if(nFlags != nCouples) { isInitialized = false; } 305 if(isInitialized) { return; } 310 if(isInitialized) { return; } 306 311 307 // reserve memory 312 // reserve memory 308 theFlag->resize(nCouples, true); 313 theFlag->resize(nCouples, true); 309 theDensityFactor->resize(nCouples,1.0); << 314 if(nullptr == table) { return; } 310 theDensityIdx->resize(nCouples, 0); << 315 >> 316 if(baseMatFlag) { >> 317 theDensityFactor->resize(nCouples,1.0); >> 318 theDensityIdx->resize(nCouples); >> 319 } 311 320 312 // define default flag and index of used mat 321 // define default flag and index of used material cut couple 313 for (G4int i=0; i<(G4int)nCouples; ++i) { << 322 for(G4int i=0; i<(G4int)nCouples; ++i) { 314 (*theFlag)[i] = (nullptr == table) ? true << 323 (*theFlag)[i] = table->GetFlag(i); 315 (*theDensityIdx)[i] = i; << 324 if(baseMatFlag) { (*theDensityIdx)[i] = i; } 316 } 325 } 317 isInitialized = true; 326 isInitialized = true; 318 if (!baseMatFlag) { return; } << 327 if(baseMatFlag) { 319 << 328 // use base materials 320 // use base materials << 329 for(G4int i=0; i<(G4int)nCouples; ++i) { 321 for (G4int i=0; i<(G4int)nCouples; ++i) { << 330 // base material is needed only for a couple which is not 322 // base material is needed only for a coup << 331 // initialised and for which tables will be computed 323 // initialised and for which tables will b << 332 auto couple = theCoupleTable->GetMaterialCutsCouple(i); 324 auto couple = theCoupleTable->GetMaterialC << 333 auto pcuts = couple->GetProductionCuts(); 325 auto pcuts = couple->GetProductionCuts(); << 334 auto mat = couple->GetMaterial(); 326 auto mat = couple->GetMaterial(); << 335 auto bmat = mat->GetBaseMaterial(); 327 auto bmat = mat->GetBaseMaterial(); << 336 328 << 337 // base material exists - find it and check if it can be reused 329 // base material exists - find it and chec << 338 if(nullptr != bmat) { 330 if(nullptr != bmat) { << 339 for(G4int j=0; j<(G4int)nCouples; ++j) { 331 for(G4int j=0; j<(G4int)nCouples; ++j) { << 340 if(j == i) { continue; } 332 if(j == i) { continue; } << 341 auto bcouple = theCoupleTable->GetMaterialCutsCouple(j); 333 auto bcouple = theCoupleTable->GetMaterialCu << 342 334 << 343 if(bcouple->GetMaterial() == bmat && 335 if(bcouple->GetMaterial() == bmat && << 344 bcouple->GetProductionCuts() == pcuts) { 336 bcouple->GetProductionCuts() == pcuts) { << 345 337 << 346 // based couple exist in the same region 338 // based couple exist in the same region << 347 (*theDensityFactor)[i] = mat->GetDensity()/bmat->GetDensity(); 339 (*theDensityFactor)[i] = mat->GetDensity() << 348 (*theDensityIdx)[i] = j; 340 (*theDensityIdx)[i] = j; << 349 (*theFlag)[i] = false; 341 (*theFlag)[i] = false; << 350 342 << 351 // ensure that there will no double initialisation 343 // ensure that there will no double initia << 352 (*theDensityFactor)[j] = 1.0; 344 (*theDensityFactor)[j] = 1.0; << 353 (*theDensityIdx)[j] = j; 345 (*theDensityIdx)[j] = j; << 354 (*theFlag)[j] = true; 346 (*theFlag)[j] = true; << 355 break; 347 break; << 356 } 348 } 357 } 349 } 358 } 350 } 359 } 351 } 360 } >> 361 /* >> 362 G4cout << "### G4LossTableBuilder::InitialiseBaseMaterials: flag=" >> 363 << baseMatFlag << G4endl; >> 364 for(std::size_t i=0; i<nCouples; ++i) { >> 365 G4cout << "CoupleIdx=" << i << " Flag= " << (*theFlag)[i] << " " >> 366 << theCoupleTable->GetMaterialCutsCouple(i)->GetMaterial()->GetName() >> 367 << " TableFlag= " << table->GetFlag(i) >> 368 << " " << (*table)[i] >> 369 << G4endl; >> 370 } >> 371 */ 352 } 372 } 353 373 354 //....oooOO0OOooo........oooOO0OOooo........oo 374 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 355 375 356 G4PhysicsTable* 376 G4PhysicsTable* 357 G4LossTableBuilder::BuildTableForModel(G4Physi 377 G4LossTableBuilder::BuildTableForModel(G4PhysicsTable* aTable, 358 G4VEmMo 378 G4VEmModel* model, 359 const G 379 const G4ParticleDefinition* part, 360 G4doubl 380 G4double emin, G4double emax, 361 G4bool 381 G4bool spline) 362 { 382 { 363 // check input 383 // check input 364 G4PhysicsTable* table = G4PhysicsTableHelper 384 G4PhysicsTable* table = G4PhysicsTableHelper::PreparePhysicsTable(aTable); 365 if (nullptr == table) { return table; } << 385 if(nullptr == table) { return table; } 366 if (aTable != nullptr && aTable != table) { << 386 if(emin >= emax) { 367 aTable->clearAndDestroy(); << 387 table->clearAndDestroy(); 368 delete aTable; << 388 delete table; >> 389 table = nullptr; >> 390 return table; 369 } 391 } 370 << 371 InitialiseBaseMaterials(table); 392 InitialiseBaseMaterials(table); 372 G4int nbins = theParameters->NumberOfBinsPer 393 G4int nbins = theParameters->NumberOfBinsPerDecade(); 373 394 374 // Access to materials 395 // Access to materials 375 const G4ProductionCutsTable* theCoupleTable= 396 const G4ProductionCutsTable* theCoupleTable= 376 G4ProductionCutsTable::GetProductionCu 397 G4ProductionCutsTable::GetProductionCutsTable(); 377 std::size_t numOfCouples = theCoupleTable->G 398 std::size_t numOfCouples = theCoupleTable->GetTableSize(); 378 /* << 399 379 G4cout << " G4LossTableBuilder::BuildTable << 380 << " isMaster=" << isInitializer << " model << 381 << " " << part->GetParticleName() << G4end << 382 */ << 383 G4PhysicsLogVector* aVector = nullptr; 400 G4PhysicsLogVector* aVector = nullptr; 384 401 385 for(G4int i=0; i<(G4int)numOfCouples; ++i) { 402 for(G4int i=0; i<(G4int)numOfCouples; ++i) { 386 //G4cout << i << ". " << (*theFlag)[i] << << 403 if ((*theFlag)[i]) { 387 if (table->GetFlag(i)) { << 388 404 389 // create physics vector and fill it 405 // create physics vector and fill it 390 auto couple = theCoupleTable->GetMateria 406 auto couple = theCoupleTable->GetMaterialCutsCouple(i); 391 delete (*table)[i]; 407 delete (*table)[i]; 392 408 393 // if start from zero then change the sc 409 // if start from zero then change the scale >> 410 394 const G4Material* mat = couple->GetMater 411 const G4Material* mat = couple->GetMaterial(); 395 412 396 G4double tmin = std::max(emin, model->Mi << 413 G4double tmin = std::max(emin,model->MinPrimaryEnergy(mat,part)); 397 if(0.0 >= tmin) { tmin = CLHEP::eV; } 414 if(0.0 >= tmin) { tmin = CLHEP::eV; } 398 G4int n = nbins; 415 G4int n = nbins; 399 416 400 if(tmin >= emax) { 417 if(tmin >= emax) { 401 aVector = nullptr; 418 aVector = nullptr; 402 } else { 419 } else { 403 n *= G4lrint(std::log10(emax/tmin)); 420 n *= G4lrint(std::log10(emax/tmin)); 404 n = std::max(n, 3); 421 n = std::max(n, 3); 405 aVector = new G4PhysicsLogVector(tmin, 422 aVector = new G4PhysicsLogVector(tmin, emax, n, spline); 406 } 423 } 407 424 408 if(nullptr != aVector) { 425 if(nullptr != aVector) { 409 //G4cout << part->GetParticleName() << 426 //G4cout << part->GetParticleName() << " in " << mat->GetName() 410 // << " emin= " << tmin << " emax=" << e << 427 // << " tmin= " << tmin << G4endl; 411 for(G4int j=0; j<=n; ++j) { 428 for(G4int j=0; j<=n; ++j) { 412 G4double e = aVector->Energy(j); << 429 aVector->PutValue(j, model->Value(couple, part, 413 G4double y = model->Value(couple, part, e) << 430 aVector->Energy(j))); 414 //G4cout << " " << j << ") E=" << e < << 415 aVector->PutValue(j, y); << 416 } 431 } 417 if(spline) { aVector->FillSecondDeriva 432 if(spline) { aVector->FillSecondDerivatives(); } 418 } 433 } 419 G4PhysicsTableHelper::SetPhysicsVector(t 434 G4PhysicsTableHelper::SetPhysicsVector(table, i, aVector); 420 } 435 } 421 } 436 } 422 /* 437 /* 423 G4cout << "G4LossTableBuilder::BuildTableFor 438 G4cout << "G4LossTableBuilder::BuildTableForModel done for " 424 << part->GetParticleName() << " and " 439 << part->GetParticleName() << " and "<< model->GetName() 425 << " " << table << G4endl; 440 << " " << table << G4endl; 426 */ 441 */ 427 //G4cout << *table << G4endl; 442 //G4cout << *table << G4endl; 428 return table; 443 return table; 429 } 444 } 430 445 431 //....oooOO0OOooo........oooOO0OOooo........oo 446 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 432 447