00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id$ 00028 // 00029 //--------------------------------------------------------------- 00030 // 00031 // G4VelocityTable.hh 00032 // 00033 // class description: 00034 // This class keeps a table of velocity as a function of 00035 // the ratio kinetic erngy and mass 00036 // This class is used by G4Track::CalculateVelocity 00037 // 00038 //--------------------------------------------------------------- 00039 // created 17.Aug. 2011 H.Kurashige 00040 // 00041 00042 #ifndef G4VelocityTable_h 00043 #define G4VelocityTable_h 1 00044 00045 #include <vector> 00046 #include <iostream> 00047 #include "globals.hh" 00048 #include "G4ios.hh" 00049 00051 class G4VelocityTable 00053 { 00054 // velocity table for massive particles used in CalculateVelocity 00055 private: 00056 typedef std::vector<G4double> G4VTDataVector; 00057 00058 public: 00059 G4VelocityTable(); 00060 ~G4VelocityTable(); 00061 00062 G4double Value(G4double theEnergy); 00063 // Get the cross-section/energy-loss value corresponding to the 00064 // given energy. An appropriate interpolation is used to calculate 00065 // the value. 00066 00067 static G4VelocityTable* GetVelocityTable(); 00068 00069 static void SetVelocityTableProperties(G4double t_max, 00070 G4double t_min, 00071 G4int nbin); 00072 static G4double GetMaxTOfVelocityTable(); 00073 static G4double GetMinTOfVelocityTable(); 00074 static G4int GetNbinOfVelocityTable(); 00075 00076 private: 00077 00078 size_t FindBinLocation(G4double theEnergy) const; 00079 // Find the bin# in which theEnergy belongs - pure virtual function 00080 00081 G4double Interpolation() const; 00082 00083 G4double edgeMin; // Energy of first point 00084 G4double edgeMax; // Energy of the last point 00085 00086 size_t numberOfNodes; 00087 00088 G4VTDataVector dataVector; // Vector to keep the crossection/energyloss 00089 G4VTDataVector binVector; // Vector to keep energy 00090 G4VTDataVector secDerivative; // Vector to keep second derivatives 00091 00092 G4double dBin; // Bin width - useful only for fixed binning 00093 G4double baseBin; // Set this in constructor for performance 00094 00095 G4double lastEnergy; // Cache the last input value 00096 G4double lastValue; // Cache the last output value 00097 size_t lastBin; // Cache the last bin location 00098 00099 private: 00100 void PrepareVelocityTable(); 00101 00102 static G4VelocityTable* theInstance; 00103 G4double maxT; 00104 G4double minT; 00105 G4int NbinT; 00106 }; 00107 00108 inline 00109 G4double G4VelocityTable::Interpolation() const 00110 { 00111 // Linear interpolation is used to get the value. If the give energy 00112 // is in the highest bin, no interpolation will be Done. Because 00113 // there is an extra bin hidden from a user at locBin=numberOfBin, 00114 // the following interpolation is valid even the current locBin= 00115 // numberOfBin-1. 00116 00117 G4double intplFactor = (lastEnergy-binVector[lastBin]) 00118 / (binVector[lastBin + 1]-binVector[lastBin]); // Interpol. factor 00119 00120 return dataVector[lastBin] + 00121 ( dataVector[lastBin + 1]-dataVector[lastBin] ) * intplFactor; 00122 } 00123 00124 #endif 00125 00126