G4PhysicsLogVector.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // --------------------------------------------------------------
00031 //      GEANT 4 class implementation file
00032 //
00033 //  G4PhysicsLogVector.cc
00034 //
00035 //  History:
00036 //    02 Dec. 1995, G.Cosmo : Structure created based on object model
00037 //    15 Feb. 1996, K.Amako : Implemented the 1st version
00038 //    01 Jul. 1996, K.Amako : Hidden bin from the user introduced
00039 //    26 Sep. 1996, K.Amako : Constructor with only 'bin size' added
00040 //    11 Nov. 2000, H.Kurashige : use STL vector for dataVector and binVector
00041 //    9  Mar. 2001, H.Kurashige : added PhysicsVector type and Retrieve
00042 //    05 Sep. 2008, V.Ivanchenko : added protections for zero-length vector
00043 //    19 Jun. 2009, V.Ivanchenko : removed hidden bin 
00044 //
00045 // --------------------------------------------------------------
00046 
00047 #include "G4PhysicsLogVector.hh"
00048 
00049 G4PhysicsLogVector::G4PhysicsLogVector()
00050   : G4PhysicsVector()
00051 { 
00052   type = T_G4PhysicsLogVector;
00053 }
00054 
00055 G4PhysicsLogVector::G4PhysicsLogVector(size_t theNbin)
00056   : G4PhysicsVector()
00057 {
00058   type = T_G4PhysicsLogVector;
00059 
00060   numberOfNodes = theNbin + 1;
00061   dataVector.reserve(numberOfNodes);
00062   binVector.reserve(numberOfNodes);      
00063 
00064   for (size_t i=0; i<numberOfNodes; i++)
00065   {
00066      binVector.push_back(0.0);
00067      dataVector.push_back(0.0);
00068   }
00069 }  
00070 
00071 G4PhysicsLogVector::G4PhysicsLogVector(G4double theEmin, 
00072                                        G4double theEmax, size_t theNbin)
00073   : G4PhysicsVector()
00074 {
00075   type = T_G4PhysicsLogVector;
00076 
00077   dBin     =  std::log10(theEmax/theEmin)/theNbin;
00078   baseBin  =  std::log10(theEmin)/dBin;
00079 
00080   numberOfNodes = theNbin + 1;
00081   dataVector.reserve(numberOfNodes);
00082   binVector.reserve(numberOfNodes);
00083   static const G4double g4log10 = std::log(10.); 
00084 
00085   binVector.push_back(theEmin);
00086   dataVector.push_back(0.0);
00087 
00088   for (size_t i=1; i<numberOfNodes-1; i++)
00089     {
00090       binVector.push_back(std::exp(g4log10*(baseBin+i)*dBin));
00091       dataVector.push_back(0.0);
00092     }
00093   binVector.push_back(theEmax);
00094   dataVector.push_back(0.0);
00095 
00096   edgeMin = binVector[0];
00097   edgeMax = binVector[numberOfNodes-1];
00098 }  
00099 
00100 G4PhysicsLogVector::~G4PhysicsLogVector()
00101 {
00102 }
00103 
00104 G4bool G4PhysicsLogVector::Retrieve(std::ifstream& fIn, G4bool ascii)
00105 {
00106   G4bool success = G4PhysicsVector::Retrieve(fIn, ascii);
00107   if (success)
00108   {
00109     G4double theEmin = binVector[0];
00110     dBin = std::log10(binVector[1]/theEmin);
00111     baseBin = std::log10(theEmin)/dBin;
00112   }
00113   return success;
00114 }
00115 
00116 void G4PhysicsLogVector::ScaleVector(G4double factorE, G4double factorV)
00117 {
00118   G4PhysicsVector::ScaleVector(factorE, factorV);
00119   G4double theEmin = binVector[0];
00120   dBin = std::log10(binVector[1]/theEmin);
00121   baseBin = std::log10(theEmin)/dBin;
00122 }
00123 
00124 size_t G4PhysicsLogVector::FindBinLocation(G4double theEnergy) const
00125 {
00126   // For G4PhysicsLogVector, FindBinLocation is implemented using
00127   // a simple arithmetic calculation.
00128   //
00129   // Because this is a virtual function, it is accessed through a
00130   // pointer to the G4PhyiscsVector object for most usages. In this
00131   // case, 'inline' will not be invoked. However, there is a possibility 
00132   // that the user access to the G4PhysicsLogVector object directly and 
00133   // not through pointers or references. In this case, the 'inline' will
00134   // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
00135   //G4cout << "G4PhysicsLogVector::FindBinLocation: e= " << theEnergy
00136 
00137   return size_t( std::log10(theEnergy)/dBin - baseBin );
00138 }
00139 

Generated on Mon May 27 17:49:19 2013 for Geant4 by  doxygen 1.4.7