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