ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VelocityTable.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VelocityTable.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 //
27 //
28 //---------------------------------------------------------------
29 //
30 // G4VelocityTable.hh
31 //
32 // class description:
33 // This class keeps a table of velocity as a function of
34 // the ratio kinetic erngy and mass
35 // This class is used by G4Track::CalculateVelocity
36 //
37 //---------------------------------------------------------------
38 // created 17.Aug. 2011 H.Kurashige
39 //
40 
41 #ifndef G4VelocityTable_h
42 #define G4VelocityTable_h 1
43 
44 #include <vector>
45 #include <iostream>
46 #include "globals.hh"
47 #include "G4ios.hh"
49 
53 {
55 
56  // velocity table for massive particles used in CalculateVelocity
57  private:
58  typedef std::vector<G4double> G4VTDataVector;
59 
60  public:
61 
62  G4double Value(G4double theEnergy);
63  // Get the cross-section/energy-loss value corresponding to the
64  // given energy. An appropriate interpolation is used to calculate
65  // the value.
66 
68 
69  static void SetVelocityTableProperties(G4double t_max,
70  G4double t_min,
71  G4int nbin);
75 
76  private:
77 
80 
81  size_t FindBinLocation(G4double theEnergy) const;
82  // Find the bin# in which theEnergy belongs - pure virtual function
83 
84  G4double Interpolation() const;
85 
86  G4double edgeMin; // Energy of first point
87  G4double edgeMax; // Energy of the last point
88 
89  size_t numberOfNodes;
90 
91  G4VTDataVector dataVector; // Vector to keep the crossection/energyloss
92  G4VTDataVector binVector; // Vector to keep energy
93  G4VTDataVector secDerivative; // Vector to keep second derivatives
94 
95  G4double dBin; // Bin width - useful only for fixed binning
96  G4double baseBin; // Set this in constructor for performance
97 
98  G4double lastEnergy; // Cache the last input value
99  G4double lastValue; // Cache the last output value
100  size_t lastBin; // Cache the last bin location
101 
102  private:
103  void PrepareVelocityTable();
104 
109 };
110 
111 inline
113 {
114  // Linear interpolation is used to get the value. If the give energy
115  // is in the highest bin, no interpolation will be Done. Because
116  // there is an extra bin hidden from a user at locBin=numberOfBin,
117  // the following interpolation is valid even the current locBin=
118  // numberOfBin-1.
119 
120  G4double intplFactor = (lastEnergy-binVector[lastBin])
121  / (binVector[lastBin + 1]-binVector[lastBin]); // Interpol. factor
122 
123  return dataVector[lastBin] +
124  ( dataVector[lastBin + 1]-dataVector[lastBin] ) * intplFactor;
125 }
126 
127 #endif
128 
129