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