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