Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4InterpolationManager.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 #ifndef G4InterpolationManager_h
30 #define G4InterpolationManager_h 1
31 
32 #include "globals.hh"
33 #include "G4InterpolationScheme.hh"
34 #include "G4ios.hh"
35 #include <fstream>
36 #include "G4HadronicException.hh"
37 
39 {
40  public:
41 
43 
45  {
46  nRanges = 1;
47  start = new G4int[1];
48  start[0] = 0;
49  range = new G4int[1];
50  range [0] = 100000;
51  scheme = new G4InterpolationScheme[1];
52  scheme[0] = LINLIN;
53  nEntries = 0;
54  }
55 
57  {
58  if(start!=0) delete [] start;
59  if(range!=0) delete [] range;
60  if(scheme!=0) delete [] scheme;
61  }
62 
64  {
65  if(this != &aManager)
66  {
67  nRanges = aManager.nRanges;
68  nEntries = aManager.nEntries;
69  if(scheme!=0) delete [] scheme;
70  if(start!=0) delete [] start;
71  if(range!=0) delete [] range;
72  scheme = new G4InterpolationScheme[nRanges];
73  start = new G4int[nRanges];
74  range = new G4int[nRanges];
75  for(G4int i=0; i<nRanges; i++)
76  {
77  scheme[i]=aManager.scheme[i];
78  start[i]=aManager.start[i];
79  range[i]=aManager.range[i];
80  }
81  }
82  return *this;
83  }
84 
85  inline void Init(G4int aScheme, G4int aRange)
86  {
87  nRanges = 1;
88  start[0] = 0;
89  range [0] = aRange;
90  scheme[0] = MakeScheme(aScheme);
91  nEntries = aRange;
92  }
93  inline void Init(G4InterpolationScheme aScheme, G4int aRange)
94  {
95  nRanges = 1;
96  start[0] = 0;
97  range [0] = aRange;
98  scheme[0] = aScheme;
99  nEntries = aRange;
100  }
101 
102  inline void Init(std::ifstream & aDataFile)
103  {
104  delete [] start;
105  delete [] range;
106  delete [] scheme;
107  aDataFile >> nRanges;
108  start = new G4int[nRanges];
109  range = new G4int[nRanges];
110  scheme = new G4InterpolationScheme[nRanges];
111  start[0] = 0;
112  G4int it;
113  for(G4int i=0; i<nRanges; i++)
114  {
115  aDataFile>>range[i];
116  //***************************************************************
117  //EMendoza -> there is a bug here.
118  /*
119  if(i!=0) start[i] = start[i-1]+range[i-1];
120  */
121  //***************************************************************
122  if(i!=0) start[i] = range[i-1];
123  //***************************************************************
124  aDataFile>>it;
125  scheme[i] = MakeScheme(it);
126  }
127  nEntries = start[nRanges-1]+range[nRanges-1];
128  }
129 
131 
133  {
134  G4int it = 0;
135  for(G4int i=1; i<nRanges; i++)
136  {
137  if(index<start[i]) break;
138  it = i;
139  }
140  return scheme[it];
141  }
142 
143  inline void CleanUp()
144  {
145  nRanges = 0;
146  nEntries = 0;
147  }
148 
150  {
151  G4InterpolationScheme result = GetScheme(index);
152  if(result == HISTO)
153  {
154  result = RANDOM;
155  }
156  else if(result == LINLOG)
157  {
158  result = LOGLIN;
159  }
160  else if(result == LOGLIN)
161  {
162  result = LINLOG;
163  }
164  else if(result == CHISTO)
165  {
166  result = CRANDOM;
167  }
168  else if(result == CLINLOG)
169  {
170  result = CLOGLIN;
171  }
172  else if(result == CLOGLIN)
173  {
174  result = CLINLOG;
175  }
176  else if(result == UHISTO)
177  {
178  result = URANDOM;
179  }
180  else if(result == ULINLOG)
181  {
182  result = ULOGLIN;
183  }
184  else if(result == ULOGLIN)
185  {
186  result = ULINLOG;
187  }
188  return result;
189  }
190 
191  void AppendScheme(G4int aPoint, const G4InterpolationScheme & aScheme);
192 
193  private:
194 
195  G4int nRanges;
196  G4InterpolationScheme * scheme;
197  G4int * start;
198  G4int * range;
199  G4int nEntries;
200 
201 };
202 #endif