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