Geant4_10
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  G4Physics2DVector(size_t nx, size_t ny);
68  // constructors
69 
72  // Copy constructor and assignment operator.
73 
75  // destructor
76 
78  size_t& lastidx, size_t& lastidy) const;
79  G4double Value(G4double x, G4double y) const;
80  // Main method to interpolate 2D vector
81  // Consumer class should provide initial values
82  // lastidx and lastidy,
83 
84  inline void PutX(size_t idx, G4double value);
85  inline void PutY(size_t idy, G4double value);
86  inline void PutValue(size_t idx, size_t idy, G4double value);
87  void PutVectors(const std::vector<G4double>& vecX,
88  const std::vector<G4double>& vecY);
89  // Methods to fill vector
90  // Take note that the 'index' starts from '0'.
91 
92  void ScaleVector(G4double factor);
93  // Scale all values of the vector by factor,
94  // This method may be applied
95  // for example after Retrieve a vector from an external file to
96  // convert values into Geant4 units
97 
98  G4double
99  FindLinearX(G4double rand, G4double y, size_t& lastidy) const;
100  inline G4double FindLinearX(G4double rand, G4double y) const;
101  // Find Y using linear interpolation for Y-vector
102  // filled by cumulative probability function
103  // value of rand should be between 0 and 1
104 
105  inline G4double GetX(size_t index) const;
106  inline G4double GetY(size_t index) const;
107  inline G4double GetValue(size_t idx, size_t idy) const;
108  // Returns simply the values of the vector by index
109  // of the energy vector. The boundary check will not be done.
110 
111  inline size_t FindBinLocationX(G4double x, size_t lastidx) const;
112  inline size_t FindBinLocationY(G4double y, size_t lastidy) const;
113  // Find the bin# in which theEnergy belongs
114  // Starting from 0
115 
116  inline size_t GetLengthX() const;
117  inline size_t GetLengthY() const;
118  // Get the lengths of the vector.
119 
120  inline G4PhysicsVectorType GetType() const;
121  // Get physics vector type
122 
123  inline void SetBicubicInterpolation(G4bool);
124  // Activate/deactivate bicubic interpolation.
125 
126  void Store(std::ofstream& fOut);
127  G4bool Retrieve(std::ifstream& fIn);
128  // To store/retrieve persistent data to/from file streams.
129 
130  inline void SetVerboseLevel(G4int value);
131  inline G4int GetVerboseLevel() const;
132  // Set/Get Verbose level
133 
134 protected:
135 
136  void PrepareVectors();
137 
138  void ClearVectors();
139 
140  void CopyData(const G4Physics2DVector& vec);
141 
142  // void ComputeValue(G4double x, G4double y) const;
143  // Main method to interpolate 2D vector
144  // by default by linear interpolation
145 
147  size_t idx, size_t idy) const;
148  // Bicubic interpolation of 2D vector
149 
150  size_t FindBinLocation(G4double z, const G4PV2DDataVector&) const;
151  // Main method to local bin
152 
153  inline size_t FindBin(G4double z, const G4PV2DDataVector&,
154  size_t idz, size_t idzmax) const;
155 
156 private:
157 
158  G4double InterpolateLinearX(G4PV2DDataVector& v, G4double rand) const;
159 
160  inline G4double DerivativeX(size_t idx, size_t idy, G4double fac) const;
161  inline G4double DerivativeY(size_t idx, size_t idy, G4double fac) const;
162  inline G4double DerivativeXY(size_t idx, size_t idy, G4double fac) const;
163  // computation of derivatives
164 
165  G4int operator==(const G4Physics2DVector &right) const ;
166  G4int operator!=(const G4Physics2DVector &right) const ;
167 
168  G4PhysicsVectorType type; // The type of PhysicsVector (enumerator)
169 
170  size_t numberOfXNodes;
171  size_t numberOfYNodes;
172 
173  G4PV2DDataVector xVector;
174  G4PV2DDataVector yVector;
175  std::vector<G4PV2DDataVector*> value;
176 
177  G4int verboseLevel;
178  G4bool useBicubic;
179 };
180 
181 #include "G4Physics2DVector.icc"
182 
183 #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
Int_t index
Definition: macro.C:9
G4PhysicsVectorType GetType() const
G4PhysicsVectorType
size_t GetLengthY() const
void Store(std::ofstream &fOut)
size_t FindBinLocation(G4double z, const G4PV2DDataVector &) const
tuple x
Definition: test.py:50
size_t FindBinLocationX(G4double x, size_t lastidx) const
int G4int
Definition: G4Types.hh:78
void CopyData(const G4Physics2DVector &vec)
G4int GetVerboseLevel() const
void PutValue(size_t idx, size_t idy, G4double value)
Double_t y
Definition: plot.C:279
G4double Value(G4double x, G4double y, size_t &lastidx, size_t &lastidy) const
void SetVerboseLevel(G4int value)
bool G4bool
Definition: G4Types.hh:79
G4Physics2DVector & operator=(const G4Physics2DVector &)
size_t GetLengthX() const
tuple v
Definition: test.py:18
void PutX(size_t idx, G4double value)
G4bool Retrieve(std::ifstream &fIn)
G4double GetY(size_t index) const
tuple z
Definition: test.py:28
G4double BicubicInterpolation(G4double x, G4double y, size_t idx, size_t idy) const
size_t FindBinLocationY(G4double y, size_t lastidy) const
const XML_Char int const XML_Char * value
Definition: expat.h:331
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