Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // G4ImportanceProcess 27 // 28 // Author: Michael Dressel, 2002 29 // ------------------------------------------- 30 31 #include "G4ImportanceProcess.hh" 32 #include "G4VImportanceAlgorithm.hh" 33 #include "G4GeometryCell.hh" 34 #include "G4SamplingPostStepAction.hh" 35 #include "G4VTrackTerminator.hh" 36 #include "G4VIStore.hh" 37 38 #include "G4Step.hh" 39 #include "G4Navigator.hh" 40 #include "G4VTouchable.hh" 41 #include "G4VPhysicalVolume.hh" 42 #include "G4ParticleChange.hh" 43 #include "G4PathFinder.hh" 44 #include "G4TransportationManager.hh" 45 #include "G4StepPoint.hh" 46 #include "G4FieldTrackUpdator.hh" 47 48 49 G4ImportanceProcess:: 50 G4ImportanceProcess(const G4VImportanceAlgorit 51 const G4VIStore &aIstore, 52 const G4VTrackTerminator * 53 const G4String &aName, G4b 54 : G4VProcess(aName, fParallel), 55 fParticleChange(new G4ParticleChange), 56 fImportanceAlgorithm(aImportanceAlgorithm), 57 fIStore(aIstore), 58 fParaflag(para) 59 { 60 G4cout << "### G4ImportanceProcess:: Creatin 61 if (TrackTerminator != nullptr) 62 { 63 fPostStepAction = new G4SamplingPostStepAc 64 } 65 else 66 { 67 fPostStepAction = new G4SamplingPostStepAc 68 } 69 if (fParticleChange == nullptr) 70 { 71 G4Exception("G4ImportanceProcess::G4Import 72 "FatalError", FatalException, 73 "Failed allocation of G4Partic 74 } 75 G4VProcess::pParticleChange = fParticleChang 76 77 78 fGhostStep = new G4Step(); 79 fGhostPreStepPoint = fGhostStep->GetPreStepP 80 fGhostPostStepPoint = fGhostStep->GetPostSte 81 82 fTransportationManager = G4TransportationMan 83 fPathFinder = G4PathFinder::GetInstance(); 84 85 if (verboseLevel>0) 86 { 87 G4cout << GetProcessName() << " is created 88 } 89 90 G4cout << "G4ImportanceProcess:: importance 91 92 } 93 94 G4ImportanceProcess::~G4ImportanceProcess() 95 { 96 delete fPostStepAction; 97 delete fParticleChange; 98 } 99 100 //-------------------------------------------- 101 // 102 // SetParallelWorld 103 // 104 //-------------------------------------------- 105 void G4ImportanceProcess::SetParallelWorld(con 106 { 107 G4cout << G4endl << G4endl << G4endl; 108 G4cout << "G4ImportanceProcess:: SetParallel 109 //++++++++++++++++++++++++++++++++++++++++++++ 110 // Get pointers of the parallel world and its 111 //++++++++++++++++++++++++++++++++++++++++++++ 112 fGhostWorldName = parallelWorldName; 113 fGhostWorld = fTransportationManager->GetPar 114 fGhostNavigator = fTransportationManager->Ge 115 //++++++++++++++++++++++++++++++++++++++++++++ 116 } 117 118 //-------------------------------------------- 119 // 120 // StartTracking 121 // 122 //-------------------------------------------- 123 void G4ImportanceProcess::StartTracking(G4Trac 124 { 125 //++++++++++++++++++++++++++++++++++++++++++++ 126 // Activate navigator and get the navigator ID 127 //++++++++++++++++++++++++++++++++++++++++++++ 128 129 if(fParaflag) 130 { 131 if(fGhostNavigator != nullptr) 132 { 133 fNavigatorID = fTransportationManager->A 134 } 135 else 136 { 137 G4Exception("G4ImportanceProcess::StartT 138 "ProcParaWorld000",FatalExce 139 "G4ImportanceProcess is used 140 } 141 142 //++++++++++++++++++++++++++++++++++++++++++++ 143 // Let PathFinder initialize 144 //++++++++++++++++++++++++++++++++++++++++++++ 145 fPathFinder->PrepareNewTrack(trk->GetPosit 146 147 //++++++++++++++++++++++++++++++++++++++++++++ 148 // Setup initial touchables for the first step 149 //++++++++++++++++++++++++++++++++++++++++++++ 150 fOldGhostTouchable = fPathFinder->CreateTo 151 fGhostPreStepPoint->SetTouchableHandle(fOl 152 fNewGhostTouchable = fOldGhostTouchable; 153 fGhostPostStepPoint->SetTouchableHandle(fN 154 155 // Initialize 156 fGhostSafety = -1.; 157 fOnBoundary = false; 158 } 159 } 160 161 G4double G4ImportanceProcess:: 162 PostStepGetPhysicalInteractionLength(const G4T 163 G4ForceCo 164 { 165 *condition = Forced; 166 return DBL_MAX; 167 } 168 169 G4VParticleChange * 170 G4ImportanceProcess::PostStepDoIt(const G4Trac 171 const G4 172 { 173 fParticleChange->Initialize(aTrack); 174 175 if(aTrack.GetNextVolume() == nullptr) 176 { 177 return fParticleChange; 178 } 179 180 if(fParaflag) 181 { 182 fOldGhostTouchable = fGhostPostStepPoint-> 183 //xbug? fOnBoundary = false; 184 CopyStep(aStep); 185 186 if(fOnBoundary) 187 { 188 //++++++++++++++++++++++++++++++++++++++++++++ 189 // Locate the point and get new touchable 190 //++++++++++++++++++++++++++++++++++++++++++++ 191 //?? fPathFinder->Locate(step.GetPostStepPo 192 //?? step.GetPostStepPo 193 fNewGhostTouchable = fPathFinder->CreateTouc 194 } 195 else 196 { 197 // reuse the touchable 198 fNewGhostTouchable = fOldGhostTouchable; 199 } 200 201 fGhostPreStepPoint->SetTouchableHandle(fOl 202 fGhostPostStepPoint->SetTouchableHandle(fN 203 204 if ( (fGhostPostStepPoint->GetStepStatus() 205 && (aStep.GetStepLength() > kCarTolerance) 206 { 207 if (aTrack.GetTrackStatus()==fStopAndKil 208 { 209 G4cout << "WARNING - G4ImportanceProce 210 << " StopAndKill track 211 } 212 213 G4GeometryCell prekey(*(fGhostPreStepPoi 214 fGhostPreStepPoint 215 G4GeometryCell postkey(*(fGhostPostStepP 216 fGhostPostStepPoi 217 218 G4Nsplit_Weight nw = 219 fImportanceAlgorithm.Calculate(fISto 220 fIStore.GetImport 221 aTrack.GetWeight( 222 fPostStepAction->DoIt(aTrack, fParticleC 223 } 224 } 225 else 226 { 227 if ( (aStep.GetPostStepPoint()->GetStepSta 228 && (aStep.GetStepLength() > kCarToler 229 { 230 if (aTrack.GetTrackStatus()==fStopAndKil 231 { 232 G4cout << "WARNING - G4ImportanceProce 233 << " StopAndKill track 234 << G4endl; 235 } 236 237 G4StepPoint *prepoint = aStep.GetPreSte 238 G4StepPoint *postpoint = aStep.GetPostSt 239 240 G4GeometryCell prekey(*(prepoint->GetPhy 241 prepoint->GetTouch 242 G4GeometryCell postkey(*(postpoint->GetP 243 postpoint->GetTou 244 245 G4Nsplit_Weight nw = 246 fImportanceAlgorithm.Calculate(fISto 247 fISto 248 aTrac 249 fPostStepAction->DoIt(aTrack, fParticleChang 250 } 251 } 252 return fParticleChange; 253 } 254 255 void G4ImportanceProcess::KillTrack() const 256 { 257 fParticleChange->ProposeTrackStatus(fStopAnd 258 } 259 260 const G4String& G4ImportanceProcess::GetName() 261 { 262 return theProcessName; 263 } 264 265 G4double G4ImportanceProcess:: 266 AlongStepGetPhysicalInteractionLength( 267 const G4Track& track, G4do 268 G4double currentMinimumSte 269 G4double& proposedSafety, 270 { 271 if(fParaflag) 272 { 273 *selection = NotCandidateForSelection; 274 G4double returnedStep = DBL_MAX; 275 276 if (previousStepSize > 0.) 277 { fGhostSafety -= previousStepSize; } 278 // else 279 // { fGhostSafety = -1.; } 280 if (fGhostSafety < 0.) { fGhostSafety = 0. 281 282 // --------------------------------------- 283 // Determination of the proposed STEP LENG 284 // --------------------------------------- 285 if (currentMinimumStep <= fGhostSafety && 286 { 287 // I have no chance to limit 288 returnedStep = currentMinimumStep; 289 fOnBoundary = false; 290 proposedSafety = fGhostSafety - currentM 291 } 292 else // (currentMinimumStep > fGhostSafety 293 { 294 G4FieldTrackUpdator::Update(&fFieldTrack 295 //++++++++++++++++++++++++++++++++++++++ 296 // ComputeStep 297 //++++++++++++++++++++++++++++++++++++++ 298 returnedStep 299 = fPathFinder->ComputeStep(fFieldTrack,cur 300 track.Get 301 fEndTrack 302 //++++++++++++++++++++++++++++++++++++++ 303 if(feLimited == kDoNot) 304 { 305 // Track is not on the boundary 306 fOnBoundary = false; 307 fGhostSafety = fGhostNavigator->Comput 308 } 309 else 310 { 311 // Track is on the boundary 312 fOnBoundary = true; 313 } 314 proposedSafety = fGhostSafety; 315 if(feLimited == kUnique || feLimited == 316 { 317 *selection = CandidateForSelection; 318 } 319 else if (feLimited == kSharedTransport) 320 { 321 returnedStep *= (1.0 + 1.0e-9); 322 // Expand to disable its selection in 323 } 324 } 325 326 // --------------------------------------- 327 // Returns the fGhostSafety as the propose 328 // The SteppingManager will take care of k 329 // the smallest one. 330 // --------------------------------------- 331 return returnedStep; 332 } 333 else 334 { 335 return DBL_MAX; 336 } 337 } 338 339 G4double G4ImportanceProcess:: 340 AtRestGetPhysicalInteractionLength(const G4Tra 341 G4ForceCond 342 { 343 return -1.0; 344 } 345 346 G4VParticleChange* G4ImportanceProcess:: 347 AtRestDoIt(const G4Track&, const G4Step&) 348 { 349 return nullptr; 350 } 351 352 G4VParticleChange* G4ImportanceProcess:: 353 AlongStepDoIt(const G4Track& aTrack, const G4S 354 { 355 // Dummy ParticleChange ie: does nothing 356 // Expecting G4Transportation to move the tr 357 pParticleChange->Initialize(aTrack); 358 return pParticleChange; 359 } 360 361 void G4ImportanceProcess::CopyStep(const G4Ste 362 { 363 fGhostStep->SetTrack(step.GetTrack()); 364 fGhostStep->SetStepLength(step.GetStepLength 365 fGhostStep->SetTotalEnergyDeposit(step.GetTo 366 fGhostStep->SetControlFlag(step.GetControlFl 367 368 *fGhostPreStepPoint = *(step.GetPreStepPoint 369 *fGhostPostStepPoint = *(step.GetPostStepPoi 370 371 //++++++++++++++++++++++++++++++++++++++++++++ 372 // Set StepStatus for ghost world 373 //++++++++++++++++++++++++++++++++++++++++++++ 374 if(fOnBoundary) 375 { fGhostPostStepPoint->SetStepStatus(fGeomBo 376 else if(fGhostPostStepPoint->GetStepStatus() 377 { fGhostPostStepPoint->SetStepStatus(fPostSt 378 //++++++++++++++++++++++++++++++++++++++++++++ 379 } 380