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