Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:55

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4Physics2DVector
0027 //
0028 // Class description:
0029 //
0030 // A 2-dimentional vector with linear interpolation.
0031 
0032 // Author: Vladimir Ivanchenko, 25.09.2011
0033 // --------------------------------------------------------------------
0034 #ifndef G4Physics2DVector_hh
0035 #define G4Physics2DVector_hh 1
0036 
0037 #include <fstream>
0038 #include <iostream>
0039 #include <vector>
0040 
0041 #include "G4PhysicsVectorType.hh"
0042 #include "G4ios.hh"
0043 #include "globals.hh"
0044 
0045 using G4PV2DDataVector = std::vector<G4double>;
0046 
0047 class G4Physics2DVector
0048 {
0049  public:
0050   G4Physics2DVector();
0051   // Vector will be filled via Retrieve method
0052 
0053   explicit G4Physics2DVector(std::size_t nx, std::size_t ny);
0054   // Vector will be filled via Put methods
0055 
0056   G4Physics2DVector(const G4Physics2DVector&);
0057   G4Physics2DVector& operator=(const G4Physics2DVector&);
0058   // Copy constructor and assignment operator
0059 
0060   G4bool operator==(const G4Physics2DVector& right) const = delete;
0061   G4bool operator!=(const G4Physics2DVector& right) const = delete;
0062 
0063   ~G4Physics2DVector();
0064   // Destructor
0065 
0066   G4double Value(G4double x, G4double y, std::size_t& lastidx,
0067                  std::size_t& lastidy) const;
0068   G4double Value(G4double x, G4double y) const;
0069   // Main method to interpolate 2D vector
0070   // Consumer class should provide initial values of lastidx and lastidy
0071 
0072   inline void PutX(std::size_t idx, G4double value);
0073   inline void PutY(std::size_t idy, G4double value);
0074   inline void PutValue(std::size_t idx, std::size_t idy, G4double value);
0075   void PutVectors(const std::vector<G4double>& vecX,
0076                   const std::vector<G4double>& vecY);
0077   // Methods to fill vector
0078   // Take note that the 'index' starts from '0'
0079 
0080   void ScaleVector(G4double factor);
0081   // Scale all values of the vector by factor.
0082   // This method may be applied for example after Retrieve a vector
0083   // from an external file to convert values into Geant4 units
0084 
0085   G4double FindLinearX(G4double rand, G4double y, std::size_t& lastidy) const;
0086   inline G4double FindLinearX(G4double rand, G4double y) const;
0087   // Find Y using linear interpolation for Y-vector filled by cumulative
0088   // probability function value of rand should be between 0 and 1
0089 
0090   inline G4double GetX(std::size_t index) const;
0091   inline G4double GetY(std::size_t index) const;
0092   inline G4double GetValue(std::size_t idx, std::size_t idy) const;
0093   // Returns simply the values of the vector by index
0094   // of the energy vector. The boundary check will not be done
0095 
0096   inline std::size_t FindBinLocationX(const G4double x,
0097                                       const std::size_t lastidx) const;
0098   inline std::size_t FindBinLocationY(const G4double y,
0099                                       const std::size_t lastidy) const;
0100   // Find the bin# in which theEnergy belongs. Starting from 0
0101 
0102   inline std::size_t GetLengthX() const;
0103   inline std::size_t GetLengthY() const;
0104   // Get the lengths of the vector
0105 
0106   inline G4PhysicsVectorType GetType() const;
0107   // Get physics vector type
0108 
0109   inline void SetBicubicInterpolation(G4bool);
0110   // Activate/deactivate bicubic interpolation
0111 
0112   void Store(std::ofstream& fOut) const;
0113   G4bool Retrieve(std::ifstream& fIn);
0114   // To store/retrieve persistent data to/from file streams
0115 
0116   inline void SetVerboseLevel(G4int value);
0117 
0118  protected:
0119   void PrepareVectors();
0120 
0121   void ClearVectors();
0122 
0123   void CopyData(const G4Physics2DVector& vec);
0124 
0125   G4double BicubicInterpolation(const G4double x, const G4double y,
0126                                 const std::size_t idx,
0127                                 const std::size_t idy) const;
0128   // Bicubic interpolation of 2D vector
0129 
0130   inline std::size_t FindBin(const G4double z, const G4PV2DDataVector&,
0131                              const std::size_t idz,
0132                              const std::size_t idzmax) const;
0133 
0134  private:
0135   G4double InterpolateLinearX(G4PV2DDataVector& v, G4double rand) const;
0136 
0137   inline G4double DerivativeX(std::size_t idx, std::size_t idy,
0138                               G4double fac) const;
0139   inline G4double DerivativeY(std::size_t idx, std::size_t idy,
0140                               G4double fac) const;
0141   inline G4double DerivativeXY(std::size_t idx, std::size_t idy,
0142                                G4double fac) const;
0143   // computation of derivatives
0144 
0145   G4PhysicsVectorType type = T_G4PhysicsFreeVector;
0146   // The type of PhysicsVector (enumerator)
0147 
0148   std::size_t numberOfXNodes = 0;
0149   std::size_t numberOfYNodes = 0;
0150 
0151   G4PV2DDataVector xVector;
0152   G4PV2DDataVector yVector;
0153   std::vector<G4PV2DDataVector*> value;
0154 
0155   G4int verboseLevel = 0;
0156   G4bool useBicubic  = false;
0157 };
0158 
0159 #include "G4Physics2DVector.icc"
0160 
0161 #endif