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