Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:55:49

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4BiasingProcessInterface
0027 //
0028 // Class Description:
0029 //
0030 // A wrapper process making the interface between the tracking
0031 // and the G4VBiasingOperator objects attached to volumes.
0032 // If this process holds a physics process, it forwards
0033 // tracking calls to this process in volume where not biasing
0034 // occurs. In volumes with biasing (with a G4VBiasingOperator
0035 // attached) the process gets what to do messaging the biasing
0036 // operator :
0037 // - at the PostStepGPIL level, for getting an occurrence biasing
0038 //   operation. If such an operation is returned to the process
0039 //   this operation will be messaged at several places.
0040 // - at the PostStepDoIt level, to get a possible final state
0041 //   biasing operation
0042 // If the process does not hold a physics process, it is meant
0043 // as handling "non physics" biasing operations: pure splitting
0044 // or pure kiling for example (ie not brem splitting).
0045 //
0046 // Author: Marc Verderi, September 2013.
0047 // --------------------------------------------------------------------
0048 #ifndef G4BiasingProcessInterface_h
0049 #define G4BiasingProcessInterface_h 1
0050 
0051 #include "globals.hh"
0052 #include "G4VProcess.hh"
0053 #include "G4Cache.hh"
0054 #include "G4BiasingProcessSharedData.hh"
0055 
0056 class G4VBiasingInteractionLaw;
0057 class G4InteractionLawPhysical;
0058 class G4VBiasingOperator;
0059 class G4VBiasingOperation;
0060 class G4ParticleChangeForOccurenceBiasing;
0061 class G4ParticleChangeForNothing;
0062 
0063 class G4BiasingProcessInterface : public G4VProcess
0064 {
0065   public:
0066 
0067     // --------------------------------------------------------------------------------
0068     // -- constructor for dealing with biasing options not affecting physics processes:
0069     // --------------------------------------------------------------------------------
0070     G4BiasingProcessInterface( const G4String& name = "biasWrapper(0)" );
0071     // ---------------------------------------------------------------
0072     // -- constructor to transform the behaviour of a physics process:
0073     // ---------------------------------------------------------------
0074     // -- wrappedProcess pointer MUST NOT be null.
0075     G4BiasingProcessInterface(G4VProcess* wrappedProcess,
0076                               G4bool wrappedIsAtRest,
0077                               G4bool wrappedIsAlongStep,
0078                               G4bool wrappedIsPostStep,
0079                               G4String useThisName = "");
0080     ~G4BiasingProcessInterface();
0081     // -- pointer of wrapped physics process:
0082     G4VProcess* GetWrappedProcess() const { return fWrappedProcess; }
0083   
0084     // ---------------------
0085     // -- Biasing interface:
0086     // ---------------------
0087     // -- Helper methods:
0088     // ------------------
0089     // -- Current step and previous step biasing operator, if any:
0090     G4VBiasingOperator* GetCurrentBiasingOperator() const
0091       { return fSharedData->fCurrentBiasingOperator; }
0092     G4VBiasingOperator* GetPreviousBiasingOperator() const
0093       { return fSharedData->fPreviousBiasingOperator; }
0094     // -- current and previous operation:
0095     G4VBiasingOperation* GetCurrentNonPhysicsBiasingOperation() const
0096       { return fNonPhysicsBiasingOperation; }
0097     G4VBiasingOperation* GetPreviousNonPhysicsBiasingOperation() const
0098       { return fPreviousNonPhysicsBiasingOperation; }
0099     G4VBiasingOperation* GetCurrentOccurenceBiasingOperation() const
0100       { return fOccurenceBiasingOperation; }
0101     G4VBiasingOperation* GetPreviousOccurenceBiasingOperation() const
0102       { return  fPreviousOccurenceBiasingOperation; }
0103     G4VBiasingOperation* GetCurrentFinalStateBiasingOperation() const
0104       { return fFinalStateBiasingOperation; }
0105     G4VBiasingOperation* GetPreviousFinalStateBiasingOperation() const
0106       { return fPreviousFinalStateBiasingOperation; }
0107   
0108     // -- Lists of processes cooperating under a same particle type/G4ProcessManager.
0109     // -- The vector ordering is:
0110     // --   - random, before first "run/beamOn"
0111     // --   - that of the PostStepGetPhysicalInteractionLength() once "/run/beamOn" has been issued
0112     const std::vector< const G4BiasingProcessInterface* >& GetBiasingProcessInterfaces() const
0113       { return fSharedData->fPublicBiasingProcessInterfaces; }
0114     const std::vector< const G4BiasingProcessInterface* >& GetPhysicsBiasingProcessInterfaces() const
0115       { return fSharedData->fPublicPhysicsBiasingProcessInterfaces; }
0116     const std::vector< const G4BiasingProcessInterface* >& GetNonPhysicsBiasingProcessInterfaces() const
0117       { return fSharedData->fPublicNonPhysicsBiasingProcessInterfaces; }
0118 
0119     // -- Get shared data for this process:
0120     const G4BiasingProcessSharedData* GetSharedData() const
0121       { return fSharedData; }
0122     // -- Get shared data associated to a G4ProcessManager:
0123     static const G4BiasingProcessSharedData* GetSharedData( const G4ProcessManager* );
0124 
0125     // ------------------
0126     // -- Helper methods:
0127     // ------------------
0128     // ---- Tell is this process is first/last in the PostStep GPIL and DoIt lists.
0129     // ---- If physOnly is true, only wrapper for physics processes are considered,
0130     // ---- otherwise all G4BiasingProcessInterface processes of this particle are
0131     // ---- considered.
0132     // ---- These methods just return the corresponding flag values setup at
0133     // ---- initialization phase by the next four ones.
0134     // ---- Will not be updated if processes are activate/unactivated on the fly.
0135     // ---- Use next methods (less fast) instead in this case.
0136     G4bool GetIsFirstPostStepGPILInterface(G4bool physOnly = true) const;
0137     G4bool GetIsLastPostStepGPILInterface(G4bool physOnly = true) const;
0138     G4bool GetIsFirstPostStepDoItInterface(G4bool physOnly = true) const;
0139     G4bool GetIsLastPostStepDoItInterface(G4bool physOnly = true) const;
0140     // ---- Determine if the process is first/last in the PostStep GPIL and DoIt lists.
0141     G4bool    IsFirstPostStepGPILInterface(G4bool physOnly = true) const;
0142     G4bool     IsLastPostStepGPILInterface(G4bool physOnly = true) const;
0143     G4bool    IsFirstPostStepDoItInterface(G4bool physOnly = true) const;
0144     G4bool     IsLastPostStepDoItInterface(G4bool physOnly = true) const;
0145     // -- Information about wrapped process:
0146     G4bool GetWrappedProcessIsAtRest() const { return fWrappedProcessIsAtRest; }
0147     G4bool GetWrappedProcessIsAlong() const { return fWrappedProcessIsAlong; }
0148     G4bool GetWrappedProcessIsPost() const { return fWrappedProcessIsPost; }
0149 
0150     // -- Information methods:
0151     G4double GetPreviousStepSize() const { return fPreviousStepSize; }
0152     G4double GetCurrentMinimumStep() const { return fCurrentMinimumStep; }
0153     G4double GetProposedSafety() const { return fProposedSafety; }
0154     void SetProposedSafety(G4double sft) { fProposedSafety = sft; }
0155     // -- return the actual PostStep and AlongStep limits returned by the process to the tracking :
0156     G4double GetPostStepGPIL() const { return fBiasingPostStepGPIL; }
0157     G4double GetAlongStepGPIL() const { return fWrappedProcessAlongStepGPIL; }
0158 
0159     // --------------------------------------------------------------
0160     // --                  G4VProcess interface                    --
0161     // --------------------------------------------------------------
0162 
0163     // -- Start/End tracking:
0164     void StartTracking(G4Track* track);
0165     void EndTracking();
0166   
0167     // -- PostStep methods:
0168     virtual G4double PostStepGetPhysicalInteractionLength(const G4Track&                track,
0169                                            G4double previousStepSize,
0170                                            G4ForceCondition* condition);
0171     virtual G4VParticleChange* PostStepDoIt(const G4Track& track,
0172                                             const G4Step& step);
0173     // -- AlongStep methods:
0174     virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track&                track,
0175                                            G4double previousStepSize,
0176                                            G4double currentMinimumStep, 
0177                                            G4double& proposedSafety, 
0178                                            G4GPILSelection* selection);
0179     virtual G4VParticleChange* AlongStepDoIt(const G4Track& track,
0180                                              const G4Step& step);
0181     // -- AtRest methods
0182     virtual G4double AtRestGetPhysicalInteractionLength(const G4Track&,
0183                                                         G4ForceCondition*);
0184     virtual G4VParticleChange* AtRestDoIt(const G4Track&, const G4Step&);
0185   
0186     virtual G4bool IsApplicable(const G4ParticleDefinition& pd);
0187     virtual void BuildPhysicsTable(const G4ParticleDefinition& pd);
0188     virtual void PreparePhysicsTable(const G4ParticleDefinition& pd);
0189     virtual G4bool StorePhysicsTable(const G4ParticleDefinition* pd,
0190                                      const G4String& s, G4bool f);
0191     virtual G4bool RetrievePhysicsTable(const G4ParticleDefinition* pd,
0192                         const G4String& s, G4bool f);
0193     // --
0194     virtual void SetProcessManager(const G4ProcessManager*); 
0195     virtual const G4ProcessManager* GetProcessManager(); 
0196     // --
0197     virtual void ResetNumberOfInteractionLengthLeft();
0198   
0199     virtual void SetMasterProcess(G4VProcess* masterP);
0200     virtual void BuildWorkerPhysicsTable(const G4ParticleDefinition& pd);
0201     virtual void PrepareWorkerPhysicsTable(const G4ParticleDefinition& pd);
0202 
0203   private:
0204 
0205     // ---- Internal utility methods:
0206     void SetUpFirstLastFlags();
0207     void ResetForUnbiasedTracking();
0208     void ReorderBiasingVectorAsGPIL();
0209 
0210     G4int IdxFirstLast(G4int firstLast, G4int GPILDoIt, G4int physAll) const
0211     {
0212       // -- be careful : all arguments are *assumed* to be 0 or 1. No check
0213       // -- for that is provided. Should be of pure internal usage.
0214       return 4*firstLast + 2*GPILDoIt + physAll;
0215     }
0216 
0217     // -- method used to anticipate stepping manager calls to PostStepGPIL
0218     // -- of wrapped processes : this method calls wrapped process PostStepGPIL
0219     // -- and caches results for PostStepGPIL and condition.
0220     void InvokeWrappedProcessPostStepGPIL( const G4Track& track,
0221                                            G4double previousStepSize,
0222                                            G4ForceCondition* condition );
0223   private:
0224 
0225     G4Track* fCurrentTrack = nullptr;
0226     G4double fPreviousStepSize = -1.0;
0227     G4double fCurrentMinimumStep = -1.0;
0228     G4double fProposedSafety = -1.0;
0229 
0230     G4VBiasingOperation* fOccurenceBiasingOperation = nullptr;
0231     G4VBiasingOperation* fFinalStateBiasingOperation = nullptr;
0232     G4VBiasingOperation* fNonPhysicsBiasingOperation = nullptr;
0233     G4VBiasingOperation* fPreviousOccurenceBiasingOperation = nullptr;
0234     G4VBiasingOperation* fPreviousFinalStateBiasingOperation = nullptr;
0235     G4VBiasingOperation* fPreviousNonPhysicsBiasingOperation = nullptr;
0236 
0237     G4bool fResetWrappedProcessInteractionLength = false;
0238 
0239     G4VProcess* fWrappedProcess = nullptr;
0240     const G4bool fIsPhysicsBasedBiasing = false;
0241     const G4bool fWrappedProcessIsAtRest = false;
0242     const G4bool fWrappedProcessIsAlong = false;
0243     const G4bool fWrappedProcessIsPost = false;
0244 
0245     G4double fWrappedProcessPostStepGPIL = -1.0;
0246     G4double fBiasingPostStepGPIL = -1.0;
0247     G4double fWrappedProcessInteractionLength = -1.0; // -- inverse of analog cross-section
0248     G4ForceCondition fWrappedProcessForceCondition = NotForced;
0249     G4ForceCondition fBiasingForceCondition = NotForced;
0250     G4double fWrappedProcessAlongStepGPIL = -1.0;
0251     G4double fBiasingAlongStepGPIL = -1.0;
0252     G4GPILSelection fWrappedProcessGPILSelection = NotCandidateForSelection;
0253     G4GPILSelection fBiasingGPILSelection = NotCandidateForSelection;
0254 
0255     const G4VBiasingInteractionLaw* fBiasingInteractionLaw = nullptr;
0256     const G4VBiasingInteractionLaw* fPreviousBiasingInteractionLaw = nullptr;
0257     G4InteractionLawPhysical* fPhysicalInteractionLaw = nullptr;
0258     G4ParticleChangeForOccurenceBiasing* fOccurenceBiasingParticleChange = nullptr;
0259     G4ParticleChangeForNothing* fDummyParticleChange = nullptr;
0260     G4bool fFirstLastFlags[8];
0261 
0262     // -- the instance being "firstGPIL" does work shared by other instances:
0263     G4bool fIamFirstGPIL = false;
0264 
0265     // -- MUST be **thread local**:
0266     static G4Cache<G4bool> fResetInteractionLaws;
0267     static G4Cache<G4bool> fCommonStart;
0268     static G4Cache<G4bool> fCommonEnd;
0269     static G4Cache<G4bool> fDoCommonConfigure;
0270 
0271     const G4ProcessManager* fProcessManager = nullptr;
0272 
0273     // -- the data shared among processes attached to a same process manager:
0274     G4BiasingProcessSharedData* fSharedData = nullptr;
0275 };
0276 
0277 #endif