Back to home page

EIC code displayed by LXR

 
 

    


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

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 // class G4ITMultiNavigator
0030 //
0031 // Class description:
0032 //
0033 // Utility class for polling the navigators of several geometries to
0034 // identify the next  boundary. 
0035 
0036 /// \brief { Class description:
0037 ///
0038 /// G4ITMultiNavigator is a duplicate version of G4MultiNavigator 
0039 ///
0040 /// Utility class for polling the navigators of several geometries to
0041 /// identify the next  boundary.
0042 ///
0043 /// }
0044 
0045 // History:
0046 // - Created. John Apostolakis, November 2006
0047 // *********************************************************************
0048 
0049 #ifndef G4ITMULTINAVIGATOR_HH
0050 #define G4ITMULTINAVIGATOR_HH
0051 
0052 #include <iostream>
0053 
0054 #include "geomdefs.hh"
0055 #include "G4ThreeVector.hh"
0056 #include "G4ITNavigator.hh"
0057 
0058 #include "G4TouchableHandle.hh"
0059 
0060 #include "G4NavigationHistory.hh"
0061 #include "G4TrackState.hh"
0062 #include "G4MultiNavigator.hh"
0063 
0064 namespace G4ITMN
0065 {
0066 enum ELimited
0067 {
0068   kDoNot,
0069   kUnique,
0070   kSharedTransport,
0071   kSharedOther,
0072   kUndefLimited
0073 };
0074 }
0075 class G4ITTransportationManager;
0076 class G4VPhysicalVolume;
0077 
0078 class G4ITMultiNavigator;
0079 
0080 // Global state (retained during stepping for one track
0081 template<>
0082   class G4TrackState<G4ITMultiNavigator> : public G4TrackState<G4ITNavigator>
0083   {
0084   public:
0085     ~G4TrackState() override
0086     = default;
0087 
0088     G4TrackState()
0089     {
0090       G4ThreeVector Big3Vector(kInfinity, kInfinity, kInfinity);
0091       fLastLocatedPosition = Big3Vector;
0092       fSafetyLocation = Big3Vector;
0093       fPreStepLocation = Big3Vector;
0094 
0095       fMinSafety_PreStepPt = -1.0;
0096       fMinSafety_atSafLocation = -1.0;
0097       fMinSafety = -kInfinity;
0098       fTrueMinStep = fMinStep = -kInfinity;
0099 
0100       for (G4int num = 0; num < G4ITNavigator::fMaxNav; ++num)
0101       {
0102         fLimitTruth[num] = false;
0103         fLimitedStep[num] = kUndefLimited;
0104         fCurrentStepSize[num] = fNewSafety[num] = -1.0;
0105         fLocatedVolume[num] = nullptr;
0106       }
0107 
0108       fNoLimitingStep = -1; // How many geometries limited the step
0109       fIdNavLimiting = -1; // Id of Navigator limiting step (if only one limits)
0110       fWasLimitedByGeometry = false;
0111     }
0112     ;
0113 
0114   protected:
0115     friend class G4ITMultiNavigator;
0116     // State after a step computation
0117     ELimited fLimitedStep[G4ITNavigator::fMaxNav];
0118     G4bool fLimitTruth[G4ITNavigator::fMaxNav];
0119     G4double fCurrentStepSize[G4ITNavigator::fMaxNav];
0120     G4double fNewSafety[G4ITNavigator::fMaxNav]; // Safety for starting point
0121     G4int fNoLimitingStep; // How many geometries limited the step
0122     G4int fIdNavLimiting; // Id of Navigator limiting step (if only one limits)
0123 
0124     G4bool fWasLimitedByGeometry;
0125 
0126     // Lowest values - determine step length, and safety
0127     G4double fMinStep; // As reported by Navigators. Can be kInfinity
0128     G4double fMinSafety;
0129     G4double fTrueMinStep; // Corrected in case fMinStep >= proposed
0130 
0131     // State after calling 'locate'
0132     G4VPhysicalVolume* fLocatedVolume[G4ITNavigator::fMaxNav];
0133     G4ThreeVector fLastLocatedPosition;
0134 
0135     // cache of safety information
0136     G4ThreeVector fSafetyLocation; //  point where ComputeSafety is called
0137     G4double fMinSafety_atSafLocation; // /\ corresponding value of safety
0138     G4ThreeVector fPreStepLocation; //  point where last ComputeStep called
0139     G4double fMinSafety_PreStepPt; //   /\ corresponding value of safety
0140   };
0141 
0142 class G4ITMultiNavigator : public G4ITNavigator,
0143                            public G4TrackStateDependent<G4ITMultiNavigator>
0144 {
0145 public:
0146   // with description
0147 
0148   friend std::ostream& operator <<(std::ostream &os, const G4ITNavigator &n);
0149 
0150   G4ITMultiNavigator();
0151   // Constructor - initialisers and setup.
0152 
0153   ~G4ITMultiNavigator() override;
0154   // Destructor. No actions.
0155 
0156   G4double ComputeStep(const G4ThreeVector &pGlobalPoint,
0157                        const G4ThreeVector &pDirection,
0158                        const G4double pCurrentProposedStepLength,
0159                        G4double &pNewSafety) override;
0160   // Return the distance to the next boundary of any geometry
0161 
0162   G4double ObtainFinalStep(G4int navigatorId, G4double &pNewSafety, // for this geom
0163                            G4double &minStepLast,
0164                            ELimited &limitedStep);
0165   // Get values for a single geometry
0166 
0167   void PrepareNavigators();
0168   // Find which geometries are registered for this particles, and keep info
0169   void PrepareNewTrack(const G4ThreeVector position,
0170                        const G4ThreeVector direction);
0171   // Prepare Navigators and locate
0172 
0173   G4VPhysicalVolume* ResetHierarchyAndLocate(const G4ThreeVector &point,
0174                                              const G4ThreeVector &direction,
0175                                              const G4TouchableHistory &h) override;
0176   // Reset the geometrical hierarchy for all geometries.
0177   // Use the touchable history for the first (mass) geometry.
0178   // Return the volume in the first (mass) geometry.
0179   //
0180   // Important Note: In order to call this the geometries MUST be closed.
0181 
0182   G4VPhysicalVolume* LocateGlobalPointAndSetup(const G4ThreeVector& point,
0183                                                const G4ThreeVector* direction =
0184                                                    nullptr,
0185                                                const G4bool pRelativeSearch =
0186                                                    true,
0187                                                const G4bool ignoreDirection =
0188                                                    true) override;
0189   // Locate in all geometries.
0190   // Return the volume in the first (mass) geometry
0191   //  Maintain vector of other volumes,  to be returned separately
0192   //
0193   // Important Note: In order to call this the geometry MUST be closed.
0194 
0195   void LocateGlobalPointWithinVolume(const G4ThreeVector& position) override;
0196   // Relocate in all geometries for point that has not changed volume
0197   // (ie is within safety  in all geometries or is distance less that
0198   // along the direction of a computed step.
0199 
0200   G4double ComputeSafety(const G4ThreeVector &globalpoint,
0201                          const G4double pProposedMaxLength = DBL_MAX,
0202                          const G4bool keepState = false) override;
0203                          // Calculate the isotropic distance to the nearest boundary
0204                          // in any geometry from the specified point in the global coordinate
0205                          // system. The geometry must be closed.
0206 
0207   G4TouchableHandle CreateTouchableHistoryHandle() const override;
0208   // Returns a reference counted handle to a touchable history.
0209 
0210   G4ThreeVector GetLocalExitNormal(G4bool* obtained) override;// const
0211   G4ThreeVector GetLocalExitNormalAndCheck(const G4ThreeVector &CurrentE_Point,
0212   G4bool* obtained) override;// const
0213   G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &CurrentE_Point,
0214   G4bool* obtained) override;// const
0215   // Return Exit Surface Normal and validity too.
0216   // Can only be called if the Navigator's last Step either
0217   //  - has just crossed a volume geometrical boundary and relocated, or
0218   //  - has arrived at a boundary in a ComputeStep
0219   // It returns the Normal to the surface pointing out of the volume that
0220   //   was left behind and/or into the volume that was entered.
0221   // Convention:x
0222   //   The *local* normal is in the coordinate system of the *final* volume.
0223   // Restriction:
0224   //   Normals are not available for replica volumes (returns obtained= false)
0225 
0226 public:// without description
0227 
0228  G4ITNavigator* GetNavigator(G4int n) const
0229  {
0230    if( (n>fNoActiveNavigators)||(n<0))
0231    { n=0;}
0232    return fpNavigator[n];
0233  }
0234 
0235 protected: // with description
0236 
0237   void ResetState() override;
0238   // Utility method to reset the navigator state machine.
0239 
0240   void SetupHierarchy() override;
0241   // Renavigate & reset hierarchy described by current history
0242   // o Reset volumes
0243   // o Recompute transforms and/or solids of replicated/parameterised
0244   //   volumes.
0245 
0246   void WhichLimited();// Flag which processes limited the step
0247   void PrintLimited();// Auxiliary, debugging printing
0248   void CheckMassWorld();
0249 
0250 private:
0251 
0252   G4int fNoActiveNavigators;
0253   G4VPhysicalVolume* fLastMassWorld{nullptr};
0254 
0255   G4ITNavigator* fpNavigator[fMaxNav];// G4ITNavigator** fpNavigator;
0256 
0257   G4ITTransportationManager* pTransportManager;// Cache for frequent use
0258 };
0259 
0260 #endif