Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4Physics2DVector.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 // GEANT 4 class header file
32 //
33 // G4Physics2DVector.hh
34 //
35 // Class description:
36 //
37 // A 2-dimentional vector with linear interpolation.
38 
39 // Author: Vladimir Ivanchenko
40 //
41 // Creation date: 25.09.2011
42 //
43 // Modified:
44 // 16.05.2013 V.Ivanchenko removed cache; changed signature of
45 // several methods; all run time methods become const;
46 // the class become read only in run time
47 //---------------------------------------------------------------
48 
49 #ifndef G4Physics2DVector_h
50 #define G4Physics2DVector_h 1
51 
52 #include <iostream>
53 #include <fstream>
54 #include <vector>
55 
56 #include "globals.hh"
57 #include "G4ios.hh"
58 #include "G4PhysicsVectorType.hh"
59 
60 typedef std::vector<G4double> G4PV2DDataVector;
61 
63 {
64 public: // with description
65 
67  // Vector will be filled via Retrieve method
68 
69  explicit G4Physics2DVector(size_t nx, size_t ny);
70  // Vector will be filled via Put methods
71 
74  // Copy constructor and assignment operator.
75 
77  // destructor
78 
80  size_t& lastidx, size_t& lastidy) const;
81  G4double Value(G4double x, G4double y) const;
82  // Main method to interpolate 2D vector
83  // Consumer class should provide initial values
84  // lastidx and lastidy,
85 
86  inline void PutX(size_t idx, G4double value);
87  inline void PutY(size_t idy, G4double value);
88  inline void PutValue(size_t idx, size_t idy, G4double value);
89  void PutVectors(const std::vector<G4double>& vecX,
90  const std::vector<G4double>& vecY);
91  // Methods to fill vector
92  // Take note that the 'index' starts from '0'.
93 
94  void ScaleVector(G4double factor);
95  // Scale all values of the vector by factor,
96  // This method may be applied
97  // for example after Retrieve a vector from an external file to
98  // convert values into Geant4 units
99 
100  G4double
101  FindLinearX(G4double rand, G4double y, size_t& lastidy) const;
102  inline G4double FindLinearX(G4double rand, G4double y) const;
103  // Find Y using linear interpolation for Y-vector
104  // filled by cumulative probability function
105  // value of rand should be between 0 and 1
106 
107  inline G4double GetX(size_t index) const;
108  inline G4double GetY(size_t index) const;
109  inline G4double GetValue(size_t idx, size_t idy) const;
110  // Returns simply the values of the vector by index
111  // of the energy vector. The boundary check will not be done.
112 
113  inline size_t FindBinLocationX(G4double x, size_t lastidx) const;
114  inline size_t FindBinLocationY(G4double y, size_t lastidy) const;
115  // Find the bin# in which theEnergy belongs
116  // Starting from 0
117 
118  inline size_t GetLengthX() const;
119  inline size_t GetLengthY() const;
120  // Get the lengths of the vector.
121 
122  inline G4PhysicsVectorType GetType() const;
123  // Get physics vector type
124 
125  inline void SetBicubicInterpolation(G4bool);
126  // Activate/deactivate bicubic interpolation.
127 
128  void Store(std::ofstream& fOut) const;
129  G4bool Retrieve(std::ifstream& fIn);
130  // To store/retrieve persistent data to/from file streams.
131 
132  inline void SetVerboseLevel(G4int value);
133 
134 protected:
135 
136  void PrepareVectors();
137 
138  void ClearVectors();
139 
140  void CopyData(const G4Physics2DVector& vec);
141 
143  size_t idx, size_t idy) const;
144  // Bicubic interpolation of 2D vector
145 
146  size_t FindBinLocation(G4double z, const G4PV2DDataVector&) const;
147  // Main method to local bin
148 
149  inline size_t FindBin(G4double z, const G4PV2DDataVector&,
150  size_t idz, size_t idzmax) const;
151 
152 private:
153 
154  G4double InterpolateLinearX(G4PV2DDataVector& v, G4double rand) const;
155 
156  inline G4double DerivativeX(size_t idx, size_t idy, G4double fac) const;
157  inline G4double DerivativeY(size_t idx, size_t idy, G4double fac) const;
158  inline G4double DerivativeXY(size_t idx, size_t idy, G4double fac) const;
159  // computation of derivatives
160 
161  G4int operator==(const G4Physics2DVector &right) const = delete;
162  G4int operator!=(const G4Physics2DVector &right) const = delete;
163 
164  G4PhysicsVectorType type; // The type of PhysicsVector (enumerator)
165 
166  size_t numberOfXNodes;
167  size_t numberOfYNodes;
168 
169  G4PV2DDataVector xVector;
170  G4PV2DDataVector yVector;
171  std::vector<G4PV2DDataVector*> value;
172 
173  G4int verboseLevel;
174  G4bool useBicubic;
175 };
176 
177 #include "G4Physics2DVector.icc"
178 
179 #endif
std::vector< G4double > G4PV2DDataVector
void SetBicubicInterpolation(G4bool)
G4double GetValue(size_t idx, size_t idy) const
size_t FindBin(G4double z, const G4PV2DDataVector &, size_t idz, size_t idzmax) const
G4PhysicsVectorType GetType() const
G4PhysicsVectorType
size_t GetLengthY() const
size_t FindBinLocation(G4double z, const G4PV2DDataVector &) const
size_t FindBinLocationX(G4double x, size_t lastidx) const
int G4int
Definition: G4Types.hh:78
void CopyData(const G4Physics2DVector &vec)
void PutValue(size_t idx, size_t idy, G4double value)
G4double Value(G4double x, G4double y, size_t &lastidx, size_t &lastidy) const
void SetVerboseLevel(G4int value)
const XML_Char int const XML_Char * value
Definition: expat.h:331
bool G4bool
Definition: G4Types.hh:79
G4Physics2DVector & operator=(const G4Physics2DVector &)
size_t GetLengthX() const
void Store(std::ofstream &fOut) const
void PutX(size_t idx, G4double value)
G4bool Retrieve(std::ifstream &fIn)
G4double GetY(size_t index) const
G4double BicubicInterpolation(G4double x, G4double y, size_t idx, size_t idy) const
size_t FindBinLocationY(G4double y, size_t lastidy) const
static const G4double fac
void PutVectors(const std::vector< G4double > &vecX, const std::vector< G4double > &vecY)
double G4double
Definition: G4Types.hh:76
G4double GetX(size_t index) const
void PutY(size_t idy, G4double value)
void ScaleVector(G4double factor)
G4double FindLinearX(G4double rand, G4double y, size_t &lastidy) const