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: G4VMultipleScattering.cc 97742 2016-06-08 09:24:54Z gcosmo $ 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, G4int index) 130 { 155 { 131 if(nullptr == ptr) { return; } << 156 G4int n = mscModels.size(); 132 if(!mscModels.empty()) { << 157 if(index >= n) { for(G4int i=n; i<=index; ++i) { mscModels.push_back(0); } } 133 for(auto & msc : mscModels) { if(msc == pt << 158 mscModels[index] = p; 134 } << 159 } 135 mscModels.push_back(ptr); << 160 >> 161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 162 >> 163 G4VMscModel* G4VMultipleScattering::EmModel(G4int index) const >> 164 { >> 165 G4VMscModel* p = nullptr; >> 166 if(index >= 0 && index < G4int(mscModels.size())) { p = mscModels[index]; } >> 167 return p; >> 168 } >> 169 >> 170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 171 >> 172 G4VEmModel* >> 173 G4VMultipleScattering::GetModelByIndex(G4int idx, G4bool ver) const >> 174 { >> 175 return modelManager->GetModel(idx, ver); 136 } 176 } 137 177 138 //....oooOO0OOooo........oooOO0OOooo........oo 178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 139 179 140 void 180 void 141 G4VMultipleScattering::PreparePhysicsTable(con 181 G4VMultipleScattering::PreparePhysicsTable(const G4ParticleDefinition& part) 142 { 182 { 143 G4bool master = emManager->IsMaster(); << 183 G4bool master = true; 144 if (nullptr == firstParticle) { firstParticl << 184 const G4VMultipleScattering* masterProc = >> 185 static_cast<const G4VMultipleScattering*>(GetMasterProcess()); >> 186 if(masterProc && masterProc != this) { master = false; } >> 187 >> 188 if(!firstParticle) { firstParticle = ∂ } >> 189 if(part.GetParticleType() == "nucleus") { >> 190 stepLimit = fMinimal; >> 191 latDisplacement = false; >> 192 facrange = 0.2; >> 193 G4String pname = part.GetParticleName(); >> 194 if(pname != "deuteron" && pname != "triton" && >> 195 pname != "alpha+" && pname != "helium" && >> 196 pname != "alpha" && pname != "He3" && >> 197 pname != "hydrogen") { >> 198 >> 199 const G4ParticleDefinition* theGenericIon = >> 200 G4ParticleTable::GetParticleTable()->FindParticle("GenericIon"); >> 201 if(&part == theGenericIon) { isIon = true; } >> 202 >> 203 if(theGenericIon && firstParticle != theGenericIon) { >> 204 G4ProcessManager* pm = theGenericIon->GetProcessManager(); >> 205 G4ProcessVector* v = pm->GetAlongStepProcessVector(); >> 206 size_t n = v->size(); >> 207 for(size_t j=0; j<n; ++j) { >> 208 if((*v)[j] == this) { >> 209 firstParticle = theGenericIon; >> 210 isIon = true; >> 211 break; >> 212 } >> 213 } >> 214 } >> 215 } >> 216 } 145 217 146 emManager->PreparePhysicsTable(&part, this); << 218 emManager->PreparePhysicsTable(&part, this, master); 147 currParticle = nullptr; << 219 currParticle = 0; >> 220 >> 221 if(1 < verboseLevel) { >> 222 G4cout << "### G4VMultipleScattering::PrepearPhysicsTable() for " >> 223 << GetProcessName() >> 224 << " and particle " << part.GetParticleName() >> 225 << " local particle " << firstParticle->GetParticleName() >> 226 << " isIon= " << isIon >> 227 << G4endl; >> 228 } 148 229 149 if(firstParticle == &part) { 230 if(firstParticle == &part) { 150 baseMat = emManager->GetTableBuilder()->Ge << 151 G4EmTableUtil::PrepareMscProcess(this, par << 152 stepLimit, facrange, << 153 latDisplacement, master, << 154 isIon, baseMat); << 155 231 >> 232 // initialise process >> 233 InitialiseProcess(firstParticle); >> 234 >> 235 // heavy particles and not ions >> 236 if(!isIon) { >> 237 if(part.GetPDGMass() > MeV) { >> 238 stepLimit = theParameters->MscMuHadStepLimitType(); >> 239 facrange = theParameters->MscMuHadRangeFactor(); >> 240 latDisplacement = theParameters->MuHadLateralDisplacement(); >> 241 } else { >> 242 stepLimit = theParameters->MscStepLimitType(); >> 243 facrange = theParameters->MscRangeFactor(); >> 244 latDisplacement = theParameters->LateralDisplacement(); >> 245 } >> 246 if(latDisplacement) { >> 247 fDispBeyondSafety = theParameters->LatDisplacementBeyondSafety(); >> 248 } >> 249 } >> 250 if(master) { SetVerboseLevel(theParameters->Verbose()); } >> 251 else { SetVerboseLevel(theParameters->WorkerVerbose()); } >> 252 >> 253 // initialisation of models 156 numberOfModels = modelManager->NumberOfMod 254 numberOfModels = modelManager->NumberOfModels(); 157 currentModel = GetModelByIndex(0); << 255 /* >> 256 G4cout << "### G4VMultipleScattering::PreparePhysicsTable() for " >> 257 << GetProcessName() >> 258 << " and particle " << part.GetParticleName() >> 259 << " Nmod= " << numberOfModels << " " << this >> 260 << G4endl; >> 261 */ >> 262 for(G4int i=0; i<numberOfModels; ++i) { >> 263 G4VMscModel* msc = static_cast<G4VMscModel*>(modelManager->GetModel(i)); >> 264 msc->SetIonisation(0, firstParticle); >> 265 msc->SetMasterThread(master); >> 266 if(0 == i) { currentModel = msc; } >> 267 msc->SetStepLimitType(stepLimit); >> 268 msc->SetLateralDisplasmentFlag(latDisplacement); >> 269 msc->SetSkin(theParameters->MscSkin()); >> 270 msc->SetRangeFactor(facrange); >> 271 msc->SetGeomFactor(theParameters->MscGeomFactor()); >> 272 msc->SetPolarAngleLimit(theParameters->MscThetaLimit()); >> 273 G4double emax = >> 274 std::min(msc->HighEnergyLimit(),theParameters->MaxKinEnergy()); >> 275 msc->SetHighEnergyLimit(emax); >> 276 } 158 277 159 if (nullptr == safetyHelper) { << 278 modelManager->Initialise(firstParticle, G4Electron::Electron(), >> 279 10.0, verboseLevel); >> 280 >> 281 if(!safetyHelper) { 160 safetyHelper = G4TransportationManager:: 282 safetyHelper = G4TransportationManager::GetTransportationManager() 161 ->GetSafetyHelper(); << 283 ->GetSafetyHelper(); 162 safetyHelper->InitialiseHelper(); 284 safetyHelper->InitialiseHelper(); 163 } 285 } 164 } 286 } 165 } 287 } 166 288 167 //....oooOO0OOooo........oooOO0OOooo........oo 289 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 168 290 169 void G4VMultipleScattering::BuildPhysicsTable( 291 void G4VMultipleScattering::BuildPhysicsTable(const G4ParticleDefinition& part) 170 { 292 { 171 G4bool master = emManager->IsMaster(); << 293 G4String num = part.GetParticleName(); >> 294 if(1 < verboseLevel) { >> 295 G4cout << "### G4VMultipleScattering::BuildPhysicsTable() for " >> 296 << GetProcessName() >> 297 << " and particle " << num >> 298 << " IsMaster= " << G4LossTableManager::Instance()->IsMaster() >> 299 << G4endl; >> 300 } >> 301 G4bool master = true; >> 302 const G4VMultipleScattering* masterProcess = >> 303 static_cast<const G4VMultipleScattering*>(GetMasterProcess()); >> 304 if(masterProcess && masterProcess != this) { master = false; } 172 305 173 if(firstParticle == &part) { << 306 if(firstParticle == &part) { 174 emManager->BuildPhysicsTable(&part); << 307 /* 175 } << 308 G4cout << "### G4VMultipleScattering::BuildPhysicsTable() for " 176 const G4VMultipleScattering* ptr = this; << 309 << GetProcessName() 177 if(!master) { << 310 << " and particle " << num 178 ptr = static_cast<const G4VMultipleScatter << 311 << " IsMaster= " << G4LossTableManager::Instance()->IsMaster() >> 312 << " " << this >> 313 << G4endl; >> 314 */ >> 315 emManager->BuildPhysicsTable(firstParticle); >> 316 >> 317 if(!master) { >> 318 // initialisation of models >> 319 G4bool printing = true; >> 320 numberOfModels = modelManager->NumberOfModels(); >> 321 /* >> 322 G4cout << "### G4VMultipleScattering::BuildPhysicsTable() for " >> 323 << GetProcessName() >> 324 << " and particle " << num >> 325 << " Nmod= " << numberOfModels << " " << this >> 326 << G4endl; >> 327 */ >> 328 for(G4int i=0; i<numberOfModels; ++i) { >> 329 G4VMscModel* msc = >> 330 static_cast<G4VMscModel*>(GetModelByIndex(i, printing)); >> 331 G4VMscModel* msc0= >> 332 static_cast<G4VMscModel*>(masterProcess->GetModelByIndex(i,printing)); >> 333 msc->SetCrossSectionTable(msc0->GetCrossSectionTable(), false); >> 334 msc->InitialiseLocal(firstParticle, msc0); >> 335 } >> 336 } 179 } 337 } 180 338 181 G4EmTableUtil::BuildMscProcess(this, ptr, pa << 339 // explicitly defined printout by particle name 182 numberOfModels, master); << 340 if(1 < verboseLevel || >> 341 (0 < verboseLevel && (num == "e-" || >> 342 num == "e+" || num == "mu+" || >> 343 num == "mu-" || num == "proton"|| >> 344 num == "pi+" || num == "pi-" || >> 345 num == "kaon+" || num == "kaon-" || >> 346 num == "alpha" || num == "anti_proton" || >> 347 num == "GenericIon"))) >> 348 { >> 349 G4cout << G4endl << GetProcessName() >> 350 << ": for " << num >> 351 << " SubType= " << GetProcessSubType() >> 352 << G4endl; >> 353 PrintInfo(); >> 354 modelManager->DumpModelList(verboseLevel); >> 355 } >> 356 >> 357 if(1 < verboseLevel) { >> 358 G4cout << "### G4VMultipleScattering::BuildPhysicsTable() done for " >> 359 << GetProcessName() >> 360 << " and particle " << num >> 361 << G4endl; >> 362 } 183 } 363 } 184 364 185 //....oooOO0OOooo........oooOO0OOooo........oo 365 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 186 366 187 void G4VMultipleScattering::StreamInfo(std::os << 367 void G4VMultipleScattering::PrintInfoDefinition() 188 const G4ParticleDefinition& << 189 { 368 { 190 G4String indent = (rst ? " " : ""); << 369 if (0 < verboseLevel) { 191 outFile << G4endl << indent << GetProcessNam << 370 G4cout << G4endl << GetProcessName() 192 if (!rst) outFile << " for " << part.GetPart << 371 << ": for " << firstParticle->GetParticleName() 193 outFile << " SubType= " << GetProcessSubTy << 372 << " SubType= " << GetProcessSubType() 194 modelManager->DumpModelList(outFile, verbose << 373 << G4endl; >> 374 PrintInfo(); >> 375 modelManager->DumpModelList(verboseLevel); >> 376 } 195 } 377 } 196 378 197 //....oooOO0OOooo........oooOO0OOooo........oo 379 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 198 380 199 void G4VMultipleScattering::StartTracking(G4Tr 381 void G4VMultipleScattering::StartTracking(G4Track* track) 200 { 382 { 201 G4VEnergyLossProcess* eloss = nullptr; 383 G4VEnergyLossProcess* eloss = nullptr; 202 if(track->GetParticleDefinition() != currPar 384 if(track->GetParticleDefinition() != currParticle) { 203 currParticle = track->GetParticleDefinitio 385 currParticle = track->GetParticleDefinition(); 204 fIonisation = emManager->GetEnergyLossProc 386 fIonisation = emManager->GetEnergyLossProcess(currParticle); 205 eloss = fIonisation; 387 eloss = fIonisation; 206 } 388 } 207 for(G4int i=0; i<numberOfModels; ++i) { << 389 /* 208 G4VMscModel* msc = GetModelByIndex(i); << 390 G4cout << "G4VMultipleScattering::StartTracking Nmod= " << numberOfModels 209 msc->StartTracking(track); << 391 << " " << currParticle->GetParticleName() 210 if(nullptr != eloss) { << 392 << " E(MeV)= " << track->GetKineticEnergy() 211 msc->SetIonisation(eloss, currParticle); << 393 << " Ion= " << eloss << " " << fIonisation << " IsMaster= " >> 394 << G4LossTableManager::Instance()->IsMaster() >> 395 << G4endl; >> 396 */ >> 397 // one model >> 398 if(1 == numberOfModels) { >> 399 currentModel->StartTracking(track); >> 400 if(eloss) { currentModel->SetIonisation(fIonisation, currParticle); } >> 401 >> 402 // many models >> 403 } else { >> 404 for(G4int i=0; i<numberOfModels; ++i) { >> 405 G4VMscModel* msc = static_cast<G4VMscModel*>(GetModelByIndex(i,true)); >> 406 msc->StartTracking(track); >> 407 if(eloss) { msc->SetIonisation(fIonisation, currParticle); } 212 } 408 } 213 } 409 } 214 } << 410 } 215 411 216 //....oooOO0OOooo........oooOO0OOooo........oo 412 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 217 413 218 G4double G4VMultipleScattering::AlongStepGetPh 414 G4double G4VMultipleScattering::AlongStepGetPhysicalInteractionLength( 219 const G4Track& tr 415 const G4Track& track, 220 G4double, 416 G4double, 221 G4double currentM 417 G4double currentMinimalStep, 222 G4double&, 418 G4double&, 223 G4GPILSelection* 419 G4GPILSelection* selection) 224 { 420 { 225 // get Step limit proposed by the process 421 // get Step limit proposed by the process 226 *selection = NotCandidateForSelection; 422 *selection = NotCandidateForSelection; 227 physStepLimit = gPathLength = tPathLength = 423 physStepLimit = gPathLength = tPathLength = currentMinimalStep; 228 424 229 G4double ekin = track.GetKineticEnergy(); 425 G4double ekin = track.GetKineticEnergy(); 230 /* 426 /* 231 G4cout << "MSC::AlongStepGPIL: Ekin= " << ek 427 G4cout << "MSC::AlongStepGPIL: Ekin= " << ekin 232 << " " << currParticle->GetParticleN 428 << " " << currParticle->GetParticleName() 233 << " currMod " << currentModel 429 << " currMod " << currentModel 234 << G4endl; 430 << G4endl; 235 */ 431 */ 236 // isIon flag is used only to select a model 432 // isIon flag is used only to select a model 237 if(isIon) { 433 if(isIon) { 238 ekin *= proton_mass_c2/track.GetParticleDe 434 ekin *= proton_mass_c2/track.GetParticleDefinition()->GetPDGMass(); 239 } 435 } 240 const G4MaterialCutsCouple* couple = track.G << 241 436 242 // select new model, static cast is possible << 437 // select new model 243 if(1 < numberOfModels) { 438 if(1 < numberOfModels) { 244 currentModel = << 439 currentModel = static_cast<G4VMscModel*>( 245 static_cast<G4VMscModel*>(SelectModel(ek << 440 SelectModel(ekin,track.GetMaterialCutsCouple()->GetIndex())); 246 } 441 } 247 currentModel->SetCurrentCouple(couple); << 248 // msc is active is model is active, energy 442 // msc is active is model is active, energy above the limit, 249 // and step size is above the limit; 443 // and step size is above the limit; 250 // if it is active msc may limit the step 444 // if it is active msc may limit the step 251 if(currentModel->IsActive(ekin) && tPathLeng 445 if(currentModel->IsActive(ekin) && tPathLength > geomMin 252 && ekin >= lowestKinEnergy) { 446 && ekin >= lowestKinEnergy) { 253 isActive = true; 447 isActive = true; 254 tPathLength = 448 tPathLength = 255 currentModel->ComputeTruePathLengthLimit 449 currentModel->ComputeTruePathLengthLimit(track, gPathLength); 256 if (tPathLength < physStepLimit) { 450 if (tPathLength < physStepLimit) { 257 *selection = CandidateForSelection; 451 *selection = CandidateForSelection; 258 } 452 } 259 } else { << 453 } else { isActive = false; } 260 isActive = false; << 261 gPathLength = DBL_MAX; << 262 } << 263 454 264 //if(currParticle->GetPDGMass() > GeV) 455 //if(currParticle->GetPDGMass() > GeV) 265 /* 456 /* 266 G4cout << "MSC::AlongStepGPIL: Ekin= " << ek 457 G4cout << "MSC::AlongStepGPIL: Ekin= " << ekin 267 << " " << currParticle->GetParticleN 458 << " " << currParticle->GetParticleName() 268 << " gPathLength= " << gPathLength 459 << " gPathLength= " << gPathLength 269 << " tPathLength= " << tPathLength 460 << " tPathLength= " << tPathLength 270 << " currentMinimalStep= " << current 461 << " currentMinimalStep= " << currentMinimalStep 271 << " isActive " << isActive << G4endl 462 << " isActive " << isActive << G4endl; 272 */ 463 */ 273 return gPathLength; 464 return gPathLength; 274 } 465 } 275 466 276 //....oooOO0OOooo........oooOO0OOooo........oo 467 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 277 468 278 G4double 469 G4double 279 G4VMultipleScattering::PostStepGetPhysicalInte 470 G4VMultipleScattering::PostStepGetPhysicalInteractionLength( 280 const G4Track&, G4double, G4Forc 471 const G4Track&, G4double, G4ForceCondition* condition) 281 { 472 { >> 473 //*condition = Forced; 282 *condition = NotForced; 474 *condition = NotForced; 283 return DBL_MAX; 475 return DBL_MAX; 284 } 476 } 285 477 286 //....oooOO0OOooo........oooOO0OOooo........oo 478 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 287 479 288 G4VParticleChange* 480 G4VParticleChange* 289 G4VMultipleScattering::AlongStepDoIt(const G4T 481 G4VMultipleScattering::AlongStepDoIt(const G4Track& track, const G4Step& step) 290 { 482 { 291 fParticleChange.InitialiseMSC(track, step); << 483 fParticleChange.ProposeMomentumDirection( 292 fNewPosition = fParticleChange.GetProposedPo << 484 step.GetPostStepPoint()->GetMomentumDirection()); >> 485 fNewPosition = step.GetPostStepPoint()->GetPosition(); >> 486 fParticleChange.ProposePosition(fNewPosition); 293 fPositionChanged = false; 487 fPositionChanged = false; 294 488 295 G4double geomLength = step.GetStepLength(); 489 G4double geomLength = step.GetStepLength(); 296 490 297 // very small step - no msc 491 // very small step - no msc 298 if(!isActive) { 492 if(!isActive) { 299 tPathLength = geomLength; 493 tPathLength = geomLength; 300 494 301 // sample msc 495 // sample msc 302 } else { 496 } else { 303 G4double range = 497 G4double range = 304 currentModel->GetRange(currParticle,trac 498 currentModel->GetRange(currParticle,track.GetKineticEnergy(), 305 track.GetMaterial 499 track.GetMaterialCutsCouple()); 306 500 307 tPathLength = currentModel->ComputeTrueSte 501 tPathLength = currentModel->ComputeTrueStepLength(geomLength); 308 502 309 /* 503 /* 310 if(currParticle->GetPDGMass() > 0.9*GeV) 504 if(currParticle->GetPDGMass() > 0.9*GeV) 311 G4cout << "G4VMsc::AlongStepDoIt: GeomLeng 505 G4cout << "G4VMsc::AlongStepDoIt: GeomLength= " 312 << geomLength 506 << geomLength 313 << " tPathLength= " << tPathLength 507 << " tPathLength= " << tPathLength 314 << " physStepLimit= " << physStepLi 508 << " physStepLimit= " << physStepLimit 315 << " dr= " << range - tPathLength 509 << " dr= " << range - tPathLength 316 << " ekin= " << track.GetKineticEne 510 << " ekin= " << track.GetKineticEnergy() << G4endl; 317 */ 511 */ 318 // protection against wrong t->g->t conver 512 // protection against wrong t->g->t conversion 319 tPathLength = std::min(tPathLength, physSt 513 tPathLength = std::min(tPathLength, physStepLimit); 320 514 321 // do not sample scattering at the last or 515 // do not sample scattering at the last or at a small step 322 if(tPathLength < range && tPathLength > ge 516 if(tPathLength < range && tPathLength > geomMin) { 323 517 324 static const G4double minSafety = 1.20*C 518 static const G4double minSafety = 1.20*CLHEP::nm; 325 static const G4double sFact = 0.99; 519 static const G4double sFact = 0.99; 326 520 327 G4ThreeVector displacement = currentMode 521 G4ThreeVector displacement = currentModel->SampleScattering( 328 step.GetPostStepPoint()->GetMomentumDi 522 step.GetPostStepPoint()->GetMomentumDirection(),minSafety); 329 523 330 G4double r2 = displacement.mag2(); 524 G4double r2 = displacement.mag2(); 331 //G4cout << " R= " << sqrt(r2) << " R 525 //G4cout << " R= " << sqrt(r2) << " Rmin= " << sqrt(minDisplacement2) 332 // << " flag= " << fDispBeyondSafety 526 // << " flag= " << fDispBeyondSafety << G4endl; 333 if(r2 > minDisplacement2) { 527 if(r2 > minDisplacement2) { 334 528 335 fPositionChanged = true; 529 fPositionChanged = true; 336 G4double dispR = std::sqrt(r2); << 530 G4double dispR = std::sqrt(r2); 337 G4double postSafety = 531 G4double postSafety = 338 sFact*safetyHelper->ComputeSafety(fN << 532 sFact*safetyHelper->ComputeSafety(fNewPosition, dispR); 339 //G4cout<<" R= "<< dispR<<" postSaf 533 //G4cout<<" R= "<< dispR<<" postSafety= "<<postSafety<<G4endl; 340 534 341 // far away from geometry boundary 535 // far away from geometry boundary 342 if(postSafety > 0.0 && dispR <= postSa 536 if(postSafety > 0.0 && dispR <= postSafety) { 343 fNewPosition += displacement; 537 fNewPosition += displacement; 344 538 345 //near the boundary << 539 //near the boundary 346 } else { 540 } else { 347 // displaced point is definitely wit 541 // displaced point is definitely within the volume 348 //G4cout<<" R= "<<dispR<<" postSa 542 //G4cout<<" R= "<<dispR<<" postSafety= "<<postSafety<<G4endl; 349 if(dispR < postSafety) { 543 if(dispR < postSafety) { 350 fNewPosition += displacement; 544 fNewPosition += displacement; 351 545 352 // reduced displacement << 546 // optional extra mechanism is applied only if a particle 353 } else if(postSafety > geomMin) { << 547 // is stopped by the boundary 354 fNewPosition += displacement*(post << 548 } else if(fDispBeyondSafety && 0.0 == postSafety) { >> 549 fNewPosition += displacement; >> 550 G4double maxshift = >> 551 std::min(2.0*dispR, geomLength*(physStepLimit/tPathLength - 1.0)); >> 552 G4double dist = 0.0; >> 553 G4double safety = postSafety + dispR; >> 554 fNewDirection = *(fParticleChange.GetMomentumDirection()); >> 555 /* >> 556 G4cout << "##MSC before Recheck maxshift= " << maxshift >> 557 << " postsafety= " << postSafety >> 558 << " Ekin= " << track.GetKineticEnergy() >> 559 << " " << track.GetDefinition()->GetParticleName() >> 560 << G4endl; >> 561 */ >> 562 // check if it is possible to shift to the boundary >> 563 // and the shift is not large >> 564 if(safetyHelper->RecheckDistanceToCurrentBoundary(fNewPosition, >> 565 fNewDirection, maxshift, &dist, &safety) >> 566 && std::abs(dist) < maxshift) { >> 567 /* >> 568 G4cout << "##MSC after Recheck dist= " << dist >> 569 << " postsafety= " << postSafety >> 570 << " t= " << tPathLength >> 571 << " g= " << geomLength >> 572 << " p= " << physStepLimit >> 573 << G4endl; >> 574 */ >> 575 // shift is positive >> 576 if(dist >= 0.0) { >> 577 tPathLength *= (1.0 + dist/geomLength); >> 578 fNewPosition += dist*fNewDirection; >> 579 >> 580 // shift is negative cannot be larger than geomLength >> 581 } else { >> 582 maxshift = std::min(maxshift, geomLength); >> 583 if(0.0 < maxshift + dist) { >> 584 G4ThreeVector postpoint = step.GetPostStepPoint()->GetPosition(); >> 585 G4ThreeVector point = fNewPosition + dist*fNewDirection; >> 586 G4double R2 = (postpoint - point).mag2(); >> 587 G4double newdist = dist; >> 588 // check not more than 10 extra boundaries >> 589 for(G4int i=0; i<10; ++i) { >> 590 dist = 0.0; >> 591 if(safetyHelper->RecheckDistanceToCurrentBoundary( >> 592 point, fNewDirection, maxshift, &dist, &safety) >> 593 && std::abs(newdist + dist) < maxshift) { >> 594 point += dist*fNewDirection; >> 595 G4double R2new = (postpoint - point).mag2(); >> 596 //G4cout << "Backward i= " << i << " dist= " << dist >> 597 // << " R2= " << R2new << G4endl; >> 598 if(dist >= 0.0 || R2new > R2) { break; } >> 599 R2 = R2new; >> 600 fNewPosition = point; >> 601 newdist += dist; >> 602 } else { >> 603 break; >> 604 } >> 605 } >> 606 tPathLength *= (1.0 + newdist/geomLength); >> 607 // shift on boundary is not possible for negative disp >> 608 } else { >> 609 fNewPosition += displacement*(postSafety/dispR - 1.0); >> 610 } >> 611 } >> 612 // shift on boundary is not possible for any disp >> 613 } else { >> 614 fNewPosition += displacement*(postSafety/dispR - 1.0); >> 615 } >> 616 // reduced displacement >> 617 } else if(postSafety > geomMin) { >> 618 fNewPosition += displacement*(postSafety/dispR); 355 619 356 // very small postSafety 620 // very small postSafety 357 } else { 621 } else { 358 fPositionChanged = false; 622 fPositionChanged = false; 359 } 623 } 360 } 624 } 361 if(fPositionChanged) { << 625 if(fPositionChanged) { 362 safetyHelper->ReLocateWithinVolume(f << 626 safetyHelper->ReLocateWithinVolume(fNewPosition); 363 fParticleChange.ProposePosition(fNew << 627 fParticleChange.ProposePosition(fNewPosition); 364 } << 628 } 365 } 629 } 366 } 630 } 367 } 631 } 368 fParticleChange.ProposeTrueStepLength(tPathL 632 fParticleChange.ProposeTrueStepLength(tPathLength); 369 return &fParticleChange; 633 return &fParticleChange; 370 } 634 } 371 635 372 //....oooOO0OOooo........oooOO0OOooo........oo 636 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 373 637 >> 638 G4VParticleChange* >> 639 G4VMultipleScattering::PostStepDoIt(const G4Track& track, const G4Step&) >> 640 { >> 641 fParticleChange.Initialize(track); >> 642 return &fParticleChange; >> 643 } >> 644 >> 645 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 646 374 G4double G4VMultipleScattering::GetContinuousS 647 G4double G4VMultipleScattering::GetContinuousStepLimit( 375 const G 648 const G4Track& track, 376 G4doubl 649 G4double previousStepSize, 377 G4doubl 650 G4double currentMinimalStep, 378 G4doubl 651 G4double& currentSafety) 379 { 652 { 380 G4GPILSelection selection = NotCandidateForS 653 G4GPILSelection selection = NotCandidateForSelection; 381 G4double x = AlongStepGetPhysicalInteraction 654 G4double x = AlongStepGetPhysicalInteractionLength(track,previousStepSize, 382 655 currentMinimalStep, 383 656 currentSafety, 384 657 &selection); 385 return x; 658 return x; 386 } 659 } 387 660 388 //....oooOO0OOooo........oooOO0OOooo........oo 661 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 389 662 390 G4double G4VMultipleScattering::ContinuousStep 663 G4double G4VMultipleScattering::ContinuousStepLimit( 391 const G 664 const G4Track& track, 392 G4doubl 665 G4double previousStepSize, 393 G4doubl 666 G4double currentMinimalStep, 394 G4doubl 667 G4double& currentSafety) 395 { 668 { 396 return GetContinuousStepLimit(track,previous 669 return GetContinuousStepLimit(track,previousStepSize,currentMinimalStep, 397 currentSafety) 670 currentSafety); 398 } 671 } 399 672 400 //....oooOO0OOooo........oooOO0OOooo........oo 673 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 401 674 402 G4double G4VMultipleScattering::GetMeanFreePat 675 G4double G4VMultipleScattering::GetMeanFreePath( 403 const G4Track&, G4double, G4Forc 676 const G4Track&, G4double, G4ForceCondition* condition) 404 { 677 { 405 *condition = Forced; 678 *condition = Forced; 406 return DBL_MAX; 679 return DBL_MAX; 407 } 680 } 408 681 409 //....oooOO0OOooo........oooOO0OOooo........oo 682 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 410 683 411 G4bool 684 G4bool 412 G4VMultipleScattering::StorePhysicsTable(const 685 G4VMultipleScattering::StorePhysicsTable(const G4ParticleDefinition* part, 413 const 686 const G4String& directory, 414 G4boo 687 G4bool ascii) 415 { 688 { 416 G4bool yes = true; 689 G4bool yes = true; 417 if(part != firstParticle || !emManager->IsMa << 690 if(part != firstParticle) { return yes; } 418 << 691 const G4VMultipleScattering* masterProcess = 419 return G4EmTableUtil::StoreMscTable(this, pa << 692 static_cast<const G4VMultipleScattering*>(GetMasterProcess()); 420 numberOfModels, verboseLevel, << 693 if(masterProcess && masterProcess != this) { return yes; } 421 ascii); << 694 >> 695 G4int nmod = modelManager->NumberOfModels(); >> 696 static const G4String ss[4] = {"1","2","3","4"}; >> 697 for(G4int i=0; i<nmod; ++i) { >> 698 G4VEmModel* msc = modelManager->GetModel(i); >> 699 yes = true; >> 700 G4PhysicsTable* table = msc->GetCrossSectionTable(); >> 701 if (table) { >> 702 G4int j = std::min(i,3); >> 703 G4String name = >> 704 GetPhysicsTableFileName(part,directory,"LambdaMod"+ss[j],ascii); >> 705 yes = table->StorePhysicsTable(name,ascii); >> 706 >> 707 if ( yes ) { >> 708 if ( verboseLevel>0 ) { >> 709 G4cout << "Physics table are stored for " >> 710 << part->GetParticleName() >> 711 << " and process " << GetProcessName() >> 712 << " with a name <" << name << "> " << G4endl; >> 713 } >> 714 } else { >> 715 G4cout << "Fail to store Physics Table for " >> 716 << part->GetParticleName() >> 717 << " and process " << GetProcessName() >> 718 << " in the directory <" << directory >> 719 << "> " << G4endl; >> 720 } >> 721 } >> 722 } >> 723 return yes; 422 } 724 } 423 725 424 //....oooOO0OOooo........oooOO0OOooo........oo 726 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 425 727 426 G4bool 728 G4bool 427 G4VMultipleScattering::RetrievePhysicsTable(co 729 G4VMultipleScattering::RetrievePhysicsTable(const G4ParticleDefinition*, 428 co 730 const G4String&, 429 G4 731 G4bool) 430 { 732 { 431 return true; 733 return true; 432 } 734 } 433 735 434 //....oooOO0OOooo........oooOO0OOooo........oo 736 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 435 737 436 void G4VMultipleScattering::ProcessDescription << 738 void G4VMultipleScattering::SetIonisation(G4VEnergyLossProcess* p) 437 { 739 { 438 if(nullptr != firstParticle) { << 740 for(G4int i=0; i<numberOfModels; ++i) { 439 StreamInfo(outFile, *firstParticle, true); << 741 G4VMscModel* msc = static_cast<G4VMscModel*>(GetModelByIndex(i, true)); >> 742 msc->SetIonisation(p, firstParticle); 440 } 743 } >> 744 } >> 745 >> 746 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... >> 747 >> 748 void G4VMultipleScattering::ProcessDescription(std::ostream& outFile) const >> 749 { >> 750 outFile << "Multiple scattering process <" << GetProcessName() >> 751 << ">" << G4endl; 441 } 752 } 442 753 443 //....oooOO0OOooo........oooOO0OOooo........oo 754 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 444 755 445 756