ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4InterpolationDriver.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4InterpolationDriver.hh
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // G4InterpolationDriver
27 //
28 // Class description:
29 //
30 // Driver class which uses Runge-Kutta stepper with interpolation property
31 // to integrate track with error control
32 
33 // Created: D.Sorokin, 2018
34 // --------------------------------------------------------------------
35 #ifndef G4INTERPOLATION_DRIVER_HH
36 #define G4INTERPOLATION_DRIVER_HH
37 
38 #include "G4RKIntegrationDriver.hh"
39 #include "G4FieldUtils.hh"
40 
41 #include "globals.hh"
42 
43 #include <vector>
44 #include <memory>
45 
46 template <class T>
48 {
49  public:
50 
52  T* stepper,
53  G4int numberOfComponents = 6,
54  G4int statisticsVerbosity = 0);
55 
56  virtual ~G4InterpolationDriver() override;
57 
60 
62  G4double hstep,
63  G4double eps,
64  G4double chordDistance) override;
65 
66  virtual void OnStartTracking() override;
67  virtual void OnComputeStep() override;
68  virtual G4bool DoesReIntegrate() override { return false; }
69  // Interpolation driver does not recalculate when AccurateAdvance is called
70  // -- reintegration would require other calls
71 
72  virtual G4bool AccurateAdvance(G4FieldTrack& track,
73  G4double hstep,
74  G4double eps, // Requested y_err/hstep
75  G4double hinitial = 0) override;
76  // Integrates ODE from current s (s=s0) to s=s0+h with accuracy eps.
77  // On output track is replaced by value at end of interval.
78  // The concept is similar to the odeint routine from NRC p.721-722.
79 
80  virtual void SetVerboseLevel(G4int level) override;
81  virtual G4int GetVerboseLevel() const override;
82 
83  private:
84 
86  {
87  std::unique_ptr<T> stepper;
91  };
92 
93  using StepperIterator = typename std::vector<InterpStepper>::iterator;
94  using ConstStepperIterator = typename std::vector<InterpStepper>::const_iterator;
95 
98  field_utils::State& dydx,
99  G4double& hstep,
100  G4double eps,
101  G4double curveLength);
102  // This takes one Step that is of size htry, or as large
103  // as possible while satisfying the accuracy criterion of:
104  // yerr < eps * |y_end-y_start|
105  // return hdid
106 
107  void Interpolate(G4double curveLength, field_utils::State& y) const;
108 
109  void InterpolateImpl(G4double curveLength,
111  field_utils::State& y) const;
112 
113  G4double DistChord(const field_utils::State& yBegin,
114  G4double curveLengthBegin,
115  const field_utils::State& yEnd,
116  G4double curveLengthEnd) const;
117 
119  G4double curveLengthBegin,
120  field_utils::State& yEnd,
121  G4double curveLengthEnd,
122  G4double dChord,
123  G4double maxChordDistance);
124 
125  G4double CalcChordStep(G4double stepTrialOld,
126  G4double dChordStep,
127  G4double fDeltaChord);
128 
129  void PrintState() const;
130 
131  void CheckState() const;
132 
133  void AccumulateStatistics(G4int noTrials);
134 
135  private:
136 
137  std::vector<InterpStepper> fSteppers;
140 
141  G4double fhnext = DBL_MAX; // Memory of last good step size for integration
142 
143  // Minimum Step allowed in a Step (in units of length) // Parameter
145 
147  const G4double fFractionNextEstimate = 0.98; // Constant
148  const G4double fSmallestCurveFraction = 0.01; // Constant
149 
150  G4int fVerboseLevel; // Parameter
151 
154 
155  const G4int fMaxTrials = 100; // Constant
157 
158  // statistics
162 
164 };
165 
166 #include "G4InterpolationDriver.icc"
167 
168 #endif