Geant4  10.02.p02
G4BiasingProcessInterface.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
27 #include "G4VBiasingOperator.hh"
28 #include "G4VBiasingOperation.hh"
30 #include "G4ParticleChange.hh"
34 #include "G4ProcessManager.hh"
35 #include "G4BiasingAppliedCase.hh"
36 
42 
43 
45  : G4VProcess ( name ),
46  fCurrentTrack ( nullptr ),
47  fPreviousStepSize (-1.0), fCurrentMinimumStep( -1.0 ), fProposedSafety ( -1.0),
48  fOccurenceBiasingOperation( nullptr ), fFinalStateBiasingOperation( nullptr ), fNonPhysicsBiasingOperation( nullptr ),
49  fPreviousOccurenceBiasingOperation( nullptr ), fPreviousFinalStateBiasingOperation( nullptr ), fPreviousNonPhysicsBiasingOperation( nullptr ),
50  fResetWrappedProcessInteractionLength( true ),
51  fWrappedProcess ( nullptr ),
52  fIsPhysicsBasedBiasing ( false ),
53  fWrappedProcessIsAtRest ( false ),
54  fWrappedProcessIsAlong ( false ),
55  fWrappedProcessIsPost ( false ),
56  fWrappedProcessPostStepGPIL ( -1.0 ),
57  fBiasingPostStepGPIL ( -1.0 ),
58  fWrappedProcessInteractionLength ( -1.0 ),
59  fWrappedProcessForceCondition ( NotForced ),
60  fBiasingForceCondition ( NotForced ),
61  fWrappedProcessAlongStepGPIL ( -1.0 ),
62  fBiasingAlongStepGPIL ( -1.0 ),
63  fWrappedProcessGPILSelection ( NotCandidateForSelection ),
64  fBiasingGPILSelection ( NotCandidateForSelection ),
65  fBiasingInteractionLaw ( nullptr ),
66  fPreviousBiasingInteractionLaw ( nullptr ),
67  fPhysicalInteractionLaw ( nullptr ),
68  fOccurenceBiasingParticleChange ( nullptr ),
69  fIamFirstGPIL ( false ),
70  fProcessManager ( nullptr ),
71  fSharedData ( nullptr )
72 {
73  for (G4int i = 0 ; i < 8 ; i++) fFirstLastFlags[i] = false;
74  fResetInteractionLaws.Put( true );
75  fCommonStart.Put(true);
76  fCommonEnd.Put(true);
77  fDoCommonConfigure.Put(true);
78 }
79 
80 
82  G4bool wrappedIsAtRest, G4bool wrappedIsAlongStep, G4bool wrappedIsPostStep,
83  G4String useThisName)
84  : G4VProcess( useThisName != "" ? useThisName : "biasWrapper("+wrappedProcess->GetProcessName()+")",
85  wrappedProcess->GetProcessType()),
86  fCurrentTrack ( nullptr ),
87  fPreviousStepSize (-1.0), fCurrentMinimumStep( -1.0 ), fProposedSafety ( -1.0),
88  fOccurenceBiasingOperation( nullptr ), fFinalStateBiasingOperation( nullptr ), fNonPhysicsBiasingOperation( nullptr ),
89  fPreviousOccurenceBiasingOperation( nullptr ), fPreviousFinalStateBiasingOperation( nullptr ), fPreviousNonPhysicsBiasingOperation( nullptr ),
90  fWrappedProcess ( wrappedProcess ),
91  fIsPhysicsBasedBiasing ( true ),
92  fWrappedProcessIsAtRest ( wrappedIsAtRest ),
93  fWrappedProcessIsAlong ( wrappedIsAlongStep ),
94  fWrappedProcessIsPost ( wrappedIsPostStep ),
95  fWrappedProcessPostStepGPIL ( -1.0 ),
96  fBiasingPostStepGPIL ( -1.0 ),
97  fWrappedProcessInteractionLength( -1.0 ),
98  fWrappedProcessForceCondition ( NotForced ),
99  fBiasingForceCondition ( NotForced ),
100  fWrappedProcessAlongStepGPIL ( -1.0 ),
101  fBiasingAlongStepGPIL ( -1.0 ),
102  fWrappedProcessGPILSelection ( NotCandidateForSelection ),
103  fBiasingGPILSelection ( NotCandidateForSelection ),
104  fBiasingInteractionLaw ( nullptr ),
105  fPreviousBiasingInteractionLaw ( nullptr ),
106  fPhysicalInteractionLaw ( nullptr ),
107  fOccurenceBiasingParticleChange ( nullptr ),
108  fIamFirstGPIL ( false ),
109  fProcessManager ( nullptr ),
110  fSharedData ( nullptr )
111 {
112  for (G4int i = 0 ; i < 8 ; i++) fFirstLastFlags[i] = false;
113  fResetInteractionLaws.Put( true );
114  fCommonStart.Put(true);
115  fCommonEnd.Put(true);
116  fDoCommonConfigure.Put(true);
117 
119 
120  // -- create physical interaction law:
121  fPhysicalInteractionLaw = new G4InteractionLawPhysical("PhysicalInteractionLawFor("+GetProcessName()+")");
122  // -- instantiate particle change wrapper for occurence biaising:
125  // -- instantiate a "do nothing" particle change:
127 }
128 
129 
130 
132 {
135  if ( fParticleChange ) delete fParticleChange;
137 }
138 
139 
141 {
142  G4MapCache< const G4ProcessManager*,
143  G4BiasingProcessSharedData* >::const_iterator itr = fSharedDataMap.Find( mgr );
144  if ( itr != fSharedDataMap.End( ) )
145  {
146  return (*itr).second;
147  }
148  else return 0;
149 }
150 
151 
153 {
154  fCurrentTrack = track;
164 
165  fPreviousStepSize = -1.0;
166 
168 
169  if ( fCommonStart.Get() )
170  {
171  fCommonStart.Put( false );// = false;
172  fCommonEnd.Put(true);// = true;
173 
174  fSharedData-> fCurrentBiasingOperator = 0;
176 
177  // -- §§ Add a "fSharedData->nStarting" here and outside bracket "fSharedData->nStarting++" and " if (fSharedData->nStarting) == fSharedData->(vector interface length)"
178  // -- §§ call to the loop "StartTracking" of operators"
179 
180  for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
182  }
183 }
184 
185 
187 {
191 
192  // -- Inform operators of end of tracking:
193  if ( fCommonEnd.Get() )
194  {
195  fCommonEnd.Put( false );// = false;
196  fCommonStart.Put( true );// = true;
197 
198  for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
200 
201  // -- §§ for above loop, do as in StartTracking.
202  }
203 }
204 
205 
206 
208  G4double previousStepSize,
210 {
211  // ---------------------------------------------------------------------------------------------
212  // -- The "biasing master" takes care for all biasing processes of update of biasing operators
213  // -- and invokes all PostStepGPIL of physical wrapped processes (anticipate stepping manager
214  // -- call ! ) so that all cross-sections are updated with current step, and available right
215  // -- away to the biasing operator.
216  // ---------------------------------------------------------------------------------------------
217  if ( fIamFirstGPIL )
218  {
219  // -- Update previous biasing operator:
221  // -- If new volume, get possible new biasing operator:
222  // ----------------------------------------------------
223  // -- [Note : bug with this first step ! Does not work if previous step was concurrently limited with geometry. Might make use of safety at last point ?]
224  G4bool firstStepInVolume = ( (track.GetStep()->GetPreStepPoint()->GetStepStatus() == fGeomBoundary) || (track.GetCurrentStepNumber() == 1) );
225  fSharedData->fIsNewOperator = false;
227  if ( firstStepInVolume )
228  {
230  fSharedData->fCurrentBiasingOperator = newOperator ;
231  if ( newOperator != fSharedData->fPreviousBiasingOperator )
232  {
234  fSharedData->fIsNewOperator = ( newOperator != 0 );
235  }
236  }
237 
238 
239  // -- calls to wrapped process PostStepGPIL's:
240  // -------------------------------------------
241  // -- Each physics wrapper process has its
242  // -- fWrappedProcessPostStepGPIL ,
243  // -- fWrappedProcessForceCondition ,
244  // -- fWrappedProcessInteractionLength
245  // -- updated.
247  {
248  for ( size_t i = 0 ; i < (fSharedData->fPhysicsBiasingProcessInterfaces).size(); i++ )
249  (fSharedData->fPhysicsBiasingProcessInterfaces)[i]->InvokeWrappedProcessPostStepGPIL( track, previousStepSize, condition );
250  }
251  }
252 
253 
254  // -- Remember previous operator and proposed operations, if any, and reset:
255  // -------------------------------------------------------------------------
256  // -- remember only in case some biasing might be called
257  if ( ( fSharedData->fPreviousBiasingOperator != 0 ) ||
259  {
264  // -- reset:
269  // -- Physics PostStep and AlongStep GPIL
270  // fWrappedProcessPostStepGPIL : updated by InvokeWrappedProcessPostStepGPIL(...) above
272  // fWrappedProcessInteractionLength : updated by InvokeWrappedProcessPostStepGPIL(...) above; inverse of analog cross-section.
273  // fWrappedProcessForceCondition : updated by InvokeWrappedProcessPostStepGPIL(...) above
279  // -- for helper:
280  fPreviousStepSize = previousStepSize;
281  }
282 
283 
284  // -- previous step size value; it is switched to zero if resetting a wrapped process:
285  // -- (same trick used than in InvokedWrappedProcessPostStepGPIL )
286  G4double usedPreviousStepSize = previousStepSize;
287 
288  // ----------------------------------------------
289  // -- If leaving a biasing operator, let it know:
290  // ----------------------------------------------
292  {
293  (fSharedData->fPreviousBiasingOperator)->ExitingBiasing( &track, this );
294  // -- if no further biasing operator, reset process behavior to standard tracking:
296  {
299  {
300  // -- if the physics process has been under occurence biasing, reset it:
302  {
305  // -- We set "previous step size" as 0.0, to let the process believe this is first step:
306  usedPreviousStepSize = 0.0;
307  }
308  }
309  }
310  }
311 
312 
313  // --------------------------------------------------------------
314  // -- no operator : analog tracking if physics-based, or nothing:
315  // --------------------------------------------------------------
317  {
318  // -- take note of the "usedPreviousStepSize" value:
319  if ( fIsPhysicsBasedBiasing ) return fWrappedProcess->PostStepGetPhysicalInteractionLength(track, usedPreviousStepSize, condition);
320  else
321  {
322  *condition = NotForced;
323  return DBL_MAX;
324  }
325  }
326 
327 
328 
329  // --------------------------------------------------
330  // -- A biasing operator exists. Proceed with
331  // -- treating non-physics and physics biasing cases:
332  //---------------------------------------------------
333 
334  // -- non-physics-based biasing case:
335  // ----------------------------------
336  if ( !fIsPhysicsBasedBiasing )
337  {
338  fNonPhysicsBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedNonPhysicsBiasingOperation( &track, this );
339  if ( fNonPhysicsBiasingOperation == 0 )
340  {
341  *condition = NotForced;
342  return DBL_MAX;
343  }
344  return fNonPhysicsBiasingOperation->DistanceToApplyOperation(&track, previousStepSize, condition);
345  }
346 
347 
348  // -- Physics based biasing case:
349  // ------------------------------
350  // -- Ask for possible GPIL biasing operation:
351  fOccurenceBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedOccurenceBiasingOperation( &track, this );
352 
353 
354  // -- no operation for occurence biasing, analog GPIL returns the wrapped process GPIL and condition values
355  if ( fOccurenceBiasingOperation == 0 )
356  {
357  *condition = fWrappedProcessForceCondition;
359  }
360 
361  // -- A valid GPIL biasing operation has been proposed:
362  // -- 0) remember wrapped process will need to be reset on biasing exit, if particle survives:
364  // -- 1) update process interaction length for reference analog interaction law ( fWrappedProcessInteractionLength updated/collected above):
366  // -- 2) Collect biasing interaction law:
367  // -- The interaction law pointer is collected as a const pointer to the interaction law object.
368  // -- This interaction law will be kept under control of the biasing operation, which is the only
369  // -- entity that will change the state of the biasing interaction law.
370  // -- The force condition for biasing is asked at the same time, passing the analog one as default:
373  // -- 3) Ask operation to sample the biasing interaction law:
375 
376  // -- finish
377  *condition = fBiasingForceCondition;
378  return fBiasingPostStepGPIL;
379 
380 }
381 
382 
383 
385  const G4Step& step)
386 {
387  // ---------------------------------------
388  // -- case outside of volume with biasing:
389  // ---------------------------------------
390  if ( fSharedData->fCurrentBiasingOperator == 0 ) return fWrappedProcess->PostStepDoIt(track, step);
391 
392  // ----------------------------
393  // -- non-physics biasing case:
394  // ----------------------------
395  if ( !fIsPhysicsBasedBiasing )
396  {
397  G4VParticleChange* particleChange = fNonPhysicsBiasingOperation->GenerateBiasingFinalState( &track, &step );
398  (fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC_NonPhysics, fNonPhysicsBiasingOperation, particleChange );
399  return particleChange;
400  }
401 
402  // -- physics biasing case:
403  // ------------------------
404  // -- It proceeds with the following logic:
405  // -- 1) Obtain the final state
406  // -- This final state may be analog or biased.
407  // -- The biased final state is obtained through a biasing operator
408  // -- returned by the operator.
409  // -- 2) The biased final state may be asked to be "force as it is"
410  // -- in what case the particle change is returned as is to the
411  // -- stepping.
412  // -- In all other cases (analog final state or biased final but
413  // -- not forced) the final state weight may be modified by the
414  // -- occurence biasing, if such an occurence biasing is at play.
415 
416  // -- Get final state, biased or analog:
417  G4VParticleChange* finalStateParticleChange;
419  fFinalStateBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedFinalStateBiasingOperation( &track, this );
420  // -- Flag below is to force the biased generated particle change to be retruned "as is" to the stepping, disregarding there
421  // -- was or not a occurence biasing that would apply. Weight relevance under full responsibility of the biasing operation.
422  G4bool forceBiasedFinalState = false;
423  if ( fFinalStateBiasingOperation != 0 )
424  {
425  finalStateParticleChange = fFinalStateBiasingOperation->ApplyFinalStateBiasing( this, &track, &step, forceBiasedFinalState );
426  BAC = BAC_FinalState;
427  }
428  else
429  {
430  finalStateParticleChange = fWrappedProcess->PostStepDoIt(track, step);
431  BAC = BAC_None ;
432  }
433 
434  // -- if no occurence biasing operation, we're done:
435  if ( fOccurenceBiasingOperation == 0 )
436  {
437  (fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC, fFinalStateBiasingOperation, finalStateParticleChange );
438  return finalStateParticleChange;
439  }
440 
441  // -- if biased final state has been asked to be forced, we're done:
442  if ( forceBiasedFinalState )
443  {
444  (fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC, fFinalStateBiasingOperation, finalStateParticleChange );
445  return finalStateParticleChange;
446  }
447 
448 
449  // -- If occurence biasing, applies the occurence biasing weight correction on top of final state (biased or not):
450  G4double weightForInteraction = 1.0;
451  if ( !fBiasingInteractionLaw->IsSingular() ) weightForInteraction =
453  fBiasingInteractionLaw ->ComputeEffectiveCrossSectionAt(step.GetStepLength());
454  else
455  {
456  // -- at this point effective XS can only be infinite, if not, there is a logic problem
458  {
460  ed << "Internal inconsistency in cross-section handling. Please report !" << G4endl;
461  G4Exception(" G4BiasingProcessInterface::PostStepDoIt(...)",
462  "BIAS.GEN.02",
463  JustWarning,
464  ed);
465  // -- if XS is infinite, weight is zero (and will stay zero), but we'll do differently.
466  // -- Should foresee in addition something to remember that in case of singular
467  // -- distribution, weight can only be partly calculated
468  }
469  }
470 
471  if ( weightForInteraction <= 0. )
472  {
474  ed << " Negative interaction weight : w_I = "
475  << weightForInteraction <<
478  " step length = " << step.GetStepLength() <<
479  " Interaction law = `" << fBiasingInteractionLaw << "'" <<
480  G4endl;
481  G4Exception(" G4BiasingProcessInterface::PostStepDoIt(...)",
482  "BIAS.GEN.03",
483  JustWarning,
484  ed);
485 
486  }
487 
488  (fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC,
489  fOccurenceBiasingOperation, weightForInteraction,
490  fFinalStateBiasingOperation, finalStateParticleChange );
491 
492 
495  fOccurenceBiasingParticleChange->SetWrappedParticleChange( finalStateParticleChange );
496  fOccurenceBiasingParticleChange->ProposeTrackStatus( finalStateParticleChange->GetTrackStatus() );
497  fOccurenceBiasingParticleChange->StealSecondaries(); // -- this also makes weightForInteraction applied to secondaries stolen
498 
499  // -- finish:
501 
502 }
503 
504 
505 // -- AlongStep methods:
507  G4double previousStepSize,
508  G4double currentMinimumStep,
509  G4double& proposedSafety,
510  G4GPILSelection* selection)
511 {
512  // -- for helper methods:
513  fCurrentMinimumStep = currentMinimumStep;
514  fProposedSafety = proposedSafety;
515 
516 
517  // -- initialization default case:
519  *selection = NotCandidateForSelection;
520  // ---------------------------------------
521  // -- case outside of volume with biasing:
522  // ---------------------------------------
524  {
527  previousStepSize,
528  currentMinimumStep,
529  proposedSafety,
530  selection);
532  }
533 
534  // --------------------------------------------------------------------
535  // -- non-physics based biasing: no along operation expected (for now):
536  // --------------------------------------------------------------------
538 
539  // ----------------------
540  // -- physics-based case:
541  // ----------------------
542  if ( fOccurenceBiasingOperation == 0 )
543  {
546  previousStepSize,
547  currentMinimumStep,
548  proposedSafety,
549  selection);
551  }
552 
553 
554  // ----------------------------------------------------------
555  // -- From here we have an valid occurence biasing operation:
556  // ----------------------------------------------------------
557  // -- Give operation opportunity to shorten step proposed by physics process:
559  G4double minimumStep = fBiasingAlongStepGPIL < currentMinimumStep ? fBiasingAlongStepGPIL : currentMinimumStep ;
560  // -- wrapped process is called with minimum step ( <= currentMinimumStep passed ) : an along process can not
561  // -- have its operation stretched over what it expects:
563  {
565  previousStepSize,
566  minimumStep,
567  proposedSafety,
568  selection);
569  fWrappedProcessGPILSelection = *selection;
571  }
572  else
573  {
576  }
577 
578  *selection = fBiasingGPILSelection;
579 
581 
582 }
583 
585  const G4Step& step)
586 {
587  // ---------------------------------------
588  // -- case outside of volume with biasing:
589  // ---------------------------------------
591  {
592  if ( fWrappedProcessIsAlong ) return fWrappedProcess->AlongStepDoIt(track, step);
593  else
594  {
596  return fDummyParticleChange;
597  }
598  }
599 
600  // -----------------------------------
601  // -- case inside volume with biasing:
602  // -----------------------------------
604  else
605  {
608  }
609  G4double weightForNonInteraction (1.0);
610  if ( fBiasingInteractionLaw != 0 )
611  {
612  weightForNonInteraction =
614  fBiasingInteractionLaw ->ComputeNonInteractionProbabilityAt(step.GetStepLength());
615 
616  fOccurenceBiasingOperation->AlongMoveBy( this, &step, weightForNonInteraction );
617 
618  if ( weightForNonInteraction <= 0. )
619  {
621  ed << " Negative non interaction weight : w_NI = " << weightForNonInteraction <<
623  " p_NI(bias) = " << fBiasingInteractionLaw ->ComputeNonInteractionProbabilityAt(step.GetStepLength()) <<
624  " step length = " << step.GetStepLength() <<
625  " biasing interaction law = `" << fBiasingInteractionLaw->GetName() << "'" << G4endl;
626  G4Exception(" G4BiasingProcessInterface::AlongStepDoIt(...)",
627  "BIAS.GEN.04",
628  JustWarning,
629  ed);
630  }
631 
632  }
633 
635 
637 
638 }
639 
640 // -- AtRest methods
643 {
644  return fWrappedProcess->AtRestGetPhysicalInteractionLength(track, condition);
645 }
647  const G4Step& step)
648 {
649  return fWrappedProcess->AtRestDoIt(track, step);
650 }
651 
652 
654 {
655  if ( fWrappedProcess != 0 ) return fWrappedProcess->IsApplicable(pd);
656  else return true;
657 }
658 
659 
661 {
662  // -- Master for this process:
664  // -- Master for wrapped process:
665  if ( fWrappedProcess != 0 )
666  {
667  const G4BiasingProcessInterface* thisWrapperMaster = (const G4BiasingProcessInterface *)GetMasterProcess();
668  // -- paranoia check: (?)
669  G4VProcess* wrappedMaster = 0;
670  wrappedMaster = thisWrapperMaster->GetWrappedProcess();
671  fWrappedProcess->SetMasterProcess( wrappedMaster );
672  }
673 }
674 
675 
677 {
678  // -- Sequential mode : called second (after PreparePhysicsTable(..))
679  // -- MT mode : called second (after PreparePhysicsTable(..)) by master thread.
680  // -- Corresponding process instance not used then by tracking.
681  // -- PreparePhysicsTable(...) has been called first for all processes,
682  // -- so the first/last flags and G4BiasingProcessInterface vector of processes have
683  // -- been properly setup, fIamFirstGPIL is valid.
684  if ( fWrappedProcess != 0 )
685  {
687  }
688 
689  if ( fIamFirstGPIL )
690  {
691  // -- Re-order vector of processes to match that of the GPIL
692  // -- (made for fIamFirstGPIL, but important is to have it made once):
694  // -- Let operators to configure themselves for the master thread or for sequential mode.
695  // -- Intended here is in particular the registration to physics model catalog.
696  // -- The fDoCommonConfigure is to ensure that this Configure is made by only one process (othewise each first process makes the call):
697  if ( fDoCommonConfigure.Get() )
698  {
699  for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
700  ( G4VBiasingOperator::GetBiasingOperators() )[optr]->Configure( );
701  fDoCommonConfigure.Put(false);
702  }
703 
704  }
705 }
706 
707 
709 {
710  // -- Sequential mode : called first (before BuildPhysicsTable(..))
711  // -- MT mode : called first (before BuildPhysicsTable(..)) by master thread.
712  // -- Corresponding process instance not used then by tracking.
713  // -- Let process finding its first/last position in the process manager:
715  if ( fWrappedProcess != 0 )
716  {
718  }
719 }
720 
721 
723 {
724  if ( fWrappedProcess != 0 ) return fWrappedProcess->StorePhysicsTable(pd, s, f);
725  else return false;
726 }
727 
728 
730 {
731  if ( fWrappedProcess != 0 ) return fWrappedProcess->RetrievePhysicsTable(pd, s, f);
732  else return false;
733 }
734 
735 
737 {
740 
741  // -- initialize fSharedData pointer:
742  if ( fSharedDataMap.Find(mgr) == fSharedDataMap.End() )
743  {
746  }
747  else fSharedData = fSharedDataMap[mgr] ;
748  // -- augment list of co-operating processes:
749  fSharedData-> fBiasingProcessInterfaces.push_back( this );
750  fSharedData-> fPublicBiasingProcessInterfaces.push_back( this );
751  if ( fIsPhysicsBasedBiasing )
752  {
753  fSharedData-> fPhysicsBiasingProcessInterfaces.push_back( this );
754  fSharedData-> fPublicPhysicsBiasingProcessInterfaces.push_back( this );
755  }
756  else
757  {
758  fSharedData-> fNonPhysicsBiasingProcessInterfaces.push_back( this );
759  fSharedData-> fPublicNonPhysicsBiasingProcessInterfaces.push_back( this );
760  }
761  // -- remember process manager:
762  fProcessManager = mgr;
763 }
764 
765 
767 {
768  if ( fWrappedProcess != 0 ) return fWrappedProcess->GetProcessManager();
769  else return G4VProcess::GetProcessManager();
770 }
771 
772 
774 {
775  // -- Sequential mode : not called
776  // -- MT mode : called after PrepareWorkerPhysicsTable(..)
777  // -- PrepareWorkerPhysicsTable(...) has been called first for all processes,
778  // -- so the first/last flags and G4BiasingProcessInterface vector of processes have
779  // -- been properly setup, fIamFirstGPIL is valid.
780  if ( fWrappedProcess != 0 )
781  {
783  }
784 
785  if ( fIamFirstGPIL )
786  {
787  // -- Re-order vector of processes to match that of the GPIL
788  // -- (made for fIamFirstGPIL, but important is to have it made once):
790  // -- Let operators to configure themselves for the worker thread, if needed.
791  // -- Registration to physics model catalog **IS NOT** to be made here, but in Configure().
792  // -- The fDoCommonConfigure is to ensure that this Configure is made by only one process (othewise each first process makes the call):
793  if ( fDoCommonConfigure.Get() )
794  {
795  for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
796  ( G4VBiasingOperator::GetBiasingOperators() )[optr]->ConfigureForWorker( );
797  fDoCommonConfigure.Put(false);
798  }
799  }
800 }
801 
802 
804 {
805  // -- Sequential mode : not called
806  // -- MT mode : called first, before BuildWorkerPhysicsTable(..)
807  // -- Let process finding its first/last position in the process manager:
809 
810  if ( fWrappedProcess != 0 )
811  {
813  }
814 }
815 
816 
818 {
820 }
821 
822 
824 {
825  G4int iPhys = ( physOnly ) ? 1 : 0;
826  return fFirstLastFlags[IdxFirstLast( 1, 1, iPhys)];
827 }
828 
829 
831 {
832  G4int iPhys = ( physOnly ) ? 1 : 0;
833  return fFirstLastFlags[IdxFirstLast( 0, 1, iPhys)];
834 }
835 
836 
838 {
839  G4int iPhys = ( physOnly ) ? 1 : 0;
840  return fFirstLastFlags[IdxFirstLast( 1, 0, iPhys)];
841 }
842 
843 
845 {
846  G4int iPhys = ( physOnly ) ? 1 : 0;
847  return fFirstLastFlags[IdxFirstLast( 0, 0, iPhys)];
848 }
849 
850 
852 {
853  G4bool isFirst = true;
855  G4int thisIdx(-1);
856  for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
857  for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
858  {
859  if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
860  {
861  G4int thatIdx(-1);
862  for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
863  if ( thisIdx > thatIdx )
864  {
865  isFirst = false;
866  break;
867  }
868  }
869  }
870  return isFirst;
871 }
872 
873 
875 {
876  G4bool isLast = true;
878  G4int thisIdx(-1);
879  for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
880  for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
881  {
882  if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
883  {
884  G4int thatIdx(-1);
885  for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
886  if ( thisIdx < thatIdx )
887  {
888  isLast = false;
889  break;
890  }
891  }
892  }
893  return isLast;
894 }
895 
896 
898 {
899  G4bool isFirst = true;
901  G4int thisIdx(-1);
902  for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
903  for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
904  {
905  if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
906  {
907  G4int thatIdx(-1);
908  for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
909  if ( thisIdx > thatIdx )
910  {
911  isFirst = false;
912  break;
913  }
914  }
915  }
916  return isFirst;
917 }
918 
919 
921 {
922  G4bool isLast = true;
924  G4int thisIdx(-1);
925  for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
926  for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
927  {
928  if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
929  {
930  G4int thatIdx(-1);
931  for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
932  if ( thisIdx < thatIdx )
933  {
934  isLast = false;
935  break;
936  }
937  }
938  }
939  return isLast;
940 }
941 
942 
944 {
945  for ( G4int iPhys = 0; iPhys < 2; iPhys++ )
946  {
947  G4bool physOnly = ( iPhys == 1 );
948  fFirstLastFlags[IdxFirstLast( 1, 1, iPhys)] = IsFirstPostStepGPILInterface(physOnly);
949  fFirstLastFlags[IdxFirstLast( 0, 1, iPhys)] = IsLastPostStepGPILInterface(physOnly);
950  fFirstLastFlags[IdxFirstLast( 1, 0, iPhys)] = IsFirstPostStepDoItInterface(physOnly);
951  fFirstLastFlags[IdxFirstLast( 0, 0, iPhys)] = IsLastPostStepDoItInterface(physOnly);
952  }
953 
954  // -- for itself, for optimization:
956 }
957 
958 
960 {
965 }
966 
967 
969  G4double previousStepSize,
971 {
972  G4double usedPreviousStepSize = previousStepSize;
973  // -- if the physics process has been under occurence biasing in the previous step
974  // -- we reset it, as we don't know if it will be biased again or not in this
975  // -- step. The pity is that PostStepGPIL and interaction length (cross-section)
976  // -- calculations are done both in the PostStepGPIL of the process, while here we
977  // -- are just interested in the calculation of the cross-section. This is a pity
978  // -- as this forces to re-generated a random number for nothing.
980  {
983  // -- We set "previous step size" as 0.0, to let the process believe this is first step:
984  usedPreviousStepSize = 0.0;
985  }
986  // -- GPIL response:
987  fWrappedProcessPostStepGPIL = fWrappedProcess->PostStepGetPhysicalInteractionLength(track, usedPreviousStepSize, condition);
989  // -- and (inverse) cross-section:
991 }
992 
993 
995 {
996  // -- re-order vector of processes to match that of the GPIL:
997  std::vector < G4BiasingProcessInterface* > tmpProcess ( fSharedData->fBiasingProcessInterfaces );
998  ( fSharedData -> fBiasingProcessInterfaces ) . clear();
999  ( fSharedData -> fPhysicsBiasingProcessInterfaces ) . clear();
1000  ( fSharedData -> fNonPhysicsBiasingProcessInterfaces ) . clear();
1001  ( fSharedData -> fPublicBiasingProcessInterfaces ) . clear();
1002  ( fSharedData -> fPublicPhysicsBiasingProcessInterfaces ) . clear();
1003  ( fSharedData -> fPublicNonPhysicsBiasingProcessInterfaces ) . clear();
1004 
1006  for (G4int i = 0; i < pv->size(); i++ )
1007  {
1008  for ( size_t j = 0; j < tmpProcess.size(); j++ )
1009  {
1010  if ( (*pv)(i) == tmpProcess[j] )
1011  {
1012  ( fSharedData -> fBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
1013  ( fSharedData -> fPublicBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
1014  if ( tmpProcess[j] -> fIsPhysicsBasedBiasing )
1015  {
1016  ( fSharedData -> fPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
1017  ( fSharedData -> fPublicPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
1018  }
1019  else
1020  {
1021  ( fSharedData -> fNonPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
1022  ( fSharedData -> fPublicNonPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
1023  }
1024  break;
1025  }
1026  }
1027  }
1028 }
virtual void SetMasterProcess(G4VProcess *masterP)
Definition: G4VProcess.cc:212
virtual void Initialize(const G4Track &track)
G4double condition(const G4ErrorSymMatrix &m)
static G4MapCache< const G4ProcessManager *, G4BiasingProcessSharedData * > fSharedDataMap
const G4VProcess * GetMasterProcess() const
Definition: G4VProcess.hh:538
virtual void BuildWorkerPhysicsTable(const G4ParticleDefinition &pd)
G4VBiasingOperation * fPreviousFinalStateBiasingOperation
G4bool IsLastPostStepGPILInterface(G4bool physOnly=true) const
virtual void PreparePhysicsTable(const G4ParticleDefinition &pd)
virtual G4VParticleChange * AtRestDoIt(const G4Track &, const G4Step &)
virtual G4double ComputeNonInteractionProbabilityAt(G4double length) const
virtual G4double AtRestGetPhysicalInteractionLength(const G4Track &track, G4ForceCondition *condition)=0
virtual void SetProcessManager(const G4ProcessManager *)
Definition: G4VProcess.hh:508
G4VBiasingOperation * fFinalStateBiasingOperation
static G4Cache< G4bool > fCommonEnd
G4VBiasingOperation * fNonPhysicsBiasingOperation
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)=0
virtual G4bool StorePhysicsTable(const G4ParticleDefinition *pd, const G4String &s, G4bool f)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
iterator End()
Definition: G4Cache.hh:411
static G4Cache< G4bool > fResetInteractionLaws
G4double GetStepLength() const
virtual void BuildPhysicsTable(const G4ParticleDefinition &pd)
virtual G4VParticleChange * ApplyFinalStateBiasing(const G4BiasingProcessInterface *, const G4Track *, const G4Step *, G4bool &)=0
virtual void PrepareWorkerPhysicsTable(const G4ParticleDefinition &pd)
static G4Cache< G4bool > fDoCommonConfigure
virtual G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &step)
G4String name
Definition: TRTMaterials.hh:40
G4StepStatus GetStepStatus() const
G4ParticleChangeForNothing * fDummyParticleChange
value_type & Get() const
Definition: G4Cache.hh:282
void InvokeWrappedProcessPostStepGPIL(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
G4TrackStatus GetTrackStatus() const
std::vector< G4BiasingProcessInterface * > fBiasingProcessInterfaces
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &step)
virtual void SetProcessManager(const G4ProcessManager *)
virtual G4double ComputeEffectiveCrossSectionAt(G4double length) const =0
virtual void ResetNumberOfInteractionLengthLeft()
Definition: G4VProcess.cc:95
G4VBiasingOperation * fPreviousOccurenceBiasingOperation
const G4ProcessManager * fProcessManager
const G4Step * GetStep() const
int G4int
Definition: G4Types.hh:78
G4BiasingAppliedCase
const G4VBiasingInteractionLaw * fPreviousBiasingInteractionLaw
virtual G4double ProposeAlongStepLimit(const G4BiasingProcessInterface *)
G4VProcess * GetWrappedProcess() const
virtual void BuildWorkerPhysicsTable(const G4ParticleDefinition &part)
Definition: G4VProcess.cc:202
G4bool GetIsFirstPostStepGPILInterface(G4bool physOnly=true) const
static const double s
Definition: G4SIunits.hh:168
G4StepPoint * GetPreStepPoint() const
virtual void StartTracking(G4Track *)
Definition: G4VProcess.cc:101
void SetSecondaryWeightByProcess(G4bool)
static G4Cache< G4bool > fCommonStart
std::vector< G4BiasingProcessInterface * > fPhysicsBiasingProcessInterfaces
G4int GetCurrentStepNumber() const
G4bool GetIsLastPostStepDoItInterface(G4bool physOnly=true) const
const G4VBiasingInteractionLaw * fBiasingInteractionLaw
G4bool GetIsLastPostStepGPILInterface(G4bool physOnly=true) const
virtual void PreparePhysicsTable(const G4ParticleDefinition &)
Definition: G4VProcess.hh:217
virtual G4double ComputeEffectiveCrossSectionAt(G4double length) const
bool G4bool
Definition: G4Types.hh:79
G4bool GetIsFirstPostStepDoItInterface(G4bool physOnly=true) const
G4VBiasingOperation * fPreviousNonPhysicsBiasingOperation
G4double GetCurrentInteractionLength() const
Definition: G4VProcess.hh:462
void SetProcessSubType(G4int)
Definition: G4VProcess.hh:432
void SetPhysicalCrossSection(G4double crossSection)
Definition: G4Step.hh:76
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
virtual G4bool RetrievePhysicsTable(const G4ParticleDefinition *, const G4String &, G4bool)
Definition: G4VProcess.hh:236
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
virtual G4VParticleChange * GenerateBiasingFinalState(const G4Track *, const G4Step *)=0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4bool IsApplicable(const G4ParticleDefinition &pd)
virtual const G4ProcessManager * GetProcessManager()
static G4VBiasingOperator * GetBiasingOperator(const G4LogicalVolume *)
virtual G4bool IsSingular() const
G4int size() const
virtual const G4ProcessManager * GetProcessManager()
Definition: G4VProcess.hh:514
iterator Find(const key_type &k)
Definition: G4Cache.hh:417
G4LogicalVolume * GetLogicalVolume() const
virtual void BuildPhysicsTable(const G4ParticleDefinition &)
Definition: G4VProcess.hh:210
G4VBiasingOperation * fOccurenceBiasingOperation
virtual G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &stepData)=0
G4ParticleChangeForOccurenceBiasing * fOccurenceBiasingParticleChange
G4bool IsFirstPostStepGPILInterface(G4bool physOnly=true) const
virtual void SetMasterProcess(G4VProcess *masterP)
G4BiasingProcessInterface(G4String name="biasWrapper(0)")
virtual G4bool RetrievePhysicsTable(const G4ParticleDefinition *pd, const G4String &s, G4bool f)
virtual G4GPILSelection ProposeGPILSelection(const G4GPILSelection wrappedProcessSelection)
G4VPhysicalVolume * GetVolume() const
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4double currentMinimumStep, G4double &proposedSafety, G4GPILSelection *selection)=0
G4double GetSampledInteractionLength() const
#define G4endl
Definition: G4ios.hh:61
static const std::vector< G4VBiasingOperator * > & GetBiasingOperators()
const G4String & GetName() const
virtual G4bool StorePhysicsTable(const G4ParticleDefinition *, const G4String &, G4bool)
Definition: G4VProcess.hh:231
virtual G4bool IsEffectiveCrossSectionInfinite() const
G4TrackStatus GetTrackStatus() const
G4bool IsFirstPostStepDoItInterface(G4bool physOnly=true) const
virtual const G4VBiasingInteractionLaw * ProvideOccurenceBiasingInteractionLaw(const G4BiasingProcessInterface *, G4ForceCondition &)=0
virtual void AlongMoveBy(const G4BiasingProcessInterface *, const G4Step *, G4double)
G4InteractionLawPhysical * fPhysicalInteractionLaw
G4BiasingProcessSharedData * fSharedData
virtual void PrepareWorkerPhysicsTable(const G4ParticleDefinition &)
Definition: G4VProcess.cc:207
double G4double
Definition: G4Types.hh:76
void ProposeTrackStatus(G4TrackStatus status)
virtual void EndTracking()
Definition: G4VProcess.cc:113
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &stepData)=0
G4ForceCondition
G4bool IsLastPostStepDoItInterface(G4bool physOnly=true) const
G4int IdxFirstLast(G4int firstLast, G4int GPILDoIt, G4int physAll) const
#define DBL_MAX
Definition: templates.hh:83
G4VBiasingOperator * fPreviousBiasingOperator
void Put(const value_type &val) const
Definition: G4Cache.hh:286
G4int GetProcessSubType() const
Definition: G4VProcess.hh:426
virtual G4double DistanceToApplyOperation(const G4Track *, G4double, G4ForceCondition *)=0
virtual G4bool IsApplicable(const G4ParticleDefinition &)
Definition: G4VProcess.hh:205
G4VBiasingOperator * fCurrentBiasingOperator
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4double currentMinimumStep, G4double &proposedSafety, G4GPILSelection *selection)
G4GPILSelection
virtual G4double AtRestGetPhysicalInteractionLength(const G4Track &, G4ForceCondition *)
virtual G4VParticleChange * AtRestDoIt(const G4Track &track, const G4Step &stepData)=0
G4ProcessVector * GetPostStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
const G4BiasingProcessSharedData * GetSharedData() const