Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VelocityTable.hh
Go to the documentation of this file.
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 // $Id$
28 //
29 //---------------------------------------------------------------
30 //
31 // G4VelocityTable.hh
32 //
33 // class description:
34 // This class keeps a table of velocity as a function of
35 // the ratio kinetic erngy and mass
36 // This class is used by G4Track::CalculateVelocity
37 //
38 //---------------------------------------------------------------
39 // created 17.Aug. 2011 H.Kurashige
40 //
41 
42 #ifndef G4VelocityTable_h
43 #define G4VelocityTable_h 1
44 
45 #include <vector>
46 #include <iostream>
47 #include "globals.hh"
48 #include "G4ios.hh"
49 
53 {
54  // velocity table for massive particles used in CalculateVelocity
55  private:
56  typedef std::vector<G4double> G4VTDataVector;
57 
58  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 
78  size_t FindBinLocation(G4double theEnergy) const;
79  // Find the bin# in which theEnergy belongs - pure virtual function
80 
81  G4double Interpolation() const;
82 
83  G4double edgeMin; // Energy of first point
84  G4double edgeMax; // Energy of the last point
85 
86  size_t numberOfNodes;
87 
88  G4VTDataVector dataVector; // Vector to keep the crossection/energyloss
89  G4VTDataVector binVector; // Vector to keep energy
90  G4VTDataVector secDerivative; // Vector to keep second derivatives
91 
92  G4double dBin; // Bin width - useful only for fixed binning
93  G4double baseBin; // Set this in constructor for performance
94 
95  G4double lastEnergy; // Cache the last input value
96  G4double lastValue; // Cache the last output value
97  size_t lastBin; // Cache the last bin location
98 
99  private:
100  void PrepareVelocityTable();
101 
102  static G4VelocityTable* theInstance;
103  G4double maxT;
104  G4double minT;
105  G4int NbinT;
106 };
107 
108 inline
109  G4double G4VelocityTable::Interpolation() const
110 {
111  // Linear interpolation is used to get the value. If the give energy
112  // is in the highest bin, no interpolation will be Done. Because
113  // there is an extra bin hidden from a user at locBin=numberOfBin,
114  // the following interpolation is valid even the current locBin=
115  // numberOfBin-1.
116 
117  G4double intplFactor = (lastEnergy-binVector[lastBin])
118  / (binVector[lastBin + 1]-binVector[lastBin]); // Interpol. factor
119 
120  return dataVector[lastBin] +
121  ( dataVector[lastBin + 1]-dataVector[lastBin] ) * intplFactor;
122 }
123 
124 #endif
125 
126