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 // G4BOptrForceCollision 27 // ------------------------------------------- 28 29 #include "G4BOptrForceCollision.hh" 30 #include "G4BOptrForceCollisionTrackData.hh" 31 #include "G4BiasingProcessInterface.hh" 32 #include "G4PhysicsModelCatalog.hh" 33 34 #include "G4BOptnForceCommonTruncatedExp.hh" 35 #include "G4ILawCommonTruncatedExp.hh" 36 #include "G4BOptnForceFreeFlight.hh" 37 #include "G4BOptnCloning.hh" 38 39 #include "G4Step.hh" 40 #include "G4StepPoint.hh" 41 #include "G4VProcess.hh" 42 43 #include "G4ParticleDefinition.hh" 44 #include "G4ParticleTable.hh" 45 46 #include "G4SystemOfUnits.hh" 47 48 // -- Consider calling other constructor, than 49 G4BOptrForceCollision:: 50 G4BOptrForceCollision(const G4String& particle 51 const G4String& name) 52 : G4VBiasingOperator(name), 53 fForceCollisionModelID(G4PhysicsModelCatal 54 { 55 fSharedForceInteractionOperation = new G4BOp 56 fCloningOperation = new G4BOptnCloning("Clon 57 fParticleToBias = G4ParticleTable::GetPartic 58 59 if ( fParticleToBias == nullptr ) 60 { 61 G4ExceptionDescription ed; 62 ed << " Particle `" << particleName << "' 63 G4Exception(" G4BOptrForceCollision::G4BOp 64 "BIAS.GEN.07", JustWarning, ed 65 } 66 } 67 68 G4BOptrForceCollision:: 69 G4BOptrForceCollision(const G4ParticleDefiniti 70 const G4String& name) 71 : G4VBiasingOperator(name), 72 fForceCollisionModelID(G4PhysicsModelCatal 73 { 74 fSharedForceInteractionOperation = new G4BOp 75 fCloningOperation = new G4BOptnCloning("Clon 76 fParticleToBias = particle; 77 } 78 79 G4BOptrForceCollision::~G4BOptrForceCollision( 80 { 81 for ( auto it = fFreeFlightOperations.cbegin 82 it != fFreeFlightOperations.cend( 83 { 84 delete (*it).second; 85 } 86 delete fSharedForceInteractionOperation; 87 delete fCloningOperation; 88 } 89 90 void G4BOptrForceCollision::Configure() 91 { 92 // -- build free flight operations: 93 ConfigureForWorker(); 94 } 95 96 void G4BOptrForceCollision::ConfigureForWorker 97 { 98 // -- start by remembering processes under b 99 // and create needed biasing operations: 100 if ( fSetup ) 101 { 102 const G4ProcessManager* processManager = f 103 const G4BiasingProcessSharedData* interfac 104 if ( interfaceProcessSharedData ) // -- sh 105 // -- to a vol 106 { 107 for ( std::size_t i = 0 ; i < (interface 108 { 109 const G4BiasingProcessInterface* wrapp 110 (interfaceProcessSharedData->GetPhys 111 const G4String& operationName = "FreeF 112 fFreeFlightOperations[wrapperProcess] 113 } 114 } 115 fSetup = false; 116 } 117 } 118 119 void G4BOptrForceCollision::StartRun() 120 { 121 } 122 123 G4VBiasingOperation* 124 G4BOptrForceCollision::ProposeOccurenceBiasing 125 const G4Biasing 126 { 127 // -- does nothing if particle is not of req 128 if ( track->GetDefinition() != fParticleToBi 129 130 // -- trying to get auxiliary track data... 131 if ( fCurrentTrackData == nullptr ) 132 { 133 // ... and if the track has no aux. track 134 fCurrentTrackData = (G4BOptrForceCollision 135 if ( fCurrentTrackData == nullptr ) return 136 } 137 138 // -- Send force free flight to the callingP 139 // ----------------------------------------- 140 // -- The track has been cloned in the previ 141 // -- forced for a free flight. 142 // -- This track will fly with 0.0 weight du 143 // -- it is to forbid the double counting wi 144 // -- Its weight is restored at the end of i 145 // -- being its initial weight * the weight 146 // -- this last one being per process. The i 147 // -- arbitrary asked to the first operation 148 if ( fCurrentTrackData->fForceCollisionState 149 { 150 G4BOptnForceFreeFlight* operation = fFreeF 151 if ( callingProcess->GetWrappedProcess()-> 152 { 153 // -- the initial track weight will be r 154 operation->ResetInitialTrackWeight(fInit 155 return operation; 156 } 157 else 158 { 159 return nullptr; 160 } 161 } 162 163 // -- Send force interaction operation to th 164 // ----------------------------------------- 165 // -- at this level, a copy of the track ent 166 // -- generated (borned) earlier. This copy 167 // -- interaction in the volume. 168 if ( fCurrentTrackData->fForceCollisionState 169 { 170 // -- Remember if this calling process is 171 // -- the PostStepGPIL loop (using default 172 G4bool isFirstPhysGPIL = callingProcess-> 173 174 // -- [*first process*] Initialize or upda 175 if ( isFirstPhysGPIL ) 176 { 177 // -- first step of cloned track, initia 178 if ( track->GetCurrentStepNumber() == 1 179 { 180 fSharedForceInteractionOperation->Init 181 } 182 else 183 { 184 if ( fSharedForceInteractionOperation- 185 { 186 // -- means that some other physics 187 // -- has occured, need to re-initia 188 // -- [ Note the re-initialization i 189 fSharedForceInteractionOperation->In 190 } 191 else 192 { 193 // -- means that some other non-phys 194 // -- but track conserves its moment 195 // -- forced interaction. 196 // -- [ Note the update is only poss 197 fSharedForceInteractionOperation->Up 198 } 199 } 200 } 201 202 // -- [*all processes*] Sanity check : it 203 // -- out is zero, weight would be infinit 204 // -- and abandon biasing. 205 if ( fSharedForceInteractionOperation->Get 206 { 207 fCurrentTrackData->Reset(); 208 return nullptr; 209 } 210 211 // -- [* first process*] collect cross-sec 212 // -- and winning process: 213 if ( isFirstPhysGPIL ) 214 { 215 // -- collect cross-sections: 216 // -- ( Remember that the first of the G 217 // -- of these cross-sections ) 218 const G4BiasingProcessSharedData* shared 219 for ( std::size_t i = 0 ; i < (sharedDat 220 { 221 const G4BiasingProcessInterface* wrapp 222 G4double interactionLength = wrapperPr 223 // -- keep only well defined cross-sec 224 // -- but cases where a threhold effec 225 if ( interactionLength < DBL_MAX/10. ) 226 fSharedForceInteractionOperation->Ad 227 } 228 // -- sample the shared law (interaction 229 if ( fSharedForceInteractionOperation->G 230 fSharedForceInteractionOperation->Samp 231 } 232 233 // -- [*all processes*] Send operation for 234 G4VBiasingOperation* operationToReturn = n 235 if ( callingProcess->GetWrappedProcess()-> 236 operationToReturn = fSharedForceInteract 237 return operationToReturn; 238 239 } // -- end of "if ( fCurrentTrackData->fFor 240 241 242 // -- other cases here: particle appearing i 243 // -- previous interaction : we decide to no 244 return nullptr; 245 } 246 247 G4VBiasingOperation* G4BOptrForceCollision:: 248 ProposeNonPhysicsBiasingOperation(const G4Trac 249 const G4Bias 250 { 251 if ( track->GetDefinition() != fParticleToBi 252 253 // -- Apply biasing scheme only to tracks en 254 // -- A "cloning" is done: 255 // -- - the primary will be forced flight u 256 // -- where the weight will be restored w 257 // -- - the clone will be forced to interac 258 if ( track->GetStep()->GetPreStepPoint()->Ge 259 { 260 // -- check that track is free of undergoi 261 // -- Get possible track data: 262 fCurrentTrackData = (G4BOptrForceCollision 263 if ( fCurrentTrackData != nullptr ) 264 { 265 if ( fCurrentTrackData->IsFreeFromBiasin 266 { 267 // -- takes "ownership" (some track da 268 fCurrentTrackData->fForceCollisionOper 269 } 270 else 271 { 272 // Would something be really wrong in 273 // Could this be that a process made a 274 } 275 } 276 else 277 { 278 fCurrentTrackData = new G4BOptrForceColl 279 track->SetAuxiliaryTrackInformation(fFor 280 } 281 fCurrentTrackData->fForceCollisionState = 282 fInitialTrackWeight = track->GetWeight(); 283 fCloningOperation->SetCloneWeights(0.0, fI 284 285 return fCloningOperation; 286 } 287 288 return nullptr; 289 } 290 291 G4VBiasingOperation* G4BOptrForceCollision:: 292 ProposeFinalStateBiasingOperation(const G4Trac 293 const G4Bias 294 { 295 // -- Propose at final state generation the 296 // -- (which is either the force free flight 297 // -- count on the process interface to coll 298 return callingProcess->GetCurrentOccurenceBi 299 } 300 301 void G4BOptrForceCollision::StartTracking( con 302 { 303 fCurrentTrack = track; 304 fCurrentTrackData = nullptr; 305 } 306 307 void G4BOptrForceCollision::EndTracking() 308 { 309 // -- check for consistency, operator should 310 if ( fCurrentTrackData != nullptr ) 311 { 312 if ( !fCurrentTrackData->IsFreeFromBiasing 313 { 314 if ( (fCurrentTrack->GetTrackStatus() == 315 || (fCurrentTrack->GetTrackStatus() == 316 { 317 G4ExceptionDescription ed; 318 ed << "Current track deleted while under bia 319 << GetName() << ". Will result in i 320 G4Exception(" G4BOptrForceCollision::E 321 "BIAS.GEN.18", JustWarning 322 } 323 } 324 } 325 } 326 327 void G4BOptrForceCollision:: 328 OperationApplied( const G4BiasingProcessInterf 329 G4BiasingAppliedCase B 330 G4VBiasingOperation* o 331 const G4VParticleChange* ) 332 { 333 if ( fCurrentTrackData == nullptr ) 334 { 335 if ( BAC != BAC_None ) 336 { 337 G4ExceptionDescription ed; 338 ed << " Internal inconsistency : please 339 G4Exception(" G4BOptrForceCollision::Ope 340 "BIAS.GEN.20.1", JustWarning 341 } 342 return; 343 } 344 345 if ( fCurrentTrackData->fForceCollisionState 346 { 347 fCurrentTrackData->fForceCollisionState = 348 auto cloneData = new G4BOptrForceCollision 349 cloneData->fForceCollisionState = ForceCol 350 fCloningOperation->GetCloneTrack()->SetAux 351 } 352 else if ( fCurrentTrackData->fForceCollision 353 { 354 if ( fFreeFlightOperations[callingProcess] 355 fCurrentTrackData->Reset(); // -- off bi 356 } 357 else if ( fCurrentTrackData->fForceCollision 358 { 359 if ( operationApplied != fSharedForceInter 360 { 361 G4ExceptionDescription ed; 362 ed << " Internal inconsistency : please 363 G4Exception(" G4BOptrForceCollision::Ope 364 "BIAS.GEN.20.2", JustWarning 365 } 366 if ( fSharedForceInteractionOperation->Get 367 { 368 if ( operationApplied != fSharedForceInt 369 { 370 G4ExceptionDescription ed; 371 ed << " Internal inconsistency : pleas 372 G4Exception(" G4BOptrForceCollision::O 373 "BIAS.GEN.20.3", JustWarni 374 } 375 } 376 } 377 else 378 { 379 if ( fCurrentTrackData->fForceCollisionSta 380 { 381 G4ExceptionDescription ed; 382 ed << " Internal inconsistency : please 383 G4Exception(" G4BOptrForceCollision::Ope 384 "BIAS.GEN.20.4", JustWarning 385 } 386 } 387 } 388 389 void G4BOptrForceCollision:: 390 OperationApplied( const G4BiasingProcessInterf 391 G4BiasingAppliedCase / 392 G4VBiasingOperation* / 393 G4double / 394 G4VBiasingOperation* f 395 const G4VParticleChange* / 396 { 397 if ( fCurrentTrackData->fForceCollisionState 398 { 399 if ( finalStateOperationApplied != fShared 400 { 401 G4ExceptionDescription ed; 402 ed << " Internal inconsistency : please 403 G4Exception(" G4BOptrForceCollision::Ope 404 "BIAS.GEN.20.5", JustWarning 405 } 406 if ( fSharedForceInteractionOperation->Get 407 fCurrentTrackData->Reset(); // -- off bi 408 } 409 else 410 { 411 G4ExceptionDescription ed; 412 ed << " Internal inconsistency : please su 413 G4Exception(" G4BOptrForceCollision::Opera 414 "BIAS.GEN.20.6", JustWarning, 415 } 416 } 417