Geant4 Cross Reference |
>> 1 // This code implementation is the intellectual property of >> 2 // the GEANT4 collaboration. 1 // 3 // 2 // ******************************************* << 4 // By copying, distributing or modifying the Program (or any work 3 // * License and Disclaimer << 5 // based on the Program) you indicate your acceptance of this statement, 4 // * << 6 // and all its terms. 5 // * The Geant4 software is copyright of th << 7 // 6 // * the Geant4 Collaboration. It is provided << 8 // $Id: G4PhysicsFreeVector.cc,v 1.3 2000/11/20 17:26:48 gcosmo Exp $ 7 // * conditions of the Geant4 Software License << 9 // GEANT4 tag $Name: geant4-03-00 $ 8 // * LICENSE and available at http://cern.ch/ << 10 // 9 // * include a list of copyright holders. << 11 // 10 // * << 12 //-------------------------------------------------------------------- 11 // * Neither the authors of this software syst << 13 // GEANT 4 class implementation file 12 // * institutes,nor the agencies providing fin << 14 // 13 // * work make any representation or warran << 15 // G4PhysicsFreeVector.cc 14 // * regarding this software system or assum << 16 // 15 // * use. Please see the license in the file << 17 // History: 16 // * for the full disclaimer and the limitatio << 18 // 02 Dec. 1995, G.Cosmo : Structure created based on object model 17 // * << 19 // 06 June 1996, K.Amako : The 1st version of implemented. 18 // * This code implementation is the result << 20 // 01 Jul. 1996, K.Amako : Cache mechanism and hidden bin from the 19 // * technical work of the GEANT4 collaboratio << 21 // user introduced. 20 // * By using, copying, modifying or distri << 22 // 26 Sep. 1996, K.Amako : Constructor with only 'bin size' added. 21 // * any work based on the software) you ag << 23 // 22 // * use in resulting scientific publicati << 24 //-------------------------------------------------------------------- 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* << 25 // << 26 // G4PhysicsFreeVector class implementation << 27 // << 28 // Authors: << 29 // - 02 Dec. 1995, G.Cosmo: Structure created << 30 // - 06 Jun. 1996, K.Amako: Implemented the 1s << 31 // Revisions: << 32 // - 11 Nov. 2000, H.Kurashige: Use STL vector << 33 // - 25 Aug. 2021, V.Ivanchenko updated for Ge << 34 // ------------------------------------------- << 35 25 36 #include "G4PhysicsFreeVector.hh" 26 #include "G4PhysicsFreeVector.hh" 37 #include "G4Exp.hh" << 38 27 39 // ------------------------------------------- << 40 G4PhysicsFreeVector::G4PhysicsFreeVector(G4boo << 41 : G4PhysicsVector(spline) << 42 {} << 43 << 44 // ------------------------------------------- << 45 G4PhysicsFreeVector::G4PhysicsFreeVector(G4int << 46 : G4PhysicsFreeVector(static_cast<std::size_ << 47 {} << 48 << 49 // ------------------------------------------- << 50 G4PhysicsFreeVector::G4PhysicsFreeVector(std:: << 51 : G4PhysicsVector(spline) << 52 { << 53 numberOfNodes = length; << 54 28 55 if (0 < length) { << 29 G4PhysicsFreeVector::G4PhysicsFreeVector() 56 binVector.resize(numberOfNodes, 0.0); << 30 { 57 dataVector.resize(numberOfNodes, 0.0); << 31 ptrNextTable = 0; 58 } << 32 edgeMin = 0.0; 59 Initialise(); << 33 edgeMax = 0.0; >> 34 numberOfBin = 0; 60 } 35 } 61 36 62 // ------------------------------------------- << 37 63 G4PhysicsFreeVector::G4PhysicsFreeVector(std:: << 38 G4PhysicsFreeVector::G4PhysicsFreeVector(size_t theNbin) 64 G4dou << 65 : G4PhysicsFreeVector(length, spline) << 66 {} << 67 << 68 // ------------------------------------------- << 69 G4PhysicsFreeVector::G4PhysicsFreeVector(const << 70 const << 71 G4boo << 72 : G4PhysicsVector(spline) << 73 { 39 { 74 numberOfNodes = energies.size(); << 40 numberOfBin = theNbin; 75 41 76 if (numberOfNodes != values.size()) << 42 // Add extra one bin (hidden to user) to handle correctly when 77 { << 43 // Energy=theEmax in getValue. 78 G4ExceptionDescription ed; << 44 dataVector.resize(numberOfBin+1); 79 ed << "The size of energy vector " << numb << 45 binVector.resize(numberOfBin+1); 80 G4Exception("G4PhysicsFreeVector construct << 81 } << 82 46 83 binVector = energies; << 47 ptrNextTable = 0; 84 dataVector = values; << 85 Initialise(); << 86 } << 87 48 88 // ------------------------------------------- << 49 edgeMin = 0.; 89 G4PhysicsFreeVector::G4PhysicsFreeVector(const << 50 edgeMax = 0.; 90 const << 91 std:: << 92 G4boo << 93 : G4PhysicsVector(spline) << 94 { << 95 numberOfNodes = length; << 96 51 97 if (0 < numberOfNodes) << 52 lastBin = INT_MAX; 98 { << 53 lastEnergy = -DBL_MAX; 99 binVector.resize(numberOfNodes); << 54 lastValue = DBL_MAX; 100 dataVector.resize(numberOfNodes); << 101 << 102 for(std::size_t i = 0; i < numberOfNodes; << 103 { << 104 binVector[i] = energies[i]; << 105 dataVector[i] = values[i]; << 106 } << 107 } << 108 Initialise(); << 109 } << 110 55 111 // ------------------------------------------- << 56 } 112 void G4PhysicsFreeVector::PutValues(const std: << 57 113 const G4do << 58 114 const G4do << 59 G4PhysicsFreeVector::G4PhysicsFreeVector(const G4DataVector& theBinVector, >> 60 const G4DataVector& theDataVector) 115 { 61 { 116 if (index >= numberOfNodes) << 62 numberOfBin = theBinVector.entries(); 117 { << 63 118 PrintPutValueError(index, value, "G4Physic << 64 // Add extra one bin (hidden to user) to handle correctly when 119 return; << 65 // Energy=theEmax in getValue. 120 } << 66 dataVector.resize(numberOfBin+1); 121 binVector[index] = e; << 67 binVector.resize(numberOfBin+1); 122 dataVector[index] = value; << 68 123 if(index == 0) << 69 ptrNextTable = 0; 124 { << 70 125 edgeMin = e; << 71 for (size_t i=0; i<numberOfBin; i++) { 126 } << 72 binVector(i) = theBinVector(i); 127 else if(numberOfNodes == index + 1) << 73 dataVector(i) = theDataVector(i); 128 { << 129 edgeMax = e; << 130 } 74 } 131 } << 132 75 133 // ------------------------------------------- << 76 // Put values to extra hidden bin. For 'binVector', the 'edgeMin' of the 134 void G4PhysicsFreeVector::InsertValues(const G << 77 // extra hidden bin is assumed to have the following value. For binary 135 const G << 78 // search, this value is completely arbitrary if it is greater than 136 { << 79 // the 'edgeMin' at 'numberOfBin-1'. 137 auto binLoc = std::lower_bound(binVector.cbe << 80 binVector(numberOfBin) = theBinVector(numberOfBin-1) + 1.0; 138 auto dataLoc = dataVector.cbegin(); << 139 dataLoc += binLoc - binVector.cbegin(); << 140 81 141 binVector.insert(binLoc, energy); << 142 dataVector.insert(dataLoc, value); << 143 82 144 ++numberOfNodes; << 83 // Put values to extra hidden bin. For 'dataVector', the 'value' of the 145 Initialise(); << 84 // extra hidden bin is assumed to have the same as the one at 'numberBin-1'. 146 } << 85 dataVector(numberOfBin) = theDataVector(numberOfBin-1); >> 86 >> 87 edgeMin = binVector(0); >> 88 edgeMax = binVector(numberOfBin-1); >> 89 >> 90 lastBin = INT_MAX; >> 91 lastEnergy = -DBL_MAX; >> 92 lastValue = DBL_MAX; >> 93 >> 94 } 147 95 148 // ------------------------------------------- << 96 149 void G4PhysicsFreeVector::EnableLogBinSearch(c << 97 G4PhysicsFreeVector::~G4PhysicsFreeVector(){} >> 98 >> 99 >> 100 void G4PhysicsFreeVector::PutValue( size_t theBinNumber, G4double theBinValue, >> 101 G4double theDataValue ) 150 { 102 { 151 // check if log search is applicable << 103 binVector(theBinNumber) = theBinValue; 152 if (0 >= n || edgeMin <= 0.0 || edgeMin == e << 104 dataVector(theBinNumber) = theDataValue; 153 { << 105 154 return; << 106 >> 107 if( theBinNumber == numberOfBin-1 ) { >> 108 edgeMax = binVector(numberOfBin-1); >> 109 >> 110 // Put values to extra hidden bin. For 'binVector', the 'edgeMin' >> 111 // of the extra hidden bin is assumed to have the following value. >> 112 // For binary search, this value is completely arbitrary if it is >> 113 // greater than the 'edgeMin' at 'numberOfBin-1'. >> 114 binVector(numberOfBin) = theBinValue + 1.0; >> 115 >> 116 // Put values to extra hidden bin. For 'dataVector', the 'value' >> 117 // of the extra hidden bin is assumed to have the same as the one >> 118 // at 'numberBin-1'. >> 119 dataVector(numberOfBin) = theDataValue; 155 } 120 } 156 nLogNodes = static_cast<std::size_t>(static_ << 121 157 if (nLogNodes < 3) { nLogNodes = 3; } << 122 if( theBinNumber == 0 ) { 158 scale.resize(nLogNodes, 0); << 123 edgeMin = binVector(0); 159 imax1 = nLogNodes - 2; << 160 iBin1 = (imax1 + 1) / G4Log(edgeMax/edgeMin) << 161 lmin1 = G4Log(edgeMin); << 162 scale[0] = 0; << 163 scale[imax1 + 1] = idxmax; << 164 std::size_t j = 0; << 165 for (std::size_t i = 1; i <= imax1; ++i) << 166 { << 167 G4double e = edgeMin*G4Exp(i/iBin1); << 168 for (; j <= idxmax; ++j) << 169 { << 170 if (binVector[j] <= e && e < binVector[j << 171 { << 172 scale[i] = j; << 173 break; << 174 } << 175 } << 176 } 124 } 177 } 125 } 178 << 179 // ------------------------------------------- << 180 126