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$ 26 // 27 // 27 // ------------------------------------------- 28 // ------------------------------------------------------------------- 28 // 29 // 29 // GEANT4 Class file 30 // GEANT4 Class file 30 // 31 // 31 // 32 // 32 // File name: G4VMultipleScattering 33 // File name: G4VMultipleScattering 33 // 34 // 34 // Author: Vladimir Ivanchenko on base 35 // Author: Vladimir Ivanchenko on base of Laszlo Urban code 35 // 36 // 36 // Creation date: 25.03.2003 37 // Creation date: 25.03.2003 37 // 38 // 38 // Modifications: 39 // Modifications: 39 // 40 // >> 41 // 13.04.03 Change printout (V.Ivanchenko) >> 42 // 04-06-03 Fix compilation warnings (V.Ivanchenko) 40 // 16-07-03 Use G4VMscModel interface (V.Ivanc 43 // 16-07-03 Use G4VMscModel interface (V.Ivanchenko) 41 // 03-11-03 Fix initialisation problem in Retr 44 // 03-11-03 Fix initialisation problem in RetrievePhysicsTable (V.Ivanchenko) 42 // 04-11-03 Update PrintInfoDefinition (V.Ivan 45 // 04-11-03 Update PrintInfoDefinition (V.Ivanchenko) 43 // 01-03-04 SampleCosineTheta signature change 46 // 01-03-04 SampleCosineTheta signature changed 44 // 22-04-04 SampleCosineTheta signature change 47 // 22-04-04 SampleCosineTheta signature changed back to original 45 // 27-08-04 Add InitialiseForRun method (V.Iva 48 // 27-08-04 Add InitialiseForRun method (V.Ivanchneko) 46 // 08-11-04 Migration to new interface of Stor 49 // 08-11-04 Migration to new interface of Store/Retrieve tables (V.Ivantchenko) 47 // 11-03-05 Shift verbose level by 1 (V.Ivantc 50 // 11-03-05 Shift verbose level by 1 (V.Ivantchenko) 48 // 15-04-05 optimize internal interface (V.Iva 51 // 15-04-05 optimize internal interface (V.Ivanchenko) 49 // 15-04-05 remove boundary flag (V.Ivanchenko 52 // 15-04-05 remove boundary flag (V.Ivanchenko) 50 // 27-10-05 introduce virtual function MscStep 53 // 27-10-05 introduce virtual function MscStepLimitation() (V.Ivanchenko) 51 // 12-04-07 Add verbosity at destruction (V.Iv 54 // 12-04-07 Add verbosity at destruction (V.Ivanchenko) 52 // 27-10-07 Virtual functions moved to source 55 // 27-10-07 Virtual functions moved to source (V.Ivanchenko) 53 // 11-03-08 Set skin value does not effect ste 56 // 11-03-08 Set skin value does not effect step limit type (V.Ivanchenko) 54 // 24-06-09 Removed hidden bin in G4PhysicsVec 57 // 24-06-09 Removed hidden bin in G4PhysicsVector (V.Ivanchenko) 55 // 04-06-13 Adoptation to MT mode (V.Ivanchenk 58 // 04-06-13 Adoptation to MT mode (V.Ivanchenko) 56 // 59 // >> 60 // Class Description: >> 61 // >> 62 // It is the generic process of multiple scattering it includes common >> 63 // part of calculations for all charged particles 57 64 58 // ------------------------------------------- 65 // ------------------------------------------------------------------- 59 // 66 // 60 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 61 //....oooOO0OOooo........oooOO0OOooo........oo 68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 62 69 63 #include "G4VMultipleScattering.hh" 70 #include "G4VMultipleScattering.hh" 64 #include "G4PhysicalConstants.hh" 71 #include "G4PhysicalConstants.hh" 65 #include "G4SystemOfUnits.hh" 72 #include "G4SystemOfUnits.hh" 66 #include "G4LossTableManager.hh" 73 #include "G4LossTableManager.hh" 67 #include "G4MaterialCutsCouple.hh" 74 #include "G4MaterialCutsCouple.hh" 68 #include "G4Step.hh" 75 #include "G4Step.hh" 69 #include "G4ParticleDefinition.hh" 76 #include "G4ParticleDefinition.hh" 70 #include "G4VEmFluctuationModel.hh" 77 #include "G4VEmFluctuationModel.hh" 71 #include "G4UnitsTable.hh" 78 #include "G4UnitsTable.hh" 72 #include "G4ProductionCutsTable.hh" 79 #include "G4ProductionCutsTable.hh" 73 #include "G4Electron.hh" 80 #include "G4Electron.hh" 74 #include "G4GenericIon.hh" 81 #include "G4GenericIon.hh" 75 #include "G4TransportationManager.hh" 82 #include "G4TransportationManager.hh" 76 #include "G4SafetyHelper.hh" 83 #include "G4SafetyHelper.hh" 77 #include "G4ParticleTable.hh" 84 #include "G4ParticleTable.hh" 78 #include "G4ProcessVector.hh" 85 #include "G4ProcessVector.hh" 79 #include "G4ProcessManager.hh" 86 #include "G4ProcessManager.hh" 80 #include "G4LossTableBuilder.hh" << 81 #include "G4EmTableUtil.hh" << 82 #include <iostream> 87 #include <iostream> 83 88 84 //....oooOO0OOooo........oooOO0OOooo........oo 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 85 90 86 G4VMultipleScattering::G4VMultipleScattering(c << 91 G4VMultipleScattering::G4VMultipleScattering(const G4String& name, G4ProcessType) 87 : G4VContinuousDiscreteProcess("msc", fElect 92 : G4VContinuousDiscreteProcess("msc", fElectromagnetic), >> 93 numberOfModels(0), >> 94 firstParticle(nullptr), >> 95 currParticle(nullptr), >> 96 stepLimit(fUseSafety), >> 97 facrange(0.04), >> 98 latDisplacement(true), >> 99 isIon(false), >> 100 fDispBeyondSafety(false), 88 fNewPosition(0.,0.,0.), 101 fNewPosition(0.,0.,0.), 89 fNewDirection(0.,0.,1.) 102 fNewDirection(0.,0.,1.) 90 { 103 { 91 theParameters = G4EmParameters::Instance(); 104 theParameters = G4EmParameters::Instance(); 92 SetVerboseLevel(1); 105 SetVerboseLevel(1); 93 SetProcessSubType(fMultipleScattering); 106 SetProcessSubType(fMultipleScattering); >> 107 if("ionmsc" == name) { firstParticle = G4GenericIon::GenericIon(); } 94 108 95 lowestKinEnergy = 10*CLHEP::eV; 109 lowestKinEnergy = 10*CLHEP::eV; 96 110 97 geomMin = 0.05*CLHEP::nm; << 111 physStepLimit = gPathLength = tPathLength = 0.0; >> 112 fIonisation = nullptr; >> 113 >> 114 geomMin = 0.05*CLHEP::nm; 98 minDisplacement2 = geomMin*geomMin; 115 minDisplacement2 = geomMin*geomMin; 99 116 100 pParticleChange = &fParticleChange; 117 pParticleChange = &fParticleChange; >> 118 safetyHelper = nullptr; >> 119 fPositionChanged = false; >> 120 isActive = false; 101 121 >> 122 currentModel = nullptr; 102 modelManager = new G4EmModelManager(); 123 modelManager = new G4EmModelManager(); 103 emManager = G4LossTableManager::Instance(); 124 emManager = G4LossTableManager::Instance(); 104 mscModels.reserve(2); << 105 emManager->Register(this); 125 emManager->Register(this); 106 } 126 } 107 127 108 //....oooOO0OOooo........oooOO0OOooo........oo 128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 109 129 110 G4VMultipleScattering::~G4VMultipleScattering( 130 G4VMultipleScattering::~G4VMultipleScattering() 111 { 131 { >> 132 /* >> 133 if(1 < verboseLevel) { >> 134 G4cout << "G4VMultipleScattering destruct " << GetProcessName() >> 135 << G4endl; >> 136 } >> 137 */ 112 delete modelManager; 138 delete modelManager; 113 emManager->DeRegister(this); 139 emManager->DeRegister(this); 114 } 140 } 115 141 116 //....oooOO0OOooo........oooOO0OOooo........oo 142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 117 143 118 void G4VMultipleScattering::AddEmModel(G4int o << 144 void G4VMultipleScattering::AddEmModel(G4int order, G4VEmModel* p, 119 const G 145 const G4Region* region) 120 { 146 { 121 if(nullptr == ptr) { return; } << 122 G4VEmFluctuationModel* fm = nullptr; 147 G4VEmFluctuationModel* fm = nullptr; 123 modelManager->AddEmModel(order, ptr, fm, reg << 148 modelManager->AddEmModel(order, p, fm, region); 124 ptr->SetParticleChange(pParticleChange); << 149 if(p) { p->SetParticleChange(pParticleChange); } 125 } 150 } 126 151 127 //....oooOO0OOooo........oooOO0OOooo........oo 152 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 128 153 129 void G4VMultipleScattering::SetEmModel(G4VMscM << 154 void G4VMultipleScattering::SetEmModel(G4VMscModel* p, size_t) 130 { 155 { 131 if(nullptr == ptr) { return; } << 156 for(auto & msc : mscModels) { if(msc == p) { return; } } 132 if(!mscModels.empty()) { << 157 mscModels.push_back(p); 133 for(auto & msc : mscModels) { if(msc == pt << 158 } 134 } << 159 135 mscModels.push_back(ptr); << 160 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 161 >> 162 G4VMscModel* G4VMultipleScattering::EmModel(size_t index) const >> 163 { >> 164 return (index < mscModels.size()) ? mscModels[index] : nullptr; 136 } 165 } 137 166 138 //....oooOO0OOooo........oooOO0OOooo........oo 167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 139 168 140 void 169 void 141 G4VMultipleScattering::PreparePhysicsTable(con 170 G4VMultipleScattering::PreparePhysicsTable(const G4ParticleDefinition& part) 142 { 171 { >> 172 if(1 < verboseLevel) { >> 173 G4cout << "### G4VMultipleScattering::PrepearPhysicsTable() for " >> 174 << GetProcessName() >> 175 << " and particle " << part.GetParticleName() >> 176 << G4endl; >> 177 } 143 G4bool master = emManager->IsMaster(); 178 G4bool master = emManager->IsMaster(); 144 if (nullptr == firstParticle) { firstParticl << 145 179 146 emManager->PreparePhysicsTable(&part, this); << 180 if(!firstParticle) { firstParticle = ∂ } >> 181 if(part.GetParticleType() == "nucleus") { >> 182 stepLimit = fMinimal; >> 183 latDisplacement = false; >> 184 facrange = 0.2; >> 185 G4String pname = part.GetParticleName(); >> 186 if(pname != "deuteron" && pname != "triton" && >> 187 pname != "alpha+" && pname != "helium" && >> 188 pname != "alpha" && pname != "He3" && >> 189 pname != "hydrogen") { >> 190 >> 191 const G4ParticleDefinition* theGenericIon = >> 192 G4ParticleTable::GetParticleTable()->FindParticle("GenericIon"); >> 193 if(&part == theGenericIon) { isIon = true; } >> 194 >> 195 if(theGenericIon && firstParticle != theGenericIon) { >> 196 G4ProcessManager* pm = theGenericIon->GetProcessManager(); >> 197 G4ProcessVector* v = pm->GetAlongStepProcessVector(); >> 198 size_t n = v->size(); >> 199 for(size_t j=0; j<n; ++j) { >> 200 if((*v)[j] == this) { >> 201 firstParticle = theGenericIon; >> 202 isIon = true; >> 203 break; >> 204 } >> 205 } >> 206 } >> 207 } >> 208 } >> 209 >> 210 emManager->PreparePhysicsTable(&part, this, master); 147 currParticle = nullptr; 211 currParticle = nullptr; 148 212 >> 213 if(1 < verboseLevel) { >> 214 G4cout << "### G4VMultipleScattering::PrepearPhysicsTable() for " >> 215 << GetProcessName() >> 216 << " and particle " << part.GetParticleName() >> 217 << " local particle " << firstParticle->GetParticleName() >> 218 << " isIon: " << isIon << " isMaster: " << master >> 219 << G4endl; >> 220 } >> 221 149 if(firstParticle == &part) { 222 if(firstParticle == &part) { 150 baseMat = emManager->GetTableBuilder()->Ge << 151 G4EmTableUtil::PrepareMscProcess(this, par << 152 stepLimit, facrange, << 153 latDisplacement, master, << 154 isIon, baseMat); << 155 223 >> 224 // initialise process >> 225 InitialiseProcess(firstParticle); >> 226 >> 227 // heavy particles and not ions >> 228 if(!isIon) { >> 229 if(part.GetPDGMass() > MeV) { >> 230 stepLimit = theParameters->MscMuHadStepLimitType(); >> 231 facrange = theParameters->MscMuHadRangeFactor(); >> 232 latDisplacement = theParameters->MuHadLateralDisplacement(); >> 233 } else { >> 234 stepLimit = theParameters->MscStepLimitType(); >> 235 facrange = theParameters->MscRangeFactor(); >> 236 latDisplacement = theParameters->LateralDisplacement(); >> 237 } >> 238 if(latDisplacement) { >> 239 fDispBeyondSafety = theParameters->LatDisplacementBeyondSafety(); >> 240 } >> 241 } >> 242 if(master) { SetVerboseLevel(theParameters->Verbose()); } >> 243 else { SetVerboseLevel(theParameters->WorkerVerbose()); } >> 244 >> 245 // initialisation of models 156 numberOfModels = modelManager->NumberOfMod 246 numberOfModels = modelManager->NumberOfModels(); 157 currentModel = GetModelByIndex(0); << 247 /* >> 248 G4cout << "### G4VMultipleScattering::PreparePhysicsTable() for " >> 249 << GetProcessName() >> 250 << " and particle " << part.GetParticleName() >> 251 << " Nmod= " << numberOfModels << " " << this >> 252 << G4endl; >> 253 */ >> 254 for(G4int i=0; i<numberOfModels; ++i) { >> 255 G4VMscModel* msc = static_cast<G4VMscModel*>(GetModelByIndex(i)); >> 256 if(!msc) { continue; } >> 257 msc->SetIonisation(nullptr, firstParticle); >> 258 msc->SetMasterThread(master); >> 259 currentModel = msc; >> 260 msc->SetStepLimitType(stepLimit); >> 261 msc->SetLateralDisplasmentFlag(latDisplacement); >> 262 msc->SetSkin(theParameters->MscSkin()); >> 263 msc->SetRangeFactor(facrange); >> 264 msc->SetGeomFactor(theParameters->MscGeomFactor()); >> 265 msc->SetPolarAngleLimit(theParameters->MscThetaLimit()); >> 266 G4double emax = >> 267 std::min(msc->HighEnergyLimit(),theParameters->MaxKinEnergy()); >> 268 msc->SetHighEnergyLimit(emax); >> 269 } 158 270 159 if (nullptr == safetyHelper) { << 271 modelManager->Initialise(firstParticle, G4Electron::Electron(), >> 272 10.0, verboseLevel); >> 273 >> 274 if(!safetyHelper) { 160 safetyHelper = G4TransportationManager:: 275 safetyHelper = G4TransportationManager::GetTransportationManager() 161 ->GetSafetyHelper(); << 276 ->GetSafetyHelper(); 162 safetyHelper->InitialiseHelper(); 277 safetyHelper->InitialiseHelper(); 163 } 278 } 164 } 279 } 165 } 280 } 166 281 167 //....oooOO0OOooo........oooOO0OOooo........oo 282 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 168 283 169 void G4VMultipleScattering::BuildPhysicsTable( 284 void G4VMultipleScattering::BuildPhysicsTable(const G4ParticleDefinition& part) 170 { 285 { >> 286 G4String num = part.GetParticleName(); 171 G4bool master = emManager->IsMaster(); 287 G4bool master = emManager->IsMaster(); 172 << 288 if(1 < verboseLevel) { 173 if(firstParticle == &part) { << 289 G4cout << "### G4VMultipleScattering::BuildPhysicsTable() for " 174 emManager->BuildPhysicsTable(&part); << 290 << GetProcessName() >> 291 << " and particle " << num << " isIon: " << isIon >> 292 << " IsMaster: " << master << G4endl; 175 } 293 } 176 const G4VMultipleScattering* ptr = this; << 294 const G4VMultipleScattering* masterProcess = 177 if(!master) { << 295 static_cast<const G4VMultipleScattering*>(GetMasterProcess()); 178 ptr = static_cast<const G4VMultipleScatter << 296 >> 297 if(firstParticle == &part) { >> 298 /* >> 299 G4cout << "### G4VMultipleScattering::BuildPhysicsTable() for " >> 300 << GetProcessName() >> 301 << " and particle " << num >> 302 << " IsMaster= " << G4LossTableManager::Instance()->IsMaster() >> 303 << " " << this >> 304 << G4endl; >> 305 */ >> 306 emManager->BuildPhysicsTable(firstParticle); >> 307 >> 308 if(!master) { >> 309 // initialisation of models >> 310 /* >> 311 G4cout << "### G4VMultipleScattering::BuildPhysicsTable() for " >> 312 << GetProcessName() >> 313 << " and particle " << num >> 314 << " Nmod= " << numberOfModels << " " << this >> 315 << G4endl; >> 316 */ >> 317 for(G4int i=0; i<numberOfModels; ++i) { >> 318 G4VMscModel* msc = static_cast<G4VMscModel*>(GetModelByIndex(i)); >> 319 if(!msc) { continue; } >> 320 G4VMscModel* msc0= >> 321 static_cast<G4VMscModel*>(masterProcess->GetModelByIndex(i)); >> 322 msc->SetCrossSectionTable(msc0->GetCrossSectionTable(), false); >> 323 msc->InitialiseLocal(firstParticle, msc0); >> 324 } >> 325 } 179 } 326 } 180 327 181 G4EmTableUtil::BuildMscProcess(this, ptr, pa << 328 // explicitly defined printout by particle name 182 numberOfModels, master); << 329 if(1 < verboseLevel || >> 330 (0 < verboseLevel && (num == "e-" || >> 331 num == "e+" || num == "mu+" || >> 332 num == "mu-" || num == "proton"|| >> 333 num == "pi+" || num == "pi-" || >> 334 num == "kaon+" || num == "kaon-" || >> 335 num == "alpha" || num == "anti_proton" || >> 336 num == "GenericIon" || num == "alpha+" || >> 337 num == "alpha++" ))) >> 338 { >> 339 StreamInfo(G4cout, part); >> 340 } >> 341 >> 342 if(1 < verboseLevel) { >> 343 G4cout << "### G4VMultipleScattering::BuildPhysicsTable() done for " >> 344 << GetProcessName() >> 345 << " and particle " << num >> 346 << G4endl; >> 347 } 183 } 348 } 184 349 185 //....oooOO0OOooo........oooOO0OOooo........oo 350 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 186 351 187 void G4VMultipleScattering::StreamInfo(std::os 352 void G4VMultipleScattering::StreamInfo(std::ostream& outFile, 188 const G4ParticleDefinition& << 353 const G4ParticleDefinition& part, G4String endOfLine) const 189 { 354 { 190 G4String indent = (rst ? " " : ""); << 355 outFile << endOfLine << GetProcessName() << ": "; 191 outFile << G4endl << indent << GetProcessNam << 356 if (endOfLine != G4String("<br>\n")) { 192 if (!rst) outFile << " for " << part.GetPart << 357 outFile << " for " << part.GetParticleName(); 193 outFile << " SubType= " << GetProcessSubTy << 358 } 194 modelManager->DumpModelList(outFile, verbose << 359 outFile << " SubType= " << GetProcessSubType() << endOfLine; >> 360 StreamProcessInfo(outFile, endOfLine); >> 361 modelManager->DumpModelList(outFile, verboseLevel, endOfLine); 195 } 362 } 196 363 197 //....oooOO0OOooo........oooOO0OOooo........oo 364 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 198 365 199 void G4VMultipleScattering::StartTracking(G4Tr 366 void G4VMultipleScattering::StartTracking(G4Track* track) 200 { 367 { 201 G4VEnergyLossProcess* eloss = nullptr; 368 G4VEnergyLossProcess* eloss = nullptr; 202 if(track->GetParticleDefinition() != currPar 369 if(track->GetParticleDefinition() != currParticle) { 203 currParticle = track->GetParticleDefinitio 370 currParticle = track->GetParticleDefinition(); 204 fIonisation = emManager->GetEnergyLossProc 371 fIonisation = emManager->GetEnergyLossProcess(currParticle); 205 eloss = fIonisation; 372 eloss = fIonisation; 206 } 373 } >> 374 /* >> 375 G4cout << "G4VMultipleScattering::StartTracking Nmod= " << numberOfModels >> 376 << " " << currParticle->GetParticleName() >> 377 << " E(MeV)= " << track->GetKineticEnergy() >> 378 << " Ion= " << eloss << " " << fIonisation << " IsMaster= " >> 379 << G4LossTableManager::Instance()->IsMaster() >> 380 << G4endl; >> 381 */ 207 for(G4int i=0; i<numberOfModels; ++i) { 382 for(G4int i=0; i<numberOfModels; ++i) { 208 G4VMscModel* msc = GetModelByIndex(i); << 383 /* >> 384 G4cout << "Next model " << i << " " << msc >> 385 << " Emin= " << msc->LowEnergyLimit() >> 386 << " Emax= " << msc->HighEnergyLimit() >> 387 << " Eact= " << msc->LowEnergyActivationLimit() << G4endl; >> 388 */ >> 389 G4VEmModel* msc = GetModelByIndex(i); 209 msc->StartTracking(track); 390 msc->StartTracking(track); 210 if(nullptr != eloss) { << 391 if(eloss) { 211 msc->SetIonisation(eloss, currParticle); << 392 G4VMscModel* mscmod = static_cast<G4VMscModel*>(msc); >> 393 if(mscmod) { mscmod->SetIonisation(fIonisation, currParticle); } 212 } 394 } 213 } 395 } 214 } << 396 } 215 397 216 //....oooOO0OOooo........oooOO0OOooo........oo 398 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 217 399 218 G4double G4VMultipleScattering::AlongStepGetPh 400 G4double G4VMultipleScattering::AlongStepGetPhysicalInteractionLength( 219 const G4Track& tr 401 const G4Track& track, 220 G4double, 402 G4double, 221 G4double currentM 403 G4double currentMinimalStep, 222 G4double&, 404 G4double&, 223 G4GPILSelection* 405 G4GPILSelection* selection) 224 { 406 { 225 // get Step limit proposed by the process 407 // get Step limit proposed by the process 226 *selection = NotCandidateForSelection; 408 *selection = NotCandidateForSelection; 227 physStepLimit = gPathLength = tPathLength = 409 physStepLimit = gPathLength = tPathLength = currentMinimalStep; 228 410 229 G4double ekin = track.GetKineticEnergy(); 411 G4double ekin = track.GetKineticEnergy(); 230 /* 412 /* 231 G4cout << "MSC::AlongStepGPIL: Ekin= " << ek 413 G4cout << "MSC::AlongStepGPIL: Ekin= " << ekin 232 << " " << currParticle->GetParticleN 414 << " " << currParticle->GetParticleName() 233 << " currMod " << currentModel 415 << " currMod " << currentModel 234 << G4endl; 416 << G4endl; 235 */ 417 */ 236 // isIon flag is used only to select a model 418 // isIon flag is used only to select a model 237 if(isIon) { 419 if(isIon) { 238 ekin *= proton_mass_c2/track.GetParticleDe 420 ekin *= proton_mass_c2/track.GetParticleDefinition()->GetPDGMass(); 239 } 421 } 240 const G4MaterialCutsCouple* couple = track.G << 241 422 242 // select new model, static cast is possible << 423 // select new model 243 if(1 < numberOfModels) { 424 if(1 < numberOfModels) { 244 currentModel = << 425 currentModel = static_cast<G4VMscModel*>( 245 static_cast<G4VMscModel*>(SelectModel(ek << 426 SelectModel(ekin,track.GetMaterialCutsCouple()->GetIndex())); 246 } 427 } 247 currentModel->SetCurrentCouple(couple); << 248 // msc is active is model is active, energy 428 // msc is active is model is active, energy above the limit, 249 // and step size is above the limit; 429 // and step size is above the limit; 250 // if it is active msc may limit the step 430 // if it is active msc may limit the step 251 if(currentModel->IsActive(ekin) && tPathLeng 431 if(currentModel->IsActive(ekin) && tPathLength > geomMin 252 && ekin >= lowestKinEnergy) { 432 && ekin >= lowestKinEnergy) { 253 isActive = true; 433 isActive = true; 254 tPathLength = 434 tPathLength = 255 currentModel->ComputeTruePathLengthLimit 435 currentModel->ComputeTruePathLengthLimit(track, gPathLength); 256 if (tPathLength < physStepLimit) { 436 if (tPathLength < physStepLimit) { 257 *selection = CandidateForSelection; 437 *selection = CandidateForSelection; 258 } 438 } 259 } else { << 439 } else { isActive = false; } 260 isActive = false; << 261 gPathLength = DBL_MAX; << 262 } << 263 440 264 //if(currParticle->GetPDGMass() > GeV) 441 //if(currParticle->GetPDGMass() > GeV) 265 /* 442 /* 266 G4cout << "MSC::AlongStepGPIL: Ekin= " << ek 443 G4cout << "MSC::AlongStepGPIL: Ekin= " << ekin 267 << " " << currParticle->GetParticleN 444 << " " << currParticle->GetParticleName() 268 << " gPathLength= " << gPathLength 445 << " gPathLength= " << gPathLength 269 << " tPathLength= " << tPathLength 446 << " tPathLength= " << tPathLength 270 << " currentMinimalStep= " << current 447 << " currentMinimalStep= " << currentMinimalStep 271 << " isActive " << isActive << G4endl 448 << " isActive " << isActive << G4endl; 272 */ 449 */ 273 return gPathLength; 450 return gPathLength; 274 } 451 } 275 452 276 //....oooOO0OOooo........oooOO0OOooo........oo 453 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 277 454 278 G4double 455 G4double 279 G4VMultipleScattering::PostStepGetPhysicalInte 456 G4VMultipleScattering::PostStepGetPhysicalInteractionLength( 280 const G4Track&, G4double, G4Forc 457 const G4Track&, G4double, G4ForceCondition* condition) 281 { 458 { 282 *condition = NotForced; 459 *condition = NotForced; 283 return DBL_MAX; 460 return DBL_MAX; 284 } 461 } 285 462 286 //....oooOO0OOooo........oooOO0OOooo........oo 463 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 287 464 288 G4VParticleChange* 465 G4VParticleChange* 289 G4VMultipleScattering::AlongStepDoIt(const G4T 466 G4VMultipleScattering::AlongStepDoIt(const G4Track& track, const G4Step& step) 290 { 467 { 291 fParticleChange.InitialiseMSC(track, step); << 468 fParticleChange.ProposeMomentumDirection( 292 fNewPosition = fParticleChange.GetProposedPo << 469 step.GetPostStepPoint()->GetMomentumDirection()); >> 470 fNewPosition = step.GetPostStepPoint()->GetPosition(); >> 471 fParticleChange.ProposePosition(fNewPosition); 293 fPositionChanged = false; 472 fPositionChanged = false; 294 473 295 G4double geomLength = step.GetStepLength(); 474 G4double geomLength = step.GetStepLength(); 296 475 297 // very small step - no msc 476 // very small step - no msc 298 if(!isActive) { 477 if(!isActive) { 299 tPathLength = geomLength; 478 tPathLength = geomLength; 300 479 301 // sample msc 480 // sample msc 302 } else { 481 } else { 303 G4double range = 482 G4double range = 304 currentModel->GetRange(currParticle,trac 483 currentModel->GetRange(currParticle,track.GetKineticEnergy(), 305 track.GetMaterial 484 track.GetMaterialCutsCouple()); 306 485 307 tPathLength = currentModel->ComputeTrueSte 486 tPathLength = currentModel->ComputeTrueStepLength(geomLength); 308 487 309 /* 488 /* 310 if(currParticle->GetPDGMass() > 0.9*GeV) 489 if(currParticle->GetPDGMass() > 0.9*GeV) 311 G4cout << "G4VMsc::AlongStepDoIt: GeomLeng 490 G4cout << "G4VMsc::AlongStepDoIt: GeomLength= " 312 << geomLength 491 << geomLength 313 << " tPathLength= " << tPathLength 492 << " tPathLength= " << tPathLength 314 << " physStepLimit= " << physStepLi 493 << " physStepLimit= " << physStepLimit 315 << " dr= " << range - tPathLength 494 << " dr= " << range - tPathLength 316 << " ekin= " << track.GetKineticEne 495 << " ekin= " << track.GetKineticEnergy() << G4endl; 317 */ 496 */ 318 // protection against wrong t->g->t conver 497 // protection against wrong t->g->t conversion 319 tPathLength = std::min(tPathLength, physSt 498 tPathLength = std::min(tPathLength, physStepLimit); 320 499 321 // do not sample scattering at the last or 500 // do not sample scattering at the last or at a small step 322 if(tPathLength < range && tPathLength > ge 501 if(tPathLength < range && tPathLength > geomMin) { 323 502 324 static const G4double minSafety = 1.20*C 503 static const G4double minSafety = 1.20*CLHEP::nm; 325 static const G4double sFact = 0.99; 504 static const G4double sFact = 0.99; 326 505 327 G4ThreeVector displacement = currentMode 506 G4ThreeVector displacement = currentModel->SampleScattering( 328 step.GetPostStepPoint()->GetMomentumDi 507 step.GetPostStepPoint()->GetMomentumDirection(),minSafety); 329 508 330 G4double r2 = displacement.mag2(); 509 G4double r2 = displacement.mag2(); 331 //G4cout << " R= " << sqrt(r2) << " R 510 //G4cout << " R= " << sqrt(r2) << " Rmin= " << sqrt(minDisplacement2) 332 // << " flag= " << fDispBeyondSafety 511 // << " flag= " << fDispBeyondSafety << G4endl; 333 if(r2 > minDisplacement2) { 512 if(r2 > minDisplacement2) { 334 513 335 fPositionChanged = true; 514 fPositionChanged = true; 336 G4double dispR = std::sqrt(r2); << 515 G4double dispR = std::sqrt(r2); 337 G4double postSafety = 516 G4double postSafety = 338 sFact*safetyHelper->ComputeSafety(fN << 517 sFact*safetyHelper->ComputeSafety(fNewPosition, dispR); 339 //G4cout<<" R= "<< dispR<<" postSaf 518 //G4cout<<" R= "<< dispR<<" postSafety= "<<postSafety<<G4endl; 340 519 341 // far away from geometry boundary 520 // far away from geometry boundary 342 if(postSafety > 0.0 && dispR <= postSa 521 if(postSafety > 0.0 && dispR <= postSafety) { 343 fNewPosition += displacement; 522 fNewPosition += displacement; 344 523 345 //near the boundary << 524 //near the boundary 346 } else { 525 } else { 347 // displaced point is definitely wit 526 // displaced point is definitely within the volume 348 //G4cout<<" R= "<<dispR<<" postSa 527 //G4cout<<" R= "<<dispR<<" postSafety= "<<postSafety<<G4endl; 349 if(dispR < postSafety) { 528 if(dispR < postSafety) { 350 fNewPosition += displacement; 529 fNewPosition += displacement; 351 530 352 // reduced displacement << 531 // optional extra mechanism is applied only if a particle 353 } else if(postSafety > geomMin) { << 532 // is stopped by the boundary 354 fNewPosition += displacement*(post << 533 } else if(fDispBeyondSafety && 0.0 == postSafety) { >> 534 fNewPosition += displacement; >> 535 G4double maxshift = >> 536 std::min(2.0*dispR, geomLength*(physStepLimit/tPathLength - 1.0)); >> 537 G4double dist = 0.0; >> 538 G4double safety = postSafety + dispR; >> 539 fNewDirection = *(fParticleChange.GetMomentumDirection()); >> 540 /* >> 541 G4cout << "##MSC before Recheck maxshift= " << maxshift >> 542 << " postsafety= " << postSafety >> 543 << " Ekin= " << track.GetKineticEnergy() >> 544 << " " << track.GetDefinition()->GetParticleName() >> 545 << G4endl; >> 546 */ >> 547 // check if it is possible to shift to the boundary >> 548 // and the shift is not large >> 549 if(safetyHelper->RecheckDistanceToCurrentBoundary(fNewPosition, >> 550 fNewDirection, maxshift, &dist, &safety) >> 551 && std::abs(dist) < maxshift) { >> 552 /* >> 553 G4cout << "##MSC after Recheck dist= " << dist >> 554 << " postsafety= " << postSafety >> 555 << " t= " << tPathLength >> 556 << " g= " << geomLength >> 557 << " p= " << physStepLimit >> 558 << G4endl; >> 559 */ >> 560 // shift is positive >> 561 if(dist >= 0.0) { >> 562 tPathLength *= (1.0 + dist/geomLength); >> 563 fNewPosition += dist*fNewDirection; >> 564 >> 565 // shift is negative cannot be larger than geomLength >> 566 } else { >> 567 maxshift = std::min(maxshift, geomLength); >> 568 if(0.0 < maxshift + dist) { >> 569 const G4ThreeVector& postpoint = step.GetPostStepPoint()->GetPosition(); >> 570 G4ThreeVector point = fNewPosition + dist*fNewDirection; >> 571 G4double R2 = (postpoint - point).mag2(); >> 572 G4double newdist = dist; >> 573 // check not more than 10 extra boundaries >> 574 for(G4int i=0; i<10; ++i) { >> 575 dist = 0.0; >> 576 if(safetyHelper->RecheckDistanceToCurrentBoundary( >> 577 point, fNewDirection, maxshift, &dist, &safety) >> 578 && std::abs(newdist + dist) < maxshift) { >> 579 point += dist*fNewDirection; >> 580 G4double R2new = (postpoint - point).mag2(); >> 581 //G4cout << "Backward i= " << i << " dist= " << dist >> 582 // << " R2= " << R2new << G4endl; >> 583 if(dist >= 0.0 || R2new > R2) { break; } >> 584 R2 = R2new; >> 585 fNewPosition = point; >> 586 newdist += dist; >> 587 } else { >> 588 break; >> 589 } >> 590 } >> 591 tPathLength *= (1.0 + newdist/geomLength); >> 592 // shift on boundary is not possible for negative disp >> 593 } else { >> 594 fNewPosition += displacement*(postSafety/dispR - 1.0); >> 595 } >> 596 } >> 597 // shift on boundary is not possible for any disp >> 598 } else { >> 599 fNewPosition += displacement*(postSafety/dispR - 1.0); >> 600 } >> 601 // reduced displacement >> 602 } else if(postSafety > geomMin) { >> 603 fNewPosition += displacement*(postSafety/dispR); 355 604 356 // very small postSafety 605 // very small postSafety 357 } else { 606 } else { 358 fPositionChanged = false; 607 fPositionChanged = false; 359 } 608 } 360 } 609 } 361 if(fPositionChanged) { << 610 if(fPositionChanged) { 362 safetyHelper->ReLocateWithinVolume(f << 611 safetyHelper->ReLocateWithinVolume(fNewPosition); 363 fParticleChange.ProposePosition(fNew << 612 fParticleChange.ProposePosition(fNewPosition); 364 } << 613 } 365 } 614 } 366 } 615 } 367 } 616 } 368 fParticleChange.ProposeTrueStepLength(tPathL 617 fParticleChange.ProposeTrueStepLength(tPathLength); 369 return &fParticleChange; 618 return &fParticleChange; 370 } 619 } 371 620 372 //....oooOO0OOooo........oooOO0OOooo........oo 621 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 373 622 >> 623 G4VParticleChange* >> 624 G4VMultipleScattering::PostStepDoIt(const G4Track& track, const G4Step&) >> 625 { >> 626 fParticleChange.Initialize(track); >> 627 return &fParticleChange; >> 628 } >> 629 >> 630 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 631 374 G4double G4VMultipleScattering::GetContinuousS 632 G4double G4VMultipleScattering::GetContinuousStepLimit( 375 const G 633 const G4Track& track, 376 G4doubl 634 G4double previousStepSize, 377 G4doubl 635 G4double currentMinimalStep, 378 G4doubl 636 G4double& currentSafety) 379 { 637 { 380 G4GPILSelection selection = NotCandidateForS 638 G4GPILSelection selection = NotCandidateForSelection; 381 G4double x = AlongStepGetPhysicalInteraction 639 G4double x = AlongStepGetPhysicalInteractionLength(track,previousStepSize, 382 640 currentMinimalStep, 383 641 currentSafety, 384 642 &selection); 385 return x; 643 return x; 386 } 644 } 387 645 388 //....oooOO0OOooo........oooOO0OOooo........oo 646 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 389 647 390 G4double G4VMultipleScattering::ContinuousStep 648 G4double G4VMultipleScattering::ContinuousStepLimit( 391 const G 649 const G4Track& track, 392 G4doubl 650 G4double previousStepSize, 393 G4doubl 651 G4double currentMinimalStep, 394 G4doubl 652 G4double& currentSafety) 395 { 653 { 396 return GetContinuousStepLimit(track,previous 654 return GetContinuousStepLimit(track,previousStepSize,currentMinimalStep, 397 currentSafety) 655 currentSafety); 398 } 656 } 399 657 400 //....oooOO0OOooo........oooOO0OOooo........oo 658 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 401 659 402 G4double G4VMultipleScattering::GetMeanFreePat 660 G4double G4VMultipleScattering::GetMeanFreePath( 403 const G4Track&, G4double, G4Forc 661 const G4Track&, G4double, G4ForceCondition* condition) 404 { 662 { 405 *condition = Forced; 663 *condition = Forced; 406 return DBL_MAX; 664 return DBL_MAX; 407 } 665 } 408 666 409 //....oooOO0OOooo........oooOO0OOooo........oo 667 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 410 668 411 G4bool 669 G4bool 412 G4VMultipleScattering::StorePhysicsTable(const 670 G4VMultipleScattering::StorePhysicsTable(const G4ParticleDefinition* part, 413 const 671 const G4String& directory, 414 G4boo 672 G4bool ascii) 415 { 673 { 416 G4bool yes = true; 674 G4bool yes = true; 417 if(part != firstParticle || !emManager->IsMa << 675 if(part != firstParticle) { return yes; } 418 << 676 const G4VMultipleScattering* masterProcess = 419 return G4EmTableUtil::StoreMscTable(this, pa << 677 static_cast<const G4VMultipleScattering*>(GetMasterProcess()); 420 numberOfModels, verboseLevel, << 678 if(masterProcess && masterProcess != this) { return yes; } 421 ascii); << 679 >> 680 G4int nmod = modelManager->NumberOfModels(); >> 681 static const G4String ss[4] = {"1","2","3","4"}; >> 682 for(G4int i=0; i<nmod; ++i) { >> 683 G4VEmModel* msc = modelManager->GetModel(i); >> 684 yes = true; >> 685 G4PhysicsTable* table = msc->GetCrossSectionTable(); >> 686 if (table) { >> 687 G4int j = std::min(i,3); >> 688 G4String name = >> 689 GetPhysicsTableFileName(part,directory,"LambdaMod"+ss[j],ascii); >> 690 yes = table->StorePhysicsTable(name,ascii); >> 691 >> 692 if ( yes ) { >> 693 if ( verboseLevel>0 ) { >> 694 G4cout << "Physics table are stored for " >> 695 << part->GetParticleName() >> 696 << " and process " << GetProcessName() >> 697 << " with a name <" << name << "> " << G4endl; >> 698 } >> 699 } else { >> 700 G4cout << "Fail to store Physics Table for " >> 701 << part->GetParticleName() >> 702 << " and process " << GetProcessName() >> 703 << " in the directory <" << directory >> 704 << "> " << G4endl; >> 705 } >> 706 } >> 707 } >> 708 return yes; 422 } 709 } 423 710 424 //....oooOO0OOooo........oooOO0OOooo........oo 711 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 425 712 426 G4bool 713 G4bool 427 G4VMultipleScattering::RetrievePhysicsTable(co 714 G4VMultipleScattering::RetrievePhysicsTable(const G4ParticleDefinition*, 428 co 715 const G4String&, 429 G4 716 G4bool) 430 { 717 { 431 return true; 718 return true; 432 } 719 } 433 720 434 //....oooOO0OOooo........oooOO0OOooo........oo 721 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 435 722 >> 723 void G4VMultipleScattering::SetIonisation(G4VEnergyLossProcess* p) >> 724 { >> 725 for(G4int i=0; i<numberOfModels; ++i) { >> 726 G4VMscModel* msc = static_cast<G4VMscModel*>(GetModelByIndex(i, true)); >> 727 if(msc) { msc->SetIonisation(p, firstParticle); } >> 728 } >> 729 } >> 730 >> 731 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 732 436 void G4VMultipleScattering::ProcessDescription 733 void G4VMultipleScattering::ProcessDescription(std::ostream& outFile) const 437 { 734 { 438 if(nullptr != firstParticle) { << 735 if(firstParticle) { 439 StreamInfo(outFile, *firstParticle, true); << 736 StreamInfo(outFile, *firstParticle, G4String("<br>\n")); 440 } 737 } 441 } 738 } 442 739 443 //....oooOO0OOooo........oooOO0OOooo........oo 740 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 444 741 445 742