Import Geant4 10.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 12:08:39 +02:00
parent 286caacf06
commit c9b32a6c0a
5770 changed files with 1050949 additions and 367105 deletions
+24 -1
View File
@@ -1,4 +1,4 @@
$Id: History 74497 2013-10-10 11:40:16Z ahoward $
$Id: History 86757 2014-11-17 15:16:50Z gcosmo $
-------------------------------------------------------------------
=========================================================
@@ -17,6 +17,29 @@ committal in the CVS repository !
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
November 14th, 2014 M.Verderi
- Serious fix in G4InteractionLawPhysical::
UpdateInteractionLengthForStep(...)
- proc-biasgen-V10-00-03
November 13th, 2014 M.Verderi
- Tentative fix of crach in optimized mode
missing initialization in second constructor of G4BiasingProcessInterface.
- proc-biasgen-V10-00-02
November 11th, 2014 M.Verderi
- fix Coverity bugs
- proc-biasgen-V10-00-01
November 11th, 2014 M.Verderi
- Introduce anticipated call to PostStepGPIL of wrapped processes
by G4BiasingProcessInterface. This allows to collect all
physics cross-sections at the first call to biasing operator.
- Adaptation to change of G4VBiasingOperation (suppression of
DenyProcessPostStepDoIt(...) ).
- tag : proc-biasgen-V10-00-00 .
October 10th, 2013 A.Howard
- Subdirectory and history file created.
@@ -55,17 +55,19 @@ public:
// -- Methods from G4VBiasingOperation interface:
// ----------------------------------------------
// -- Used:
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* );
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface*,
G4ForceCondition& proposeForceCondition );
// -- Unused:
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface*,
const G4Track*,
const G4Step* ) {return 0;}
const G4Step*,
G4bool& ) {return 0;}
virtual G4double DistanceToApplyOperation( const G4Track*,
G4double,
G4ForceCondition*) {return DBL_MAX;}
G4ForceCondition*) {return DBL_MAX;}
virtual G4VParticleChange* GenerateBiasingFinalState( const G4Track*,
const G4Step* ) {return 0;}
const G4Step* ) {return 0;}
public:
// -- Additional methods, specific to this class:
@@ -56,10 +56,11 @@ public:
// -- Methods from G4VBiasingOperation interface:
// -------------------------------------------
// -- Unsed:
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* ) {return 0;}
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface*, G4ForceCondition& ) {return 0;}
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface*,
const G4Track*,
const G4Step* ) {return 0;}
const G4Step*,
G4bool& ) {return 0;}
// -- Used:
virtual G4double DistanceToApplyOperation( const G4Track*,
G4double,
@@ -52,7 +52,9 @@
#include "G4VBiasingOperation.hh"
#include "G4ThreeVector.hh"
#include "G4ParticleChangeForNothing.hh"
class G4ILawCommonTruncatedExp;
class G4ILawForceFreeFlight;
#include <map>
class G4BOptnForceCommonTruncatedExp : public G4VBiasingOperation {
@@ -66,30 +68,33 @@ public:
// -- Methods from G4VBiasingOperation interface:
// -------------------------------------------
// -- Used:
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* );
virtual G4ForceCondition ProposeForceCondition( const G4ForceCondition processCondition );
virtual G4bool DenyProcessPostStepDoIt( const G4BiasingProcessInterface*, const G4Track*, const G4Step*, G4double& );
virtual G4double ProposeAlongStepLimit( const G4BiasingProcessInterface* );
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface*, G4ForceCondition& );
virtual G4double ProposeAlongStepLimit( const G4BiasingProcessInterface* ) { return DBL_MAX; }
virtual G4GPILSelection ProposeGPILSelection( const G4GPILSelection processSelection );
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface*,
const G4Track*,
const G4Step*,
G4bool& );
// -- Unused:
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface*,
const G4Track*,
const G4Step* ) {return 0;}
virtual G4double DistanceToApplyOperation( const G4Track*,
G4double,
G4ForceCondition*) {return DBL_MAX;}
G4ForceCondition*) {return DBL_MAX;}
virtual G4VParticleChange* GenerateBiasingFinalState( const G4Track*,
const G4Step* ) {return 0;}
const G4Step* ) {return 0;}
public:
// -- Additional methods, specific to this class:
// ----------------------------------------------
// -- return concrete type of interaction law:
// -- return concrete type of interaction laws:
G4ILawCommonTruncatedExp* GetCommonTruncatedExpLaw()
{
return fCommonTruncatedExpLaw;
}
G4ILawForceFreeFlight* GetForceFreeFlightLaw()
{
return fForceFreeFlightLaw;
}
void Initialize( const G4Track* );
void UpdateForStep( const G4Step* );
void Sample();
@@ -98,21 +103,22 @@ public:
void ChooseProcessToApply();
const G4VProcess* GetProcessToApply() const { return fProcessToApply; }
void AddCrossSection( const G4VProcess*, G4double );
G4double GetTriggeredProcessXSfraction();
size_t GetNumberOfSharing() const { return fNumberOfSharing;}
void PostStepInteractionOccured( const G4VProcess* );
void SetInteractionOccured( G4bool b ) { fInteractionOccured = b; }
G4bool GetInteractionOccured() const { return fInteractionOccured; }
private:
G4ILawCommonTruncatedExp* fCommonTruncatedExpLaw;
G4ILawForceFreeFlight* fForceFreeFlightLaw;
G4double fTotalCrossSection;
std::map < const G4VProcess*, G4double > fCrossSections;
size_t fNumberOfSharing;
//G4bool fFirstCallToDeny;
const G4VProcess* fProcessToApply;
G4bool fInteractionOccured;
G4ThreeVector fInitialMomentum;
G4double fMaximumDistance;
G4ParticleChangeForNothing fDummyParticleChange;
};
#endif
@@ -39,7 +39,7 @@
// change for making this uninteracting flight,
// cumulatedWeightChange.
// When the track reaches the current volume boundary, its
// weight is restore with value :
// weight is restored with value :
// initialWeight * cumulatedWeightChange
//
//---------------------------------------------------------------
@@ -49,8 +49,10 @@
#include "G4VBiasingOperation.hh"
#include "G4ForceCondition.hh"
#include "G4ParticleChange.hh" // -- §§ should add a dedicated "weight change only" particle change
class G4ILawForceFreeFlight;
class G4BOptnForceFreeFlight : public G4VBiasingOperation {
public:
// -- Constructor :
@@ -62,20 +64,17 @@ public:
// -- Methods from G4VBiasingOperation interface:
// -------------------------------------------
// -- Used:
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* );
virtual G4ForceCondition ProposeForceCondition( const G4ForceCondition ) {return Forced;}
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface*, G4ForceCondition& );
virtual G4bool DenyProcessPostStepDoIt( const G4BiasingProcessInterface*, const G4Track*, const G4Step*, G4double& );
virtual void AlongMoveBy( const G4BiasingProcessInterface*, const G4Step*, G4double );
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface*, const G4Track*, const G4Step*, G4bool&);
// -- Unused:
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface*,
const G4Track*,
const G4Step* ) {return 0;}
virtual G4double DistanceToApplyOperation( const G4Track*,
G4double,
G4ForceCondition*) {return DBL_MAX;}
G4ForceCondition*) {return DBL_MAX;}
virtual G4VParticleChange* GenerateBiasingFinalState( const G4Track*,
const G4Step* ) {return 0;}
const G4Step* ) {return 0;}
public:
@@ -91,6 +90,7 @@ public:
private:
G4ILawForceFreeFlight* fForceFreeFlightInteractionLaw;
G4double fCumulatedWeightChange, fInitialTrackWeight;
G4ParticleChange fParticleChange;
};
#endif
@@ -63,11 +63,12 @@ public:
private:
// -- Mandatory from base class :
virtual G4VBiasingOperation* ProposeOccurenceBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess);
virtual G4VBiasingOperation* ProposeFinalStateBiasingOperation(const G4Track*, const G4BiasingProcessInterface*) {return 0;}
virtual G4VBiasingOperation* ProposeNonPhysicsBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess);
virtual G4VBiasingOperation* ProposeOccurenceBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess);
virtual G4VBiasingOperation* ProposeFinalStateBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess);
// -- optional methods from base class:
public:
virtual void StartRun();
virtual void StartTracking( const G4Track* track );
virtual void ExitBiasing( const G4Track*, const G4BiasingProcessInterface* );
@@ -83,13 +84,10 @@ private:
G4BOptnForceCommonTruncatedExp* fSharedForceInteractionOperation;
G4BOptnCloning* fCloningOperation;
G4double fInitialTrackWeight;
//G4double fWeightToRestore;
std::vector < const G4VProcess* > fProcesses;
const G4VProcess *fFirstProcess, *fLastProcess;
G4bool fSetup;
const G4ParticleDefinition* fParticle;
G4VBiasingOperation* fPreviousOperationApplied;
G4ThreeVector fPreviousMomentum;
G4bool fSetup;
const G4ParticleDefinition* fParticleToBias;
G4VBiasingOperation* fPreviousOperationApplied;
G4ThreeVector fPreviousMomentum;
};
@@ -49,6 +49,8 @@
//
//--------------------------------------------------------------------
// Initial version Sep. 2013 M. Verderi
// Use of "shared data" class Sep. 2014 M. Verderi
#ifndef G4BiasingProcessInterface_h
#define G4BiasingProcessInterface_h
@@ -56,6 +58,7 @@
#include "globals.hh"
#include "G4VProcess.hh"
#include "G4Cache.hh"
#include "G4BiasingProcessSharedData.hh"
class G4VBiasingInteractionLaw;
class G4InteractionLawPhysical;
@@ -88,15 +91,31 @@ public:
// -- Helper methods:
// ------------------
// -- Current step and previous step biasing operator, if any:
G4VBiasingOperator* GetCurrentBiasingOperator() const {return fCurrentBiasingOperator; }
G4VBiasingOperator* GetPreviousBiasingOperator() const {return fPreviousBiasingOperator; }
G4VBiasingOperator* GetCurrentBiasingOperator() const {return fSharedData-> fCurrentBiasingOperator; }
G4VBiasingOperator* GetPreviousBiasingOperator() const {return fSharedData->fPreviousBiasingOperator; }
// -- current and previous operation:
G4VBiasingOperation* GetCurrentNonPhysicsBiasingOperation() const { return fNonPhysicsBiasingOperation; }
G4VBiasingOperation* GetPreviousNonPhysicsBiasingOperation() const { return fPreviousNonPhysicsBiasingOperation; }
G4VBiasingOperation* GetCurrentOccurenceBiasingOperation() const { return fOccurenceBiasingOperation; }
G4VBiasingOperation* GetPreviousOccurenceBiasingOperation() const { return fPreviousOccurenceBiasingOperation; }
G4VBiasingOperation* GetCurrentFinalStateBiasingOperation() const { return fFinalStateBiasingOperation; }
G4VBiasingOperation* GetPreviousFinalStateBiasingOperation() const { return fPreviousFinalStateBiasingOperation; }
G4VBiasingOperation* GetCurrentNonPhysicsBiasingOperation() const { return fNonPhysicsBiasingOperation; }
G4VBiasingOperation* GetPreviousNonPhysicsBiasingOperation() const { return fPreviousNonPhysicsBiasingOperation; }
// -- Lists of processes cooperating under a same particle type/G4ProcessManager.
// -- The vector ordering is:
// -- - random, before first "run/beamOn"
// -- - that of the PostStepGetPhysicalInteractionLength() once "/run/beamOn" has been issued
const std::vector< const G4BiasingProcessInterface* >& GetBiasingProcessInterfaces() const
{return fSharedData-> fPublicBiasingProcessInterfaces;}
const std::vector< const G4BiasingProcessInterface* >& GetPhysicsBiasingProcessInterfaces() const
{return fSharedData-> fPublicPhysicsBiasingProcessInterfaces;}
const std::vector< const G4BiasingProcessInterface* >& GetNonPhysicsBiasingProcessInterfaces() const
{return fSharedData->fPublicNonPhysicsBiasingProcessInterfaces;}
// -- Get shared data for this process:
const G4BiasingProcessSharedData* GetSharedData() const { return fSharedData; }
// -- Get shared data associated to a G4ProcessManager:
static const G4BiasingProcessSharedData* GetSharedData( const G4ProcessManager* );
@@ -186,17 +205,16 @@ public:
private:
// ---- Setup first/last flags:
void SetUpFirstLastFlags();
void ResetForUnbiasedTracking();
// ---- Internal utility methods:
void SetUpFirstLastFlags();
void ResetForUnbiasedTracking();
void ReorderBiasingVectorAsGPIL();
G4Track* fCurrentTrack;
G4double fPreviousStepSize;
G4double fCurrentMinimumStep;
G4double fProposedSafety;
G4VBiasingOperator* fCurrentBiasingOperator;
G4VBiasingOperator* fPreviousBiasingOperator;
G4VBiasingOperation* fOccurenceBiasingOperation;
G4VBiasingOperation* fFinalStateBiasingOperation;
G4VBiasingOperation* fNonPhysicsBiasingOperation;
@@ -236,32 +254,34 @@ private:
// -- for that is provided. Should be of pure internal usage.
return 4*firstLast + 2*GPILDoIt + physAll;
}
// -- TO DO : let some common operation be done only once, by the first
// -- process in GPIL. Nothing done yet, may help to reduce overhead.
// -- For example each process instance fetch for the current operator,
// -- which could be done once, and with pointer shared.
// -- Idea is to have a class containing the data members shared among
// -- the instances.
// -- Could make these shared data members shared only per particle type
// -- (at present, with a single static, any instance of a process shares
// -- its members with any other instance, regardless of particle type.)
G4bool fIamFirstGPIL;
// -- method used to anticipate stepping manager calls to PostStepGPIL
// -- of wrapped processes : this method calls wrapped process PostStepGPIL
// -- and caches results for PostStepGPIL and condition.
void InvokeWrappedProcessPostStepGPIL( const G4Track& track,
G4double previousStepSize,
G4ForceCondition* condition );
// -- the instance being "firstGPIL" does work shared by other instances:
G4bool fIamFirstGPIL;
// -- MUST be **thread local**:
static G4Cache<G4bool> fResetInteractionLaws;
static G4Cache<G4bool> fCommonStart;
static G4Cache<G4bool> fCommonEnd;
static G4Cache<G4bool> fResetInteractionLaws;
static G4Cache<G4bool> fCommonStart;
static G4Cache<G4bool> fCommonEnd;
// -- Maintain lists of interfaces attached to a same particle (ie
// -- to a same G4ProcessManager ).
// -- This is used when biasing operations in different processes need to
// -- cooperate (like for knowing the total cross-section for example).
std::vector< G4BiasingProcessInterface* >* fCoInterfaces;
// -- thread local:
static G4MapCache< const G4ProcessManager*,
std::vector< G4BiasingProcessInterface* > > fManagerInterfaceMap;
const G4ProcessManager* fProcessManager;
// -- the data shared among processes attached to a same process manager:
G4BiasingProcessSharedData* fSharedData;
// -- thread local:
// -- Map between process managers and shared data. This map is made of
// -- pointers of G4BiasingSharedData instead of objects themselves :
// -- each process needs to keep a valid pointer of a shared data object
// -- but a map of object will make pointers invalid when map is increaded.
static G4MapCache< const G4ProcessManager*,
G4BiasingProcessSharedData* > fSharedDataMap;
};
@@ -0,0 +1,106 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: $
//
//--------------------------------------------------------------------------
//
// G4BiasingProcessSharedData
//
// Class Description:
// This class represents the data that the G4BiasingProcessInterface
// objects attached to a same particle / hold by a same G4ProcessManager
// share. It allows the active G4BiasingProcessInterface objects to share
// information on operations that are common the these instances:
// - the current and previous G4VBiasingOperator objects (their
// pointers are collected once, at the beginning of the PostStepGPIL
// by the first interface invoked)
// - add the list of cooperating G4BiasingProcessInterface objects,
// acting on a same particle type.
// G4BiasingProcessInterface is friend class of this one.
//---------------------------------------------------------------------------
// Initial version Sep. 2014 M. Verderi
#ifndef G4BiasingProcessSharedData_h
#define G4BiasingProcessSharedData_h
#include "globals.hh"
#include <vector>
class G4VBiasingOperator;
class G4BiasingProcessInterface;
class G4ProcessManager;
class G4BiasingProcessSharedData {
friend class G4BiasingProcessInterface;
public:
// -------------------------
// -- Public access methods:
// -------------------------
// -- The biasing process interface objects sharing this shared data class:
const std::vector< const G4BiasingProcessInterface* >& GetBiasingProcessInterfaces() const
{return fPublicBiasingProcessInterfaces;}
const std::vector< const G4BiasingProcessInterface* >& GetPhysicsBiasingProcessInterfaces() const
{return fPublicPhysicsBiasingProcessInterfaces;}
const std::vector< const G4BiasingProcessInterface* >& GetNonPhysicsBiasingProcessInterfaces() const
{return fPublicNonPhysicsBiasingProcessInterfaces;}
private:
// -- Methods used by the G4BiasingProcessInterface objects, thanks to class friendness.
// -- Object is created by G4BiasingProcessInterface object:
G4BiasingProcessSharedData( const G4ProcessManager* mgr) : fProcessManager(mgr) {}
~G4BiasingProcessSharedData() {}
// -- biasing operators:
void CurrentBiasingOperator( G4VBiasingOperator* );
G4VBiasingOperator* CurrentBiasingOperator() const;
void PreviousBiasingOperator( G4VBiasingOperator* );
G4VBiasingOperator* PreviousBiasingOperator() const;
private:
// --
const G4ProcessManager* fProcessManager;
// -- biasing operators:
G4VBiasingOperator* fCurrentBiasingOperator;
G4VBiasingOperator* fPreviousBiasingOperator;
// --
G4bool fIsNewOperator;
G4bool fLeavingPreviousOperator;
// -- biaising process interfaces sharing this object:
std::vector < G4BiasingProcessInterface* > fBiasingProcessInterfaces;
std::vector < G4BiasingProcessInterface* > fPhysicsBiasingProcessInterfaces;
std::vector < G4BiasingProcessInterface* > fNonPhysicsBiasingProcessInterfaces;
// -- the same ones, for public use:
std::vector < const G4BiasingProcessInterface* > fPublicBiasingProcessInterfaces;
std::vector < const G4BiasingProcessInterface* > fPublicPhysicsBiasingProcessInterfaces;
std::vector < const G4BiasingProcessInterface* > fPublicNonPhysicsBiasingProcessInterfaces;
};
#endif
@@ -37,8 +37,10 @@
// is used to drive the law.
//
// ---------------------------------------------------------------
// Refactored version Oct. 2014 M. Verderi
// Initial version Nov. 2013 M. Verderi
#ifndef G4ILawCommonTruncatedExp_hh
#define G4ILawCommonTruncatedExp_hh 1
@@ -46,8 +48,6 @@
#include "G4ILawTruncatedExp.hh"
#include "G4ThreeVector.hh"
class G4BOptnForceCommonTruncatedExp;
class G4ILawCommonTruncatedExp : public G4VBiasingInteractionLaw
{
public:
@@ -57,12 +57,10 @@ public:
public:
virtual G4bool IsSingular() const
{return fExpInteractionLaw.IsSingular();}
virtual G4bool IsEffectiveCrossSectionInfinite() const
virtual G4bool IsEffectiveCrossSectionInfinite() const
{return fExpInteractionLaw.IsEffectiveCrossSectionInfinite();}
private:
// -- sample the distribution:
// -- in this case, cheat by returning DBL_MAX, to let operation proposing the
// -- step length in the alongGPIL
virtual G4double SampleInteractionLength();
// -- move by true path length, this position becomes the new initial point
// -- in this case, cheat by returning DBL_MAX, to let operation proposing the
@@ -73,25 +71,17 @@ public:
virtual G4double ComputeNonInteractionProbabilityAt(G4double length) const;
public:
void SetNumberOfSharing(G4int n) { fNumberOfSharing = n; }
G4int GetNumberOfSharing() const { return fNumberOfSharing; }
void SetForceCrossSection( G4double xs ) { fExpInteractionLaw.SetForceCrossSection( xs ); }
void reset();
void SetMaximumDistance(G4double d) { fExpInteractionLaw.SetMaximumDistance(d); }
G4double GetMaximumDistance() const {return fExpInteractionLaw.GetMaximumDistance();}
G4double GetInteractionDistance() const {return fExpInteractionLaw.GetInteractionDistance();}
void SetOperation( G4BOptnForceCommonTruncatedExp* operation) {fOperation = operation;}
void SetForceCrossSection( G4double xs ) { fExpInteractionLaw.SetForceCrossSection( xs ); }
void SetSelectedProcessXSfraction( G4double fXS ) { fSelectedProcessXSfraction = fXS; }
G4double SetSelectedProcessXSfraction() const { return fSelectedProcessXSfraction; }
void SetMaximumDistance(G4double d) { fExpInteractionLaw.SetMaximumDistance(d); }
G4double GetMaximumDistance() const { return fExpInteractionLaw.GetMaximumDistance(); }
G4double GetInteractionDistance() const { return fExpInteractionLaw.GetInteractionDistance(); }
private:
G4ILawTruncatedExp fExpInteractionLaw;
//G4bool fIsSingular;
G4int fNumberOfSharing;
//G4bool fFirstInitializationCall;
G4bool fFirstUpdateCall;
G4bool fFirstSamplingCall;
G4double fInteractionDistance;
// TRICKY
G4BOptnForceCommonTruncatedExp* fOperation;
G4ILawTruncatedExp fExpInteractionLaw;
G4double fSelectedProcessXSfraction;
G4double fInteractionDistance;
};
#endif
@@ -39,6 +39,7 @@
//
// ---------------------------------------------------------------
// Initial version Nov. 2013 M. Verderi
//
#ifndef G4ParticleChangeForOccurenceBiasing_hh
#define G4ParticleChangeForOccurenceBiasing_hh 1
@@ -11,7 +11,7 @@
#
# Generated on : 24/9/2010
#
# $Id: sources.cmake 76470 2013-11-11 10:31:24Z gcosmo $
# $Id: sources.cmake 86197 2014-11-07 15:09:00Z gcosmo $
#
#------------------------------------------------------------------------------
@@ -46,6 +46,7 @@ GEANT4_DEFINE_MODULE(NAME G4biasing_gen
HEADERS
G4BiasingHelper.hh
G4BiasingProcessInterface.hh
G4BiasingProcessSharedData.hh
G4BOptnChangeCrossSection.hh
G4BOptnCloning.hh
G4BOptnForceCommonTruncatedExp.hh
@@ -35,9 +35,11 @@ G4BOptnChangeCrossSection::G4BOptnChangeCrossSection(G4String name)
}
G4BOptnChangeCrossSection::~G4BOptnChangeCrossSection()
{}
{
if ( fBiasedExponentialLaw ) delete fBiasedExponentialLaw;
}
const G4VBiasingInteractionLaw* G4BOptnChangeCrossSection::ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* )
const G4VBiasingInteractionLaw* G4BOptnChangeCrossSection::ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface*, G4ForceCondition& )
{
return fBiasedExponentialLaw;
}
@@ -25,6 +25,7 @@
//
#include "G4BOptnForceCommonTruncatedExp.hh"
#include "G4ILawCommonTruncatedExp.hh"
#include "G4ILawForceFreeFlight.hh"
#include "G4TransportationManager.hh"
#include "Randomize.hh"
@@ -35,65 +36,89 @@ G4BOptnForceCommonTruncatedExp::G4BOptnForceCommonTruncatedExp(G4String name)
fInteractionOccured(false)
{
fCommonTruncatedExpLaw = new G4ILawCommonTruncatedExp("ExpLawForOperation"+name);
fCommonTruncatedExpLaw->SetOperation( this );
fForceFreeFlightLaw = new G4ILawForceFreeFlight ("FFFLawForOperation"+name);
fTotalCrossSection = 0.0;
}
G4BOptnForceCommonTruncatedExp::~G4BOptnForceCommonTruncatedExp()
{}
const G4VBiasingInteractionLaw* G4BOptnForceCommonTruncatedExp::ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* )
{
return fCommonTruncatedExpLaw;
if ( fCommonTruncatedExpLaw ) delete fCommonTruncatedExpLaw;
if ( fForceFreeFlightLaw ) delete fForceFreeFlightLaw;
}
G4ForceCondition G4BOptnForceCommonTruncatedExp::ProposeForceCondition( const G4ForceCondition )
const G4VBiasingInteractionLaw* G4BOptnForceCommonTruncatedExp::ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* callingProcess,
G4ForceCondition& proposeForceCondition )
{
return Forced;
if ( callingProcess->GetWrappedProcess() == fProcessToApply )
{
proposeForceCondition = Forced;
return fCommonTruncatedExpLaw;
}
else
{
proposeForceCondition = Forced;
return fForceFreeFlightLaw;
}
}
G4double G4BOptnForceCommonTruncatedExp::ProposeAlongStepLimit( const G4BiasingProcessInterface* callingProcess )
{
if ( callingProcess->GetWrappedProcess() == fProcessToApply )
return fCommonTruncatedExpLaw->GetInteractionDistance();
else return DBL_MAX;
}
G4GPILSelection G4BOptnForceCommonTruncatedExp::ProposeGPILSelection( const G4GPILSelection )
{
return CandidateForSelection;
return NotCandidateForSelection;
}
G4bool G4BOptnForceCommonTruncatedExp::DenyProcessPostStepDoIt( const G4BiasingProcessInterface* callingProcess,
const G4Track*, const G4Step* step, G4double& )
G4VParticleChange* G4BOptnForceCommonTruncatedExp::ApplyFinalStateBiasing( const G4BiasingProcessInterface* callingProcess,
const G4Track* track,
const G4Step* step,
G4bool& forceFinalState )
{
if ( callingProcess->GetWrappedProcess() != fProcessToApply )
{
forceFinalState = true;
fDummyParticleChange.Initialize( *track );
return &fDummyParticleChange;
}
if ( fInteractionOccured )
{
forceFinalState = true;
fDummyParticleChange.Initialize( *track );
return &fDummyParticleChange;
}
// -- checks if process won the GPIL race:
G4double processGPIL = callingProcess->GetPostStepGPIL() < callingProcess->GetAlongStepGPIL() ?
callingProcess->GetPostStepGPIL() : callingProcess->GetAlongStepGPIL() ;
if ( processGPIL <= step->GetStepLength() )
{
G4bool denyProcess = (callingProcess->GetWrappedProcess() != fProcessToApply );
fInteractionOccured = (fInteractionOccured || !denyProcess);
return denyProcess;
// -- if process won, wrapped process produces the final state.
// -- In this case, the weight for occurence biasing is applied
// -- by the callingProcess, at exit of present method. This is
// -- selected by "forceFinalState = false":
forceFinalState = false;
fInteractionOccured = true;
return callingProcess->GetWrappedProcess()->PostStepDoIt( *track, *step );
}
else
{
forceFinalState = true;
fDummyParticleChange.Initialize( *track );
return &fDummyParticleChange;
}
else return true;
}
G4double G4BOptnForceCommonTruncatedExp::GetTriggeredProcessXSfraction()
{
return fCrossSections[fProcessToApply] / fTotalCrossSection;
}
void G4BOptnForceCommonTruncatedExp::PostStepInteractionOccured( const G4VProcess* )
{
}
void G4BOptnForceCommonTruncatedExp::AddCrossSection( const G4VProcess* process, G4double crossSection )
{
fTotalCrossSection += crossSection;
fCrossSections[process] = crossSection;
fNumberOfSharing = fCrossSections.size();
fCommonTruncatedExpLaw->SetNumberOfSharing ( fNumberOfSharing );
fCommonTruncatedExpLaw->SetForceCrossSection( fTotalCrossSection );
fTotalCrossSection += crossSection;
fCrossSections[process] = crossSection;
fNumberOfSharing = fCrossSections.size();
}
@@ -105,7 +130,6 @@ void G4BOptnForceCommonTruncatedExp::Initialize( const G4Track* track )
fProcessToApply = 0;
fInitialMomentum = track->GetMomentum();
fCommonTruncatedExpLaw->reset();
G4VSolid* currentSolid = track->GetVolume()->GetLogicalVolume()->GetSolid();
G4ThreeVector localPosition = (G4TransportationManager::GetTransportationManager()->
GetNavigatorForTracking()->
@@ -125,22 +149,24 @@ void G4BOptnForceCommonTruncatedExp::UpdateForStep( const G4Step* step )
fTotalCrossSection = 0.0;
fNumberOfSharing = 0;
fProcessToApply = 0;
fCommonTruncatedExpLaw->UpdateForStep( step->GetStepLength() );
fMaximumDistance = fCommonTruncatedExpLaw->GetMaximumDistance();
}
void G4BOptnForceCommonTruncatedExp::Sample()
{
fCommonTruncatedExpLaw->reset();
fCommonTruncatedExpLaw->SetForceCrossSection( fTotalCrossSection );
fCommonTruncatedExpLaw->Sample();
ChooseProcessToApply();
ChooseProcessToApply();
fCommonTruncatedExpLaw->SetSelectedProcessXSfraction(fCrossSections[fProcessToApply] / fTotalCrossSection);
}
void G4BOptnForceCommonTruncatedExp::ChooseProcessToApply()
{
G4double sigmaRand = G4UniformRand() * fTotalCrossSection;
G4double sigmaRand = G4UniformRand() * fTotalCrossSection;
G4double sigmaSelect = 0.0;
for ( std::map< const G4VProcess*, G4double>::const_iterator it = fCrossSections.begin();
it != fCrossSections.end();
@@ -25,6 +25,7 @@
//
#include "G4BOptnForceFreeFlight.hh"
#include "G4ILawForceFreeFlight.hh"
#include "G4BiasingProcessInterface.hh"
#include "G4Step.hh"
@@ -36,10 +37,13 @@ G4BOptnForceFreeFlight::G4BOptnForceFreeFlight(G4String name)
}
G4BOptnForceFreeFlight::~G4BOptnForceFreeFlight()
{}
const G4VBiasingInteractionLaw* G4BOptnForceFreeFlight::ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* )
{
if ( fForceFreeFlightInteractionLaw ) delete fForceFreeFlightInteractionLaw;
}
const G4VBiasingInteractionLaw* G4BOptnForceFreeFlight::ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface*, G4ForceCondition& proposeForceCondition )
{
proposeForceCondition = Forced;
return fForceFreeFlightInteractionLaw;
}
@@ -74,6 +78,51 @@ G4bool G4BOptnForceFreeFlight::DenyProcessPostStepDoIt( const G4BiasingProcessIn
return true;
}
G4VParticleChange* G4BOptnForceFreeFlight::ApplyFinalStateBiasing( const G4BiasingProcessInterface* callingProcess,
const G4Track* track,
const G4Step* step,
G4bool& forceFinalState)
{
// -- If the track is reaching the volume boundary, its free flight ends. In this case, its zero
// -- weight is brought back to non-zero value: its initial weight is restored by the first
// -- ApplyFinalStateBiasing operation called, and the weight for force free flight is applied
// -- is applied by each operation.
// -- If the track is not reaching the volume boundary, it zero weight flight continues.
fParticleChange.Initialize( *track );
forceFinalState = true;
if ( step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary )
{
// -- Sanity checks:
if ( fInitialTrackWeight <= DBL_MIN )
{
G4ExceptionDescription ed;
ed << " Initial track weight is null ! " << G4endl;
G4Exception(" G4BOptnForceFreeFlight::ApplyFinalStateBiasing(...)",
"BIAS.GEN.05",
JustWarning,
ed);
}
if ( fCumulatedWeightChange <= DBL_MIN )
{
G4ExceptionDescription ed;
ed << " Cumulated weight is null ! " << G4endl;
G4Exception(" G4BOptnForceFreeFlight::ApplyFinalStateBiasing(...)",
"BIAS.GEN.06",
JustWarning,
ed);
}
G4double proposedWeight = track->GetWeight();
if ( callingProcess->GetIsFirstPostStepDoItInterface() ) proposedWeight = fCumulatedWeightChange * fInitialTrackWeight;
else proposedWeight *= fCumulatedWeightChange;
fParticleChange.ProposeWeight(proposedWeight);
}
return &fParticleChange;
}
void G4BOptnForceFreeFlight::AlongMoveBy( const G4BiasingProcessInterface*, const G4Step*, G4double weightChange )
{
fCumulatedWeightChange *= weightChange;
@@ -40,16 +40,16 @@
#include "G4SystemOfUnits.hh"
G4BOptrForceCollision::G4BOptrForceCollision(G4String particleName, G4String name)
: G4VBiasingOperator(name),
fFirstProcess(0), fLastProcess(0),
fSetup(true)
{
fSharedForceInteractionOperation = new G4BOptnForceCommonTruncatedExp("SharedForceInteraction");
fCloningOperation = new G4BOptnCloning("Cloning");
fParticle = G4ParticleTable::GetParticleTable()->FindParticle(particleName);
fParticleToBias = G4ParticleTable::GetParticleTable()->FindParticle(particleName);
if ( fParticle == 0 )
if ( fParticleToBias == 0 )
{
G4ExceptionDescription ed;
ed << " Particle `" << particleName << "' not found !" << G4endl;
@@ -60,16 +60,17 @@ G4BOptrForceCollision::G4BOptrForceCollision(G4String particleName, G4String nam
}
}
G4BOptrForceCollision::G4BOptrForceCollision(const G4ParticleDefinition* particle, G4String name)
: G4VBiasingOperator(name),
fFirstProcess(0), fLastProcess(0),
fSetup(true)
{
fSharedForceInteractionOperation = new G4BOptnForceCommonTruncatedExp("SharedForceInteraction");
fCloningOperation = new G4BOptnCloning("Cloning");
fParticle = particle;
fParticleToBias = particle;
}
G4BOptrForceCollision::~G4BOptrForceCollision()
{
for ( std::map< const G4BiasingProcessInterface*, G4BOptnForceFreeFlight* >::iterator it = fFreeFlightOperations.begin() ;
@@ -80,27 +81,32 @@ G4BOptrForceCollision::~G4BOptrForceCollision()
}
G4VBiasingOperation* G4BOptrForceCollision::ProposeOccurenceBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess)
void G4BOptrForceCollision::StartRun()
{
if ( track->GetDefinition() != fParticle ) return 0;
// -- start by remembering processes under biasing, and create needed biasing operations:
// -- ( Might consider moving this in a less called method. )
if ( fSetup )
{
if ( ( fFirstProcess == 0 ) && ( callingProcess->GetIsFirstPostStepGPILInterface() ) ) fFirstProcess = callingProcess;
if ( fLastProcess == 0 )
const G4ProcessManager* processManager = fParticleToBias->GetProcessManager();
const G4BiasingProcessSharedData* sharedData =
G4BiasingProcessInterface::GetSharedData( processManager );
if (sharedData ) // -- sharedData tested, as is can happen a user attaches an operator to a volume but without defined BiasingProcessInterface processes.
{
fProcesses.push_back(callingProcess);
G4String operationName = "FreeFlight-"+callingProcess->GetWrappedProcess()->GetProcessName();
fFreeFlightOperations[callingProcess] = new G4BOptnForceFreeFlight(operationName);
if ( callingProcess->GetIsLastPostStepGPILInterface() )
for ( size_t i = 0 ; i < (sharedData->GetPhysicsBiasingProcessInterfaces()).size(); i++ )
{
fLastProcess = callingProcess;
fSetup = false;
const G4BiasingProcessInterface* wrapperProcess =
(sharedData->GetPhysicsBiasingProcessInterfaces())[i];
G4String operationName = "FreeFlight-"+wrapperProcess->GetWrappedProcess()->GetProcessName();
fFreeFlightOperations[wrapperProcess] = new G4BOptnForceFreeFlight(operationName);
}
}
fSetup = false;
}
}
G4VBiasingOperation* G4BOptrForceCollision::ProposeOccurenceBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess)
{
if ( track->GetDefinition() != fParticleToBias ) return 0;
// -- Send force interaction operation to the callingProcess:
@@ -115,8 +121,13 @@ G4VBiasingOperation* G4BOptrForceCollision::ProposeOccurenceBiasingOperation(con
// -- would require an other cloning before, if one wants to conserve
// -- the weight.]
if ( fSharedForceInteractionOperation->GetInteractionOccured() ) return 0;
// -- Remember if this calling process is the first of the physics wrapper in
// -- the PostStepGPIL loop (using default argument of method below):
G4bool isFirstPhysGPIL = callingProcess-> GetIsFirstPostStepGPILInterface();
if ( callingProcess == fFirstProcess )
// -- [*first process*] Initialize or update force interaction operation:
if ( isFirstPhysGPIL )
{
// -- first step of cloned track, initialize the forced interaction operation:
if ( track->GetCurrentStepNumber() == 1 ) fSharedForceInteractionOperation->Initialize( track );
@@ -140,27 +151,36 @@ G4VBiasingOperation* G4BOptrForceCollision::ProposeOccurenceBiasingOperation(con
}
}
// -- Sanity check : it may happen in limit cases that distance to out is zero,
// -- weight would be infinite in this case. Abort forced interaction.
// -- [*all processes*] Sanity check : it may happen in limit cases that distance to
// -- out is zero, weight would be infinite in this case: abort forced interaction.
if ( fSharedForceInteractionOperation->GetMaximumDistance() < DBL_MIN ) return 0;
// -- conditions to apply forced interaction are met, set up physics:
// -- Collects well-defined cross-sections...
// -- [* first process*] collect cross-sections and sample force law to determine interaction length
// -- and winning process:
if ( isFirstPhysGPIL )
{
// -- collect cross-sections:
// -- ( Remember that the first of the G4BiasingProcessInterface triggers the update
// -- of these cross-sections )
const G4BiasingProcessSharedData* sharedData = callingProcess->GetSharedData();
for ( size_t i = 0 ; i < (sharedData->GetPhysicsBiasingProcessInterfaces()).size() ; i++ )
{
const G4BiasingProcessInterface* wrapperProcess = ( sharedData->GetPhysicsBiasingProcessInterfaces() )[i];
G4double interactionLength = wrapperProcess->GetWrappedProcess()->GetCurrentInteractionLength();
// -- keep only well defined cross-section (*§*):
if ( interactionLength < DBL_MAX/10. )
fSharedForceInteractionOperation->AddCrossSection( wrapperProcess->GetWrappedProcess(), 1.0/interactionLength );
}
// -- sample the shared law (interaction length, and winning process:
if ( fSharedForceInteractionOperation->GetNumberOfSharing() > 0 ) fSharedForceInteractionOperation->Sample();
}
// -- [*all processes*] Send operation, after sanity check (same criterium than (*§*) !):
G4double currentInteractionLength = callingProcess->GetWrappedProcess()->GetCurrentInteractionLength();
G4VBiasingOperation* operationToReturn = 0;
if ( currentInteractionLength < DBL_MAX/10. )
{
fSharedForceInteractionOperation->AddCrossSection( callingProcess->GetWrappedProcess(), 1.0/currentInteractionLength );
operationToReturn = fSharedForceInteractionOperation;
}
// -- ... if current process is the last one, cross-section collection is finished.
// -- Operation is ready to sample the force interaction law and to randomly select
// -- the process to be applied.
if ( ( callingProcess == fLastProcess ) &&
( fSharedForceInteractionOperation->GetCommonTruncatedExpLaw()->GetNumberOfSharing() > 0 ) )
fSharedForceInteractionOperation->Sample();
// -- back to current process (last one or not), if meaningful cross section, bias it returning the force operation:
if ( currentInteractionLength < DBL_MAX/10. ) operationToReturn = fSharedForceInteractionOperation;
return operationToReturn;
} // -- end of " if ( GetBirthOperation( track ) == fCloningOperation ) "
@@ -193,7 +213,9 @@ G4VBiasingOperation* G4BOptrForceCollision::ProposeOccurenceBiasingOperation(con
// -- ** ?? ** Incorrect here in case of flight interrupted by a *physics process*. Ie case
// -- ** ?? ** of a subset of physics processes forced is not treated correctly here ** ?? **
else if ( callingProcess->GetPreviousOccurenceBiasingOperation() == fFreeFlightOperations[callingProcess] )
return fFreeFlightOperations[callingProcess];
{
return fFreeFlightOperations[callingProcess];
}
// -- other cases here: particle appearing in the volume by some
// -- previous interaction : we decide to not bias these.
@@ -203,9 +225,9 @@ G4VBiasingOperation* G4BOptrForceCollision::ProposeOccurenceBiasingOperation(con
G4VBiasingOperation* G4BOptrForceCollision::ProposeNonPhysicsBiasingOperation(const G4Track* track,
const G4BiasingProcessInterface*)
const G4BiasingProcessInterface* /* callingProcess */)
{
if ( track->GetDefinition() != fParticle ) return 0;
if ( track->GetDefinition() != fParticleToBias ) return 0;
// -- bias only tracks entering the volume.
// -- A "cloning" is done:
@@ -225,13 +247,22 @@ G4VBiasingOperation* G4BOptrForceCollision::ProposeNonPhysicsBiasingOperation(co
}
G4VBiasingOperation* G4BOptrForceCollision::ProposeFinalStateBiasingOperation(const G4Track*, const G4BiasingProcessInterface* callingProcess)
{
// -- Propose at final state generation the same operation which was proposed at GPIL level,
// -- (which is either the force free flight or the force interaction operation).
// -- count on the process interface to collect this operation:
return callingProcess->GetCurrentOccurenceBiasingOperation();
}
void G4BOptrForceCollision::StartTracking( const G4Track* )
{
fPreviousOperationApplied = 0;
}
void G4BOptrForceCollision::ExitBiasing( const G4Track* track, const G4BiasingProcessInterface* )
void G4BOptrForceCollision::ExitBiasing( const G4Track* track, const G4BiasingProcessInterface* /*callingProcess*/ )
{
fPreviousOperationApplied = 0;
// -- clean-up track for what happens with this operator:
@@ -39,28 +39,28 @@
G4Cache<G4bool> G4BiasingProcessInterface::fResetInteractionLaws;// = true;
G4Cache<G4bool> G4BiasingProcessInterface::fCommonStart;// = true;
G4Cache<G4bool> G4BiasingProcessInterface::fCommonEnd;// = true;
G4MapCache< const G4ProcessManager*, std::vector< G4BiasingProcessInterface* > > G4BiasingProcessInterface::fManagerInterfaceMap;
G4MapCache< const G4ProcessManager*, G4BiasingProcessSharedData* > G4BiasingProcessInterface::fSharedDataMap;
G4BiasingProcessInterface::G4BiasingProcessInterface(G4String name)
: G4VProcess( name ),
fCurrentBiasingOperator ( 0 ),
fPreviousBiasingOperator( 0 ),
fWrappedProcess ( 0 ),
fIsPhysicsBasedBiasing ( false ),
fWrappedProcessIsAtRest( false ),
fWrappedProcessIsAlong ( false ),
fWrappedProcessIsPost ( false ),
fWrappedProcessInteractionLength( -1.0 ),
fBiasingInteractionLaw ( 0 ),
fPhysicalInteractionLaw( 0 ),
fOccurenceBiasingParticleChange( 0 ),
fIamFirstGPIL ( false )
: G4VProcess ( name ),
fWrappedProcess ( 0 ),
fIsPhysicsBasedBiasing ( false ),
fWrappedProcessIsAtRest ( false ),
fWrappedProcessIsAlong ( false ),
fWrappedProcessIsPost ( false ),
fWrappedProcessInteractionLength( -1.0 ),
fBiasingInteractionLaw ( 0 ),
fPhysicalInteractionLaw ( 0 ),
fOccurenceBiasingParticleChange ( 0 ),
fIamFirstGPIL ( false ),
fSharedData ( 0 )
{
for (G4int i = 0 ; i < 8 ; i++) fFirstLastFlags[i] = false;
fResetInteractionLaws.Put( true );
fCommonStart.Put(true);
fCommonEnd.Put(true);
fResetInteractionLaws.Put( true );
fCommonStart.Put(true);
fCommonEnd.Put(true);
}
@@ -69,20 +69,22 @@ G4BiasingProcessInterface::G4BiasingProcessInterface(G4VProcess* wrappedProcess,
G4String useThisName)
: G4VProcess( useThisName != "" ? useThisName : "biasWrapper("+wrappedProcess->GetProcessName()+")",
wrappedProcess->GetProcessType()),
fCurrentBiasingOperator ( 0 ),
fPreviousBiasingOperator( 0 ),
fWrappedProcess ( wrappedProcess ),
fIsPhysicsBasedBiasing ( true ),
fWrappedProcessIsAtRest( wrappedIsAtRest ),
fWrappedProcessIsAlong ( wrappedIsAlongStep ),
fWrappedProcessIsPost ( wrappedIsPostStep ),
fWrappedProcessInteractionLength( -1.0 ),
fBiasingInteractionLaw ( 0 ),
fPhysicalInteractionLaw( 0 ),
fOccurenceBiasingParticleChange( 0 ),
fIamFirstGPIL ( false )
fWrappedProcess ( wrappedProcess ),
fIsPhysicsBasedBiasing ( true ),
fWrappedProcessIsAtRest ( wrappedIsAtRest ),
fWrappedProcessIsAlong ( wrappedIsAlongStep ),
fWrappedProcessIsPost ( wrappedIsPostStep ),
fWrappedProcessInteractionLength( -1.0 ),
fBiasingInteractionLaw ( 0 ),
fPhysicalInteractionLaw ( 0 ),
fOccurenceBiasingParticleChange ( 0 ),
fIamFirstGPIL ( false ),
fSharedData ( 0 )
{
for (G4int i = 0 ; i < 8 ; i++) fFirstLastFlags[i] = false;
fResetInteractionLaws.Put( true );
fCommonStart.Put(true);
fCommonEnd.Put(true);
SetProcessSubType(fWrappedProcess->GetProcessSubType());
@@ -101,16 +103,27 @@ G4BiasingProcessInterface::~G4BiasingProcessInterface()
{
if ( fPhysicalInteractionLaw != 0 ) delete fPhysicalInteractionLaw;
if ( fOccurenceBiasingParticleChange ) delete fOccurenceBiasingParticleChange;
if ( fParticleChange ) delete fParticleChange;
if ( fDummyParticleChange ) delete fDummyParticleChange;
}
const G4BiasingProcessSharedData* G4BiasingProcessInterface::GetSharedData( const G4ProcessManager* mgr )
{
G4MapCache< const G4ProcessManager*,
G4BiasingProcessSharedData* >::const_iterator itr = fSharedDataMap.Find( mgr );
if ( itr != fSharedDataMap.End( ) )
{
return (*itr).second;
}
else return 0;
}
void G4BiasingProcessInterface::StartTracking(G4Track* track)
{
fCurrentTrack = track;
if ( fIsPhysicsBasedBiasing ) fWrappedProcess->StartTracking(fCurrentTrack);
fCurrentBiasingOperator = 0;
fPreviousBiasingOperator = 0;
fOccurenceBiasingOperation = 0;
fPreviousOccurenceBiasingOperation = 0;
fFinalStateBiasingOperation = 0;
@@ -122,13 +135,18 @@ void G4BiasingProcessInterface::StartTracking(G4Track* track)
fPreviousStepSize = -1.0;
fResetWrappedProcessInteractionLength = false;
if ( fCommonStart.Get() )
{
fCommonStart.Put( false );// = false;
fCommonEnd.Put(true);// = true;
fCommonStart.Put( false );// = false;
fCommonEnd.Put(true);// = true;
fSharedData-> fCurrentBiasingOperator = 0;
fSharedData->fPreviousBiasingOperator = 0;
// -- §§ Add a "fSharedData->nStarting" here and outside bracket "fSharedData->nStarting++" and " if (fSharedData->nStarting) == fSharedData->(vector interface length)"
// -- §§ call to the loop "StartTracking" of operators"
for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
( G4VBiasingOperator::GetBiasingOperators() )[optr]->StartTracking( fCurrentTrack );
@@ -139,9 +157,7 @@ void G4BiasingProcessInterface::StartTracking(G4Track* track)
void G4BiasingProcessInterface::EndTracking()
{
if ( fIsPhysicsBasedBiasing ) fWrappedProcess->EndTracking();
if ( fCurrentBiasingOperator) fCurrentBiasingOperator->ExitingBiasing( fCurrentTrack, this );
fCurrentBiasingOperator = 0;
fPreviousBiasingOperator = 0;
if ( fSharedData->fCurrentBiasingOperator) (fSharedData->fCurrentBiasingOperator)->ExitingBiasing( fCurrentTrack, this );
fBiasingInteractionLaw = 0;
@@ -150,11 +166,13 @@ void G4BiasingProcessInterface::EndTracking()
// -- !! not true : stacking operations may kill tracks
if ( fCommonEnd.Get() )
{
fCommonEnd.Put( false );// = false;
fCommonStart.Put( true );// = true;
fCommonEnd.Put( false );// = false;
fCommonStart.Put( true );// = true;
for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
( G4VBiasingOperator::GetBiasingOperators() )[optr]->EndTracking( );
// -- §§ for above loop, do as in StartTracking.
if ( ( fCurrentTrack->GetTrackStatus() == fStopAndKill ) || ( fCurrentTrack->GetTrackStatus() == fKillTrackAndSecondaries ) )
{
@@ -175,77 +193,119 @@ void G4BiasingProcessInterface::EndTracking()
G4double G4BiasingProcessInterface::PostStepGetPhysicalInteractionLength(const G4Track& track,
G4double previousStepSize,
G4ForceCondition* condition)
G4double G4BiasingProcessInterface::PostStepGetPhysicalInteractionLength( const G4Track& track,
G4double previousStepSize,
G4ForceCondition* condition )
{
// ---------------------------------------------------------------------------------------------
// -- The "biasing master" takes care for all biasing processes of update of biasing operators
// -- and invokes all PostStepGPIL of physical wrapped processes (anticipate stepping manager
// -- call ! ) so that all cross-sections are updated with current step, and available right
// -- away to the biasing operator.
// ---------------------------------------------------------------------------------------------
if ( fIamFirstGPIL )
{
// -- Update previous biasing operator:
fSharedData->fPreviousBiasingOperator = fSharedData->fCurrentBiasingOperator;
// -- If new volume, get possible new biasing operator:
// ----------------------------------------------------
// -- [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 ?]
G4bool firstStepInVolume = ( (track.GetStep()->GetPreStepPoint()->GetStepStatus() == fGeomBoundary) || (track.GetCurrentStepNumber() == 1) );
fSharedData->fIsNewOperator = false;
fSharedData->fLeavingPreviousOperator = false;
if ( firstStepInVolume )
{
G4VBiasingOperator* newOperator = G4VBiasingOperator::GetBiasingOperator( track.GetVolume()->GetLogicalVolume() );
fSharedData->fCurrentBiasingOperator = newOperator ;
if ( newOperator != fSharedData->fPreviousBiasingOperator )
{
fSharedData->fLeavingPreviousOperator = ( fSharedData->fPreviousBiasingOperator != 0 ) ;
fSharedData->fIsNewOperator = ( newOperator != 0 );
}
}
// -- calls to wrapped process PostStepGPIL's:
// -------------------------------------------
// -- Each physics wrapper process has its
// -- fWrappedProcessPostStepGPIL ,
// -- fWrappedProcessForceCondition ,
// -- fWrappedProcessInteractionLength
// -- updated.
if ( fSharedData->fCurrentBiasingOperator != 0 )
{
for ( size_t i = 0 ; i < (fSharedData->fPhysicsBiasingProcessInterfaces).size(); i++ )
(fSharedData->fPhysicsBiasingProcessInterfaces)[i]->InvokeWrappedProcessPostStepGPIL( track, previousStepSize, condition );
}
}
// -- Remember previous operator and proposed operations, if any, and reset:
// -------------------------------------------------------------------------
// -- remember:
fPreviousBiasingOperator = fCurrentBiasingOperator;
fPreviousOccurenceBiasingOperation = fOccurenceBiasingOperation;
fPreviousFinalStateBiasingOperation = fFinalStateBiasingOperation;
fPreviousNonPhysicsBiasingOperation = fNonPhysicsBiasingOperation;
fPreviousBiasingInteractionLaw = fBiasingInteractionLaw;
// -- reset:
fOccurenceBiasingOperation = 0;
fFinalStateBiasingOperation = 0;
fNonPhysicsBiasingOperation = 0;
fBiasingInteractionLaw = 0;
// -- Physics PostStep and AlongStep GPIL
fWrappedProcessPostStepGPIL = DBL_MAX;
fBiasingPostStepGPIL = DBL_MAX;
fWrappedProcessInteractionLength = DBL_MAX; // -- inverse of analog cross-section, no biasing counter-part in general
fWrappedProcessForceCondition = NotForced;
fBiasingForceCondition = NotForced;
fWrappedProcessAlongStepGPIL = DBL_MAX;
fBiasingAlongStepGPIL = DBL_MAX;
fWrappedProcessGPILSelection = NotCandidateForSelection;
fBiasingGPILSelection = NotCandidateForSelection;
// -- for helper:
fPreviousStepSize = previousStepSize;
// -- If new volume, get possible new biasing operator:
// ----------------------------------------------------
// -- [Note : bug with this first step ! Does not work if previous step was concurrently limited with geometry]
G4bool firstStepInVolume = ( (track.GetStep()->GetPreStepPoint()->GetStepStatus() == fGeomBoundary) || (track.GetCurrentStepNumber() == 1) );
if ( firstStepInVolume ) fCurrentBiasingOperator = G4VBiasingOperator::GetBiasingOperator( track.GetVolume()->GetLogicalVolume() );
// -----------------------------------
// -- Previous step was under biasing:
// -----------------------------------
if ( fPreviousBiasingOperator != 0 )
// -- remember only in case some biasing might be called
if ( ( fSharedData->fPreviousBiasingOperator != 0 ) ||
( fSharedData->fCurrentBiasingOperator != 0 ) )
{
// -- if current step not under same operator, let this operator knows:
if ( fPreviousBiasingOperator != fCurrentBiasingOperator ) fPreviousBiasingOperator->ExitingBiasing( &track, this );
// -- if biasing does not continue, set process behavior to standard tracking:
// -- ... and see [*] below...
if ( fCurrentBiasingOperator == 0 )
fPreviousOccurenceBiasingOperation = fOccurenceBiasingOperation;
fPreviousFinalStateBiasingOperation = fFinalStateBiasingOperation;
fPreviousNonPhysicsBiasingOperation = fNonPhysicsBiasingOperation;
fPreviousBiasingInteractionLaw = fBiasingInteractionLaw;
// -- reset:
fOccurenceBiasingOperation = 0;
fFinalStateBiasingOperation = 0;
fNonPhysicsBiasingOperation = 0;
fBiasingInteractionLaw = 0;
// -- Physics PostStep and AlongStep GPIL
// fWrappedProcessPostStepGPIL : updated by InvokeWrappedProcessPostStepGPIL(...) above
fBiasingPostStepGPIL = DBL_MAX;
// fWrappedProcessInteractionLength : updated by InvokeWrappedProcessPostStepGPIL(...) above; inverse of analog cross-section.
// fWrappedProcessForceCondition : updated by InvokeWrappedProcessPostStepGPIL(...) above
fBiasingForceCondition = NotForced;
fWrappedProcessAlongStepGPIL = DBL_MAX;
fBiasingAlongStepGPIL = DBL_MAX;
fWrappedProcessGPILSelection = NotCandidateForSelection;
fBiasingGPILSelection = NotCandidateForSelection;
// -- for helper:
fPreviousStepSize = previousStepSize;
}
// -- previous step size value; it is switched to zero if resetting a wrapped process:
// -- (same trick used than in InvokedWrappedProcessPostStepGPIL )
G4double usedPreviousStepSize = previousStepSize;
// ----------------------------------------------
// -- If leaving a biasing operator, let it know:
// ----------------------------------------------
if ( fSharedData->fLeavingPreviousOperator )
{
(fSharedData->fPreviousBiasingOperator)->ExitingBiasing( &track, this );
// -- if no further biasing operator, reset process behavior to standard tracking:
if ( fSharedData->fCurrentBiasingOperator == 0 )
{
fResetWrappedProcessInteractionLength = true;
ResetForUnbiasedTracking();
if ( fIsPhysicsBasedBiasing )
{
// -- if the physics process has been under occurence biasing, reset it:
if ( fResetWrappedProcessInteractionLength )
{
fResetWrappedProcessInteractionLength = false;
fWrappedProcess->ResetNumberOfInteractionLengthLeft();
// -- We set "previous step size" as 0.0, to let the process believe this is first step:
usedPreviousStepSize = 0.0;
}
}
}
}
// --------------------------------------------------------------
// -- no operator : analog tracking if physics-based, or nothing:
// --------------------------------------------------------------
if ( fCurrentBiasingOperator == 0 )
if ( fSharedData->fCurrentBiasingOperator == 0 )
{
if ( fIsPhysicsBasedBiasing )
{
// -- [*] this wrapped process has just been ResetForUnbiasedTracking(), it has a fresh #int length, and is
// -- in a state where it believes it is starting tracking : let it believe hence the previous step
// -- length was 0.0, as for a normal first step:
if ( fResetWrappedProcessInteractionLength )
{
fResetWrappedProcessInteractionLength = false;
fWrappedProcess->ResetNumberOfInteractionLengthLeft();
return fWrappedProcess->PostStepGetPhysicalInteractionLength(track, 0.0, condition);
}
return fWrappedProcess->PostStepGetPhysicalInteractionLength(track, previousStepSize, condition);
}
// -- take note of the "usedPreviousStepSize" value:
if ( fIsPhysicsBasedBiasing ) return fWrappedProcess->PostStepGetPhysicalInteractionLength(track, usedPreviousStepSize, condition);
else
{
*condition = NotForced;
@@ -264,7 +324,7 @@ G4double G4BiasingProcessInterface::PostStepGetPhysicalInteractionLength(const G
// ----------------------------------
if ( !fIsPhysicsBasedBiasing )
{
fNonPhysicsBiasingOperation = fCurrentBiasingOperator->GetProposedNonPhysicsBiasingOperation( &track, this );
fNonPhysicsBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedNonPhysicsBiasingOperation( &track, this );
if ( fNonPhysicsBiasingOperation == 0 )
{
*condition = NotForced;
@@ -276,34 +336,31 @@ G4double G4BiasingProcessInterface::PostStepGetPhysicalInteractionLength(const G
// -- Physics based biasing case:
// ------------------------------
// -- call to underneath physics process PostStepGPIL to update it with current point:
fWrappedProcessPostStepGPIL = fWrappedProcess->PostStepGetPhysicalInteractionLength(track, previousStepSize, condition);
fWrappedProcessForceCondition = *condition;
// -- **! At this point, might have to be careful of previousStepSize being larger than the previous process
// -- **! PostStepGPIL proposed: as we disregard this PostStepGPIL value, such situation does happen. Does not
// -- **! look to have generated problems for now, but might be fragile.
// -- Ask for possible GPIL biasing operation:
fOccurenceBiasingOperation = fCurrentBiasingOperator->GetProposedOccurenceBiasingOperation( &track, this );
fOccurenceBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedOccurenceBiasingOperation( &track, this );
// -- no operation for occurence biasing, analog GPIL returns the wrapped process GPIL and condition values
// -- (note that condition was set above):
if ( fOccurenceBiasingOperation == 0 ) return fWrappedProcessPostStepGPIL;
if ( fOccurenceBiasingOperation == 0 )
{
*condition = fWrappedProcessForceCondition;
return fWrappedProcessPostStepGPIL;
}
// -- A valid GPIL biasing operation has been proposed:
// -- 0) remember wrapped process will need to be reset on biasing exit, if particle survives:
fResetWrappedProcessInteractionLength = true;
// -- 1) collect/update process interaction length for reference analog interaction law:
fWrappedProcessInteractionLength = fWrappedProcess->GetCurrentInteractionLength();
// -- 1) update process interaction length for reference analog interaction law ( fWrappedProcessInteractionLength updated/collected above):
fPhysicalInteractionLaw->SetPhysicalCrossSection( 1.0 / fWrappedProcessInteractionLength );
// -- 2) Collect biasing interaction law:
// -- The interaction law pointer is collected as a const pointer to the interaction law object.
// -- This interaction law will be kept under control of the biasing operation, which is the only
// -- entity that will change the state of the biasing interaction law.
fBiasingInteractionLaw = fOccurenceBiasingOperation->ProvideOccurenceBiasingInteractionLaw( this );
// -- The force condition for biasing is asked at the same time, passing the analog one as default:
fBiasingForceCondition = fWrappedProcessForceCondition;
fBiasingInteractionLaw = fOccurenceBiasingOperation->ProvideOccurenceBiasingInteractionLaw( this, fBiasingForceCondition );
// -- 3) Ask operation to sample the biasing interaction law:
fBiasingPostStepGPIL = fBiasingInteractionLaw->GetSampledInteractionLength();
fBiasingForceCondition = fOccurenceBiasingOperation->ProposeForceCondition( fWrappedProcessForceCondition );
fBiasingPostStepGPIL = fBiasingInteractionLaw->GetSampledInteractionLength();
// -- finish
*condition = fBiasingForceCondition;
@@ -319,7 +376,7 @@ G4VParticleChange* G4BiasingProcessInterface::PostStepDoIt(const G4Track& track,
// ---------------------------------------
// -- case outside of volume with biasing:
// ---------------------------------------
if ( fCurrentBiasingOperator == 0 ) return fWrappedProcess->PostStepDoIt(track, step);
if ( fSharedData->fCurrentBiasingOperator == 0 ) return fWrappedProcess->PostStepDoIt(track, step);
// ----------------------------
// -- non-physics biasing case:
@@ -327,42 +384,34 @@ G4VParticleChange* G4BiasingProcessInterface::PostStepDoIt(const G4Track& track,
if ( !fIsPhysicsBasedBiasing )
{
G4VParticleChange* particleChange = fNonPhysicsBiasingOperation->GenerateBiasingFinalState( &track, &step );
fCurrentBiasingOperator->ReportOperationApplied( this, BAC_NonPhysics, fNonPhysicsBiasingOperation, particleChange );
(fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC_NonPhysics, fNonPhysicsBiasingOperation, particleChange );
return particleChange;
}
// -- physics biasing case:
// ------------------------
// -- It proceeds with the following logic:
// -- 1) If an occurence biasing operation exists, it makes the
// -- decision about the interaction to happen or not.
// -- If the occurence operation refuses the interaction, it
// -- can only propose a new track weight.
// -- 2) The interaction is produced by the final state biasing
// -- operation, if it exists, or by the wrapped process in
// -- the other case.
// -- Hence 2) happens if 1) decides so
// 2) happens if there is no occurence biasing operation
if ( fOccurenceBiasingOperation != 0 )
{
G4double proposedTrackWeight = track.GetWeight();
if ( fOccurenceBiasingOperation->DenyProcessPostStepDoIt( this, &track, &step, proposedTrackWeight ) )
{
fParticleChange->Initialize( track ); // **??** <= might use a light version for particle change here
fParticleChange->ProposeParentWeight( proposedTrackWeight );
fCurrentBiasingOperator->ReportOperationApplied( this, BAC_DenyInteraction, fOccurenceBiasingOperation, fParticleChange );
return fParticleChange;
}
}
// -- 1) Obtain the final state
// -- This final state may be analog or biased.
// -- The biased final state is obtained through a biasing operator
// -- returned by the operator.
// -- 2) The biased final state may be asked to be "force as it is"
// -- in what case the particle change is returned as is to the
// -- stepping.
// -- In all other cases (analog final state or biased final but
// -- not forced) the final state weight may be modified by the
// -- occurence biasing, if such an occurence biasing is at play.
// -- usual case with generated final state:
// -- Get final state, biased or analog:
G4VParticleChange* finalStateParticleChange;
G4BiasingAppliedCase BAC;
fFinalStateBiasingOperation = fCurrentBiasingOperator->GetProposedFinalStateBiasingOperation( &track, this );
fFinalStateBiasingOperation = (fSharedData->fCurrentBiasingOperator)->GetProposedFinalStateBiasingOperation( &track, this );
// -- Flag below is to force the biased generated particle change to be retruned "as is" to the stepping, disregarding there
// -- was or not a occurence biasing that would apply. Weight relevance under full responsibility of the biasing operation.
G4bool forceBiasedFinalState = false;
if ( fFinalStateBiasingOperation != 0 )
{
finalStateParticleChange = fFinalStateBiasingOperation->ApplyFinalStateBiasing( this, &track, &step );
finalStateParticleChange = fFinalStateBiasingOperation->ApplyFinalStateBiasing( this, &track, &step, forceBiasedFinalState );
BAC = BAC_FinalState;
}
else
@@ -370,14 +419,22 @@ G4VParticleChange* G4BiasingProcessInterface::PostStepDoIt(const G4Track& track,
finalStateParticleChange = fWrappedProcess->PostStepDoIt(track, step);
BAC = BAC_None ;
}
// -- if no occurence biasing operation, we're done:
if ( fOccurenceBiasingOperation == 0 )
{
fCurrentBiasingOperator->ReportOperationApplied( this, BAC, fFinalStateBiasingOperation, finalStateParticleChange );
(fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC, fFinalStateBiasingOperation, finalStateParticleChange );
return finalStateParticleChange;
}
// -- If occurence biasing, applies on top of final state occurence biasing weight correction:
// -- if biased final state has been asked to be forced, we're done:
if ( forceBiasedFinalState )
{
(fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC, fFinalStateBiasingOperation, finalStateParticleChange );
return finalStateParticleChange;
}
// -- If occurence biasing, applies the occurence biasing weight correction on top of final state (biased or not):
G4double weightForInteraction = 1.0;
if ( !fBiasingInteractionLaw->IsSingular() ) weightForInteraction =
fPhysicalInteractionLaw->ComputeEffectiveCrossSectionAt(step.GetStepLength()) /
@@ -404,9 +461,9 @@ G4VParticleChange* G4BiasingProcessInterface::PostStepDoIt(const G4Track& track,
G4ExceptionDescription ed;
ed << " Negative interaction weight : w_I = "
<< weightForInteraction <<
" XS_I(phys) = " << fBiasingInteractionLaw ->ComputeEffectiveCrossSectionAt(step.GetStepLength()) <<
" XS_I(bias) = " << fPhysicalInteractionLaw->ComputeEffectiveCrossSectionAt(step.GetStepLength()) <<
" step length = " << step.GetStepLength() <<
" XS_I(phys) = " << fBiasingInteractionLaw ->ComputeEffectiveCrossSectionAt(step.GetStepLength()) <<
" XS_I(bias) = " << fPhysicalInteractionLaw->ComputeEffectiveCrossSectionAt(step.GetStepLength()) <<
" step length = " << step.GetStepLength() <<
" Interaction law = `" << fBiasingInteractionLaw << "'" <<
G4endl;
G4Exception(" G4BiasingProcessInterface::PostStepDoIt(...)",
@@ -416,9 +473,9 @@ G4VParticleChange* G4BiasingProcessInterface::PostStepDoIt(const G4Track& track,
}
fCurrentBiasingOperator->ReportOperationApplied( this, BAC,
fOccurenceBiasingOperation, weightForInteraction,
fFinalStateBiasingOperation, finalStateParticleChange );
(fSharedData->fCurrentBiasingOperator)->ReportOperationApplied( this, BAC,
fOccurenceBiasingOperation, weightForInteraction,
fFinalStateBiasingOperation, finalStateParticleChange );
fOccurenceBiasingParticleChange->SetOccurenceWeightForInteraction( weightForInteraction );
fOccurenceBiasingParticleChange->SetSecondaryWeightByProcess( true );
@@ -450,7 +507,7 @@ G4double G4BiasingProcessInterface::AlongStepGetPhysicalInteractionLen
// ---------------------------------------
// -- case outside of volume with biasing:
// ---------------------------------------
if ( fCurrentBiasingOperator == 0 )
if ( fSharedData->fCurrentBiasingOperator == 0 )
{
if ( fWrappedProcessIsAlong ) fWrappedProcessAlongStepGPIL =
fWrappedProcess->AlongStepGetPhysicalInteractionLength(track,
@@ -506,6 +563,7 @@ G4double G4BiasingProcessInterface::AlongStepGetPhysicalInteractionLen
}
*selection = fBiasingGPILSelection;
return fWrappedProcessAlongStepGPIL;
}
@@ -516,7 +574,7 @@ G4VParticleChange* G4BiasingProcessInterface::AlongStepDoIt(const G4Track& track
// ---------------------------------------
// -- case outside of volume with biasing:
// ---------------------------------------
if ( fCurrentBiasingOperator == 0 )
if ( fSharedData->fCurrentBiasingOperator == 0 )
{
if ( fWrappedProcessIsAlong ) return fWrappedProcess->AlongStepDoIt(track, step);
else
@@ -594,29 +652,31 @@ void G4BiasingProcessInterface::SetMasterProcess(G4VProcess* masterP)
if ( fWrappedProcess != 0 )
{
const G4BiasingProcessInterface* thisWrapperMaster = (const G4BiasingProcessInterface *)GetMasterProcess();
// -- paranoia check:
// -- paranoia check: (?)
G4VProcess* wrappedMaster = 0;
wrappedMaster = thisWrapperMaster->GetWrappedProcess();
fWrappedProcess->SetMasterProcess( wrappedMaster );
}
}
void G4BiasingProcessInterface::BuildPhysicsTable(const G4ParticleDefinition& pd)
{
// -- Inform existing operators about start of the run.
// -- IMPORTANT : as PreparePhysicsTable(...) has been called first for all processes,
// -- the first/last flags and G4BiasingProcessInterface vector of processes have
// -- been properly setup.
if ( fIamFirstGPIL )
{
for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
( G4VBiasingOperator::GetBiasingOperators() )[optr]->StartRun( );
}
// -- PreparePhysicsTable(...) has been called first for all processes,
// -- so the first/last flags and G4BiasingProcessInterface vector of processes have
// -- been properly setup, fIamFirstGPIL is valid.
if ( fWrappedProcess != 0 )
{
fWrappedProcess->BuildPhysicsTable(pd);
fWrappedProcess->BuildPhysicsTable(pd);
}
// -- Re-order vector of processes to match that of the GPIL
// -- (made for fIamFirstGPIL, but important is to have it made once):
if ( fIamFirstGPIL ) ReorderBiasingVectorAsGPIL();
}
void G4BiasingProcessInterface::PreparePhysicsTable(const G4ParticleDefinition& pd)
{
// -- Let process finding its first/last position in the process manager:
@@ -626,57 +686,87 @@ void G4BiasingProcessInterface::PreparePhysicsTable(const G4ParticleDefinitio
fWrappedProcess->PreparePhysicsTable(pd);
}
}
G4bool G4BiasingProcessInterface::StorePhysicsTable(const G4ParticleDefinition* pd, const G4String& s, G4bool f)
{
if ( fWrappedProcess != 0 ) return fWrappedProcess->StorePhysicsTable(pd, s, f);
else return false;
}
G4bool G4BiasingProcessInterface::RetrievePhysicsTable(const G4ParticleDefinition* pd, const G4String& s, G4bool f)
{
if ( fWrappedProcess != 0 ) return fWrappedProcess->RetrievePhysicsTable(pd, s, f);
else return false;
}
void G4BiasingProcessInterface::SetProcessManager(const G4ProcessManager* mgr)
{
{
if ( fWrappedProcess != 0 ) fWrappedProcess->SetProcessManager(mgr);
else G4VProcess::SetProcessManager(mgr);
(fManagerInterfaceMap[mgr]).push_back(this);
fCoInterfaces = &(fManagerInterfaceMap[mgr]);
// -- initialize fSharedData pointer:
if ( fSharedDataMap.Find(mgr) == fSharedDataMap.End() )
{
fSharedData = new G4BiasingProcessSharedData( mgr );
fSharedDataMap[mgr] = fSharedData;
}
else fSharedData = fSharedDataMap[mgr] ;
// -- augment list of co-operating processes:
fSharedData-> fBiasingProcessInterfaces.push_back( this );
fSharedData-> fPublicBiasingProcessInterfaces.push_back( this );
if ( fIsPhysicsBasedBiasing )
{
fSharedData-> fPhysicsBiasingProcessInterfaces.push_back( this );
fSharedData-> fPublicPhysicsBiasingProcessInterfaces.push_back( this );
}
else
{
fSharedData-> fNonPhysicsBiasingProcessInterfaces.push_back( this );
fSharedData-> fPublicNonPhysicsBiasingProcessInterfaces.push_back( this );
}
// -- remember process manager:
fProcessManager = mgr;
}
const G4ProcessManager* G4BiasingProcessInterface::GetProcessManager()
{
if ( fWrappedProcess != 0 ) return fWrappedProcess->GetProcessManager();
else return G4VProcess::GetProcessManager();
}
void G4BiasingProcessInterface::BuildWorkerPhysicsTable(const G4ParticleDefinition& pd)
{
// -- Inform existing operators about start of the run.
// -- IMPORTANT : as PreparePhysicsTable(...) has been called first for all processes,
// -- the first/last flags and G4BiasingProcessInterface vector of processes have
// -- been properly setup.
if ( fIamFirstGPIL )
{
for ( size_t optr = 0 ; optr < ( G4VBiasingOperator::GetBiasingOperators() ).size() ; optr ++)
( G4VBiasingOperator::GetBiasingOperators() )[optr]->StartRun( );
}
// -- PrepareWorkerPhysicsTable(...) has been called first for all processes,
// -- so the first/last flags and G4BiasingProcessInterface vector of processes have
// -- been properly setup, fIamFirstGPIL is valid.
if ( fWrappedProcess != 0 )
{
fWrappedProcess->BuildWorkerPhysicsTable(pd);
}
// -- Re-order vector of processes to match that of the GPIL
// -- (made for fIamFirstGPIL, but important is to have it made once):
if ( fIamFirstGPIL ) ReorderBiasingVectorAsGPIL();
}
void G4BiasingProcessInterface::PrepareWorkerPhysicsTable(const G4ParticleDefinition& pd)
{
// -- Let process finding its first/last position in the process manager:
SetUpFirstLastFlags();
if ( fWrappedProcess != 0 )
{
fWrappedProcess->PrepareWorkerPhysicsTable(pd);
}
}
}
void G4BiasingProcessInterface::ResetNumberOfInteractionLengthLeft()
{
if ( fWrappedProcess != 0 ) fWrappedProcess->ResetNumberOfInteractionLengthLeft();
@@ -688,16 +778,22 @@ G4bool G4BiasingProcessInterface::GetIsFirstPostStepGPILInterface( G4bool physOn
G4int iPhys = ( physOnly ) ? 1 : 0;
return fFirstLastFlags[IdxFirstLast( 1, 1, iPhys)];
}
G4bool G4BiasingProcessInterface::GetIsLastPostStepGPILInterface( G4bool physOnly ) const
{
G4int iPhys = ( physOnly ) ? 1 : 0;
return fFirstLastFlags[IdxFirstLast( 0, 1, iPhys)];
}
G4bool G4BiasingProcessInterface::GetIsFirstPostStepDoItInterface( G4bool physOnly ) const
{
G4int iPhys = ( physOnly ) ? 1 : 0;
return fFirstLastFlags[IdxFirstLast( 1, 0, iPhys)];
}
G4bool G4BiasingProcessInterface::GetIsLastPostStepDoItInterface( G4bool physOnly ) const
{
G4int iPhys = ( physOnly ) ? 1 : 0;
@@ -711,12 +807,15 @@ G4bool G4BiasingProcessInterface::IsFirstPostStepGPILInterface(G4bool physOnly)
const G4ProcessVector* pv = fProcessManager->GetPostStepProcessVector(typeGPIL);
G4int thisIdx(-1);
for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
for ( size_t i = 0; i < fCoInterfaces->size(); i++ )
// for ( size_t i = 0; i < fCoInterfaces->size(); i++ )
for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
{
if ( ( (*fCoInterfaces)[i]->GetWrappedProcess() != 0 ) || !physOnly )
// if ( ( (*fCoInterfaces)[i]->GetWrappedProcess() != 0 ) || !physOnly )
if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
{
G4int thatIdx(-1);
for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j; break; }
// for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j; break; }
for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
if ( thisIdx > thatIdx )
{
isFirst = false;
@@ -727,18 +826,22 @@ G4bool G4BiasingProcessInterface::IsFirstPostStepGPILInterface(G4bool physOnly)
return isFirst;
}
G4bool G4BiasingProcessInterface::IsLastPostStepGPILInterface(G4bool physOnly) const
{
G4bool isLast = true;
const G4ProcessVector* pv = fProcessManager->GetPostStepProcessVector(typeGPIL);
G4int thisIdx(-1);
for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
for ( size_t i = 0; i < fCoInterfaces->size(); i++ )
// for ( size_t i = 0; i < fCoInterfaces->size(); i++ )
for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
{
if ( ( (*fCoInterfaces)[i]->GetWrappedProcess() != 0 ) || !physOnly )
// if ( ( (*fCoInterfaces)[i]->GetWrappedProcess() != 0 ) || !physOnly )
if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
{
G4int thatIdx(-1);
for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j; break; }
// for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j; break; }
for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
if ( thisIdx < thatIdx )
{
isLast = false;
@@ -749,18 +852,22 @@ G4bool G4BiasingProcessInterface::IsLastPostStepGPILInterface(G4bool physOnly) c
return isLast;
}
G4bool G4BiasingProcessInterface::IsFirstPostStepDoItInterface(G4bool physOnly) const
{
G4bool isFirst = true;
const G4ProcessVector* pv = fProcessManager->GetPostStepProcessVector(typeDoIt);
G4int thisIdx(-1);
for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
for ( size_t i = 0; i < fCoInterfaces->size(); i++ )
// for ( size_t i = 0; i < fCoInterfaces->size(); i++ )
for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
{
if ( ( (*fCoInterfaces)[i]->GetWrappedProcess() != 0 ) || !physOnly )
// if ( ( (*fCoInterfaces)[i]->GetWrappedProcess() != 0 ) || !physOnly )
if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
{
G4int thatIdx(-1);
for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j; break; }
// for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j; break; }
for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
if ( thisIdx > thatIdx )
{
isFirst = false;
@@ -771,18 +878,22 @@ G4bool G4BiasingProcessInterface::IsFirstPostStepDoItInterface(G4bool physOnly)
return isFirst;
}
G4bool G4BiasingProcessInterface::IsLastPostStepDoItInterface(G4bool physOnly) const
{
G4bool isLast = true;
const G4ProcessVector* pv = fProcessManager->GetPostStepProcessVector(typeDoIt);
G4int thisIdx(-1);
for (G4int i = 0; i < pv->size(); i++ ) if ( (*pv)(i) == this ) { thisIdx = i; break; }
for ( size_t i = 0; i < fCoInterfaces->size(); i++ )
// for ( size_t i = 0; i < fCoInterfaces->size(); i++ )
for ( size_t i = 0; i < (fSharedData->fBiasingProcessInterfaces).size(); i++ )
{
if ( ( (*fCoInterfaces)[i]->GetWrappedProcess() != 0 ) || !physOnly )
// if ( ( (*fCoInterfaces)[i]->GetWrappedProcess() != 0 ) || !physOnly )
if ( (fSharedData->fBiasingProcessInterfaces)[i]->fIsPhysicsBasedBiasing || !physOnly )
{
G4int thatIdx(-1);
for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j; break; }
// for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (*fCoInterfaces)[i] ) { thatIdx = j; break; }
for (G4int j = 0; j < pv->size(); j++ ) if ( (*pv)(j) == (fSharedData->fBiasingProcessInterfaces)[i] ) { thatIdx = j; break; }
if ( thisIdx < thatIdx )
{
isLast = false;
@@ -810,7 +921,6 @@ void G4BiasingProcessInterface::SetUpFirstLastFlags()
}
void G4BiasingProcessInterface::ResetForUnbiasedTracking()
{
fOccurenceBiasingOperation = 0;
@@ -818,3 +928,66 @@ void G4BiasingProcessInterface::ResetForUnbiasedTracking()
fNonPhysicsBiasingOperation = 0;
fBiasingInteractionLaw = 0;
}
void G4BiasingProcessInterface::InvokeWrappedProcessPostStepGPIL( const G4Track& track,
G4double previousStepSize,
G4ForceCondition* condition )
{
G4double usedPreviousStepSize = previousStepSize;
// -- if the physics process has been under occurence biasing in the previous step
// -- we reset it, as we don't know if it will be biased again or not in this
// -- step. The pity is that PostStepGPIL and interaction length (cross-section)
// -- calculations are done both in the PostStepGPIL of the process, while here we
// -- are just interested in the calculation of the cross-section. This is a pity
// -- as this forces to re-generated a random number for nothing.
if ( fResetWrappedProcessInteractionLength )
{
fResetWrappedProcessInteractionLength = false;
fWrappedProcess->ResetNumberOfInteractionLengthLeft();
// -- We set "previous step size" as 0.0, to let the process believe this is first step:
usedPreviousStepSize = 0.0;
}
// -- GPIL response:
fWrappedProcessPostStepGPIL = fWrappedProcess->PostStepGetPhysicalInteractionLength(track, usedPreviousStepSize, condition);
fWrappedProcessForceCondition = *condition;
// -- and (inverse) cross-section:
fWrappedProcessInteractionLength = fWrappedProcess->GetCurrentInteractionLength();
}
void G4BiasingProcessInterface::ReorderBiasingVectorAsGPIL()
{
// -- re-order vector of processes to match that of the GPIL:
std::vector < G4BiasingProcessInterface* > tmpProcess ( fSharedData->fBiasingProcessInterfaces );
( fSharedData -> fBiasingProcessInterfaces ) . clear();
( fSharedData -> fPhysicsBiasingProcessInterfaces ) . clear();
( fSharedData -> fNonPhysicsBiasingProcessInterfaces ) . clear();
( fSharedData -> fPublicBiasingProcessInterfaces ) . clear();
( fSharedData -> fPublicPhysicsBiasingProcessInterfaces ) . clear();
( fSharedData -> fPublicNonPhysicsBiasingProcessInterfaces ) . clear();
const G4ProcessVector* pv = fProcessManager->GetPostStepProcessVector(typeGPIL);
for (G4int i = 0; i < pv->size(); i++ )
{
for ( size_t j = 0; j < tmpProcess.size(); j++ )
{
if ( (*pv)(i) == tmpProcess[j] )
{
( fSharedData -> fBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
( fSharedData -> fPublicBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
if ( tmpProcess[j] -> fIsPhysicsBasedBiasing )
{
( fSharedData -> fPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
( fSharedData -> fPublicPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
}
else
{
( fSharedData -> fNonPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
( fSharedData -> fPublicNonPhysicsBiasingProcessInterfaces ) . push_back( tmpProcess[j] );
}
break;
}
}
}
}
@@ -29,12 +29,10 @@
#include "G4BOptnForceCommonTruncatedExp.hh"
#include "G4BiasingProcessInterface.hh"
//#include "G4Exception.hh"
G4ILawCommonTruncatedExp::G4ILawCommonTruncatedExp(G4String name)
: G4VBiasingInteractionLaw(name),
fExpInteractionLaw("expLawFor"+name)
//fIsSingular(false)
{}
G4ILawCommonTruncatedExp::~G4ILawCommonTruncatedExp()
@@ -43,18 +41,14 @@ G4ILawCommonTruncatedExp::~G4ILawCommonTruncatedExp()
G4double G4ILawCommonTruncatedExp::ComputeEffectiveCrossSectionAt(G4double distance) const
{
return fExpInteractionLaw.ComputeEffectiveCrossSectionAt( distance ) * fOperation->GetTriggeredProcessXSfraction();
return fExpInteractionLaw.ComputeEffectiveCrossSectionAt( distance ) * fSelectedProcessXSfraction;
}
G4double G4ILawCommonTruncatedExp::ComputeNonInteractionProbabilityAt(G4double distance) const
{
G4double niProba = fExpInteractionLaw.ComputeNonInteractionProbabilityAt( distance );
if ( niProba > 0.0 )
{
return std::exp( std::log(niProba) / fNumberOfSharing );
}
else
if ( niProba <= 0.0 )
{
G4ExceptionDescription ed;
ed << " Negative probability for `" << GetName() << "' p = " << niProba << " distance = " << distance << " !!! " << G4endl;
@@ -62,27 +56,20 @@ G4double G4ILawCommonTruncatedExp::ComputeNonInteractionProbabilityAt(G4double d
"BIAS.GEN.08",
JustWarning,
ed);
return niProba;
}
return niProba;
}
G4double G4ILawCommonTruncatedExp::SampleInteractionLength()
{
if ( fFirstSamplingCall ) fInteractionDistance = fExpInteractionLaw.SampleInteractionLength();
fFirstSamplingCall = false;
return DBL_MAX;
fInteractionDistance = fExpInteractionLaw.SampleInteractionLength();
return fInteractionDistance;
}
G4double G4ILawCommonTruncatedExp::UpdateInteractionLengthForStep(G4double truePathLength)
{
if ( fFirstUpdateCall )
fInteractionDistance = fExpInteractionLaw.UpdateInteractionLengthForStep(truePathLength);
fFirstUpdateCall = false;
return DBL_MAX;
}
void G4ILawCommonTruncatedExp::reset()
{
fFirstSamplingCall = true;
fFirstUpdateCall = true;
fInteractionDistance = fExpInteractionLaw.UpdateInteractionLengthForStep(truePathLength);
return fInteractionDistance;
}
@@ -27,7 +27,6 @@
#include "Randomize.hh"
#include "G4Track.hh"
//#include "G4Exception.hh"
G4ILawTruncatedExp::G4ILawTruncatedExp(G4String name)
: G4VBiasingInteractionLaw(name),
@@ -82,8 +81,8 @@ G4double G4ILawTruncatedExp::ComputeNonInteractionProbabilityAt(G4double distanc
// -- return limit case of null cross-section:
return 1.0 - distance / fMaximumDistance;
}
G4double num = 1.0 - std::exp( -fCrossSection*distance);
G4double denum = 1.0 - std::exp( -fCrossSection*fMaximumDistance);
G4double num = 1.0 - std::exp( -fCrossSection*distance );
G4double denum = 1.0 - std::exp( -fCrossSection*fMaximumDistance );
return 1.0 - num/denum;
}
@@ -86,6 +86,7 @@ G4double G4InteractionLawPhysical::SampleInteractionLength()
G4double G4InteractionLawPhysical::UpdateInteractionLengthForStep(G4double truePathLength)
{
fNumberOfInteractionLength -= truePathLength*fCrossSection;
if ( fNumberOfInteractionLength < 0 )
{
G4ExceptionDescription ed;
@@ -96,5 +97,5 @@ G4double G4InteractionLawPhysical::UpdateInteractionLengthForStep(G4double
ed);
fNumberOfInteractionLength = 0.;
}
return fNumberOfInteractionLength;
return fNumberOfInteractionLength/fCrossSection;
}
@@ -66,7 +66,6 @@ G4Step* G4ParticleChangeForOccurenceBiasing::UpdateStepForAlongStep(G4Step* step
// -- multiply parent weight by weight due to occurence biasing:
G4StepPoint* postStepPoint = step->GetPostStepPoint();
// G4cout << " part change along : w = " << postStepPoint->GetWeight() << " , wOcc = " << fOccurenceWeightForNonInteraction << G4endl; // !
postStepPoint->SetWeight( postStepPoint->GetWeight() * fOccurenceWeightForNonInteraction );
return step;
+12 -1
View File
@@ -1,4 +1,4 @@
$Id: History 77477 2013-11-25 09:42:24Z gcosmo $
$Id: History 86417 2014-11-11 08:52:10Z gcosmo $
-------------------------------------------------------------------
=========================================================
@@ -17,6 +17,17 @@ committal in the CVS repository !
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
November 10th, 2014 M. Verderi
- Fix G4BiasingOperatorStateNotifier::Notify(...) to detect
start of run.
- tag : proc-biasmng-V10-00-01
November 7th, 2014 M. Verderi
- G4VBiasingOperation : suppression of DenyProcessPostStepDoIt(...)
as redondant and special case of ApplyFinalStateBiasing(...).
tag : proc-biasmng-V10-00-00
November 22nd, 2013 A.Howard
- Moved G4VProcessPlacer and G4ProcessPlacer from importance
@@ -64,9 +64,6 @@ private:
G4BiasingOperationManager();
static G4VectorCache<G4VBiasingOperation*> fBiasingOperationVector;
static G4MapCache<G4VBiasingOperation*,std::size_t > fBiasingOperationIDtoPointerMap;
//static G4BiasingOperationManager* fInstance;
//static std::vector< G4VBiasingOperation* > fBiasingOperationVector;
//static std::map < G4VBiasingOperation*, std::size_t > fBiasingOperationIDtoPointerMap;
};
#endif
@@ -62,7 +62,6 @@ public:
private:
G4BiasingTrackDataStore();
//static G4BiasingTrackDataStore* fInstance;
std::map < const G4Track*, G4BiasingTrackData* > fTrackDataStore;
};
@@ -55,6 +55,8 @@
//
// Author: M.Verderi (LLR), November 2013
// - 05/11/13 : first implementation
// - 07/11/14 : suppress DenyProcessPostStepDoIt(...) as redondant
// and special case of ApplyFinalStateBiasing(...)
// ---------------------------------------------------------------------
@@ -114,15 +116,11 @@ public:
// ------ 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.
virtual const G4VBiasingInteractionLaw* ProvideOccurenceBiasingInteractionLaw( const G4BiasingProcessInterface* /* callingProcess */ ) = 0;
// ------ o Additionnal method for PostStep occurence:
// ------ - operation can propose a force condition in the PostStepGPIL
// ------ - this condition superseedes the wrapped process condition (taken as default condition)
// ------ - it is called after above ProvideOccurenceBiasingInteractionLaw(...) by the same calling process.
virtual G4ForceCondition ProposeForceCondition( const G4ForceCondition wrappedProcessCondition )
{
return wrappedProcessCondition;
}
// ------ - 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 :
// ----
@@ -150,11 +148,13 @@ public:
// ------ - has to return true if interaction is denied by the operation
// ------ - the primary is left unchanged in this case
// ------ - but its weight becomes the one given by proposedTrackWeight.
virtual G4bool DenyProcessPostStepDoIt( const G4BiasingProcessInterface* /* callingProcess */,
const G4Track* /* track */,
const G4Step* /* step */,
G4double& /* proposedTrackWeight */ )
{return false;}
// DEPRECATED
// virtual G4bool DenyProcessPostStepDoIt( const G4BiasingProcessInterface* /* callingProcess */,
// const G4Track* /* track */,
// const G4Step* /* step */,
// G4double& /* proposedTrackWeight */ )
// {return false;}
// ---- II. Biasing of the process post step final state:
@@ -163,13 +163,19 @@ public:
// ------ 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 occurence 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 conjonction with an occurence biasing, provided this final
// ------ state biasing is uncorrelated with the occurence biasing (as single multiplication
// ------ of weights occur between these two biasings).
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface* /* callingProcess */,
const G4Track* /* track */,
const G4Step* /* step */) = 0;
virtual G4VParticleChange* ApplyFinalStateBiasing( const G4BiasingProcessInterface* /* callingProcess */,
const G4Track* /* track */,
const G4Step* /* step */,
G4bool& /* forceBiasedFinalState */) = 0;
// ---- III. Biasing of the process along step final state:
@@ -183,12 +183,20 @@ class G4Track;
class G4BiasingProcessInterface;
class G4LogicalVolume;
class G4VParticleChange;
class G4BiasingOperatorStateNotifier;
#include <map>
#include <vector>
#include "G4BiasingAppliedCase.hh"
#include "G4Cache.hh"
class G4VBiasingOperator {
// -- State machine used to inform operators
// -- about run starting.
// -- Defined at the end of this file.
friend class G4BiasingOperatorStateNotifier;
public:
// ---------------
// -- Constructor:
@@ -314,6 +322,9 @@ private:
static G4VectorCache<G4VBiasingOperator* > fOperators;
// static std::vector < G4VBiasingOperator* > fOperators;
// -- thread local:
static G4Cache< G4BiasingOperatorStateNotifier* > fStateNotifier;
// -- For this operator:
std::vector< const G4LogicalVolume* > fRootVolumes;
@@ -335,4 +346,17 @@ private:
};
// -- 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;
};
#endif
@@ -31,13 +31,17 @@
G4MapCache< const G4LogicalVolume*, G4VBiasingOperator* > G4VBiasingOperator::fLogicalToSetupMap;
G4VectorCache< G4VBiasingOperator* > G4VBiasingOperator::fOperators;
G4VectorCache< G4VBiasingOperator* > G4VBiasingOperator::fOperators;
G4Cache< G4BiasingOperatorStateNotifier* > G4VBiasingOperator::fStateNotifier(0);
G4VBiasingOperator::G4VBiasingOperator(G4String name)
: fName(name)
{
fOperators.Push_back(this);
if ( fStateNotifier.Get() == 0 ) fStateNotifier.Put( new G4BiasingOperatorStateNotifier() );
}
G4VBiasingOperator::~G4VBiasingOperator()
@@ -74,42 +78,21 @@ G4VBiasingOperator* G4VBiasingOperator::GetBiasingOperator(const G4LogicalVolume
G4VBiasingOperation* G4VBiasingOperator::GetProposedOccurenceBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess)
{
fOccurenceBiasingOperation = ProposeOccurenceBiasingOperation(track, callingProcess);
// G4cout << GetName() << " Occurence : ";
// if ( fOccurenceBiasingOperation ) G4cout << fOccurenceBiasingOperation->GetName() << G4endl;
// else G4cout << " (none) " << G4endl;
return fOccurenceBiasingOperation;
}
G4VBiasingOperation* G4VBiasingOperator::GetProposedFinalStateBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess)
{
fFinalStateBiasingOperation = ProposeFinalStateBiasingOperation(track, callingProcess);
// G4cout << GetName() << " Final State : ";
// if ( fFinalStateBiasingOperation ) G4cout << fFinalStateBiasingOperation->GetName() << G4endl;
// else G4cout << " (none) " << G4endl;
return fFinalStateBiasingOperation;
}
G4VBiasingOperation* G4VBiasingOperator::GetProposedNonPhysicsBiasingOperation(const G4Track* track, const G4BiasingProcessInterface* callingProcess)
{
fNonPhysicsBiasingOperation = ProposeNonPhysicsBiasingOperation(track, callingProcess);
// G4cout << GetName() << " Non Physics : ";
// if ( fNonPhysicsBiasingOperation ) G4cout << fNonPhysicsBiasingOperation->GetName() << G4endl;
// else G4cout << " (none) " << G4endl;
return fNonPhysicsBiasingOperation;
}
// void G4VBiasingOperator::RegisterSecondariesBirth( G4VBiasingOperation* operation, const G4VParticleChange* pChange )
// {
// for (G4int i2nd = 0; i2nd < pChange->GetNumberOfSecondaries (); i2nd++)
// RegisterSecondaryBirth( operation, pChange->GetSecondary (i2nd) );
// }
// void G4VBiasingOperator::RegisterSecondaryBirth( G4VBiasingOperation* operation, const G4Track* track )
// {
// // G4cout << " --> Registering operation, track = " << operation->GetName() << " " << track << G4endl;
// fSecondaryBirthOperation[track] = operation;
// }
const G4VBiasingOperation* G4VBiasingOperator::GetBirthOperation( const G4Track* track )
{
const G4BiasingTrackData* biasingData = G4BiasingTrackDataStore::GetInstance()->GetBiasingTrackData(track);
@@ -124,17 +107,6 @@ void G4VBiasingOperator::ReportOperationApplied( const G4BiasingProcessInterface
const G4VParticleChange* particleChangeProduced )
{
fPreviousBiasingAppliedCase = biasingCase;
// if ( operationApplied != 0 )
// {
// if ( operationApplied->GetRememberSecondaries() )
// {
// for (G4int i2nd = 0; i2nd < particleChangeProduced->GetNumberOfSecondaries (); i2nd++)
// new G4BiasingTrackData( particleChangeProduced->GetSecondary (i2nd),
// operationApplied,
// this,
// callingProcess);
// }
// }
fPreviousAppliedOccurenceBiasingOperation = 0;
fPreviousAppliedFinalStateBiasingOperation = 0;
fPreviousAppliedNonPhysicsBiasingOperation = 0;
@@ -174,17 +146,6 @@ void G4VBiasingOperator::ReportOperationApplied( const G4BiasingProcessInterface
const G4VParticleChange* particleChangeProduced )
{
fPreviousBiasingAppliedCase = biasingCase;
// G4VBiasingOperation* operation(finalStateOperationApplied != 0 ? finalStateOperationApplied : occurenceOperationApplied);
// G4bool remember = occurenceOperationApplied->GetRememberSecondaries();
// if ( finalStateOperationApplied != 0 ) remember = remember || finalStateOperationApplied->GetRememberSecondaries();
// if ( remember )
// {
// for (G4int i2nd = 0; i2nd < particleChangeProduced->GetNumberOfSecondaries (); i2nd++)
// new G4BiasingTrackData( particleChangeProduced->GetSecondary (i2nd),
// operation,
// this,
// callingProcess);
// }
fPreviousAppliedOccurenceBiasingOperation = occurenceOperationApplied;
fPreviousAppliedFinalStateBiasingOperation = finalStateOperationApplied;
OperationApplied( callingProcess, biasingCase, occurenceOperationApplied, weightForOccurenceInteraction, finalStateOperationApplied, particleChangeProduced );
@@ -239,3 +200,29 @@ void G4VBiasingOperator::OperationApplied( const G4BiasingProcessInterface*, G4B
G4VBiasingOperation*, G4double,
G4VBiasingOperation*, const G4VParticleChange* )
{}
// ----------------------------------------------------------------------------
// -- state machine to get biasing operators messaged at the beginning of runs:
// ----------------------------------------------------------------------------
G4BiasingOperatorStateNotifier::G4BiasingOperatorStateNotifier()
: G4VStateDependent()
{
fPreviousState = G4State_PreInit;
}
G4BiasingOperatorStateNotifier::~G4BiasingOperatorStateNotifier()
{}
G4bool G4BiasingOperatorStateNotifier::Notify( G4ApplicationState requestedState )
{
if ( ( fPreviousState == G4State_Idle ) && ( requestedState == G4State_GeomClosed ) )
{
for ( size_t i = 0 ; i < G4VBiasingOperator::fOperators.Size() ; i++ ) G4VBiasingOperator::fOperators[i]->StartRun();
}
fPreviousState = requestedState;
return true;
}