Geant4  10.02
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  fWrappedProcess ( 0 ),
47  fIsPhysicsBasedBiasing ( false ),
48  fWrappedProcessIsAtRest ( false ),
49  fWrappedProcessIsAlong ( false ),
50  fWrappedProcessIsPost ( false ),
51  fWrappedProcessInteractionLength( -1.0 ),
52  fBiasingInteractionLaw ( 0 ),
53  fPhysicalInteractionLaw ( 0 ),
54  fOccurenceBiasingParticleChange ( 0 ),
55  fIamFirstGPIL ( false ),
56  fSharedData ( 0 )
57 
58 {
59  for (G4int i = 0 ; i < 8 ; i++) fFirstLastFlags[i] = false;
60  fResetInteractionLaws.Put( true );
61  fCommonStart.Put(true);
62  fCommonEnd.Put(true);
63  fDoCommonConfigure.Put(true);
64 }
65 
66 
68  G4bool wrappedIsAtRest, G4bool wrappedIsAlongStep, G4bool wrappedIsPostStep,
69  G4String useThisName)
70  : G4VProcess( useThisName != "" ? useThisName : "biasWrapper("+wrappedProcess->GetProcessName()+")",
71  wrappedProcess->GetProcessType()),
72  fWrappedProcess ( wrappedProcess ),
73  fIsPhysicsBasedBiasing ( true ),
74  fWrappedProcessIsAtRest ( wrappedIsAtRest ),
75  fWrappedProcessIsAlong ( wrappedIsAlongStep ),
76  fWrappedProcessIsPost ( wrappedIsPostStep ),
77  fWrappedProcessInteractionLength( -1.0 ),
78  fBiasingInteractionLaw ( 0 ),
79  fPhysicalInteractionLaw ( 0 ),
80  fOccurenceBiasingParticleChange ( 0 ),
81  fIamFirstGPIL ( false ),
82  fSharedData ( 0 )
83 {
84  for (G4int i = 0 ; i < 8 ; i++) fFirstLastFlags[i] = false;
85  fResetInteractionLaws.Put( true );
86  fCommonStart.Put(true);
87  fCommonEnd.Put(true);
88  fDoCommonConfigure.Put(true);
89 
91 
92  // -- create physical interaction law:
93  fPhysicalInteractionLaw = new G4InteractionLawPhysical("PhysicalInteractionLawFor("+GetProcessName()+")");
94  // -- instantiate particle change wrapper for occurence biaising:
97  // -- instantiate a "do nothing" particle change:
99 }
100 
101 
102 
104 {
107  if ( fParticleChange ) delete fParticleChange;
109 }
110 
111 
113 {
114  G4MapCache< const G4ProcessManager*,
115  G4BiasingProcessSharedData* >::const_iterator itr = fSharedDataMap.Find( mgr );
116  if ( itr != fSharedDataMap.End( ) )
117  {
118  return (*itr).second;
119  }
120  else return 0;
121 }
122 
123 
125 {
126  fCurrentTrack = track;
136 
137  fPreviousStepSize = -1.0;
138 
140 
141  if ( fCommonStart.Get() )
142  {
143  fCommonStart.Put( false );// = false;
144  fCommonEnd.Put(true);// = true;
145 
146  fSharedData-> fCurrentBiasingOperator = 0;
148 
149  // -- §§ Add a "fSharedData->nStarting" here and outside bracket "fSharedData->nStarting++" and " if (fSharedData->nStarting) == fSharedData->(vector interface length)"
150  // -- §§ call to the loop "StartTracking" of operators"
151 
152  for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
154  }
155 }
156 
157 
159 {
163 
164  // -- Inform operators of end of tracking:
165  if ( fCommonEnd.Get() )
166  {
167  fCommonEnd.Put( false );// = false;
168  fCommonStart.Put( true );// = true;
169 
170  for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
172 
173  // -- §§ for above loop, do as in StartTracking.
174  }
175 }
176 
177 
178 
180  G4double previousStepSize,
182 {
183  // ---------------------------------------------------------------------------------------------
184  // -- The "biasing master" takes care for all biasing processes of update of biasing operators
185  // -- and invokes all PostStepGPIL of physical wrapped processes (anticipate stepping manager
186  // -- call ! ) so that all cross-sections are updated with current step, and available right
187  // -- away to the biasing operator.
188  // ---------------------------------------------------------------------------------------------
189  if ( fIamFirstGPIL )
190  {
191  // -- Update previous biasing operator:
193  // -- If new volume, get possible new biasing operator:
194  // ----------------------------------------------------
195  // -- [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 ?]
196  G4bool firstStepInVolume = ( (track.GetStep()->GetPreStepPoint()->GetStepStatus() == fGeomBoundary) || (track.GetCurrentStepNumber() == 1) );
197  fSharedData->fIsNewOperator = false;
199  if ( firstStepInVolume )
200  {
202  fSharedData->fCurrentBiasingOperator = newOperator ;
203  if ( newOperator != fSharedData->fPreviousBiasingOperator )
204  {
206  fSharedData->fIsNewOperator = ( newOperator != 0 );
207  }
208  }
209 
210 
211  // -- calls to wrapped process PostStepGPIL's:
212  // -------------------------------------------
213  // -- Each physics wrapper process has its
214  // -- fWrappedProcessPostStepGPIL ,
215  // -- fWrappedProcessForceCondition ,
216  // -- fWrappedProcessInteractionLength
217  // -- updated.
219  {
220  for ( size_t i = 0 ; i < (fSharedData->fPhysicsBiasingProcessInterfaces).size(); i++ )
221  (fSharedData->fPhysicsBiasingProcessInterfaces)[i]->InvokeWrappedProcessPostStepGPIL( track, previousStepSize, condition );
222  }
223  }
224 
225 
226  // -- Remember previous operator and proposed operations, if any, and reset:
227  // -------------------------------------------------------------------------
228  // -- remember only in case some biasing might be called
229  if ( ( fSharedData->fPreviousBiasingOperator != 0 ) ||
231  {
236  // -- reset:
241  // -- Physics PostStep and AlongStep GPIL
242  // fWrappedProcessPostStepGPIL : updated by InvokeWrappedProcessPostStepGPIL(...) above
244  // fWrappedProcessInteractionLength : updated by InvokeWrappedProcessPostStepGPIL(...) above; inverse of analog cross-section.
245  // fWrappedProcessForceCondition : updated by InvokeWrappedProcessPostStepGPIL(...) above
251  // -- for helper:
252  fPreviousStepSize = previousStepSize;
253  }
254 
255 
256  // -- previous step size value; it is switched to zero if resetting a wrapped process:
257  // -- (same trick used than in InvokedWrappedProcessPostStepGPIL )
258  G4double usedPreviousStepSize = previousStepSize;
259 
260  // ----------------------------------------------
261  // -- If leaving a biasing operator, let it know:
262  // ----------------------------------------------
264  {
265  (fSharedData->fPreviousBiasingOperator)->ExitingBiasing( &track, this );
266  // -- if no further biasing operator, reset process behavior to standard tracking:
268  {
271  {
272  // -- if the physics process has been under occurence biasing, reset it:
274  {
277  // -- We set "previous step size" as 0.0, to let the process believe this is first step:
278  usedPreviousStepSize = 0.0;
279  }
280  }
281  }
282  }
283 
284 
285  // --------------------------------------------------------------
286  // -- no operator : analog tracking if physics-based, or nothing:
287  // --------------------------------------------------------------
289  {
290  // -- take note of the "usedPreviousStepSize" value:
291  if ( fIsPhysicsBasedBiasing ) return fWrappedProcess->PostStepGetPhysicalInteractionLength(track, usedPreviousStepSize, condition);
292  else
293  {
294  *condition = NotForced;
295  return DBL_MAX;
296  }
297  }
298 
299 
300 
301  // --------------------------------------------------
302  // -- A biasing operator exists. Proceed with
303  // -- treating non-physics and physics biasing cases:
304  //---------------------------------------------------
305 
306  // -- non-physics-based biasing case:
307  // ----------------------------------
308  if ( !fIsPhysicsBasedBiasing )
309  {
310  fNonPhysicsBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedNonPhysicsBiasingOperation( &track, this );
311  if ( fNonPhysicsBiasingOperation == 0 )
312  {
313  *condition = NotForced;
314  return DBL_MAX;
315  }
316  return fNonPhysicsBiasingOperation->DistanceToApplyOperation(&track, previousStepSize, condition);
317  }
318 
319 
320  // -- Physics based biasing case:
321  // ------------------------------
322  // -- Ask for possible GPIL biasing operation:
323  fOccurenceBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedOccurenceBiasingOperation( &track, this );
324 
325 
326  // -- no operation for occurence biasing, analog GPIL returns the wrapped process GPIL and condition values
327  if ( fOccurenceBiasingOperation == 0 )
328  {
329  *condition = fWrappedProcessForceCondition;
331  }
332 
333  // -- A valid GPIL biasing operation has been proposed:
334  // -- 0) remember wrapped process will need to be reset on biasing exit, if particle survives:
336  // -- 1) update process interaction length for reference analog interaction law ( fWrappedProcessInteractionLength updated/collected above):
338  // -- 2) Collect biasing interaction law:
339  // -- The interaction law pointer is collected as a const pointer to the interaction law object.
340  // -- This interaction law will be kept under control of the biasing operation, which is the only
341  // -- entity that will change the state of the biasing interaction law.
342  // -- The force condition for biasing is asked at the same time, passing the analog one as default:
345  // -- 3) Ask operation to sample the biasing interaction law:
347 
348  // -- finish
349  *condition = fBiasingForceCondition;
350  return fBiasingPostStepGPIL;
351 
352 }
353 
354 
355 
357  const G4Step& step)
358 {
359  // ---------------------------------------
360  // -- case outside of volume with biasing:
361  // ---------------------------------------
362  if ( fSharedData->fCurrentBiasingOperator == 0 ) return fWrappedProcess->PostStepDoIt(track, step);
363 
364  // ----------------------------
365  // -- non-physics biasing case:
366  // ----------------------------
367  if ( !fIsPhysicsBasedBiasing )
368  {
369  G4VParticleChange* particleChange = fNonPhysicsBiasingOperation->GenerateBiasingFinalState( &track, &step );
370  (fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC_NonPhysics, fNonPhysicsBiasingOperation, particleChange );
371  return particleChange;
372  }
373 
374  // -- physics biasing case:
375  // ------------------------
376  // -- It proceeds with the following logic:
377  // -- 1) Obtain the final state
378  // -- This final state may be analog or biased.
379  // -- The biased final state is obtained through a biasing operator
380  // -- returned by the operator.
381  // -- 2) The biased final state may be asked to be "force as it is"
382  // -- in what case the particle change is returned as is to the
383  // -- stepping.
384  // -- In all other cases (analog final state or biased final but
385  // -- not forced) the final state weight may be modified by the
386  // -- occurence biasing, if such an occurence biasing is at play.
387 
388  // -- Get final state, biased or analog:
389  G4VParticleChange* finalStateParticleChange;
391  fFinalStateBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedFinalStateBiasingOperation( &track, this );
392  // -- Flag below is to force the biased generated particle change to be retruned "as is" to the stepping, disregarding there
393  // -- was or not a occurence biasing that would apply. Weight relevance under full responsibility of the biasing operation.
394  G4bool forceBiasedFinalState = false;
395  if ( fFinalStateBiasingOperation != 0 )
396  {
397  finalStateParticleChange = fFinalStateBiasingOperation->ApplyFinalStateBiasing( this, &track, &step, forceBiasedFinalState );
398  BAC = BAC_FinalState;
399  }
400  else
401  {
402  finalStateParticleChange = fWrappedProcess->PostStepDoIt(track, step);
403  BAC = BAC_None ;
404  }
405 
406  // -- if no occurence biasing operation, we're done:
407  if ( fOccurenceBiasingOperation == 0 )
408  {
409  (fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC, fFinalStateBiasingOperation, finalStateParticleChange );
410  return finalStateParticleChange;
411  }
412 
413  // -- if biased final state has been asked to be forced, we're done:
414  if ( forceBiasedFinalState )
415  {
416  (fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC, fFinalStateBiasingOperation, finalStateParticleChange );
417  return finalStateParticleChange;
418  }
419 
420 
421  // -- If occurence biasing, applies the occurence biasing weight correction on top of final state (biased or not):
422  G4double weightForInteraction = 1.0;
423  if ( !fBiasingInteractionLaw->IsSingular() ) weightForInteraction =
425  fBiasingInteractionLaw ->ComputeEffectiveCrossSectionAt(step.GetStepLength());
426  else
427  {
428  // -- at this point effective XS can only be infinite, if not, there is a logic problem
430  {
432  ed << "Internal inconsistency in cross-section handling. Please report !" << G4endl;
433  G4Exception(" G4BiasingProcessInterface::PostStepDoIt(...)",
434  "BIAS.GEN.02",
435  JustWarning,
436  ed);
437  // -- if XS is infinite, weight is zero (and will stay zero), but we'll do differently.
438  // -- Should foresee in addition something to remember that in case of singular
439  // -- distribution, weight can only be partly calculated
440  }
441  }
442 
443  if ( weightForInteraction <= 0. )
444  {
446  ed << " Negative interaction weight : w_I = "
447  << weightForInteraction <<
450  " step length = " << step.GetStepLength() <<
451  " Interaction law = `" << fBiasingInteractionLaw << "'" <<
452  G4endl;
453  G4Exception(" G4BiasingProcessInterface::PostStepDoIt(...)",
454  "BIAS.GEN.03",
455  JustWarning,
456  ed);
457 
458  }
459 
460  (fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC,
461  fOccurenceBiasingOperation, weightForInteraction,
462  fFinalStateBiasingOperation, finalStateParticleChange );
463 
464 
467  fOccurenceBiasingParticleChange->SetWrappedParticleChange( finalStateParticleChange );
468  fOccurenceBiasingParticleChange->ProposeTrackStatus( finalStateParticleChange->GetTrackStatus() );
469  fOccurenceBiasingParticleChange->StealSecondaries(); // -- this also makes weightForInteraction applied to secondaries stolen
470 
471  // -- finish:
473 
474 }
475 
476 
477 // -- AlongStep methods:
479  G4double previousStepSize,
480  G4double currentMinimumStep,
481  G4double& proposedSafety,
482  G4GPILSelection* selection)
483 {
484  // -- for helper methods:
485  fCurrentMinimumStep = currentMinimumStep;
486  fProposedSafety = proposedSafety;
487 
488 
489  // -- initialization default case:
491  *selection = NotCandidateForSelection;
492  // ---------------------------------------
493  // -- case outside of volume with biasing:
494  // ---------------------------------------
496  {
499  previousStepSize,
500  currentMinimumStep,
501  proposedSafety,
502  selection);
504  }
505 
506  // --------------------------------------------------------------------
507  // -- non-physics based biasing: no along operation expected (for now):
508  // --------------------------------------------------------------------
510 
511  // ----------------------
512  // -- physics-based case:
513  // ----------------------
514  if ( fOccurenceBiasingOperation == 0 )
515  {
518  previousStepSize,
519  currentMinimumStep,
520  proposedSafety,
521  selection);
523  }
524 
525 
526  // ----------------------------------------------------------
527  // -- From here we have an valid occurence biasing operation:
528  // ----------------------------------------------------------
529  // -- Give operation opportunity to shorten step proposed by physics process:
531  G4double minimumStep = fBiasingAlongStepGPIL < currentMinimumStep ? fBiasingAlongStepGPIL : currentMinimumStep ;
532  // -- wrapped process is called with minimum step ( <= currentMinimumStep passed ) : an along process can not
533  // -- have its operation stretched over what it expects:
535  {
537  previousStepSize,
538  minimumStep,
539  proposedSafety,
540  selection);
541  fWrappedProcessGPILSelection = *selection;
543  }
544  else
545  {
548  }
549 
550  *selection = fBiasingGPILSelection;
551 
553 
554 }
555 
557  const G4Step& step)
558 {
559  // ---------------------------------------
560  // -- case outside of volume with biasing:
561  // ---------------------------------------
563  {
564  if ( fWrappedProcessIsAlong ) return fWrappedProcess->AlongStepDoIt(track, step);
565  else
566  {
568  return fDummyParticleChange;
569  }
570  }
571 
572  // -----------------------------------
573  // -- case inside volume with biasing:
574  // -----------------------------------
576  else
577  {
580  }
581  G4double weightForNonInteraction (1.0);
582  if ( fBiasingInteractionLaw != 0 )
583  {
584  weightForNonInteraction =
586  fBiasingInteractionLaw ->ComputeNonInteractionProbabilityAt(step.GetStepLength());
587 
588  fOccurenceBiasingOperation->AlongMoveBy( this, &step, weightForNonInteraction );
589 
590  if ( weightForNonInteraction <= 0. )
591  {
593  ed << " Negative non interaction weight : w_NI = " << weightForNonInteraction <<
595  " p_NI(bias) = " << fBiasingInteractionLaw ->ComputeNonInteractionProbabilityAt(step.GetStepLength()) <<
596  " step length = " << step.GetStepLength() <<
597  " biasing interaction law = `" << fBiasingInteractionLaw->GetName() << "'" << G4endl;
598  G4Exception(" G4BiasingProcessInterface::AlongStepDoIt(...)",
599  "BIAS.GEN.04",
600  JustWarning,
601  ed);
602  }
603 
604  }
605 
607 
609 
610 }
611 
612 // -- AtRest methods
615 {
616  return fWrappedProcess->AtRestGetPhysicalInteractionLength(track, condition);
617 }
619  const G4Step& step)
620 {
621  return fWrappedProcess->AtRestDoIt(track, step);
622 }
623 
624 
626 {
627  if ( fWrappedProcess != 0 ) return fWrappedProcess->IsApplicable(pd);
628  else return true;
629 }
630 
631 
633 {
634  // -- Master for this process:
636  // -- Master for wrapped process:
637  if ( fWrappedProcess != 0 )
638  {
639  const G4BiasingProcessInterface* thisWrapperMaster = (const G4BiasingProcessInterface *)GetMasterProcess();
640  // -- paranoia check: (?)
641  G4VProcess* wrappedMaster = 0;
642  wrappedMaster = thisWrapperMaster->GetWrappedProcess();
643  fWrappedProcess->SetMasterProcess( wrappedMaster );
644  }
645 }
646 
647 
649 {
650  // -- Sequential mode : called second (after PreparePhysicsTable(..))
651  // -- MT mode : called second (after PreparePhysicsTable(..)) by master thread.
652  // -- Corresponding process instance not used then by tracking.
653  // -- PreparePhysicsTable(...) has been called first for all processes,
654  // -- so the first/last flags and G4BiasingProcessInterface vector of processes have
655  // -- been properly setup, fIamFirstGPIL is valid.
656  if ( fWrappedProcess != 0 )
657  {
659  }
660 
661  if ( fIamFirstGPIL )
662  {
663  // -- Re-order vector of processes to match that of the GPIL
664  // -- (made for fIamFirstGPIL, but important is to have it made once):
666  // -- Let operators to configure themselves for the master thread or for sequential mode.
667  // -- Intended here is in particular the registration to physics model catalog.
668  // -- The fDoCommonConfigure is to ensure that this Configure is made by only one process (othewise each first process makes the call):
669  if ( fDoCommonConfigure.Get() )
670  {
671  for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
672  ( G4VBiasingOperator::GetBiasingOperators() )[optr]->Configure( );
673  fDoCommonConfigure.Put(false);
674  }
675 
676  }
677 }
678 
679 
681 {
682  // -- Sequential mode : called first (before BuildPhysicsTable(..))
683  // -- MT mode : called first (before BuildPhysicsTable(..)) by master thread.
684  // -- Corresponding process instance not used then by tracking.
685  // -- Let process finding its first/last position in the process manager:
687  if ( fWrappedProcess != 0 )
688  {
690  }
691 }
692 
693 
695 {
696  if ( fWrappedProcess != 0 ) return fWrappedProcess->StorePhysicsTable(pd, s, f);
697  else return false;
698 }
699 
700 
702 {
703  if ( fWrappedProcess != 0 ) return fWrappedProcess->RetrievePhysicsTable(pd, s, f);
704  else return false;
705 }
706 
707 
709 {
712 
713  // -- initialize fSharedData pointer:
714  if ( fSharedDataMap.Find(mgr) == fSharedDataMap.End() )
715  {
718  }
719  else fSharedData = fSharedDataMap[mgr] ;
720  // -- augment list of co-operating processes:
721  fSharedData-> fBiasingProcessInterfaces.push_back( this );
722  fSharedData-> fPublicBiasingProcessInterfaces.push_back( this );
723  if ( fIsPhysicsBasedBiasing )
724  {
725  fSharedData-> fPhysicsBiasingProcessInterfaces.push_back( this );
726  fSharedData-> fPublicPhysicsBiasingProcessInterfaces.push_back( this );
727  }
728  else
729  {
730  fSharedData-> fNonPhysicsBiasingProcessInterfaces.push_back( this );
731  fSharedData-> fPublicNonPhysicsBiasingProcessInterfaces.push_back( this );
732  }
733  // -- remember process manager:
734  fProcessManager = mgr;
735 }
736 
737 
739 {
740  if ( fWrappedProcess != 0 ) return fWrappedProcess->GetProcessManager();
741  else return G4VProcess::GetProcessManager();
742 }
743 
744 
746 {
747  // -- Sequential mode : not called
748  // -- MT mode : called after PrepareWorkerPhysicsTable(..)
749  // -- PrepareWorkerPhysicsTable(...) has been called first for all processes,
750  // -- so the first/last flags and G4BiasingProcessInterface vector of processes have
751  // -- been properly setup, fIamFirstGPIL is valid.
752  if ( fWrappedProcess != 0 )
753  {
755  }
756 
757  if ( fIamFirstGPIL )
758  {
759  // -- Re-order vector of processes to match that of the GPIL
760  // -- (made for fIamFirstGPIL, but important is to have it made once):
762  // -- Let operators to configure themselves for the worker thread, if needed.
763  // -- Registration to physics model catalog **IS NOT** to be made here, but in Configure().
764  // -- The fDoCommonConfigure is to ensure that this Configure is made by only one process (othewise each first process makes the call):
765  if ( fDoCommonConfigure.Get() )
766  {
767  for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
768  ( G4VBiasingOperator::GetBiasingOperators() )[optr]->ConfigureForWorker( );
769  fDoCommonConfigure.Put(false);
770  }
771  }
772 }
773 
774 
776 {
777  // -- Sequential mode : not called
778  // -- MT mode : called first, before BuildWorkerPhysicsTable(..)
779  // -- Let process finding its first/last position in the process manager:
781 
782  if ( fWrappedProcess != 0 )
783  {
785  }
786 }
787 
788 
790 {
792 }
793 
794 
796 {
797  G4int iPhys = ( physOnly ) ? 1 : 0;
798  return fFirstLastFlags[IdxFirstLast( 1, 1, iPhys)];
799 }
800 
801 
803 {
804  G4int iPhys = ( physOnly ) ? 1 : 0;
805  return fFirstLastFlags[IdxFirstLast( 0, 1, iPhys)];
806 }
807 
808 
810 {
811  G4int iPhys = ( physOnly ) ? 1 : 0;
812  return fFirstLastFlags[IdxFirstLast( 1, 0, iPhys)];
813 }
814 
815 
817 {
818  G4int iPhys = ( physOnly ) ? 1 : 0;
819  return fFirstLastFlags[IdxFirstLast( 0, 0, iPhys)];
820 }
821 
822 
824 {
825  G4bool isFirst = true;
827  G4int thisIdx(-1);
828  for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
829  for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
830  {
831  if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
832  {
833  G4int thatIdx(-1);
834  for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
835  if ( thisIdx > thatIdx )
836  {
837  isFirst = false;
838  break;
839  }
840  }
841  }
842  return isFirst;
843 }
844 
845 
847 {
848  G4bool isLast = true;
850  G4int thisIdx(-1);
851  for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
852  for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
853  {
854  if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
855  {
856  G4int thatIdx(-1);
857  for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
858  if ( thisIdx < thatIdx )
859  {
860  isLast = false;
861  break;
862  }
863  }
864  }
865  return isLast;
866 }
867 
868 
870 {
871  G4bool isFirst = true;
873  G4int thisIdx(-1);
874  for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
875  for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
876  {
877  if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
878  {
879  G4int thatIdx(-1);
880  for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
881  if ( thisIdx > thatIdx )
882  {
883  isFirst = false;
884  break;
885  }
886  }
887  }
888  return isFirst;
889 }
890 
891 
893 {
894  G4bool isLast = true;
896  G4int thisIdx(-1);
897  for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
898  for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
899  {
900  if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
901  {
902  G4int thatIdx(-1);
903  for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
904  if ( thisIdx < thatIdx )
905  {
906  isLast = false;
907  break;
908  }
909  }
910  }
911  return isLast;
912 }
913 
914 
916 {
917  for ( G4int iPhys = 0; iPhys < 2; iPhys++ )
918  {
919  G4bool physOnly = ( iPhys == 1 );
920  fFirstLastFlags[IdxFirstLast( 1, 1, iPhys)] = IsFirstPostStepGPILInterface(physOnly);
921  fFirstLastFlags[IdxFirstLast( 0, 1, iPhys)] = IsLastPostStepGPILInterface(physOnly);
922  fFirstLastFlags[IdxFirstLast( 1, 0, iPhys)] = IsFirstPostStepDoItInterface(physOnly);
923  fFirstLastFlags[IdxFirstLast( 0, 0, iPhys)] = IsLastPostStepDoItInterface(physOnly);
924  }
925 
926  // -- for itself, for optimization:
928 }
929 
930 
932 {
937 }
938 
939 
941  G4double previousStepSize,
943 {
944  G4double usedPreviousStepSize = previousStepSize;
945  // -- if the physics process has been under occurence biasing in the previous step
946  // -- we reset it, as we don't know if it will be biased again or not in this
947  // -- step. The pity is that PostStepGPIL and interaction length (cross-section)
948  // -- calculations are done both in the PostStepGPIL of the process, while here we
949  // -- are just interested in the calculation of the cross-section. This is a pity
950  // -- as this forces to re-generated a random number for nothing.
952  {
955  // -- We set "previous step size" as 0.0, to let the process believe this is first step:
956  usedPreviousStepSize = 0.0;
957  }
958  // -- GPIL response:
959  fWrappedProcessPostStepGPIL = fWrappedProcess->PostStepGetPhysicalInteractionLength(track, usedPreviousStepSize, condition);
961  // -- and (inverse) cross-section:
963 }
964 
965 
967 {
968  // -- re-order vector of processes to match that of the GPIL:
969  std::vector < G4BiasingProcessInterface* > tmpProcess ( fSharedData->fBiasingProcessInterfaces );
970  ( fSharedData -> fBiasingProcessInterfaces ) . clear();
971  ( fSharedData -> fPhysicsBiasingProcessInterfaces ) . clear();
972  ( fSharedData -> fNonPhysicsBiasingProcessInterfaces ) . clear();
973  ( fSharedData -> fPublicBiasingProcessInterfaces ) . clear();
974  ( fSharedData -> fPublicPhysicsBiasingProcessInterfaces ) . clear();
975  ( fSharedData -> fPublicNonPhysicsBiasingProcessInterfaces ) . clear();
976 
978  for (G4int i = 0; i < pv->size(); i++ )
979  {
980  for ( size_t j = 0; j < tmpProcess.size(); j++ )
981  {
982  if ( (*pv)(i) == tmpProcess[j] )
983  {
984  ( fSharedData -> fBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
985  ( fSharedData -> fPublicBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
986  if ( tmpProcess[j] -> fIsPhysicsBasedBiasing )
987  {
988  ( fSharedData -> fPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
989  ( fSharedData -> fPublicPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
990  }
991  else
992  {
993  ( fSharedData -> fNonPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
994  ( fSharedData -> fPublicNonPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
995  }
996  break;
997  }
998  }
999  }
1000 }
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