source: trunk/source/materials/src/G4MaterialPropertyVector.cc@ 1354

Last change on this file since 1354 was 1337, checked in by garnier, 15 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 9.4 KB
RevLine 
[822]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//
[1315]27// $Id: G4MaterialPropertyVector.cc,v 1.18 2010/04/22 21:15:19 gum Exp $
[1337]28// GEANT4 tag $Name: geant4-09-04-beta-01 $
[822]29//
30//
31////////////////////////////////////////////////////////////////////////
32// G4MaterialPropertyVector Class Implementation
33////////////////////////////////////////////////////////////////////////
34//
35// File: G4MaterialPropertyVector.cc
36// Version: 1.0
37// Created: 1996-02-08
38// Author: Juliet Armstrong
39// Updated: 1997-03-25 by Peter Gumplinger
40// > cosmetics (only)
41// mail: gum@triumf.ca
42//
43////////////////////////////////////////////////////////////////////////
44
45#include "G4MaterialPropertyVector.hh"
46
47// = operator
48// ----------
49//
50G4MaterialPropertyVector&
51G4MaterialPropertyVector::operator =(const G4MaterialPropertyVector& right)
52{
[1058]53 if (this == &right) { return *this; }
[822]54
[1058]55 // clear the vector of current contents
[822]56
[1058]57 MPV.clear();
[822]58
[1058]59 // create an actual copy (instead of the shallow copy that the
60 // assignment operator defaults to for G4RWTPtrSortedVector)
[822]61
[1058]62 NumEntries = 0;
63 CurrentEntry = -1;
[822]64
[1058]65 for (G4int i = 0 ; i < right.NumEntries; i++)
66 {
67 G4MPVEntry *newElement = new G4MPVEntry(right.GetEntry(i));
68 MPV.push_back(newElement);
69 NumEntries++;
70 }
71
72 return *this;
[822]73}
74
[1058]75/////////////////
76// Constructors
77/////////////////
[822]78
[1058]79G4MaterialPropertyVector::
80G4MaterialPropertyVector(G4double *PhotonEnergies,
81 G4double *PropertyValues,
82 G4int NumElements)
[822]83{
[1058]84 NumEntries = 0;
85 CurrentEntry = -1;
[822]86
[1058]87 // create a vector filling it with the values
88 // from PhotonEnergies[] and PropertyValues[]
[822]89
[1058]90 for(G4int i = 0; i < NumElements; i++)
91 {
92 AddElement(PhotonEnergies[i], PropertyValues[i]);
93 }
[822]94}
95
[1058]96G4MaterialPropertyVector::
97G4MaterialPropertyVector(const G4MaterialPropertyVector &right)
[822]98{
[1058]99 // create an actual copy (instead of the shallow copy that the
100 // assignment operator defaults to for G4RWTPtrSortedVector)
[822]101
[1058]102 NumEntries = 0;
103 CurrentEntry = -1;
[822]104
[1058]105 for (G4int i = 0 ; i < right.NumEntries; i++)
106 {
107 G4MPVEntry *newElement = new G4MPVEntry(right.GetEntry(i));
108 MPV.push_back(newElement);
109 NumEntries++;
110 }
[822]111}
112
[1058]113////////////////
114// Destructor
115////////////////
[822]116
117G4MaterialPropertyVector::~G4MaterialPropertyVector()
118{
[1058]119 MPV.clear();
[822]120}
121
[1058]122////////////
123// Methods
124////////////
[822]125
[850]126void G4MaterialPropertyVector::RemoveElement(G4double aPhotonEnergy)
[822]127{
[1058]128 G4MPVEntry *newElement;
129 G4MPVEntry *success=0;
[822]130
[1058]131 newElement = new G4MPVEntry(aPhotonEnergy, DBL_MAX);
[822]132
[1058]133 std::vector<G4MPVEntry*>::iterator i;
134 for (i = MPV.begin(); i != MPV.end(); i++)
135 {
136 if (**i == *newElement) { success = *i; break; }
137 }
138 // success = MPV.remove(newElement);
[822]139
[1058]140 if(success == 0)
141 {
142 G4Exception("G4MaterialPropertyVector::RemoveElement()", "NotFound",
143 FatalException, "Element not found !");
144 return;
145 }
146 else
147 {
148 MPV.erase(i); // remove done here.
149 }
[822]150
[1058]151 NumEntries--;
[822]152}
153
[1058]154G4double G4MaterialPropertyVector::GetProperty(G4double aPhotonEnergy) const
[822]155{
[1058]156 G4int left, right;
157 G4double ratio1, ratio2, pmright, pmleft, InterpolatedValue;
[822]158
[1058]159 /////////////////////////
160 // Establish table range
161 /////////////////////////
[822]162
[1058]163 G4double PMmin = MPV.front()->GetPhotonEnergy();
164 G4double minProp = MPV.front()->GetProperty();
165 G4double PMmax = MPV.back() ->GetPhotonEnergy();
166 G4double maxProp = MPV.back() ->GetProperty();
[822]167
[1058]168 ///////////////////////////////////////////
169 // Does value fall outside range of table?
170 ///////////////////////////////////////////
[822]171
[1058]172 if (aPhotonEnergy < PMmin)
173 {
174 G4Exception("G4MaterialPropertyVector::GetProperty()", "OutOfRange",
175 JustWarning, "Attempt to retrieve property below range !");
[1315]176 G4cout << " aPhotonEnergy = " << aPhotonEnergy/MeV
177 << " [MeV] PMmin = " << PMmin << " [MeV]" << G4endl;
[1058]178 return minProp;
179 }
[822]180
[850]181 if (aPhotonEnergy > PMmax)
[1058]182 {
183 G4Exception("G4MaterialPropertyVector::GetProperty()", "OutOfRange",
184 JustWarning, "Attempt to retrieve property above range !");
[1315]185 G4cout << " aPhotonEnergy = " << aPhotonEnergy/MeV
186 << " [MeV] PMmax = " << PMmax << " [MeV]" << G4endl;
[1058]187 return maxProp;
188 }
[822]189
[1315]190 //////////////////////////////
191 // Return interpolated value
192 //////////////////////////////
[822]193
[1315]194 GetAdjacentBins(aPhotonEnergy, &left, &right);
195 pmleft = MPV[left]->GetPhotonEnergy();
196 pmright = MPV[right]->GetPhotonEnergy();
197 ratio1 = (aPhotonEnergy-pmleft)/(pmright-pmleft);
198 ratio2 = 1 - ratio1;
199 InterpolatedValue = MPV[left]->GetProperty()*ratio2 +
200 MPV[right]->GetProperty()*ratio1;
201 return InterpolatedValue;
[822]202}
203
[1058]204G4double G4MaterialPropertyVector::GetPhotonEnergy(G4double aProperty) const
[822]205{
[1058]206 // ***NB***
207 // Assumes that the property is an increasing function of photon energy
208 // (e.g. refraction index)
209 // ***NB***
210 //
211 // Returns the photon energy corresponding to the property value passed in.
212 // If several photon energy values correspond to the value passed in, the
213 // function returns the first photon energy in the vector that corresponds
214 // to that value.
[822]215
[1058]216 G4int left, right, mid;
217 G4double ratio1, ratio2, pright, pleft;
[822]218
[1058]219 //////////////////////////
220 // Establish Table range
221 //////////////////////////
[822]222
[1058]223 G4double PropMin = MPV.front()->GetProperty();
224 G4double PMmin = MPV.front()->GetPhotonEnergy();
225 G4double PropMax = MPV.back() ->GetProperty();
226 G4double PMmax = MPV.back() ->GetPhotonEnergy();
[822]227
[1058]228 ///////////////////////////////////////////
229 // Does value fall outside range of table?
230 ///////////////////////////////////////////
[822]231
[1058]232 if (aProperty < PropMin)
233 {
234 G4Exception("G4MaterialPropertyVector::GetPhotonEnergy()",
235 "OutOfRange", JustWarning,
236 "Attempt to retrieve photon energy out of range");
237 return PMmin;
238 }
[822]239
[1058]240 if (aProperty > PropMax)
241 {
242 G4Exception("G4MaterialPropertyVector::GetPhotonEnergy()",
243 "OutOfRange", JustWarning,
244 "Attempt to retrieve photon energy out of range");
245 return PMmax;
246 }
[822]247
[1058]248 //////////////////////////////
249 // Return interpolated value
250 //////////////////////////////
[822]251
[1058]252 left = 0;
253 right = MPV.size(); // was .entries()
[822]254
[1058]255 // find values in bins on either side of aProperty
256
257 do
258 {
259 mid = (left + right)/2;
260 if (MPV[mid]->GetProperty() == aProperty)
261 {
262 // Get first photon energy value in vector that
263 // corresponds to property value
[822]264
[1058]265 while ((mid-1 >= 0) && (MPV[mid-1]->GetProperty() == aProperty))
266 {
267 mid--;
268 }
269 return MPV[mid]->GetPhotonEnergy();
270 }
271 if (MPV[mid]->GetProperty() < aProperty)
272 {
273 left = mid;
274 }
275 else
276 {
277 right = mid;
278 }
279 } while ((right - left) > 1);
[822]280
[1058]281 pleft = MPV[left]->GetProperty();
282 pright = MPV[right]->GetProperty();
283 ratio1 = (aProperty - pleft) / (pright - pleft);
284 ratio2 = 1 - ratio1;
[822]285
[1058]286 return (MPV[left]->GetPhotonEnergy()*ratio2 +
287 MPV[right]->GetPhotonEnergy()*ratio1);
[822]288}
289
290void G4MaterialPropertyVector::DumpVector()
291{
[1058]292 if (MPV.empty())
293 {
294 G4Exception("G4MaterialPropertyVector::DumpVector()", "EmptyVector",
295 JustWarning, "Nothing to dump. Vector is empty !");
296 }
297 else
298 {
299 for (G4int i = 0; i < NumEntries; i++)
300 {
301 G4cout << "MPV["<< i << "]: ";
302 MPV[i]->DumpEntry();
303 }
304 G4cout << " Done DumpVector of " << NumEntries << " entries." << G4endl;
305 }
[822]306}
307
[1058]308void G4MaterialPropertyVector::GetAdjacentBins(G4double aPhotonEnergy,
309 G4int *left, G4int *right) const
[822]310{
[1058]311 G4int mid;
[822]312
[1058]313 *left = 0;
314 *right = (MPV.size() - 1); // was .entries()
[822]315
[1058]316 // find values in bins on either side of aPhotonEnergy
[822]317
[1058]318 do
319 {
320 mid = (*left + *right)/2;
[1315]321 if (MPV[mid]->GetPhotonEnergy() <= aPhotonEnergy)
[1058]322 {
323 *left = mid;
324 }
325 else
326 {
327 *right = mid;
328 }
329 } while ((*right - *left) > 1);
[822]330}
Note: See TracBrowser for help on using the repository browser.