Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4FieldManager.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 // G4FieldManager
0027 //
0028 // Class description:
0029 //
0030 // A class to manage (Store) a pointer to the Field subclass that
0031 // describes the field of a detector (magnetic, electric or other).
0032 // Also stores a reference to the chord finder.
0033 //
0034 // The G4FieldManager class exists to allow the user program to specify 
0035 // the electric, magnetic and/or other field(s) of the detector.
0036 // 
0037 // A field manager can be set to a logical volume (or to more than one), 
0038 // in order to vary its field from that of the world.  In this manner
0039 // a zero or constant field can override a global field,  a more or 
0040 // less exact version can override the external approximation, lower
0041 // or higher precision for tracking can be specified, a different 
0042 // stepper can be chosen for different volumes, ...
0043 //
0044 // It also stores a pointer to the ChordFinder object that can do the
0045 // propagation in this field. All geometrical track "advancement" 
0046 // in the field is handled by this ChordFinder object.
0047 //
0048 // G4FieldManager allows the other classes/object (of the MagneticField 
0049 // & other class categories) to find out whether a detector field object 
0050 // exists and what that object is.
0051 //
0052 // The Chord Finder must be created either by calling CreateChordFinder
0053 // for a Magnetic Field or by the user creating a Chord Finder object
0054 // "manually" and setting the pointer.
0055 //
0056 // A default FieldManager is created by the singleton class
0057 // G4NavigatorForTracking and exists before main is called.
0058 // However a new one can be created and given to G4NavigatorForTracking.
0059 //
0060 // Our current design envisions that one Field manager is 
0061 // valid for each region detector.
0062 //
0063 // It is expected that a particular geometrical region has a Field manager.
0064 // By default a Field Manager is created for the world volume, and
0065 // will be utilised for all volumes unless it is overridden by a 'local'
0066 // field manager.
0067 // Note also that a region with both electric E and magnetic B field will 
0068 // have these treated as one field.
0069 // Similarly it could be extended to treat other fields as additional
0070 // components of a single field type.
0071 
0072 // Author: John Apostolakis (CERN), 10.03.1997 - Design and implementation
0073 // -------------------------------------------------------------------
0074 #ifndef G4FIELDMANAGER_HH
0075 #define G4FIELDMANAGER_HH
0076 
0077 #include "G4FieldParameters.hh"
0078 #include "globals.hh"
0079 
0080 class G4Field;
0081 class G4MagneticField;
0082 class G4ChordFinder;
0083 class G4Track;  // Forward reference for parameter configuration
0084 
0085 /**
0086  * @brief G4FieldManager is a manager (store) for a pointer to the Field
0087  * subclass that describes the field of a detector (magnetic, electric or
0088  * other). It also stores a reference to the chord finder.
0089  * A field manager can be set to a logical volume (or to more than one), 
0090  * in order to vary its field from that of the world volume. In this manner
0091  * a zero or constant field can override a global field, a more or less exact
0092  * version can override the external approximation, lower or higher precision
0093  * for tracking can be specified, a different stepper can be chosen for
0094  * different volumes, etc...
0095  * The Chord Finder must be created either by calling CreateChordFinder()
0096  * for a Magnetic Field or by the user creating a Chord Finder object
0097  * "manually" and setting the pointer.
0098  * The current design envisions that one Field manager is valid for each
0099  * detector region. It is expected that a particular geometrical region has
0100  * a Field manager. By default a Field Manager is created for the world volume,
0101  * and will be utilised for all volumes unless it is overridden by a 'local'
0102  * field manager.
0103  * Note also that a region with both electric E and magnetic B field will 
0104  * have these treated as one field. Similarly it could be extended to treat
0105  * other fields as additional components of a single field type.
0106  */
0107 
0108 class G4FieldManager
0109 {
0110   public:
0111 
0112     /**
0113      * General Constructor for any field. Must be set with field and chord finder
0114      * for use.
0115      *  @param[in] detectorField Pointer to the field.
0116      *  @param[in] pChordFinder Pointer to the chord finder object.
0117      *  @param[in] b Flag to indicate if the field changes the energy; it is
0118      *             taken from the provided field, if specified.
0119      */
0120     G4FieldManager(G4Field* detectorField = nullptr, 
0121                    G4ChordFinder* pChordFinder = nullptr, 
0122                    G4bool b = true ); // fieldChangesEnergy is taken from field
0123 
0124     /**
0125      * Constructor creating the chord finder. It assumes pure magnetic field,
0126      * so energy constant.
0127      *  @param[in] detectorMagneticField Pointer to the magnetic field.
0128      */
0129     G4FieldManager(G4MagneticField* detectorMagneticField);
0130 
0131     /**
0132      * Virtual Destructor.
0133      */
0134     virtual ~G4FieldManager();
0135 
0136     /**
0137      * Copy constructor and assignment operator not allowed.
0138      */
0139     G4FieldManager(const G4FieldManager&) = delete;
0140     G4FieldManager& operator=(const G4FieldManager&) = delete;
0141 
0142     /**
0143      * Pushes the field to the equation. Failure to push the field (due to
0144      * absence of a chord finder, driver, stepper or equation) is
0145      *  - '0' = quiet      : Do not complain if chordFinder == 0
0146      *                       (It will still warn for other error);
0147      *  - '1' = warn       : a warning if anything is missing;
0148      *  - '2'/else = FATAL : a fatal error for all other values.
0149      *  @param[in] detectorField Pointer to the field.
0150      *  @param[in] failMode Flag (0/1/2) for selected failure mode.
0151      *  @returns Success (true) or failure (false).
0152      */
0153     G4bool SetDetectorField(G4Field* detectorField, G4int failMode = 0);
0154 
0155     /**
0156      * Pushes the field to this class only -- no further.
0157      * Should be used to initialise this field, only *before* creating
0158      * the chord finder and its dependent classes.
0159      * User is then responsible to ensure that:
0160      *    i) an equation, stepper, driver and chord finder are created;
0161      *   ii) this field is used by the equation.
0162      *  @param[in] detectorField Pointer to the field.
0163      */
0164     inline void ProposeDetectorField(G4Field* detectorField);
0165 
0166     /**
0167      * Pushes the field to the equation and keeps its address.
0168      * Can be used only once the equation, stepper, driver and chord finder
0169      * have all been created; else it is an error.
0170      *  @param[in] detectorField Pointer to the field.
0171      */
0172     inline void ChangeDetectorField(G4Field* detectorField);    
0173         
0174     /**
0175      * Methods to get and check (existance of) the field object.
0176      */
0177     inline const G4Field* GetDetectorField() const;
0178     inline G4bool DoesFieldExist() const;
0179 
0180     /**
0181      * Methods to create, set or get the associated Chord Finder.
0182      */
0183     void CreateChordFinder(G4MagneticField* detectorMagField);
0184     inline void SetChordFinder(G4ChordFinder* aChordFinder);
0185     inline G4ChordFinder* GetChordFinder();
0186     inline const G4ChordFinder* GetChordFinder() const;
0187 
0188     /**
0189      * Setups the choice of the configurable parameters, relying on the
0190      * current track's energy, particle identity...
0191      * Note: in addition to the values of member variables, a user can use
0192      * this to change the ChordFinder, the field, etc.
0193      *  @param[in] pTrack Pointer to a track.
0194      */
0195     virtual void ConfigureForTrack( const G4Track* pTrack );
0196 
0197     /**
0198      * Static methods to set/get the global field.
0199      */
0200     static void SetGlobalFieldManager(G4FieldManager* fieldManager);
0201     static G4FieldManager* GetGlobalFieldManager();
0202 
0203     /**
0204      * Returns the accuracy for boundary intersection.
0205      */
0206     inline G4double GetDeltaIntersection() const;
0207 
0208     /**
0209      * Returns the accuracy for one tracking/physics step.
0210      */
0211     inline G4double GetDeltaOneStep() const;
0212 
0213     /**
0214      * Sets both accuracies, maintaining a fixed ratio for accuracies 
0215      * of volume Intersection and Integration (in One Step).
0216      */
0217     inline void SetAccuraciesWithDeltaOneStep(G4double valDeltaOneStep); 
0218 
0219     /**
0220      * Sets the accuracy for integration of one step (only).
0221      */
0222     inline void SetDeltaOneStep(G4double valueD1step); 
0223 
0224     /**
0225      * Sets the accuracy of intersection of a volume (only).
0226      */
0227     inline void     SetDeltaIntersection(G4double valueDintersection); 
0228 
0229     /**
0230      * Methods to set/get the minimum for Relative accuracy of a Step.
0231      */
0232     inline G4double GetMinimumEpsilonStep() const;
0233     G4bool SetMinimumEpsilonStep( G4double newEpsMin );
0234 
0235     /**
0236      * Methods to set/get the maximum for Relative accuracy of a Step.
0237      */
0238     inline G4double GetMaximumEpsilonStep() const;
0239     G4bool SetMaximumEpsilonStep( G4double newEpsMax );
0240  
0241     /**
0242      * Methods to set/get flag for field changing energy.
0243      * For electric field this should be true; for magnetic field this
0244      * should be false.
0245      */
0246     inline G4bool DoesFieldChangeEnergy() const;
0247     inline void SetFieldChangesEnergy(G4bool value);
0248     
0249     /**
0250      * Needed for multi-threading, create and returns an allocated clone
0251      * of this object.
0252      */
0253     virtual G4FieldManager* Clone() const;
0254 
0255     /**
0256      * Static methods to set/get the maximum accepted epsilon.
0257      * If setting fails, with softFail=true it gives Warning, else
0258      * a FatalException.
0259      */
0260     static G4double GetMaxAcceptedEpsilon();
0261     static G4bool SetMaxAcceptedEpsilon(G4double maxEps, G4bool softFail= false);
0262    
0263   protected:
0264 
0265     /**
0266      * Logger for reporting on correctness of the proposed epsilon value.
0267      */
0268     void ReportBadEpsilonValue(G4ExceptionDescription& erm, G4double value,
0269                                const G4String& name) const;
0270 
0271     /** Epsilon_min/max values must be smaller than this for robust integration. */
0272     static G4double fMaxAcceptedEpsilon;
0273     static constexpr G4double fMinAcceptedEpsilon = 1000.0 * std::numeric_limits<G4double>::epsilon();
0274 
0275     /** Setting larger value will give warning. */
0276     static constexpr G4double fMaxWarningEpsilon = 0.001;
0277 
0278     /** Will not accept larger values. */
0279     static constexpr G4double fMaxFinalEpsilon = 0.02;
0280    
0281     /** Controls verbosity of constructors. */
0282     static G4bool fVerboseConstruction;
0283   
0284   private:
0285 
0286     /**
0287      * Checks whether the field/equation changes the energy and sets the data
0288      * member accordingly. Does not handle special cases - this must be done
0289      * separately (e.g. magnetic monopole in B field).
0290      */
0291     void InitialiseFieldChangesEnergy();
0292   
0293   private:
0294 
0295     /** Dependent objects -- with state that depends on tracking. */
0296     G4Field* fDetectorField = nullptr;
0297     G4ChordFinder* fChordFinder = nullptr;
0298 
0299     /** Flag to indicate if "new" was used to create the Chord Finder. */
0300     G4bool fAllocatedChordFinder = false; // 
0301 
0302     //  1. CHARACTERISTIC of field
0303 
0304     G4bool fFieldChangesEnergy = false;
0305 
0306     //  2. PARAMETERS that determine the accuracy of integration or intersection
0307 
0308     /** Value for the required accuracies for one tracking/physics step. */
0309     G4double fDelta_One_Step_Value = G4FieldDefaults::kDeltaOneStep;
0310 
0311     /** Value for the required accuracies for boundary intersection. */
0312     G4double fDelta_Intersection_Val = G4FieldDefaults::kDeltaIntersection;
0313 
0314     /** Values for the small possible relative accuracy of a step
0315         (corresponding to the greatest possible integration accuracy). */
0316     G4double fEpsilonMin = G4FieldDefaults::kMinimumEpsilonStep;
0317     G4double fEpsilonMax = G4FieldDefaults::kMaximumEpsilonStep;
0318 
0319     /** Global field manager set by G4TransportationManager to allow accessing
0320         the global field without dependency on navigation. */
0321     static G4ThreadLocal G4FieldManager* fGlobalFieldManager;
0322 };
0323 
0324 // Implementation of inline functions
0325 
0326 #include "G4FieldManager.icc"
0327 
0328 #endif