Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:57:58

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