| 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: G4PhysicsOrderedFreeVector.cc,v 1.12 2008/09/22 14:49:57 gcosmo Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $
|
|---|
| 29 | //
|
|---|
| 30 | ////////////////////////////////////////////////////////////////////////
|
|---|
| 31 | // PhysicsOrderedFreeVector Class Implementation
|
|---|
| 32 | ////////////////////////////////////////////////////////////////////////
|
|---|
| 33 | //
|
|---|
| 34 | // File: G4PhysicsOrderedFreeVector.cc
|
|---|
| 35 | // Version: 2.0
|
|---|
| 36 | // Created: 1996-08-13
|
|---|
| 37 | // Author: Juliet Armstrong
|
|---|
| 38 | // Updated: 1997-03-25 by Peter Gumplinger
|
|---|
| 39 | // > cosmetics (only)
|
|---|
| 40 | // 1998-11-11 by Peter Gumplinger
|
|---|
| 41 | // > initialize all data members of the base class in
|
|---|
| 42 | // derived class constructors
|
|---|
| 43 | // 2000-11-11 by H.Kurashige
|
|---|
| 44 | // > use STL vector for dataVector and binVector
|
|---|
| 45 | // mail: gum@triumf.ca
|
|---|
| 46 | //
|
|---|
| 47 | //
|
|---|
| 48 | ////////////////////////////////////////////////////////////////////////
|
|---|
| 49 |
|
|---|
| 50 | #include "G4PhysicsOrderedFreeVector.hh"
|
|---|
| 51 |
|
|---|
| 52 | /////////////////////////
|
|---|
| 53 | // Class Implementation
|
|---|
| 54 | /////////////////////////
|
|---|
| 55 |
|
|---|
| 56 | /////////////////
|
|---|
| 57 | // Constructors
|
|---|
| 58 | /////////////////
|
|---|
| 59 |
|
|---|
| 60 | G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector(G4double *Energies,
|
|---|
| 61 | G4double *Values,
|
|---|
| 62 | size_t VectorLength)
|
|---|
| 63 | : G4PhysicsVector()
|
|---|
| 64 | {
|
|---|
| 65 | type = T_G4PhysicsOrderedFreeVector;
|
|---|
| 66 |
|
|---|
| 67 | dataVector.reserve(VectorLength+1);
|
|---|
| 68 | binVector.reserve(VectorLength+1);
|
|---|
| 69 | numberOfBin = VectorLength;
|
|---|
| 70 |
|
|---|
| 71 | for (size_t i = 0 ; i < VectorLength ; i++)
|
|---|
| 72 | {
|
|---|
| 73 | binVector.push_back(Energies[i]);
|
|---|
| 74 | dataVector.push_back(Values[i]);
|
|---|
| 75 | }
|
|---|
| 76 | edgeMin = binVector.front();
|
|---|
| 77 | edgeMax = binVector.back();
|
|---|
| 78 | binVector.push_back ( binVector[numberOfBin-1] + 1.0 );
|
|---|
| 79 | dataVector.push_back( dataVector[numberOfBin-1] );
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector()
|
|---|
| 83 | : G4PhysicsVector()
|
|---|
| 84 | {
|
|---|
| 85 | type = T_G4PhysicsOrderedFreeVector;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | ////////////////
|
|---|
| 89 | // Destructors
|
|---|
| 90 | ////////////////
|
|---|
| 91 |
|
|---|
| 92 | G4PhysicsOrderedFreeVector::~G4PhysicsOrderedFreeVector() {}
|
|---|
| 93 |
|
|---|
| 94 | ////////////
|
|---|
| 95 | // Methods
|
|---|
| 96 | ////////////
|
|---|
| 97 |
|
|---|
| 98 | void
|
|---|
| 99 | G4PhysicsOrderedFreeVector::InsertValues(G4double energy, G4double value)
|
|---|
| 100 | {
|
|---|
| 101 | binVector.push_back(energy);
|
|---|
| 102 | dataVector.push_back(value);
|
|---|
| 103 | numberOfBin++;
|
|---|
| 104 | edgeMin = binVector.front();
|
|---|
| 105 | edgeMax = binVector.back();
|
|---|
| 106 |
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | G4double
|
|---|
| 110 | G4PhysicsOrderedFreeVector::GetLowEdgeEnergy(size_t binNumber) const
|
|---|
| 111 | {
|
|---|
| 112 | return binVector[binNumber];
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | G4double
|
|---|
| 116 | G4PhysicsOrderedFreeVector::GetEnergy(G4double aValue)
|
|---|
| 117 | {
|
|---|
| 118 |
|
|---|
| 119 | if (aValue <= GetMinValue()) {
|
|---|
| 120 | return GetMinLowEdgeEnergy();
|
|---|
| 121 | } else if (aValue >= GetMaxValue()) {
|
|---|
| 122 | return GetMaxLowEdgeEnergy();
|
|---|
| 123 | } else {
|
|---|
| 124 | size_t closestBin = FindValueBinLocation(aValue);
|
|---|
| 125 | G4double theEnergy = LinearInterpolationOfEnergy(aValue, closestBin);
|
|---|
| 126 |
|
|---|
| 127 | return theEnergy;
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | size_t
|
|---|
| 132 | G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
|
|---|
| 133 | {
|
|---|
| 134 | G4int n1 = 0;
|
|---|
| 135 | G4int n2 = numberOfBin/2;
|
|---|
| 136 | G4int n3 = numberOfBin - 1;
|
|---|
| 137 | while (n1 != n3 - 1) {
|
|---|
| 138 | if (aValue > dataVector[n2])
|
|---|
| 139 | { n1 = n2; }
|
|---|
| 140 | else
|
|---|
| 141 | { n3 = n2; }
|
|---|
| 142 | n2 = n1 + (n3 - n1 + 1)/2;
|
|---|
| 143 | }
|
|---|
| 144 | return (size_t)n1;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | G4double
|
|---|
| 148 | G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(G4double aValue,
|
|---|
| 149 | size_t theLocBin)
|
|---|
| 150 | {
|
|---|
| 151 | G4double intplFactor = (aValue-dataVector[theLocBin])
|
|---|
| 152 | / (dataVector[theLocBin+1]-dataVector[theLocBin]); // Interpolation factor
|
|---|
| 153 |
|
|---|
| 154 | return binVector[theLocBin] +
|
|---|
| 155 | ( binVector[theLocBin+1]-binVector[theLocBin] ) * intplFactor;
|
|---|
| 156 | }
|
|---|