47 fCurrentBiasingOperator ( 0 ),
48 fPreviousBiasingOperator( 0 ),
49 fWrappedProcess ( 0 ),
50 fIsPhysicsBasedBiasing ( false ),
51 fWrappedProcessIsAtRest( false ),
52 fWrappedProcessIsAlong ( false ),
53 fWrappedProcessIsPost ( false ),
54 fWrappedProcessInteractionLength( -1.0 ),
55 fBiasingInteractionLaw ( 0 ),
56 fPhysicalInteractionLaw( 0 ),
57 fOccurenceBiasingParticleChange( 0 ),
58 fIamFirstGPIL ( false )
60 for (
G4int i = 0 ; i < 8 ; i++) fFirstLastFlags[i] =
false;
61 fResetInteractionLaws.
Put(
true );
62 fCommonStart.
Put(
true);
70 :
G4VProcess( useThisName !=
"" ? useThisName :
"biasWrapper("+wrappedProcess->GetProcessName()+
")",
71 wrappedProcess->GetProcessType()),
72 fCurrentBiasingOperator ( 0 ),
73 fPreviousBiasingOperator( 0 ),
74 fWrappedProcess ( wrappedProcess ),
75 fIsPhysicsBasedBiasing ( true ),
76 fWrappedProcessIsAtRest( wrappedIsAtRest ),
77 fWrappedProcessIsAlong ( wrappedIsAlongStep ),
78 fWrappedProcessIsPost ( wrappedIsPostStep ),
79 fWrappedProcessInteractionLength( -1.0 ),
80 fBiasingInteractionLaw ( 0 ),
81 fPhysicalInteractionLaw( 0 ),
82 fOccurenceBiasingParticleChange( 0 ),
83 fIamFirstGPIL ( false )
85 for (
G4int i = 0 ; i < 8 ; i++) fFirstLastFlags[i] =
false;
102 if ( fPhysicalInteractionLaw != 0 )
delete fPhysicalInteractionLaw;
103 if ( fOccurenceBiasingParticleChange )
delete fOccurenceBiasingParticleChange;
104 if ( fDummyParticleChange )
delete fDummyParticleChange;
110 fCurrentTrack = track;
111 if ( fIsPhysicsBasedBiasing ) fWrappedProcess->
StartTracking(fCurrentTrack);
112 fCurrentBiasingOperator = 0;
113 fPreviousBiasingOperator = 0;
114 fOccurenceBiasingOperation = 0;
115 fPreviousOccurenceBiasingOperation = 0;
116 fFinalStateBiasingOperation = 0;
117 fPreviousFinalStateBiasingOperation = 0;
118 fNonPhysicsBiasingOperation = 0;
119 fPreviousNonPhysicsBiasingOperation = 0;
120 fBiasingInteractionLaw = 0;
121 fPreviousBiasingInteractionLaw = 0;
123 fPreviousStepSize = -1.0;
126 fResetWrappedProcessInteractionLength =
false;
128 if ( fCommonStart.
Get() )
130 fCommonStart.
Put(
false );
131 fCommonEnd.
Put(
true);
141 if ( fIsPhysicsBasedBiasing ) fWrappedProcess->
EndTracking();
142 if ( fCurrentBiasingOperator) fCurrentBiasingOperator->
ExitingBiasing( fCurrentTrack,
this );
143 fCurrentBiasingOperator = 0;
144 fPreviousBiasingOperator = 0;
145 fBiasingInteractionLaw = 0;
151 if ( fCommonEnd.
Get() )
153 fCommonEnd.
Put(
false );
154 fCommonStart.
Put(
true );
162 if ( biasingData )
delete biasingData;
166 for (
size_t i2nd = 0 ; i2nd < secondaries->size() ; i2nd++ )
169 if ( biasingData )
delete biasingData;
185 fPreviousBiasingOperator = fCurrentBiasingOperator;
186 fPreviousOccurenceBiasingOperation = fOccurenceBiasingOperation;
187 fPreviousFinalStateBiasingOperation = fFinalStateBiasingOperation;
188 fPreviousNonPhysicsBiasingOperation = fNonPhysicsBiasingOperation;
189 fPreviousBiasingInteractionLaw = fBiasingInteractionLaw;
191 fOccurenceBiasingOperation = 0;
192 fFinalStateBiasingOperation = 0;
193 fNonPhysicsBiasingOperation = 0;
194 fBiasingInteractionLaw = 0;
196 fWrappedProcessPostStepGPIL =
DBL_MAX;
197 fBiasingPostStepGPIL =
DBL_MAX;
198 fWrappedProcessInteractionLength =
DBL_MAX;
199 fWrappedProcessForceCondition =
NotForced;
201 fWrappedProcessAlongStepGPIL =
DBL_MAX;
202 fBiasingAlongStepGPIL =
DBL_MAX;
206 fPreviousStepSize = previousStepSize;
218 if ( fPreviousBiasingOperator != 0 )
221 if ( fPreviousBiasingOperator != fCurrentBiasingOperator ) fPreviousBiasingOperator->
ExitingBiasing( &track,
this );
224 if ( fCurrentBiasingOperator == 0 )
226 fResetWrappedProcessInteractionLength =
true;
227 ResetForUnbiasedTracking();
234 if ( fCurrentBiasingOperator == 0 )
236 if ( fIsPhysicsBasedBiasing )
241 if ( fResetWrappedProcessInteractionLength )
243 fResetWrappedProcessInteractionLength =
false;
265 if ( !fIsPhysicsBasedBiasing )
268 if ( fNonPhysicsBiasingOperation == 0 )
281 fWrappedProcessForceCondition = *
condition;
291 if ( fOccurenceBiasingOperation == 0 )
return fWrappedProcessPostStepGPIL;
295 fResetWrappedProcessInteractionLength =
true;
306 fBiasingForceCondition = fOccurenceBiasingOperation->
ProposeForceCondition( fWrappedProcessForceCondition );
309 *condition = fBiasingForceCondition;
310 return fBiasingPostStepGPIL;
322 if ( fCurrentBiasingOperator == 0 )
return fWrappedProcess->
PostStepDoIt(track, step);
327 if ( !fIsPhysicsBasedBiasing )
331 return particleChange;
346 if ( fOccurenceBiasingOperation != 0 )
354 return fParticleChange;
363 if ( fFinalStateBiasingOperation != 0 )
370 finalStateParticleChange = fWrappedProcess->
PostStepDoIt(track, step);
374 if ( fOccurenceBiasingOperation == 0 )
376 fCurrentBiasingOperator->
ReportOperationApplied(
this, BAC, fFinalStateBiasingOperation, finalStateParticleChange );
377 return finalStateParticleChange;
381 G4double weightForInteraction = 1.0;
382 if ( !fBiasingInteractionLaw->
IsSingular() ) weightForInteraction =
384 fBiasingInteractionLaw ->ComputeEffectiveCrossSectionAt(step.
GetStepLength());
391 ed <<
"Internal inconsistency in cross-section handling. Please report !" <<
G4endl;
392 G4Exception(
" G4BiasingProcessInterface::PostStepDoIt(...)",
402 if ( weightForInteraction <= 0. )
405 ed <<
" Negative interaction weight : w_I = "
406 << weightForInteraction <<
410 " Interaction law = `" << fBiasingInteractionLaw <<
"'" <<
412 G4Exception(
" G4BiasingProcessInterface::PostStepDoIt(...)",
420 fOccurenceBiasingOperation, weightForInteraction,
421 fFinalStateBiasingOperation, finalStateParticleChange );
430 return fOccurenceBiasingParticleChange;
443 fCurrentMinimumStep = currentMinimumStep;
444 fProposedSafety = proposedSafety;
448 fWrappedProcessAlongStepGPIL =
DBL_MAX;
453 if ( fCurrentBiasingOperator == 0 )
455 if ( fWrappedProcessIsAlong ) fWrappedProcessAlongStepGPIL =
461 return fWrappedProcessAlongStepGPIL;
467 if ( !fIsPhysicsBasedBiasing )
return fWrappedProcessAlongStepGPIL;
472 if ( fOccurenceBiasingOperation == 0 )
474 if ( fWrappedProcessIsAlong ) fWrappedProcessAlongStepGPIL =
480 return fWrappedProcessAlongStepGPIL;
489 G4double minimumStep = fBiasingAlongStepGPIL < currentMinimumStep ? fBiasingAlongStepGPIL : currentMinimumStep ;
492 if ( fWrappedProcessIsAlong )
499 fWrappedProcessGPILSelection = *selection;
500 fBiasingGPILSelection = fOccurenceBiasingOperation->
ProposeGPILSelection( fWrappedProcessGPILSelection );
505 fWrappedProcessAlongStepGPIL = fBiasingAlongStepGPIL;
508 *selection = fBiasingGPILSelection;
509 return fWrappedProcessAlongStepGPIL;
519 if ( fCurrentBiasingOperator == 0 )
521 if ( fWrappedProcessIsAlong )
return fWrappedProcess->
AlongStepDoIt(track, step);
525 return fDummyParticleChange;
538 G4double weightForNonInteraction (1.0);
539 if ( fBiasingInteractionLaw != 0 )
541 weightForNonInteraction =
543 fBiasingInteractionLaw ->ComputeNonInteractionProbabilityAt(step.
GetStepLength());
545 fOccurenceBiasingOperation->
AlongMoveBy(
this, &step, weightForNonInteraction );
547 if ( weightForNonInteraction <= 0. )
550 ed <<
" Negative non interaction weight : w_NI = " << weightForNonInteraction <<
552 " p_NI(bias) = " << fBiasingInteractionLaw ->ComputeNonInteractionProbabilityAt(step.
GetStepLength()) <<
554 " biasing interaction law = `" << fBiasingInteractionLaw->
GetName() <<
"'" <<
G4endl;
555 G4Exception(
" G4BiasingProcessInterface::AlongStepDoIt(...)",
565 return fOccurenceBiasingParticleChange;
578 return fWrappedProcess->
AtRestDoIt(track, step);
584 if ( fWrappedProcess != 0 )
return fWrappedProcess->
IsApplicable(pd);
594 if ( fWrappedProcess != 0 )
615 if ( fWrappedProcess != 0 )
623 SetUpFirstLastFlags();
624 if ( fWrappedProcess != 0 )
644 (fManagerInterfaceMap[mgr]).push_back(
this);
645 fCoInterfaces = &(fManagerInterfaceMap[mgr]);
646 fProcessManager = mgr;
666 if ( fWrappedProcess != 0 )
674 SetUpFirstLastFlags();
675 if ( fWrappedProcess != 0 )
688 G4int iPhys = ( physOnly ) ? 1 : 0;
689 return fFirstLastFlags[IdxFirstLast( 1, 1, iPhys)];
693 G4int iPhys = ( physOnly ) ? 1 : 0;
694 return fFirstLastFlags[IdxFirstLast( 0, 1, iPhys)];
698 G4int iPhys = ( physOnly ) ? 1 : 0;
699 return fFirstLastFlags[IdxFirstLast( 1, 0, iPhys)];
703 G4int iPhys = ( physOnly ) ? 1 : 0;
704 return fFirstLastFlags[IdxFirstLast( 0, 0, iPhys)];
713 for (
G4int i = 0; i < pv->
size(); i++ )
if ( (*pv)(i) ==
this ) { thisIdx = i;
break; }
714 for (
size_t i = 0; i < fCoInterfaces->size(); i++ )
719 for (
G4int j = 0; j < pv->
size(); j++ )
if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j;
break; }
720 if ( thisIdx > thatIdx )
735 for (
G4int i = 0; i < pv->
size(); i++ )
if ( (*pv)(i) ==
this ) { thisIdx = i;
break; }
736 for (
size_t i = 0; i < fCoInterfaces->size(); i++ )
741 for (
G4int j = 0; j < pv->
size(); j++ )
if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j;
break; }
742 if ( thisIdx < thatIdx )
757 for (
G4int i = 0; i < pv->
size(); i++ )
if ( (*pv)(i) ==
this ) { thisIdx = i;
break; }
758 for (
size_t i = 0; i < fCoInterfaces->size(); i++ )
763 for (
G4int j = 0; j < pv->
size(); j++ )
if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j;
break; }
764 if ( thisIdx > thatIdx )
779 for (
G4int i = 0; i < pv->
size(); i++ )
if ( (*pv)(i) ==
this ) { thisIdx = i;
break; }
780 for (
size_t i = 0; i < fCoInterfaces->size(); i++ )
785 for (
G4int j = 0; j < pv->
size(); j++ )
if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j;
break; }
786 if ( thisIdx < thatIdx )
797 void G4BiasingProcessInterface::SetUpFirstLastFlags()
799 for (
G4int iPhys = 0; iPhys < 2; iPhys++ )
801 G4bool physOnly = ( iPhys == 1 );
814 void G4BiasingProcessInterface::ResetForUnbiasedTracking()
816 fOccurenceBiasingOperation = 0;
817 fFinalStateBiasingOperation = 0;
818 fNonPhysicsBiasingOperation = 0;
819 fBiasingInteractionLaw = 0;
virtual void SetMasterProcess(G4VProcess *masterP)
virtual void Initialize(const G4Track &track)
G4double condition(const G4ErrorSymMatrix &m)
const G4VProcess * GetMasterProcess() const
virtual void BuildWorkerPhysicsTable(const G4ParticleDefinition &pd)
G4bool IsLastPostStepGPILInterface(G4bool physOnly=true) const
virtual void PreparePhysicsTable(const G4ParticleDefinition &pd)
G4VBiasingOperation * GetProposedFinalStateBiasingOperation(const G4Track *track, const G4BiasingProcessInterface *callingProcess)
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 *)
void SetWrappedParticleChange(G4VParticleChange *wpc)
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)=0
static G4BiasingTrackDataStore * GetInstance()
virtual G4bool StorePhysicsTable(const G4ParticleDefinition *pd, const G4String &s, G4bool f)
std::ostringstream G4ExceptionDescription
G4double GetStepLength() const
virtual void BuildPhysicsTable(const G4ParticleDefinition &pd)
virtual G4bool DenyProcessPostStepDoIt(const G4BiasingProcessInterface *, const G4Track *, const G4Step *, G4double &)
virtual void PrepareWorkerPhysicsTable(const G4ParticleDefinition &pd)
virtual G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &step)
G4StepStatus GetStepStatus() const
void ProposeParentWeight(G4double finalWeight)
G4TrackStatus GetTrackStatus() const
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &step)
G4VBiasingOperation * GetProposedOccurenceBiasingOperation(const G4Track *track, const G4BiasingProcessInterface *callingProcess)
virtual G4VParticleChange * ApplyFinalStateBiasing(const G4BiasingProcessInterface *, const G4Track *, const G4Step *)=0
virtual void SetProcessManager(const G4ProcessManager *)
virtual G4double ComputeEffectiveCrossSectionAt(G4double length) const =0
virtual void ResetNumberOfInteractionLengthLeft()
void SetOccurenceWeightForNonInteraction(G4double w)
const G4Step * GetStep() const
G4BiasingTrackData * GetBiasingTrackData(const G4Track *track)
virtual G4double ProposeAlongStepLimit(const G4BiasingProcessInterface *)
G4VProcess * GetWrappedProcess() const
virtual void BuildWorkerPhysicsTable(const G4ParticleDefinition &part)
G4bool GetIsFirstPostStepGPILInterface(G4bool physOnly=true) const
G4StepPoint * GetPreStepPoint() const
virtual void StartTracking(G4Track *)
void SetSecondaryWeightByProcess(G4bool)
G4int GetCurrentStepNumber() const
G4bool GetIsLastPostStepDoItInterface(G4bool physOnly=true) const
G4bool GetIsLastPostStepGPILInterface(G4bool physOnly=true) const
virtual void PreparePhysicsTable(const G4ParticleDefinition &)
virtual G4double ComputeEffectiveCrossSectionAt(G4double length) const
G4bool GetIsFirstPostStepDoItInterface(G4bool physOnly=true) const
virtual G4ForceCondition ProposeForceCondition(const G4ForceCondition wrappedProcessCondition)
G4double GetCurrentInteractionLength() const
void SetProcessSubType(G4int)
void SetPhysicalCrossSection(G4double crossSection)
void SetOccurenceWeightForInteraction(G4double w)
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
virtual G4bool RetrievePhysicsTable(const G4ParticleDefinition *, const G4String &, G4bool)
const G4String & GetProcessName() const
virtual G4VParticleChange * GenerateBiasingFinalState(const G4Track *, const G4Step *)=0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual G4bool IsApplicable(const G4ParticleDefinition &pd)
virtual const G4ProcessManager * GetProcessManager()
static G4VBiasingOperator * GetBiasingOperator(const G4LogicalVolume *)
virtual G4bool IsSingular() const
virtual const G4ProcessManager * GetProcessManager()
virtual void Initialize(const G4Track &)
G4LogicalVolume * GetLogicalVolume() const
virtual void BuildPhysicsTable(const G4ParticleDefinition &)
std::vector< G4Track * > G4TrackVector
virtual G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &stepData)=0
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
G4double GetWeight() const
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4double currentMinimumStep, G4double &proposedSafety, G4GPILSelection *selection)=0
G4double GetSampledInteractionLength() const
static const std::vector< G4VBiasingOperator * > & GetBiasingOperators()
const G4String & GetName() const
virtual G4bool StorePhysicsTable(const G4ParticleDefinition *, const G4String &, G4bool)
virtual G4bool IsEffectiveCrossSectionInfinite() const
G4TrackStatus GetTrackStatus() const
G4bool IsFirstPostStepDoItInterface(G4bool physOnly=true) const
virtual void AlongMoveBy(const G4BiasingProcessInterface *, const G4Step *, G4double)
virtual void ResetNumberOfInteractionLengthLeft()
virtual const G4VBiasingInteractionLaw * ProvideOccurenceBiasingInteractionLaw(const G4BiasingProcessInterface *)=0
virtual void PrepareWorkerPhysicsTable(const G4ParticleDefinition &)
void ProposeTrackStatus(G4TrackStatus status)
virtual void EndTracking()
void ReportOperationApplied(const G4BiasingProcessInterface *callingProcess, G4BiasingAppliedCase biasingCase, G4VBiasingOperation *operationApplied, const G4VParticleChange *particleChangeProduced)
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &stepData)=0
G4VBiasingOperation * GetProposedNonPhysicsBiasingOperation(const G4Track *track, const G4BiasingProcessInterface *callingProcess)
G4bool IsLastPostStepDoItInterface(G4bool physOnly=true) const
void ExitingBiasing(const G4Track *track, const G4BiasingProcessInterface *callingProcess)
void Put(const value_type &val) const
G4int GetProcessSubType() const
void StartTracking(G4Track *track)
virtual G4double DistanceToApplyOperation(const G4Track *, G4double, G4ForceCondition *)=0
virtual G4bool IsApplicable(const G4ParticleDefinition &)
const G4TrackVector * GetSecondary() const
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4double currentMinimumStep, G4double &proposedSafety, G4GPILSelection *selection)
virtual G4double AtRestGetPhysicalInteractionLength(const G4Track &, G4ForceCondition *)
~G4BiasingProcessInterface()
virtual G4VParticleChange * AtRestDoIt(const G4Track &track, const G4Step &stepData)=0
G4ProcessVector * GetPostStepProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const