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 // G4PhysicsLinearVector class implementation << 27 // 26 // 28 // Authors: << 27 // $Id: G4PhysicsLinearVector.cc,v 1.18 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 vector << 31 //-------------------------------------------------------------------- 33 // ------------------------------------------- << 32 // GEANT 4 class implementation file >> 33 // >> 34 // G4PhysicsLinearVector.cc >> 35 // >> 36 // 15 Feb 1996 - K.Amako : 1st version >> 37 // 19 Jun 2009 - V.Ivanchenko : removed hidden bin >> 38 // >> 39 //-------------------------------------------------------------------- 34 40 35 #include "G4PhysicsLinearVector.hh" 41 #include "G4PhysicsLinearVector.hh" 36 42 37 // ------------------------------------------- << 43 G4PhysicsLinearVector::G4PhysicsLinearVector() 38 G4PhysicsLinearVector::G4PhysicsLinearVector(G << 44 : G4PhysicsVector() 39 : G4PhysicsVector(spline) << 40 { 45 { 41 type = T_G4PhysicsLinearVector; 46 type = T_G4PhysicsLinearVector; 42 } 47 } 43 48 44 // ------------------------------------------- << 49 G4PhysicsLinearVector::G4PhysicsLinearVector(size_t theNbin) 45 G4PhysicsLinearVector::G4PhysicsLinearVector(G << 50 : G4PhysicsVector() 46 s << 47 : G4PhysicsVector(spline) << 48 { 51 { 49 numberOfNodes = Nbin + 1; << 52 type = T_G4PhysicsLinearVector; 50 if (Nbin < 1 || Emin >= Emax) << 53 51 { << 54 numberOfNodes = theNbin + 1; 52 G4ExceptionDescription ed; << 55 dataVector.reserve(numberOfNodes); 53 ed << "G4PhysicsLinearVector with wrong pa << 56 binVector.reserve(numberOfNodes); 54 << " Emin= " << Emin << " Emax= " << Em << 57 55 G4Exception("G4PhysicsLinearVector::G4Phys << 58 for (size_t i=0; i<numberOfNodes; i++) 56 FatalException, ed, "theNbins << 57 } << 58 if (numberOfNodes < 2) << 59 { 59 { 60 numberOfNodes = 2; << 60 binVector.push_back(0.0); >> 61 dataVector.push_back(0.0); 61 } 62 } >> 63 } >> 64 >> 65 G4PhysicsLinearVector::G4PhysicsLinearVector(G4double theEmin, >> 66 G4double theEmax, size_t theNbin) >> 67 : G4PhysicsVector() >> 68 { 62 type = T_G4PhysicsLinearVector; 69 type = T_G4PhysicsLinearVector; 63 70 64 binVector.resize(numberOfNodes); << 71 dBin = (theEmax-theEmin)/theNbin; 65 dataVector.resize(numberOfNodes, 0.0); << 72 baseBin = theEmin/dBin; 66 binVector[0] = Emin; << 73 67 binVector[numberOfNodes - 1] = Emax; << 74 numberOfNodes = theNbin + 1; 68 Initialise(); << 75 dataVector.reserve(numberOfNodes); 69 if (2 < numberOfNodes) << 76 binVector.reserve(numberOfNodes); 70 { << 77 71 for(std::size_t i = 1; i <= idxmax; ++i) << 78 binVector.push_back(theEmin); >> 79 dataVector.push_back(0.0); >> 80 >> 81 for (size_t i=1; i<numberOfNodes-1; i++) 72 { 82 { 73 binVector[i] = edgeMin + i / invdBin; << 83 binVector.push_back( theEmin + i*dBin ); >> 84 dataVector.push_back(0.0); 74 } 85 } >> 86 binVector.push_back(theEmax); >> 87 dataVector.push_back(0.0); >> 88 >> 89 edgeMin = binVector[0]; >> 90 edgeMax = binVector[numberOfNodes-1]; >> 91 >> 92 } >> 93 >> 94 G4PhysicsLinearVector::~G4PhysicsLinearVector(){} >> 95 >> 96 G4bool G4PhysicsLinearVector::Retrieve(std::ifstream& fIn, G4bool ascii) >> 97 { >> 98 G4bool success = G4PhysicsVector::Retrieve(fIn, ascii); >> 99 if (success) >> 100 { >> 101 G4double theEmin = binVector[0]; >> 102 dBin = binVector[1]-theEmin; >> 103 baseBin = theEmin/dBin; 75 } 104 } >> 105 return success; 76 } 106 } 77 107 78 // ------------------------------------------- << 108 void G4PhysicsLinearVector::ScaleVector(G4double factorE, G4double factorV) 79 void G4PhysicsLinearVector::Initialise() << 80 { 109 { 81 idxmax = numberOfNodes - 2; << 110 G4PhysicsVector::ScaleVector(factorE, factorV); 82 edgeMin = binVector[0]; << 111 G4double theEmin = binVector[0]; 83 edgeMax = binVector[numberOfNodes - 1]; << 112 dBin = binVector[1]-theEmin; 84 invdBin = (idxmax + 1) / (edgeMax - edgeMin) << 113 baseBin = theEmin/dBin; 85 } 114 } 86 115 87 // ------------------------------------------- << 116 >> 117 size_t G4PhysicsLinearVector::FindBinLocation(G4double theEnergy) const >> 118 { >> 119 // For G4PhysicsLinearVector, FindBinLocation is implemented using >> 120 // a simple arithmetic calculation. >> 121 // >> 122 // Because this is a virtual function, it is accessed through a >> 123 // pointer to the G4PhyiscsVector object for most usages. In this >> 124 // case, 'inline' will not be invoked. However, there is a possibility >> 125 // that the user access to the G4PhysicsLinearVector object directly and >> 126 // not through pointers or references. In this case, the 'inline' will >> 127 // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6) >> 128 >> 129 return size_t( theEnergy/dBin - baseBin ); >> 130 } 88 131