Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4PhysicsFreeVector class implementation << 27 // 26 // 28 // Authors: << 27 // $Id$ 29 // - 02 Dec. 1995, G.Cosmo: Structure created << 28 // 30 // - 06 Jun. 1996, K.Amako: Implemented the 1s << 29 // 31 // Revisions: << 30 //-------------------------------------------------------------------- 32 // - 11 Nov. 2000, H.Kurashige: Use STL vector << 31 // GEANT 4 class implementation file 33 // - 25 Aug. 2021, V.Ivanchenko updated for Ge << 32 // 34 // ------------------------------------------- << 33 // G4PhysicsFreeVector.cc >> 34 // >> 35 // History: >> 36 // 02 Dec. 1995, G.Cosmo : Structure created based on object model >> 37 // 06 June 1996, K.Amako : The 1st version of implemented >> 38 // 01 Jul. 1996, K.Amako : Cache mechanism and hidden bin from the >> 39 // user introduced >> 40 // 26 Sep. 1996, K.Amako : Constructor with only 'bin size' added >> 41 // 11 Nov. 2000, H.Kurashige : use STL vector for dataVector and binVector >> 42 // 19 Jun. 2009, V.Ivanchenko : removed hidden bin >> 43 // >> 44 //-------------------------------------------------------------------- 35 45 36 #include "G4PhysicsFreeVector.hh" 46 #include "G4PhysicsFreeVector.hh" 37 #include "G4Exp.hh" << 38 47 39 // ------------------------------------------- << 48 40 G4PhysicsFreeVector::G4PhysicsFreeVector(G4boo << 49 G4PhysicsFreeVector::G4PhysicsFreeVector() 41 : G4PhysicsVector(spline) << 50 : G4PhysicsVector() 42 {} << 51 { 43 << 52 type = T_G4PhysicsFreeVector; 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 << 55 if (0 < length) { << 56 binVector.resize(numberOfNodes, 0.0); << 57 dataVector.resize(numberOfNodes, 0.0); << 58 } << 59 Initialise(); << 60 } 53 } 61 54 62 // ------------------------------------------- << 55 G4PhysicsFreeVector::G4PhysicsFreeVector(size_t theNbin) 63 G4PhysicsFreeVector::G4PhysicsFreeVector(std:: << 56 : G4PhysicsVector() 64 G4dou << 65 : G4PhysicsFreeVector(length, spline) << 66 {} << 67 << 68 // ------------------------------------------- << 69 G4PhysicsFreeVector::G4PhysicsFreeVector(const << 70 const << 71 G4boo << 72 : G4PhysicsVector(spline) << 73 { 57 { 74 numberOfNodes = energies.size(); << 58 type = T_G4PhysicsFreeVector; >> 59 numberOfNodes = theNbin; 75 60 76 if (numberOfNodes != values.size()) << 61 dataVector.reserve(numberOfNodes); >> 62 binVector.reserve(numberOfNodes); >> 63 >> 64 for (size_t i=0; i<numberOfNodes; i++) 77 { 65 { 78 G4ExceptionDescription ed; << 66 binVector.push_back(0.0); 79 ed << "The size of energy vector " << numb << 67 dataVector.push_back(0.0); 80 G4Exception("G4PhysicsFreeVector construct << 81 } 68 } >> 69 } 82 70 83 binVector = energies; << 71 G4PhysicsFreeVector::G4PhysicsFreeVector(const G4DataVector& theBinVector, 84 dataVector = values; << 72 const G4DataVector& theDataVector) 85 Initialise(); << 86 } << 87 << 88 // ------------------------------------------- << 89 G4PhysicsFreeVector::G4PhysicsFreeVector(const << 90 const << 91 std:: << 92 G4boo << 93 : G4PhysicsVector(spline) << 94 { 73 { 95 numberOfNodes = length; << 74 type = T_G4PhysicsFreeVector; >> 75 numberOfNodes = theBinVector.size(); 96 76 97 if (0 < numberOfNodes) << 77 dataVector.reserve(numberOfNodes); 98 { << 78 binVector.reserve(numberOfNodes); 99 binVector.resize(numberOfNodes); << 100 dataVector.resize(numberOfNodes); << 101 79 102 for(std::size_t i = 0; i < numberOfNodes; << 80 for (size_t i=0; i<numberOfNodes; i++) 103 { << 81 { 104 binVector[i] = energies[i]; << 82 binVector.push_back(theBinVector[i]); 105 dataVector[i] = values[i]; << 83 dataVector.push_back(theDataVector[i]); 106 } << 107 } 84 } 108 Initialise(); << 85 >> 86 edgeMin = binVector[0]; >> 87 edgeMax = binVector[numberOfNodes-1]; >> 88 } >> 89 >> 90 G4PhysicsFreeVector::~G4PhysicsFreeVector() >> 91 { 109 } 92 } 110 93 111 // ------------------------------------------- << 94 void G4PhysicsFreeVector::PutValue( size_t theBinNumber, 112 void G4PhysicsFreeVector::PutValues(const std: << 95 G4double theBinValue, 113 const G4do << 96 G4double theDataValue ) 114 const G4do << 115 { 97 { 116 if (index >= numberOfNodes) << 98 binVector[theBinNumber] = theBinValue; 117 { << 99 dataVector[theBinNumber] = theDataValue; 118 PrintPutValueError(index, value, "G4Physic << 100 119 return; << 101 if( theBinNumber == numberOfNodes-1 ) 120 } << 121 binVector[index] = e; << 122 dataVector[index] = value; << 123 if(index == 0) << 124 { 102 { 125 edgeMin = e; << 103 edgeMax = binVector[numberOfNodes-1]; 126 } 104 } 127 else if(numberOfNodes == index + 1) << 105 >> 106 if( theBinNumber == 0 ) 128 { 107 { 129 edgeMax = e; << 108 edgeMin = binVector[0]; 130 } 109 } 131 } 110 } 132 111 133 // ------------------------------------------- << 112 size_t G4PhysicsFreeVector::FindBinLocation(G4double theEnergy) const 134 void G4PhysicsFreeVector::InsertValues(const G << 113 { 135 const G << 114 // For G4PhysicsFreeVector, FindBinLocation is implemented using 136 { << 115 // the binary search algorithm. 137 auto binLoc = std::lower_bound(binVector.cbe << 116 // 138 auto dataLoc = dataVector.cbegin(); << 117 // Because this is a virtual function, it is accessed through a 139 dataLoc += binLoc - binVector.cbegin(); << 118 // pointer to the G4PhysicsVector object for most usages. In this >> 119 // case, 'inline' will not be invoked. However, there is a possibility >> 120 // that the user access to the G4PhysicsFreeVector object directly and >> 121 // not through pointers or references. In this case, the 'inline' will >> 122 // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6) 140 123 141 binVector.insert(binLoc, energy); << 124 size_t lowerBound = 0; 142 dataVector.insert(dataLoc, value); << 125 size_t upperBound = numberOfNodes-2; 143 126 144 ++numberOfNodes; << 127 while (lowerBound <= upperBound) 145 Initialise(); << 146 } << 147 << 148 // ------------------------------------------- << 149 void G4PhysicsFreeVector::EnableLogBinSearch(c << 150 { << 151 // check if log search is applicable << 152 if (0 >= n || edgeMin <= 0.0 || edgeMin == e << 153 { << 154 return; << 155 } << 156 nLogNodes = static_cast<std::size_t>(static_ << 157 if (nLogNodes < 3) { nLogNodes = 3; } << 158 scale.resize(nLogNodes, 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 { 128 { 167 G4double e = edgeMin*G4Exp(i/iBin1); << 129 size_t midBin = (lowerBound + upperBound)/2; 168 for (; j <= idxmax; ++j) << 130 if( theEnergy < binVector[midBin] ) 169 { << 131 { upperBound = midBin-1; } 170 if (binVector[j] <= e && e < binVector[j << 132 else 171 { << 133 { lowerBound = midBin+1; } 172 scale[i] = j; << 173 break; << 174 } << 175 } << 176 } 134 } 177 } << 178 135 179 // ------------------------------------------- << 136 return upperBound; >> 137 } 180 138