Import Geant4 11.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2024-12-06 11:11:40 +01:00
parent e58e650b32
commit 32390e802b
1984 changed files with 98713 additions and 83996 deletions
@@ -23,20 +23,17 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// ----------------------------------------------------------------------
// Class G4ProcessPlacer
// G4ProcessPlacer
//
// Class description:
//
// Used internally by importance sampling and scoring.
// See G4VProcessPlacer.
// Author: Michael Dressel (Michael.Dressel@cern.ch)
// ----------------------------------------------------------------------
//
// Author: Michael Dressel, CERN
// --------------------------------------------------------------------
#ifndef G4ProcessPlacer_hh
#define G4ProcessPlacer_hh G4ProcessPlacer_hh
#define G4ProcessPlacer_hh 1
#include "G4Types.hh"
#include "G4String.hh"
@@ -48,24 +45,24 @@ class G4ProcessVector;
class G4ProcessPlacer : public G4VProcessPlacer
{
public: // with description
public:
explicit G4ProcessPlacer(const G4String &particlename);
explicit G4ProcessPlacer(const G4String& particlename);
// create a process placer for a particle type
virtual ~G4ProcessPlacer();
virtual void AddProcessAsLastDoIt(G4VProcess *process);
virtual void AddProcessAsLastDoIt(G4VProcess* process);
// place a post step do it process such that the
// PostStepDoIt function is called last
// THE ORDER CHANGES BY SUBSEQUENT CALLS
virtual void AddProcessAsSecondDoIt(G4VProcess *process);
virtual void AddProcessAsSecondDoIt(G4VProcess* process);
// place a post step do it process such that the
// PostStepDoIt function is called second
// THE ORDER CHANGES BY SUBSEQUENT CALLS
virtual void RemoveProcess(G4VProcess *process);
virtual void RemoveProcess(G4VProcess* process);
// removes a given process
enum SecondOrLast
@@ -74,10 +71,10 @@ public: // with description
eLast = 0
};
private:
private:
G4ProcessManager *GetProcessManager();
void AddProcessAs(G4VProcess *process, SecondOrLast);
G4ProcessManager* GetProcessManager();
void AddProcessAs(G4VProcess* process, SecondOrLast);
void PrintProcVec(G4ProcessVector* processVec);
void PrintAlongStepGPILVec();
@@ -85,7 +82,7 @@ private:
void PrintPostStepGPILVec();
void PrintPostStepDoItVec();
private:
private:
G4String fParticleName;
@@ -23,10 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
// G4VBiasingInteractionLaw
//
// Class Description:
//
@@ -43,13 +40,8 @@
// - an effective cross-section which is the
// sum on the individual effective cross-sections.
//
// ----------------G4VBiasingInteractionLaw ----------------
//
// Author: M.Verderi (LLR), November 2013
// - 05/11/13 : First Implementation
// --------------------------------------------------------------------
#ifndef G4VBiasingInteractionLaw_hh
#define G4VBiasingInteractionLaw_hh 1
@@ -58,58 +50,60 @@
class G4BiasingProcessInterface;
class G4VBiasingInteractionLaw {
public:
G4VBiasingInteractionLaw(G4String name) : fName(name), fSampledInteractionLength(DBL_MAX) {}
virtual ~G4VBiasingInteractionLaw() {}
class G4VBiasingInteractionLaw
{
public:
public:
const G4String& GetName() const { return fName; }
// ----------------------------
// -- Interface to sub-classes:
// ----------------------------
protected:
// -- Sample the distribution for point like interaction (PostStep ones)
virtual G4double SampleInteractionLength() = 0;
public:
// -- Compute non-interaction probability and effective cross-section:
// -- (probability of interaction over dl = effective_cross-section* dl)
virtual G4double ComputeNonInteractionProbabilityAt(G4double length) const = 0;
virtual G4double ComputeEffectiveCrossSectionAt(G4double length) const = 0;
protected:
// -- Convenience method, used in many daughters classes :
// -- update the distribution for a made step of truePathLength size:
virtual G4double UpdateInteractionLengthForStep(G4double /* truePathLength */) { return DBL_MAX; }
public:
// -- Methods to deal with singularities : null cross sections or infinite ones.
// -- In such cases, weight can not always be computed.
// -- Tells if this interaction law has singularities:
virtual G4bool IsSingular() const {return false;}
G4VBiasingInteractionLaw(const G4String& name)
: fName(name), fSampledInteractionLength(DBL_MAX) {}
virtual ~G4VBiasingInteractionLaw() = default;
const G4String& GetName() const { return fName; }
// -- Compute non-interaction probability and effective cross-section:
// -- (probability of interaction over dl = effective_cross-section* dl)
virtual G4double ComputeNonInteractionProbabilityAt(G4double length) const = 0;
virtual G4double ComputeEffectiveCrossSectionAt(G4double length) const = 0;
// -- Methods to deal with singularities : null cross sections or infinite ones.
// -- In such cases, weight can not always be computed.
// -- Tells if this interaction law has singularities:
virtual G4bool IsSingular() const { return false; }
// -- method interrogated only in case interaction law is IsSingular() == true:
virtual G4bool IsEffectiveCrossSectionInfinite() const {return false;}
// -----------------------------------------
// -- public interface to protected methods:
// -----------------------------------------
public:
G4double Sample()
{
fSampledInteractionLength = SampleInteractionLength();
return fSampledInteractionLength;
}
G4double UpdateForStep(G4double truePathLength)
{
fSampledInteractionLength = UpdateInteractionLengthForStep(truePathLength);
return fSampledInteractionLength;
}
G4double GetSampledInteractionLength() const { return fSampledInteractionLength; }
virtual G4bool IsEffectiveCrossSectionInfinite() const { return false; }
private:
G4String fName;
G4double fSampledInteractionLength;
// -----------------------------------------
// -- public interface to protected methods:
// -----------------------------------------
G4double Sample()
{
fSampledInteractionLength = SampleInteractionLength();
return fSampledInteractionLength;
}
G4double UpdateForStep(G4double truePathLength)
{
fSampledInteractionLength = UpdateInteractionLengthForStep(truePathLength);
return fSampledInteractionLength;
}
G4double GetSampledInteractionLength() const
{
return fSampledInteractionLength;
}
protected:
// -- Sample the distribution for point like interaction (PostStep ones)
virtual G4double SampleInteractionLength() = 0;
// -- Convenience method, used in many daughters classes :
// -- update the distribution for a made step of truePathLength size:
virtual G4double UpdateInteractionLengthForStep(G4double /* truePathLength */)
{ return DBL_MAX; }
private:
G4String fName;
G4double fSampledInteractionLength;
};
#endif
@@ -23,10 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// --------------------------------------------------------------------
// Geant4 class header file
// G4VBiasingOperation
//
// Class Description:
//
@@ -50,159 +47,145 @@
// specify where this biasing should happen, and one for generating
// the related final-state.
//
// ----------------G4VBiasingOperation ----------------
//
// Author: M.Verderi (LLR), November 2013
// - 05/11/13 : first implementation
// - 07/11/14 : suppress DenyProcessPostStepDoIt(...) as redondant
// and special case of ApplyFinalStateBiasing(...)
// ---------------------------------------------------------------------
// Author: Marc Verderi (LLR), November 2013
// --------------------------------------------------------------------
#ifndef G4VBiasingOperation_hh
#define G4VBiasingOperation_hh 1
#include "globals.hh"
#include "G4ForceCondition.hh"
#include "G4GPILSelection.hh"
class G4VParticleChange;
class G4Track;
class G4Step;
class G4VBiasingInteractionLaw;
class G4VProcess;
class G4BiasingProcessInterface;
#include "G4ForceCondition.hh"
#include "G4GPILSelection.hh"
class G4VBiasingOperation {
public:
// ---------------
// -- Constructor:
// ---------------
//
// -- Constructor for biasing operations:
// -----------------------------------
// -- Operation is given a name.
G4VBiasingOperation(G4String name);
class G4VBiasingOperation
{
public:
// -- destructor:
virtual ~G4VBiasingOperation();
// -- Constructor:
G4VBiasingOperation(const G4String& name);
public:
// -----------------------------
// -- Interface to sub-classes :
// -----------------------------
// --
// *************************************
// ** Methods for physics-based biasing:
// *************************************
// --
// ---- I. Biasing of the process occurrence:
// -----------------------------------------
// ---- The biasing of the process occurrence regards the occurrence of the PostStepDoIt
// ---- behavior. But the weight is manipulated by both AlongStep methods (weight for
// ---- non-interaction) and PostStep methods (weight for interaction). For this
// ---- reason, occurrence biasing is handled by both AlongStep and PostStep methods.
// ----
// ---- If the operation is returned to the G4BiasingProcessInterface process by the
// ---- ProposeOccurenceBiasingOperation(...)/GetProposedOccurenceBiasingOperation(...) method
// ---- of the biasing operator, all methods below will be called for this operation.
// ----
// ---- I.1) Methods called in at the PostStepGetPhysicalInteractionLength(...) level :
// ----
// ------ o Main and mandatory method for biasing of the PostStep process biasing occurrence :
// ------ - propose an interaction law to be substituted to the process that is biased
// ------ - the operation is told which is the G4BiasingProcessInterface calling it with
// ------ callingProcess argument.
// ------ - the returned law will have to have been sampled prior to be returned as it will be
// ------ asked for its GetSampledInteractionLength() by the callingProcess.
// ------ - the operation can propose a force condition in the PostStepGPIL (the passed value
// ------ to the operation is the one of the wrapped process, if proposeForceCondition is
// ------ unchanged, this same value will be used as the biasing foroce condition)
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* /* callingProcess */ ,
G4ForceCondition& /* proposeForceCondition */ ) = 0;
// ----
// ---- I.2) Methods called in at the AlongStepGetPhysicalInteractionLength(...) level :
// ----
// ------ o Operation can optionnally limit GPIL Along Step:
virtual G4double ProposeAlongStepLimit( const G4BiasingProcessInterface* /* callingProcess */ ) { return DBL_MAX; }
// ------ o Operation can propose a GPILSelection in the AlongStepGPIL
// ------ this selection superseeded the wrapped process selection
// ------ if the wrapped process exists, and if has along methods:
virtual G4GPILSelection ProposeGPILSelection( const G4GPILSelection wrappedProcessSelection )
{return wrappedProcessSelection;}
// -- destructor:
virtual ~G4VBiasingOperation() = default;
// -----------------------------
// -- Interface to sub-classes :
// -----------------------------
// --
// *************************************
// ** Methods for physics-based biasing:
// *************************************
// --
// ---- I. Biasing of the process occurrence:
// -----------------------------------------
// ---- The biasing of the process occurrence regards the occurrence of the PostStepDoIt
// ---- behavior. But the weight is manipulated by both AlongStep methods (weight for
// ---- non-interaction) and PostStep methods (weight for interaction). For this
// ---- reason, occurrence biasing is handled by both AlongStep and PostStep methods.
// ----
// ---- If the operation is returned to the G4BiasingProcessInterface process by the
// ---- ProposeOccurenceBiasingOperation(...)/GetProposedOccurenceBiasingOperation(...) method
// ---- of the biasing operator, all methods below will be called for this operation.
// ----
// ---- I.1) Methods called in at the PostStepGetPhysicalInteractionLength(...) level :
// ----
// ------ o Main and mandatory method for biasing of the PostStep process biasing occurrence :
// ------ - propose an interaction law to be substituted to the process that is biased
// ------ - the operation is told which is the G4BiasingProcessInterface calling it with
// ------ callingProcess argument.
// ------ - the returned law will have to have been sampled prior to be returned as it will be
// ------ asked for its GetSampledInteractionLength() by the callingProcess.
// ------ - the operation can propose a force condition in the PostStepGPIL (the passed value
// ------ to the operation is the one of the wrapped process, if proposeForceCondition is
// ------ unchanged, this same value will be used as the biasing foroce condition)
virtual const G4VBiasingInteractionLaw*
ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* /* callingProcess */ ,
G4ForceCondition& /* proposeForceCondition */ ) = 0;
// ----
// ---- I.2) Methods called in at the AlongStepGetPhysicalInteractionLength(...) level :
// ----
// ------ o Operation can optionnally limit GPIL Along Step:
virtual G4double ProposeAlongStepLimit( const G4BiasingProcessInterface* /* callingProcess */ )
{ return DBL_MAX; }
// ------ o Operation can propose a GPILSelection in the AlongStepGPIL
// ------ this selection superseeded the wrapped process selection
// ------ if the wrapped process exists, and if has along methods:
virtual G4GPILSelection ProposeGPILSelection( const G4GPILSelection wrappedProcessSelection )
{ return wrappedProcessSelection; }
// ----
// ---- I.3) Methods called in at the AlongStepDoIt(...) level :
// ----
// ------ o Helper method to inform the operation of the move made in the along, and related non-interaction weight
// ------ applied to the primary track for this move:
virtual void AlongMoveBy( const G4BiasingProcessInterface* /* callingProcess */,
const G4Step* /* step */,
G4double /* weightForNonInteraction */ ) {}
// ----
// ---- I.3) Methods called in at the AlongStepDoIt(...) level :
// ----
// ------ o Helper method to inform the operation of the move made in the along, and related non-interaction weight
// ------ applied to the primary track for this move:
virtual void AlongMoveBy( const G4BiasingProcessInterface* /* callingProcess */,
const G4Step* /* step */,
G4double /* weightForNonInteraction */ ) {}
// ---- II. Biasing of the process post step final state:
// ------------------------------------------------------
// ------ Mandatory method for biasing of the PostStepDoIt of the wrapped process
// ------ holds by the G4BiasingProcessInterface callingProcess.
// ------ User has full freedom for the particle change returned, and is reponsible for
// ------ the correctness of weights set to tracks.
// ------ The forcedBiasedFinalState should be left as is (ie false) in general. In this
// ------ way, if an occurrence biasing is also applied in the step, the weight correction
// ------ for it will be applied. If returned forceBiasedFinalState is returned true, then
// ------ the returned particle change will be returned as is to the stepping. Full
// ------ responsibility of the weight correctness is taken by the biasing operation.
// ------ The wrappedProcess can be accessed through the G4BiasingProcessInterface if needed.
// ------ This can be used in conjunction with an occurrence biasing, provided this final
// ------ state biasing is uncorrelated with the occurrence biasing (as single multiplication
// ------ of weights occur between these two biasings).
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface* /* callingProcess */,
const G4Track* /* track */,
const G4Step* /* step */,
G4bool& /* forceBiasedFinalState */) = 0;
// ---- II. Biasing of the process post step final state:
// ------------------------------------------------------
// ------ Mandatory method for biasing of the PostStepDoIt of the wrapped process
// ------ holds by the G4BiasingProcessInterface callingProcess.
// ------ User has full freedom for the particle change returned, and is reponsible for
// ------ the correctness of weights set to tracks.
// ------ The forcedBiasedFinalState should be left as is (ie false) in general. In this
// ------ way, if an occurrence biasing is also applied in the step, the weight correction
// ------ for it will be applied. If returned forceBiasedFinalState is returned true, then
// ------ the returned particle change will be returned as is to the stepping. Full
// ------ responsibility of the weight correctness is taken by the biasing operation.
// ------ The wrappedProcess can be accessed through the G4BiasingProcessInterface if needed.
// ------ This can be used in conjunction with an occurrence biasing, provided this final
// ------ state biasing is uncorrelated with the occurrence biasing (as single multiplication
// ------ of weights occur between these two biasings).
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface* /* callingProcess */,
const G4Track* /* track */,
const G4Step* /* step */,
G4bool& /* forceBiasedFinalState */) = 0;
// ---- III. Biasing of the process along step final state:
// --------------------------------------------------------
// ---- Unprovided for now : requires significant developments.
// ---- III. Biasing of the process along step final state:
// --------------------------------------------------------
// ---- Unprovided for now : requires significant developments.
// ***************************************************
// -- Methods for non-physics-based biasing operation:
// ***************************************************
// ----
// ---- If the operation is returned to the G4BiasingProcessInterface process by the
// ---- ProposeNonPhysicsBiasingOperation(...)/GetProposedNonPhysicsBiasingOperation(...) method
// ---- of the biasing operator, all methods below will be called for this operation.
// -----
// ---- 1) Method called in at the PostStepGetPhysicalInteractionLength(...) level :
// ----
// ---- o Return to the distance at which the operation should be applied, or may
// ---- play with the force condition flags.
virtual G4double DistanceToApplyOperation( const G4Track* /* track */,
G4double /* previousStepSize */,
G4ForceCondition* /* condition */) = 0;
// ----
// ---- 2) Method called in at the PostStepDoIt(...) level :
// ----
// ---- o Generate the final state for biasing (eg: splitting, killing, etc.)
virtual G4VParticleChange* GenerateBiasingFinalState( const G4Track* /* track */,
const G4Step* /* step */) = 0;
// ----------------------------------------
// -- public interface and utility methods:
// ----------------------------------------
const G4String& GetName() const { return fName; }
std::size_t GetUniqueID() const { return fUniqueID; }
// ***************************************************
// -- Methods for non-physics-based biasing operation:
// ***************************************************
// ----
// ---- If the operation is returned to the G4BiasingProcessInterface process by the
// ---- ProposeNonPhysicsBiasingOperation(...)/GetProposedNonPhysicsBiasingOperation(...) method
// ---- of the biasing operator, all methods below will be called for this operation.
// -----
// ---- 1) Method called in at the PostStepGetPhysicalInteractionLength(...) level :
// ----
// ---- o Return to the distance at which the operation should be applied, or may
// ---- play with the force condition flags.
virtual G4double DistanceToApplyOperation( const G4Track* /* track */,
G4double /* previousStepSize */,
G4ForceCondition* /* condition */) = 0;
// ----
// ---- 2) Method called in at the PostStepDoIt(...) level :
// ----
// ---- o Generate the final state for biasing (eg: splitting, killing, etc.)
virtual G4VParticleChange* GenerateBiasingFinalState( const G4Track* /* track */,
const G4Step* /* step */) = 0;
private:
// ----------------------------------------
// -- public interface and utility methods:
// ----------------------------------------
public:
const G4String& GetName() const {return fName;}
std::size_t GetUniqueID() const {return fUniqueID;}
private:
const G4String fName;
// -- better would be to have fUniqueID const, but pb on windows with constructor.
std::size_t fUniqueID;
const G4String fName;
// -- better would be to have fUniqueID const, but pb on windows with constructor.
std::size_t fUniqueID;
};
#endif
@@ -23,14 +23,11 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
// G4VBiasingOperator, G4BiasingOperatorStateNotifier
//
// Class Description:
//
// An abstract class to pilot the biasing in a logical volume. This
// An abstract class to pilot the biasing in a logical volume. This
// class is for *making decisions* on biasing operations to be applied.
// These ones are represented by the G4VBiasingOperation class.
// The volume in which biasing is applied is specified by the
@@ -38,13 +35,13 @@
// at detector construction time in the method ConstructSDandField() of
// G4VUsedDetectorConstruction.
//
// At tracking time the biasing operator is messaged by each
// At tracking time the biasing operator is messaged by each
// G4BiasingProcessInterface object attached to the current track. For
// example, if three physics processes are under biasing, and if an
// additional G4BiasingProcessInterface is present to handle non-physics
// based biasing (splitting, killing), the operator will be messaged by
// these four G4BiasingProcessInterface objects.
// The idendity of the calling G4BiasingProcessInterface is known
// The idendity of the calling G4BiasingProcessInterface is known
// to the G4VBiasingOperator by passing this process pointer to the
// operator.
//
@@ -122,10 +119,10 @@
// for operation(s) which have been applied during the step. One of the two following
// methods is called:
//
// virtual void OperationApplied( const G4BiasingProcessInterface* callingProcess,
// G4BiasingAppliedCase biasingCase,
// G4VBiasingOperation* operationApplied,
// const G4VParticleChange* particleChangeProduced );
// virtual void OperationApplied( const G4BiasingProcessInterface* callingProcess,
// G4BiasingAppliedCase biasingCase,
// G4VBiasingOperation* operationApplied,
// const G4VParticleChange* particleChangeProduced );
// At most a single biasing operation was applied by the process:
// - a non-physics biasing operation was applied, biasingCase == BAC_NonPhysics ;
// - physics-based biasing:
@@ -136,12 +133,12 @@
// The operation applied and final state passed to the tracking (particleChangeProduced) are
// passed as information to the operator.
//
// virtual void OperationApplied( const G4BiasingProcessInterface* callingProcess,
// G4BiasingAppliedCase biasingCase,
// G4VBiasingOperation* occurenceOperationApplied,
// G4double weightForOccurenceInteraction,
// G4VBiasingOperation* finalStateOperationApplied,
// const G4VParticleChange* particleChangeProduced );
// virtual void OperationApplied( const G4BiasingProcessInterface* callingProcess,
// G4BiasingAppliedCase biasingCase,
// G4VBiasingOperation* occurenceOperationApplied,
// G4double weightForOccurenceInteraction,
// G4VBiasingOperation* finalStateOperationApplied,
// const G4VParticleChange* particleChangeProduced );
// This method is called in case an occurrence biasing operation has been applied during the step.
// The biasingCase value is then the one of the final state biasing, if any : depending on if the
// occurrence operation was applied alone and together with a final state operation, the
@@ -153,17 +150,18 @@
// either the particle change of the (analog) physics process, or the biased final state, resulting
// from the biasing by the finalStateOperationApplied operation.
//
//
// ----------------G4VBiasingOperation ----------------
//
// Author: M.Verderi (LLR), November 2013
//
// --------------------------------------------------------------------
#ifndef G4VBiasingOperator_hh
#define G4VBiasingOperator_hh 1
#include "globals.hh"
#include "G4BiasingAppliedCase.hh"
#include "G4Cache.hh"
#include "G4VStateDependent.hh"
#include <map>
#include <vector>
class G4VBiasingOperation;
class G4Track;
@@ -171,194 +169,188 @@ class G4BiasingProcessInterface;
class G4LogicalVolume;
class G4VParticleChange;
class G4BiasingOperatorStateNotifier;
#include <map>
#include <vector>
#include "G4BiasingAppliedCase.hh"
#include "G4Cache.hh"
class G4VBiasingOperator {
class G4VBiasingOperator
{
// -- State machine used to inform operators
// -- about run starting.
// -- Defined at the end of this file.
friend class G4BiasingOperatorStateNotifier;
public:
// ---------------
// -- Constructor:
// ---------------
G4VBiasingOperator(G4String name);
virtual ~G4VBiasingOperator();
// ----------------------------------------------
// -- abstract and user interface to sub-classes:
// ----------------------------------------------
protected:
// -- mandatory methods to let the operator tell about biasing operations to be applied:
// -------------------------------------------------------------------------------------
// -- These three methods have the same arguments passed : the current G4Track pointer, and the pointer of the
// -- G4BiasingProcessInterface instance calling this biasing operator. This same biasing operator will be called by each
// -- of the G4BiasingProcessInterface instances, meaning for example that:
// -- - if one G4BiasingProcessInterface with no wrapped physics process exits, ProposeNonPhysicsBiasingOperation(...)
// -- will be called one time at the beginning of the step,
// -- - if three G4BiasingProcessInterface instances exist, each of these one wrapping a physics process (eg
// -- conversion, Compton, photo-electric), ProposeOccurenceBiasingOperation(...) will be called three times,
// -- by each of these instances, at the beginning of the step and ProposeFinalStateBiasingOperation(...) will
// -- also be called by each of these instances, at the PostStepDoIt level.
// -- If a null pointer is returned, the analog -unbiased- behavior is adopted.
// -- non-physics-based biasing:
// -----------------------------
// -- [ First operator method called, at the PostStepGetPhysicalInterationLength(...) level. ]
virtual G4VBiasingOperation* ProposeNonPhysicsBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess ) = 0;
// -- physics-based biasing:
// -------------------------
// -- Method to propose an occurrence biasing operation : ie a change of the interaction length distribution. The proposed
// -- biasing operation will then be asked for its interaction law.
// -- Note that *** all sanity checks regarding the operation and its interaction law will have to have been performed
// -- before returning the biasing operation pointer *** as no corrective/aborting actions will be possible beyond this point.
// -- The informations provided by the G4BiasingProcessInterface calling process (previous occurrence operation, previous step length,
// -- etc.) might be useful for doing this. They will be useful also to decide with continuing with a same operation proposed
// -- in the previous step, updating the interaction law taking into account the new G4Track state and the previous step size.
// -- [ Second operator method called, at the PostStepGetPhysicalInterationLength(...) level. ]
virtual G4VBiasingOperation* ProposeOccurenceBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess ) = 0;
// -- [ Third operator method called, at the PostStepDoIt(...) level. ]
virtual G4VBiasingOperation* ProposeFinalStateBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess ) = 0;
protected:
// -- optional methods for further information passed to the operator:
// -------------------------------------------------------------------
// ---- report to operator about the operation applied, the biasingCase value provides the case of biasing applied:
virtual void OperationApplied( const G4BiasingProcessInterface* callingProcess, G4BiasingAppliedCase biasingCase,
G4VBiasingOperation* operationApplied, const G4VParticleChange* particleChangeProduced );
// ---- same as above, report about the operation applied, for the case an occurrence biasing was applied, together or not with a final state biasing.
// ---- The variable biasingCase tells if the final state is a biased one or not. **But in all cases**, this call happens only
// ---- for an occurrence biasing : ie the occurrence weight is applied on top of the particleChangeProduced, which is the particle
// ---- *before* the weight application for occurence biasing.
virtual void OperationApplied( const G4BiasingProcessInterface* callingProcess, G4BiasingAppliedCase biasingCase,
G4VBiasingOperation* occurenceOperationApplied, G4double weightForOccurenceInteraction,
G4VBiasingOperation* finalStateOperationApplied, const G4VParticleChange* particleChangeProduced );
protected:
// ---- method to inform operator that its biasing control is over (exit volume, or end of tracking):
// ---- [Called at the beginning of next step, or at the end of tracking.]
virtual void ExitBiasing( const G4Track* track, const G4BiasingProcessInterface* callingProcess );
public:
// ---------------
// -- Constructor:
// ---------------
G4VBiasingOperator(const G4String& name);
virtual ~G4VBiasingOperator() = default;
protected:
// ----------------------------------
// -- Delegation to another operator:
// ----------------------------------
// -- An operator may wish to select a sequence of operations already implemented in an
// -- existing biasing operator. In this case, this operator can delegate its work to
// -- the "delegated" one by calling DelegateTo( G4VBiasingOperation* delegated );
// -- §§ Should we have:
// -- §§ - a "step delegation" -where the delegation is made for the current step only-
// -- §§ - a long delegation where the delegation can hold over several steps, as long as
// -- §§ the scheme is not completed. [let's call it "scheme delegation"]
// -- §§ In this case the "execution/delegated" operator might switch off back the
// -- §§ delegation from the "delegator" when it knows it has done its work.
// -- §§ Add a private SetDelegator( G4VBiasingOperator* ) method, call on the delegated
// -- §§ operator.
// -- §§ For a step long delegation, the ReportOperationApplied should be used to "unset"
// -- §§ the delegation. For a scheme long delegation, the delegater operator will unset
// -- §§ itself has delegation. Likely to happen in the ReportOperationApplied as well,
// -- §§ but not sure it is mandatory though.
// ---- Configure() is called in sequential mode or for master thread in MT mode.
// ---- It is in particular aimed at registering ID's to physics model at run initialization.
virtual void Configure() {}
// ---- ConfigureForWorker() is called in MT mode only, and only for worker threads.
// ---- It is not not to be used to register ID's to physics model catalog.
virtual void ConfigureForWorker() {}
// ---- inform the operator of the start of the run:
virtual void StartRun() {}
// ---- inform the operator of the start (end) of the tracking of a new track:
virtual void StartTracking( const G4Track* /* track */ ) {}
virtual void EndTracking() {}
// --------------------
// -- public interface:
// --------------------
// -- needed by user:
const G4String& GetName() const { return fName; }
void AttachTo( const G4LogicalVolume* ); // -- attach to single volume
public:
// ---- Configure() is called in sequential mode or for master thread in MT mode.
// ---- It is in particular aimed at registering ID's to physics model at run initialization.
virtual void Configure() {}
// ---- ConfigureForWorker() is called in MT mode only, and only for worker threads.
// ---- It is not not to be used to register ID's to physics model catalog.
virtual void ConfigureForWorker() {}
// ---- inform the operator of the start of the run:
virtual void StartRun() {}
// ---- inform the operator of the start (end) of the tracking of a new track:
virtual void StartTracking( const G4Track* /* track */ ) {}
virtual void EndTracking() {}
// --------------------
// -- public interface:
// --------------------
// -- needed by user:
public:
const G4String GetName() const {return fName;}
void AttachTo( const G4LogicalVolume* ); // -- attach to single volume
G4BiasingAppliedCase GetPreviousBiasingAppliedCase() const
{ return fPreviousBiasingAppliedCase; }
// -- all operators (might got to a manager):
static const std::vector < G4VBiasingOperator* >& GetBiasingOperators();
// -- get operator associated to a logical volume:
static G4VBiasingOperator* GetBiasingOperator( const G4LogicalVolume* );
// -- might go to a manager ; or moved to volume
G4BiasingAppliedCase GetPreviousBiasingAppliedCase() const {return fPreviousBiasingAppliedCase;}
// -- all operators (might got to a manager):
static const std::vector < G4VBiasingOperator* >& GetBiasingOperators() {return fOperators.Get();}
// -- get operator associated to a logical volume:
static G4VBiasingOperator* GetBiasingOperator( const G4LogicalVolume* ); // -- might go to a manager ; or moved to volume
// -- used by biasing process interface, or used by another operator (not expected to be invoked differently than with these two cases):
G4VBiasingOperation* GetProposedOccurenceBiasingOperation( const G4Track* track,
const G4BiasingProcessInterface* callingProcess );
G4VBiasingOperation* GetProposedFinalStateBiasingOperation( const G4Track* track,
const G4BiasingProcessInterface* callingProcess );
G4VBiasingOperation* GetProposedNonPhysicsBiasingOperation( const G4Track* track,
const G4BiasingProcessInterface* callingProcess );
void ExitingBiasing( const G4Track* track,
const G4BiasingProcessInterface* callingProcess );
void ReportOperationApplied( const G4BiasingProcessInterface* callingProcess,
G4BiasingAppliedCase biasingCase,
G4VBiasingOperation* operationApplied,
const G4VParticleChange* particleChangeProduced );
void ReportOperationApplied( const G4BiasingProcessInterface* callingProcess,
G4BiasingAppliedCase biasingCase,
G4VBiasingOperation* occurenceOperationApplied,
G4double weightForOccurenceInteraction,
G4VBiasingOperation* finalStateOperationApplied,
const G4VParticleChange* particleChangeProduced );
// -- used by biasing process interface, or used by another operator (not expected to be invoked differently than with these two cases):
public:
G4VBiasingOperation* GetProposedOccurenceBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess );
G4VBiasingOperation* GetProposedFinalStateBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess );
G4VBiasingOperation* GetProposedNonPhysicsBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess );
void ExitingBiasing( const G4Track* track, const G4BiasingProcessInterface* callingProcess );
public:
void ReportOperationApplied( const G4BiasingProcessInterface* callingProcess, G4BiasingAppliedCase biasingCase,
G4VBiasingOperation* operationApplied, const G4VParticleChange* particleChangeProduced );
void ReportOperationApplied( const G4BiasingProcessInterface* callingProcess, G4BiasingAppliedCase biasingCase,
G4VBiasingOperation* occurenceOperationApplied, G4double weightForOccurenceInteraction,
G4VBiasingOperation* finalStateOperationApplied, const G4VParticleChange* particleChangeProduced );
public:
const G4VBiasingOperation* GetPreviousNonPhysicsAppliedOperation() {return fPreviousAppliedNonPhysicsBiasingOperation;}
private:
const G4String fName;
// -- thread local:
// static std::map< const G4LogicalVolume*, G4VBiasingOperator* > fLogicalToSetupMap;
static G4MapCache< const G4LogicalVolume*, G4VBiasingOperator* > fLogicalToSetupMap;
// -- thread local:
static G4VectorCache<G4VBiasingOperator* > fOperators;
// static std::vector < G4VBiasingOperator* > fOperators;
const G4VBiasingOperation* GetPreviousNonPhysicsAppliedOperation()
{ return fPreviousAppliedNonPhysicsBiasingOperation; }
// -- thread local:
static G4Cache< G4BiasingOperatorStateNotifier* > fStateNotifier;
protected:
// -- mandatory methods to let the operator tell about biasing operations to be applied:
// -------------------------------------------------------------------------------------
// -- These three methods have the same arguments passed : the current G4Track pointer, and the pointer of the
// -- G4BiasingProcessInterface instance calling this biasing operator. This same biasing operator will be called by each
// -- of the G4BiasingProcessInterface instances, meaning for example that:
// -- - if one G4BiasingProcessInterface with no wrapped physics process exits, ProposeNonPhysicsBiasingOperation(...)
// -- will be called one time at the beginning of the step,
// -- - if three G4BiasingProcessInterface instances exist, each of these one wrapping a physics process (eg
// -- conversion, Compton, photo-electric), ProposeOccurenceBiasingOperation(...) will be called three times,
// -- by each of these instances, at the beginning of the step and ProposeFinalStateBiasingOperation(...) will
// -- also be called by each of these instances, at the PostStepDoIt level.
// -- If a null pointer is returned, the analog -unbiased- behavior is adopted.
// -- non-physics-based biasing:
// -----------------------------
// -- [ First operator method called, at the PostStepGetPhysicalInterationLength(...) level. ]
virtual G4VBiasingOperation* ProposeNonPhysicsBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess ) = 0;
// -- For this operator:
std::vector< const G4LogicalVolume* > fRootVolumes;
std::map < const G4LogicalVolume*, G4int > fDepthInTree;
// -- physics-based biasing:
// -------------------------
// -- Method to propose an occurrence biasing operation : ie a change of the interaction length distribution. The proposed
// -- biasing operation will then be asked for its interaction law.
// -- Note that *** all sanity checks regarding the operation and its interaction law will have to have been performed
// -- before returning the biasing operation pointer *** as no corrective/aborting actions will be possible beyond this point.
// -- The informations provided by the G4BiasingProcessInterface calling process (previous occurrence operation, previous step length,
// -- etc.) might be useful for doing this. They will be useful also to decide with continuing with a same operation proposed
// -- in the previous step, updating the interaction law taking into account the new G4Track state and the previous step size.
// -- [ Second operator method called, at the PostStepGetPhysicalInterationLength(...) level. ]
virtual G4VBiasingOperation* ProposeOccurenceBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess ) = 0;
// -- [ Third operator method called, at the PostStepDoIt(...) level. ]
virtual G4VBiasingOperation* ProposeFinalStateBiasingOperation( const G4Track* track, const G4BiasingProcessInterface* callingProcess ) = 0;
// -- optional methods for further information passed to the operator:
// -------------------------------------------------------------------
// ---- report to operator about the operation applied, the biasingCase value provides the case of biasing applied:
virtual void OperationApplied( const G4BiasingProcessInterface* callingProcess, G4BiasingAppliedCase biasingCase,
G4VBiasingOperation* operationApplied, const G4VParticleChange* particleChangeProduced );
// ---- same as above, report about the operation applied, for the case an occurrence biasing was applied, together or not with a final state biasing.
// ---- The variable biasingCase tells if the final state is a biased one or not. **But in all cases**, this call happens only
// ---- for an occurrence biasing : ie the occurrence weight is applied on top of the particleChangeProduced, which is the particle
// ---- *before* the weight application for occurence biasing.
virtual void OperationApplied( const G4BiasingProcessInterface* callingProcess, G4BiasingAppliedCase biasingCase,
G4VBiasingOperation* occurenceOperationApplied, G4double weightForOccurenceInteraction,
G4VBiasingOperation* finalStateOperationApplied, const G4VParticleChange* particleChangeProduced );
// ---- method to inform operator that its biasing control is over (exit volume, or end of tracking):
// ---- [Called at the beginning of next step, or at the end of tracking.]
virtual void ExitBiasing( const G4Track* track, const G4BiasingProcessInterface* callingProcess );
// ----------------------------------
// -- Delegation to another operator:
// ----------------------------------
// -- An operator may wish to select a sequence of operations already implemented in an
// -- existing biasing operator. In this case, this operator can delegate its work to
// -- the "delegated" one by calling DelegateTo( G4VBiasingOperation* delegated );
// -- Should we have:
// -- - a "step delegation" -where the delegation is made for the current step only-
// -- - a long delegation where the delegation can hold over several steps, as long as
// -- the scheme is not completed. [let's call it "scheme delegation"]
// -- In this case the "execution/delegated" operator might switch off back the
// -- delegation from the "delegator" when it knows it has done its work.
// -- Add a private SetDelegator( G4VBiasingOperator* ) method, call on the delegated
// -- operator.
// -- For a step long delegation, the ReportOperationApplied should be used to "unset"
// -- the delegation. For a scheme long delegation, the delegater operator will unset
// -- itself has delegation. Likely to happen in the ReportOperationApplied as well,
// -- but not sure it is mandatory though.
// -- current operation:
G4VBiasingOperation* fOccurenceBiasingOperation;
G4VBiasingOperation* fFinalStateBiasingOperation;
G4VBiasingOperation* fNonPhysicsBiasingOperation;
private:
const G4String fName;
// -- thread local:
static G4MapCache< const G4LogicalVolume*, G4VBiasingOperator* > fLogicalToSetupMap;
// -- thread local:
static G4VectorCache<G4VBiasingOperator* > fOperators;
// -- thread local:
static G4Cache< G4BiasingOperatorStateNotifier* > fStateNotifier;
// -- For this operator:
std::vector< const G4LogicalVolume* > fRootVolumes;
std::map< const G4LogicalVolume*, G4int > fDepthInTree;
// -- previous operations:
const G4VBiasingOperation* fPreviousProposedOccurenceBiasingOperation;
const G4VBiasingOperation* fPreviousProposedFinalStateBiasingOperation;
const G4VBiasingOperation* fPreviousProposedNonPhysicsBiasingOperation;
const G4VBiasingOperation* fPreviousAppliedOccurenceBiasingOperation;
const G4VBiasingOperation* fPreviousAppliedFinalStateBiasingOperation;
const G4VBiasingOperation* fPreviousAppliedNonPhysicsBiasingOperation;
G4BiasingAppliedCase fPreviousBiasingAppliedCase;
// -- current operation:
G4VBiasingOperation* fOccurenceBiasingOperation = nullptr;
G4VBiasingOperation* fFinalStateBiasingOperation = nullptr;
G4VBiasingOperation* fNonPhysicsBiasingOperation = nullptr;
// -- previous operations:
const G4VBiasingOperation* fPreviousProposedOccurenceBiasingOperation = nullptr;
const G4VBiasingOperation* fPreviousProposedFinalStateBiasingOperation = nullptr;
const G4VBiasingOperation* fPreviousProposedNonPhysicsBiasingOperation = nullptr;
const G4VBiasingOperation* fPreviousAppliedOccurenceBiasingOperation = nullptr;
const G4VBiasingOperation* fPreviousAppliedFinalStateBiasingOperation = nullptr;
const G4VBiasingOperation* fPreviousAppliedNonPhysicsBiasingOperation = nullptr;
G4BiasingAppliedCase fPreviousBiasingAppliedCase = BAC_None;
};
// -- state machine to get biasing operators
// -- messaged at the beginning of runs:
#include "G4VStateDependent.hh"
class G4BiasingOperatorStateNotifier : public G4VStateDependent {
public:
G4BiasingOperatorStateNotifier();
~G4BiasingOperatorStateNotifier();
public:
G4bool Notify(G4ApplicationState requestedState);
private:
G4ApplicationState fPreviousState;
class G4BiasingOperatorStateNotifier : public G4VStateDependent
{
public:
G4BiasingOperatorStateNotifier();
~G4BiasingOperatorStateNotifier() = default;
G4bool Notify(G4ApplicationState requestedState);
private:
G4ApplicationState fPreviousState;
};
#endif