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