Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-30 08:51:59

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 // G4BFieldIntegrationDriver
0027 //
0028 // Class description:
0029 //
0030 // Specialised integration driver for pure magnetic field.
0031 
0032 // Author: Dmitry Sorokin (CERN, Google Summer of Code 2017), 12.09.2018
0033 // Supervision: John Apostolakis (CERN)
0034 // --------------------------------------------------------------------
0035 #ifndef G4BFIELD_INTEGRATION_DRIVER_HH
0036 #define G4BFIELD_INTEGRATION_DRIVER_HH
0037 
0038 #include "G4VIntegrationDriver.hh"
0039 #include "G4Mag_EqRhs.hh"
0040 
0041 #include <memory>
0042 
0043 /**
0044  * @brief G4BFieldIntegrationDriver is specialised integration driver
0045  * for pure magnetic field.
0046  */
0047 
0048 class G4BFieldIntegrationDriver : public G4VIntegrationDriver
0049 {
0050   public:
0051 
0052     /**
0053      * Constructor for the integrator driver.
0054      *  @param[in] smallStepDriver Pointer to driver for small steps.
0055      *  @param[in] largeStepDriver Pointer to driver for large steps.
0056      */
0057     G4BFieldIntegrationDriver(
0058         std::unique_ptr<G4VIntegrationDriver> smallStepDriver, 
0059         std::unique_ptr<G4VIntegrationDriver> largeStepDriver);
0060 
0061     /**
0062      * Default Destructor.
0063      */
0064     ~G4BFieldIntegrationDriver() override = default;
0065 
0066     /**
0067      * Copy constructor and assignment operator not allowed.
0068      */
0069     G4BFieldIntegrationDriver(const G4BFieldIntegrationDriver &) = delete;
0070     const G4BFieldIntegrationDriver& operator =(const G4BFieldIntegrationDriver &) = delete;
0071 
0072     /**
0073      * Computes the step to take, based on chord limits.
0074      *  @param[in,out] track The current track in field.
0075      *  @param[in] hstep Proposed step length.
0076      *  @param[in] eps Requested accuracy, y_err/hstep.
0077      *  @param[in] chordDistance Maximum sagitta distance.
0078      *  @returns The length of step taken.
0079      */
0080     G4double AdvanceChordLimited(G4FieldTrack& track,
0081                                  G4double hstep,
0082                                  G4double eps,
0083                                  G4double chordDistance) override;
0084 
0085     /**
0086      * Integrates ODE from current s (s=s0) to s=s0+h with accuracy eps.
0087      *  @param[in,out] track The current track in field.
0088      *  @param[in] hstep Proposed step length.
0089      *  @param[in] eps Requested accuracy, y_err/hstep.
0090      *  @param[in] hinitial Initial minimum integration step.
0091      *  @returns true if integration succeeds.
0092      */
0093     inline G4bool AccurateAdvance(G4FieldTrack& track,
0094                                   G4double hstep,
0095                                   G4double eps,
0096                                   G4double hinitial = 0) override;
0097 
0098     /**
0099      * Checks whether the driver implements re-integration.
0100      *  @returns true if driver *Recalculates* when AccurateAdvance() is called.
0101      */
0102     inline G4bool DoesReIntegrate() const override;
0103    
0104     /**
0105      * Setter and getter for the equation of motion.
0106      */
0107     void SetEquationOfMotion(G4EquationOfMotion* equation) override;
0108     inline G4EquationOfMotion* GetEquationOfMotion() override;
0109 
0110     /**
0111      * Returns a pointer to the integrator stepper.
0112      */
0113     inline G4MagIntegratorStepper* GetStepper() override;
0114 
0115     /**
0116      * Computes a step size for the next step, taking the last step's
0117      * normalised error 'errMaxNorm'.
0118      *  @param[in] errMaxNorm The normalised error on last step.
0119      *  @param[in] hstepCurrent The current proposed step.
0120      *  @returns The step size for the next step.
0121      */
0122     inline G4double ComputeNewStepSize(G4double errMaxNorm,
0123                                        G4double hstepCurrent) override;
0124 
0125     /**
0126      * Setter and getter for verbosity.
0127      */
0128     inline void SetVerboseLevel(G4int level) override;
0129     inline G4int GetVerboseLevel() const override;
0130 
0131     /**
0132      * Dispatch interface method for computing step.
0133      */
0134     inline void OnComputeStep(const G4FieldTrack* track) override;
0135 
0136     /**
0137      * Dispatch interface method for initialisation/reset of driver.
0138      */
0139     inline void OnStartTracking() override;
0140 
0141     /**
0142      * Writes out to stream the parameters/state of the driver.
0143      */
0144     inline void StreamInfo( std::ostream& os ) const override;
0145    
0146     /**
0147      * Prints out statistics of the integrator driver.
0148      */
0149     void PrintStatistics() const;
0150 
0151     /** [[deprecated("will be removed")]] */
0152     inline void GetDerivatives(const G4FieldTrack& track,
0153                                G4double dydx[]) const override;
0154 
0155     /** [[deprecated("will be removed")]] */
0156     inline void GetDerivatives(const G4FieldTrack& track,
0157                                G4double dydx[],
0158                                G4double field[]) const override;
0159 
0160     /** [[deprecated("use GetEquationOfMotion() instead of GetStepper()->GetEquationOfMotion()")]] */
0161     inline const G4MagIntegratorStepper* GetStepper() const override;
0162 
0163   private:
0164 
0165     /**
0166      * Given the field track, computes the radius of the curvature in field.
0167      */
0168     G4double CurvatureRadius(const G4FieldTrack& track) const;
0169 
0170     /**
0171      * Returns the value of the field in the 'Field' array, give the track.
0172      *  @param[in] track The current field track.
0173      *  @param[in,out] Field The array with field values.
0174      */
0175     void GetFieldValue(const G4FieldTrack& track, 
0176                              G4double Field[] ) const;
0177    
0178   private:
0179 
0180     std::unique_ptr<G4VIntegrationDriver> fSmallStepDriver;
0181     std::unique_ptr<G4VIntegrationDriver> fLargeStepDriver;
0182     G4VIntegrationDriver* fCurrDriver = nullptr;
0183     G4Mag_EqRhs* fEquation = nullptr;
0184 
0185     G4int fSmallDriverSteps = 0;
0186     G4int fLargeDriverSteps = 0;
0187 };
0188 
0189 #include "G4BFieldIntegrationDriver.icc"
0190 
0191 #endif