Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-03 07:56:01

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 /// \file F04GlobalField.hh
0027 /// \brief Definition of the F04GlobalField class
0028 
0029 #ifndef F04GlobalField_h
0030 #define F04GlobalField_h 1
0031 
0032 #include "F04DetectorConstruction.hh"
0033 #include "F04ElementField.hh"
0034 #include "F04FieldMessenger.hh"
0035 
0036 #include "G4ChordFinder.hh"
0037 #include "G4ElectroMagneticField.hh"
0038 #include "G4EqEMFieldWithSpin.hh"
0039 #include "G4EqMagElectricField.hh"
0040 #include "G4FieldManager.hh"
0041 #include "G4MagIntegratorStepper.hh"
0042 #include "G4Mag_EqRhs.hh"
0043 #include "G4Mag_SpinEqRhs.hh"
0044 #include "G4MagneticField.hh"
0045 #include "G4PropagatorInField.hh"
0046 
0047 #include <vector>
0048 
0049 //  F04GlobalField - handles the global ElectroMagnetic field
0050 //
0051 //  There is a single G04GlobalField object.
0052 //
0053 //  The field from each individual beamline element is given by a
0054 //  ElementField object. Any number of overlapping ElementField
0055 //  objects can be added to the global field. Any element that
0056 //  represents an element with an EM field must add the appropriate
0057 //  ElementField to the global GlobalField object.
0058 
0059 using FieldList = std::vector<F04ElementField*>;
0060 
0061 class F04GlobalField : public G4ElectroMagneticField
0062 {
0063     // class F04GlobalField : public G4MagneticField {
0064 
0065   private:
0066     F04GlobalField(F04DetectorConstruction* const);
0067     F04GlobalField(const F04GlobalField&);
0068 
0069     F04GlobalField& operator=(const F04GlobalField&);
0070 
0071     void SetupArray();
0072 
0073   public:
0074     ~F04GlobalField() override;
0075 
0076     /// GetObject() returns the single F04GlobalField object.
0077     /// It is constructed, if necessary.
0078     static F04GlobalField* GetObject(F04DetectorConstruction* const);
0079     static F04GlobalField* GetObject();
0080 
0081     /// GetFieldValue() returns the field value at a given point[].
0082     /// field is really field[6]: Bx,By,Bz,Ex,Ey,Ez.
0083     /// point[] is in global coordinates: x,y,z,t.
0084     void GetFieldValue(const G4double* point, G4double* field) const override;
0085 
0086     /// DoesFieldChangeEnergy() returns true.
0087     G4bool DoesFieldChangeEnergy() const override { return true; }
0088 
0089     /// AddElementField() adds the ElementField object for a single
0090     /// element to the global field.
0091     void AddElementField(F04ElementField* f)
0092     {
0093       if (fFields) fFields->push_back(f);
0094     }
0095 
0096     /// Clear() removes all ElementField-s from the global object,
0097     /// and destroys them. Used before the geometry is completely
0098     /// re-created.
0099     void Clear();
0100 
0101     /// constructs all field tracking objects
0102     void ConstructField();
0103 
0104     /// Set the Stepper types
0105     void SetStepperType(G4int i) { fStepperType = i; }
0106 
0107     /// Set the Stepper
0108     void SetStepper();
0109 
0110     /// Set the minimum step length
0111     void SetMinStep(G4double stp) { fMinStep = stp; }
0112 
0113     /// Set the delta chord length
0114     void SetDeltaChord(G4double dcr) { fDeltaChord = dcr; }
0115 
0116     /// Set the delta one step length
0117     void SetDeltaOneStep(G4double stp) { fDeltaOneStep = stp; }
0118 
0119     /// Set the delta intersection length
0120     void SetDeltaIntersection(G4double its) { fDeltaIntersection = its; }
0121 
0122     /// Set the minimum eps length
0123     void SetEpsMin(G4double eps) { fEpsMin = eps; }
0124 
0125     /// Set the maximum eps length
0126     void SetEpsMax(G4double eps) { fEpsMax = eps; }
0127 
0128     /// Return the list of Element Fields
0129     FieldList* GetFields() { return fFields; }
0130 
0131   protected:
0132     /// Get the global field manager
0133     G4FieldManager* GetGlobalFieldManager();
0134 
0135   private:
0136     static G4ThreadLocal F04GlobalField* fObject;
0137 
0138     G4int fNfp = 0;
0139     G4bool fFirst = true;
0140 
0141     FieldList* fFields = nullptr;
0142 
0143     const F04ElementField** fFp = nullptr;
0144 
0145   private:
0146     // A. INVARIANTS:
0147     // --------------
0148     // INVARIANT: an integer to indicate the type of RK integration method ('stepper') used
0149     G4int fStepperType = 4;  // ClassicalRK4 is default stepper;
0150 
0151     // INVARIANTS: Accuracy parameters of field propagation (and the integration it uses.)
0152     // 1. These values are lengths - initialised in src
0153     G4double fMinStep = 0.01 * CLHEP::mm;
0154     G4double fDeltaChord = 3.0 * CLHEP::mm;
0155     G4double fDeltaOneStep = 0.01 * CLHEP::mm;
0156     G4double fDeltaIntersection = 0.1 * CLHEP::mm;
0157     // 2. Dimensionless numbers - can initialise here
0158     G4double fEpsMin = 2.5e-7;  // Relative accuracy of integration (minimum)
0159     G4double fEpsMax = 0.001;  // Relative accuracy of integration (maximum)
0160 
0161     // B. STATE: objects which carry out the propagation and are modified during tracking
0162     // --------
0163     //  G4Mag_EqRhs*            fEquation;
0164     //  G4Mag_SpinEqRhs*        fEquation;
0165 
0166     //  G4EqMagElectricField*   fEquation;
0167     G4EqEMFieldWithSpin* fEquation = nullptr;
0168 
0169     G4FieldManager* fFieldManager = nullptr;
0170     G4PropagatorInField* fFieldPropagator = nullptr;
0171     G4MagIntegratorStepper* fStepper = nullptr;
0172     G4ChordFinder* fChordFinder = nullptr;
0173 
0174     // INVARIANTS during tracking: Auxiliary class & information - used for setup
0175     F04FieldMessenger* fFieldMessenger;
0176     F04DetectorConstruction* fDetectorConstruction = nullptr;
0177 };
0178 
0179 #endif