[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 | // |
---|
[1058] | 27 | // $Id: G4MaterialPropertyVector.cc,v 1.17 2009/04/21 15:35:45 gcosmo Exp $ |
---|
[1196] | 28 | // GEANT4 tag $Name: materials-V09-02-18 $ |
---|
[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 | // |
---|
| 50 | G4MaterialPropertyVector& |
---|
| 51 | G4MaterialPropertyVector::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] | 79 | G4MaterialPropertyVector:: |
---|
| 80 | G4MaterialPropertyVector(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] | 96 | G4MaterialPropertyVector:: |
---|
| 97 | G4MaterialPropertyVector(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 | |
---|
| 117 | G4MaterialPropertyVector::~G4MaterialPropertyVector() |
---|
| 118 | { |
---|
[1058] | 119 | MPV.clear(); |
---|
[822] | 120 | } |
---|
| 121 | |
---|
[1058] | 122 | //////////// |
---|
| 123 | // Methods |
---|
| 124 | //////////// |
---|
[822] | 125 | |
---|
[850] | 126 | void 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] | 154 | G4double G4MaterialPropertyVector::GetProperty(G4double aPhotonEnergy) const |
---|
[822] | 155 | { |
---|
[1058] | 156 | G4MPVEntry *target, *temp; |
---|
| 157 | G4int left, right; |
---|
| 158 | G4double ratio1, ratio2, pmright, pmleft, InterpolatedValue; |
---|
[822] | 159 | |
---|
[1058] | 160 | ///////////////////////// |
---|
| 161 | // Establish table range |
---|
| 162 | ///////////////////////// |
---|
[822] | 163 | |
---|
[1058] | 164 | G4double PMmin = MPV.front()->GetPhotonEnergy(); |
---|
| 165 | G4double minProp = MPV.front()->GetProperty(); |
---|
| 166 | G4double PMmax = MPV.back() ->GetPhotonEnergy(); |
---|
| 167 | G4double maxProp = MPV.back() ->GetProperty(); |
---|
[822] | 168 | |
---|
[1058] | 169 | /////////////////////////////////////////// |
---|
| 170 | // Does value fall outside range of table? |
---|
| 171 | /////////////////////////////////////////// |
---|
[822] | 172 | |
---|
[1058] | 173 | if (aPhotonEnergy < PMmin) |
---|
| 174 | { |
---|
| 175 | G4Exception("G4MaterialPropertyVector::GetProperty()", "OutOfRange", |
---|
| 176 | JustWarning, "Attempt to retrieve property below range !"); |
---|
| 177 | return minProp; |
---|
| 178 | } |
---|
[822] | 179 | |
---|
[850] | 180 | if (aPhotonEnergy > PMmax) |
---|
[1058] | 181 | { |
---|
| 182 | G4Exception("G4MaterialPropertyVector::GetProperty()", "OutOfRange", |
---|
| 183 | JustWarning, "Attempt to retrieve property above range !"); |
---|
| 184 | return maxProp; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | target = new G4MPVEntry(aPhotonEnergy, 0.0); |
---|
[822] | 188 | |
---|
[1058] | 189 | temp = 0; |
---|
| 190 | //temp = MPV.find(target); |
---|
| 191 | std::vector<G4MPVEntry*>::const_iterator i; |
---|
| 192 | for (i = MPV.begin(); i != MPV.end(); i++) |
---|
| 193 | { |
---|
| 194 | if (**i == *target) { temp = *i; break; } |
---|
| 195 | } |
---|
| 196 | if (temp != 0) |
---|
| 197 | { |
---|
| 198 | //////////////////////// |
---|
| 199 | // Return actual value |
---|
| 200 | //////////////////////// |
---|
[822] | 201 | |
---|
[1058] | 202 | G4double retval = temp->GetProperty(); |
---|
| 203 | delete target; |
---|
| 204 | return retval; |
---|
| 205 | } |
---|
| 206 | else |
---|
| 207 | { |
---|
| 208 | ////////////////////////////// |
---|
| 209 | // Return interpolated value |
---|
| 210 | ////////////////////////////// |
---|
[822] | 211 | |
---|
[1058] | 212 | GetAdjacentBins(aPhotonEnergy, &left, &right); |
---|
[822] | 213 | |
---|
[1058] | 214 | pmleft = MPV[left]->GetPhotonEnergy(); |
---|
| 215 | pmright = MPV[right]->GetPhotonEnergy(); |
---|
| 216 | ratio1 = (aPhotonEnergy-pmleft)/(pmright-pmleft); |
---|
| 217 | ratio2 = 1 - ratio1; |
---|
| 218 | InterpolatedValue = MPV[left]->GetProperty()*ratio2 + |
---|
| 219 | MPV[right]->GetProperty()*ratio1; |
---|
| 220 | delete target; |
---|
| 221 | return InterpolatedValue; |
---|
| 222 | } |
---|
[822] | 223 | } |
---|
| 224 | |
---|
[1058] | 225 | G4double G4MaterialPropertyVector::GetPhotonEnergy(G4double aProperty) const |
---|
[822] | 226 | { |
---|
[1058] | 227 | // ***NB*** |
---|
| 228 | // Assumes that the property is an increasing function of photon energy |
---|
| 229 | // (e.g. refraction index) |
---|
| 230 | // ***NB*** |
---|
| 231 | // |
---|
| 232 | // Returns the photon energy corresponding to the property value passed in. |
---|
| 233 | // If several photon energy values correspond to the value passed in, the |
---|
| 234 | // function returns the first photon energy in the vector that corresponds |
---|
| 235 | // to that value. |
---|
[822] | 236 | |
---|
[1058] | 237 | G4int left, right, mid; |
---|
| 238 | G4double ratio1, ratio2, pright, pleft; |
---|
[822] | 239 | |
---|
[1058] | 240 | ////////////////////////// |
---|
| 241 | // Establish Table range |
---|
| 242 | ////////////////////////// |
---|
[822] | 243 | |
---|
[1058] | 244 | G4double PropMin = MPV.front()->GetProperty(); |
---|
| 245 | G4double PMmin = MPV.front()->GetPhotonEnergy(); |
---|
| 246 | G4double PropMax = MPV.back() ->GetProperty(); |
---|
| 247 | G4double PMmax = MPV.back() ->GetPhotonEnergy(); |
---|
[822] | 248 | |
---|
[1058] | 249 | /////////////////////////////////////////// |
---|
| 250 | // Does value fall outside range of table? |
---|
| 251 | /////////////////////////////////////////// |
---|
[822] | 252 | |
---|
[1058] | 253 | if (aProperty < PropMin) |
---|
| 254 | { |
---|
| 255 | G4Exception("G4MaterialPropertyVector::GetPhotonEnergy()", |
---|
| 256 | "OutOfRange", JustWarning, |
---|
| 257 | "Attempt to retrieve photon energy out of range"); |
---|
| 258 | return PMmin; |
---|
| 259 | } |
---|
[822] | 260 | |
---|
[1058] | 261 | if (aProperty > PropMax) |
---|
| 262 | { |
---|
| 263 | G4Exception("G4MaterialPropertyVector::GetPhotonEnergy()", |
---|
| 264 | "OutOfRange", JustWarning, |
---|
| 265 | "Attempt to retrieve photon energy out of range"); |
---|
| 266 | return PMmax; |
---|
| 267 | } |
---|
[822] | 268 | |
---|
[1058] | 269 | ////////////////////////////// |
---|
| 270 | // Return interpolated value |
---|
| 271 | ////////////////////////////// |
---|
[822] | 272 | |
---|
[1058] | 273 | left = 0; |
---|
| 274 | right = MPV.size(); // was .entries() |
---|
[822] | 275 | |
---|
[1058] | 276 | // find values in bins on either side of aProperty |
---|
| 277 | |
---|
| 278 | do |
---|
| 279 | { |
---|
| 280 | mid = (left + right)/2; |
---|
| 281 | if (MPV[mid]->GetProperty() == aProperty) |
---|
| 282 | { |
---|
| 283 | // Get first photon energy value in vector that |
---|
| 284 | // corresponds to property value |
---|
[822] | 285 | |
---|
[1058] | 286 | while ((mid-1 >= 0) && (MPV[mid-1]->GetProperty() == aProperty)) |
---|
| 287 | { |
---|
| 288 | mid--; |
---|
| 289 | } |
---|
| 290 | return MPV[mid]->GetPhotonEnergy(); |
---|
| 291 | } |
---|
| 292 | if (MPV[mid]->GetProperty() < aProperty) |
---|
| 293 | { |
---|
| 294 | left = mid; |
---|
| 295 | } |
---|
| 296 | else |
---|
| 297 | { |
---|
| 298 | right = mid; |
---|
| 299 | } |
---|
| 300 | } while ((right - left) > 1); |
---|
[822] | 301 | |
---|
[1058] | 302 | pleft = MPV[left]->GetProperty(); |
---|
| 303 | pright = MPV[right]->GetProperty(); |
---|
| 304 | ratio1 = (aProperty - pleft) / (pright - pleft); |
---|
| 305 | ratio2 = 1 - ratio1; |
---|
[822] | 306 | |
---|
[1058] | 307 | return (MPV[left]->GetPhotonEnergy()*ratio2 + |
---|
| 308 | MPV[right]->GetPhotonEnergy()*ratio1); |
---|
[822] | 309 | } |
---|
| 310 | |
---|
| 311 | void G4MaterialPropertyVector::DumpVector() |
---|
| 312 | { |
---|
[1058] | 313 | if (MPV.empty()) |
---|
| 314 | { |
---|
| 315 | G4Exception("G4MaterialPropertyVector::DumpVector()", "EmptyVector", |
---|
| 316 | JustWarning, "Nothing to dump. Vector is empty !"); |
---|
| 317 | } |
---|
| 318 | else |
---|
| 319 | { |
---|
| 320 | for (G4int i = 0; i < NumEntries; i++) |
---|
| 321 | { |
---|
| 322 | G4cout << "MPV["<< i << "]: "; |
---|
| 323 | MPV[i]->DumpEntry(); |
---|
| 324 | } |
---|
| 325 | G4cout << " Done DumpVector of " << NumEntries << " entries." << G4endl; |
---|
| 326 | } |
---|
[822] | 327 | } |
---|
| 328 | |
---|
[1058] | 329 | void G4MaterialPropertyVector::GetAdjacentBins(G4double aPhotonEnergy, |
---|
| 330 | G4int *left, G4int *right) const |
---|
[822] | 331 | { |
---|
[1058] | 332 | G4int mid; |
---|
[822] | 333 | |
---|
[1058] | 334 | *left = 0; |
---|
| 335 | *right = (MPV.size() - 1); // was .entries() |
---|
[822] | 336 | |
---|
[1058] | 337 | // find values in bins on either side of aPhotonEnergy |
---|
[822] | 338 | |
---|
[1058] | 339 | do |
---|
| 340 | { |
---|
| 341 | mid = (*left + *right)/2; |
---|
| 342 | if (MPV[mid]->GetPhotonEnergy() < aPhotonEnergy) |
---|
| 343 | { |
---|
| 344 | *left = mid; |
---|
| 345 | } |
---|
| 346 | else |
---|
| 347 | { |
---|
| 348 | *right = mid; |
---|
| 349 | } |
---|
| 350 | } while ((*right - *left) > 1); |
---|
[822] | 351 | } |
---|