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 // G4PhysicsLogVector class implementation << 27 // 26 // 28 // Authors: << 27 // $Id: G4PhysicsLogVector.cc,v 1.25 2010-05-28 05:13:43 kurasige Exp $ 29 // - 02 Dec. 1995, G.Cosmo: Structure created << 28 // GEANT4 tag $Name: not supported by cvs2svn $ 30 // - 03 Mar. 1996, K.Amako: Implemented the 1s << 29 // 31 // Revisions: << 30 // 32 // - 11 Nov. 2000, H.Kurashige : Use STL vecto << 31 // -------------------------------------------------------------- 33 // ------------------------------------------- << 32 // GEANT 4 class implementation file >> 33 // >> 34 // G4PhysicsLogVector.cc >> 35 // >> 36 // History: >> 37 // 02 Dec. 1995, G.Cosmo : Structure created based on object model >> 38 // 15 Feb. 1996, K.Amako : Implemented the 1st version >> 39 // 01 Jul. 1996, K.Amako : Hidden bin from the 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 // 9 Mar. 2001, H.Kurashige : added PhysicsVector type and Retrieve >> 43 // 05 Sep. 2008, V.Ivanchenko : added protections for zero-length vector >> 44 // 19 Jun. 2009, V.Ivanchenko : removed hidden bin >> 45 // >> 46 // -------------------------------------------------------------- 34 47 35 #include "G4PhysicsLogVector.hh" 48 #include "G4PhysicsLogVector.hh" 36 #include "G4Exp.hh" << 37 #include "G4Log.hh" << 38 49 39 // ------------------------------------------- << 50 G4PhysicsLogVector::G4PhysicsLogVector() 40 G4PhysicsLogVector::G4PhysicsLogVector(G4bool << 51 : G4PhysicsVector() 41 : G4PhysicsVector(spline) << 52 { 42 { << 43 type = T_G4PhysicsLogVector; 53 type = T_G4PhysicsLogVector; 44 } 54 } 45 55 46 // ------------------------------------------- << 56 G4PhysicsLogVector::G4PhysicsLogVector(size_t theNbin) 47 G4PhysicsLogVector::G4PhysicsLogVector(G4doubl << 57 : G4PhysicsVector() 48 std::si << 49 : G4PhysicsVector(spline) << 50 { 58 { 51 numberOfNodes = Nbin + 1; << 59 type = T_G4PhysicsLogVector; 52 if (Nbin < 2 || Emin >= Emax || Emin <= 0.0) << 60 53 { << 61 numberOfNodes = theNbin + 1; 54 G4ExceptionDescription ed; << 62 dataVector.reserve(numberOfNodes); 55 ed << "G4PhysicsLogVector with wrong param << 63 binVector.reserve(numberOfNodes); 56 << " Emin= " << Emin << " Emax= " << Em << 64 57 G4Exception("G4PhysicsLogVector::G4Physics << 65 for (size_t i=0; i<numberOfNodes; i++) 58 FatalException, ed, "Nbins sho << 59 } << 60 if (numberOfNodes < 3) << 61 { 66 { 62 numberOfNodes = 3; << 67 binVector.push_back(0.0); >> 68 dataVector.push_back(0.0); 63 } 69 } >> 70 } >> 71 >> 72 G4PhysicsLogVector::G4PhysicsLogVector(G4double theEmin, >> 73 G4double theEmax, size_t theNbin) >> 74 : G4PhysicsVector() >> 75 { 64 type = T_G4PhysicsLogVector; 76 type = T_G4PhysicsLogVector; 65 77 66 binVector.resize(numberOfNodes); << 78 dBin = std::log10(theEmax/theEmin)/theNbin; 67 dataVector.resize(numberOfNodes, 0.0); << 79 baseBin = std::log10(theEmin)/dBin; 68 binVector[0] = Emin; << 69 binVector[numberOfNodes - 1] = Emax; << 70 Initialise(); << 71 80 72 for (std::size_t i = 1; i <= idxmax; ++i) << 81 numberOfNodes = theNbin + 1; >> 82 dataVector.reserve(numberOfNodes); >> 83 binVector.reserve(numberOfNodes); >> 84 static const G4double g4log10 = std::log(10.); >> 85 >> 86 binVector.push_back(theEmin); >> 87 dataVector.push_back(0.0); >> 88 >> 89 for (size_t i=1; i<numberOfNodes-1; i++) >> 90 { >> 91 binVector.push_back(std::exp(g4log10*(baseBin+i)*dBin)); >> 92 dataVector.push_back(0.0); >> 93 } >> 94 binVector.push_back(theEmax); >> 95 dataVector.push_back(0.0); >> 96 >> 97 edgeMin = binVector[0]; >> 98 edgeMax = binVector[numberOfNodes-1]; >> 99 } >> 100 >> 101 G4PhysicsLogVector::~G4PhysicsLogVector() >> 102 { >> 103 } >> 104 >> 105 G4bool G4PhysicsLogVector::Retrieve(std::ifstream& fIn, G4bool ascii) >> 106 { >> 107 G4bool success = G4PhysicsVector::Retrieve(fIn, ascii); >> 108 if (success) 73 { 109 { 74 binVector[i] = edgeMin*G4Exp(i / invdBin); << 110 G4double theEmin = binVector[0]; >> 111 dBin = std::log10(binVector[1]/theEmin); >> 112 baseBin = std::log10(theEmin)/dBin; 75 } 113 } >> 114 return success; 76 } 115 } 77 116 78 // ------------------------------------------- << 117 void G4PhysicsLogVector::ScaleVector(G4double factorE, G4double factorV) 79 void G4PhysicsLogVector::Initialise() << 80 { 118 { 81 idxmax = numberOfNodes - 2; << 119 G4PhysicsVector::ScaleVector(factorE, factorV); 82 edgeMin = binVector[0]; << 120 G4double theEmin = binVector[0]; 83 edgeMax = binVector[idxmax + 1]; << 121 dBin = std::log10(binVector[1]/theEmin); 84 invdBin = (idxmax + 1) / G4Log(edgeMax/edgeM << 122 baseBin = std::log10(theEmin)/dBin; 85 logemin = G4Log(edgeMin); << 123 } >> 124 >> 125 size_t G4PhysicsLogVector::FindBinLocation(G4double theEnergy) const >> 126 { >> 127 // For G4PhysicsLogVector, FindBinLocation is implemented using >> 128 // a simple arithmetic calculation. >> 129 // >> 130 // Because this is a virtual function, it is accessed through a >> 131 // pointer to the G4PhyiscsVector object for most usages. In this >> 132 // case, 'inline' will not be invoked. However, there is a possibility >> 133 // that the user access to the G4PhysicsLogVector object directly and >> 134 // not through pointers or references. In this case, the 'inline' will >> 135 // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6) >> 136 //G4cout << "G4PhysicsLogVector::FindBinLocation: e= " << theEnergy >> 137 >> 138 return size_t( std::log10(theEnergy)/dBin - baseBin ); 86 } 139 } 87 140 88 // ------------------------------------------- << 89 141