// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // $Id: G4PhysicsVector.icc 98864 2016-08-15 11:53:26Z gcosmo $ // // //--------------------------------------------------------------- // GEANT 4 class source file // // G4PhysicsVector.icc // // Description: // A physics vector which has values of energy-loss, cross-section, // and other physics values of a particle in matter in a given // range of the energy, momentum, etc. // This class serves as the base class for a vector having various // energy scale, for example like 'log', 'linear', 'free', etc. // //--------------------------------------------------------------- inline G4double G4PhysicsVector::operator[](const size_t index) const { return dataVector[index]; } //--------------------------------------------------------------- inline G4double G4PhysicsVector::operator()(const size_t index) const { return dataVector[index]; } //--------------------------------------------------------------- inline G4double G4PhysicsVector::Energy(const size_t index) const { return binVector[index]; } //--------------------------------------------------------------- inline G4double G4PhysicsVector::GetMaxEnergy() const { return edgeMax; } //--------------------------------------------------------------- inline size_t G4PhysicsVector::GetVectorLength() const { return numberOfNodes; } //------------------------------------------------ inline G4double G4PhysicsVector::LinearInterpolation(size_t idx, G4double e) const { // Linear interpolation is used to get the value. Before this method // is called it is ensured that the energy is inside the bin // 0 < idx < numberOfNodes-1 return dataVector[idx] + ( dataVector[idx + 1]-dataVector[idx] ) * (e - binVector[idx]) /( binVector[idx + 1]-binVector[idx] ); } //--------------------------------------------------------------- inline G4double G4PhysicsVector::SplineInterpolation(size_t idx, G4double e) const { // Spline interpolation is used to get the value. Before this method // is called it is ensured that the energy is inside the bin // 0 < idx < numberOfNodes-1 static const G4double onesixth = 1.0/6.0; // check bin value G4double x1 = binVector[idx]; G4double x2 = binVector[idx + 1]; G4double delta = x2 - x1; G4double a = (x2 - e)/delta; G4double b = (e - x1)/delta; // Final evaluation of cubic spline polynomial for return G4double y1 = dataVector[idx]; G4double y2 = dataVector[idx + 1]; G4double res = a*y1 + b*y2 + ( (a*a*a - a)*secDerivative[idx] + (b*b*b - b)*secDerivative[idx + 1] )*delta*delta*onesixth; return res; } //--------------------------------------------------------------- inline G4double G4PhysicsVector::Interpolation(size_t idx, G4double e) const { return useSpline ? SplineInterpolation(idx, e) : LinearInterpolation(idx, e); } //--------------------------------------------------------------- inline void G4PhysicsVector::PutValue(size_t index, G4double theValue) { if(index >= numberOfNodes) { PrintPutValueError(index); } dataVector[index] = theValue; } //--------------------------------------------------------------- inline G4bool G4PhysicsVector::IsFilledVectorExist() const { return (numberOfNodes > 0) ? true : false; } //--------------------------------------------------------------- inline G4PhysicsVectorType G4PhysicsVector::GetType() const { return type; } //--------------------------------------------------------------- // Flag useSpline is "true" only if second derivatives are filled inline void G4PhysicsVector::SetSpline(G4bool val) { if(val) { if(0 == secDerivative.size() && 0 < dataVector.size()) { FillSecondDerivatives(); } } else { useSpline = false; secDerivative.clear(); } } //--------------------------------------------------------------- inline void G4PhysicsVector::SetVerboseLevel(G4int value) { verboseLevel = value; } //--------------------------------------------------------------- /* inline G4int G4PhysicsVector::GetVerboseLevel() const { return verboseLevel; } */ //--------------------------------------------------------------- inline size_t G4PhysicsVector::FindBinLocation(G4double theEnergy) const { size_t bin; if(type == T_G4PhysicsLogVector) { bin = size_t(G4Log(theEnergy)/dBin - baseBin); if(bin > 0 && theEnergy < binVector[bin]) { --bin; } else if(theEnergy > binVector[bin+1]) { ++bin; } } else if(type == T_G4PhysicsLinearVector) { bin = size_t( theEnergy/dBin - baseBin ); if(bin > 0 && theEnergy < binVector[bin]) { --bin; } else if(theEnergy > binVector[bin+1]) { ++bin; } } else { // Bin location proposed by K.Genser (FNAL) bin = std::lower_bound(binVector.begin(), binVector.end(), theEnergy) - binVector.begin() - 1; } return std::min(bin, numberOfNodes-2); } //--------------------------------------------------------------- inline size_t G4PhysicsVector::FindBin(G4double e, size_t idx) const { size_t id = idx; if(e < binVector[1]) { id = 0; } else if(e >= binVector[numberOfNodes-2]) { id = numberOfNodes - 2; } else if(idx >= numberOfNodes || e < binVector[idx] || e > binVector[idx+1]) { id = FindBinLocation(e); } return id; } //--------------------------------------------------------------- inline G4double G4PhysicsVector::Value(G4double theEnergy) const { size_t idx=0; return Value(theEnergy, idx); } //--------------------------------------------------------------- inline G4double G4PhysicsVector::GetValue(G4double theEnergy, G4bool&) const { size_t idx=0; return Value(theEnergy, idx); } //---------------------------------------------------------------