G4PhysicsFreeVector.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 //  G4PhysicsFreeVector.cc
00034 //
00035 //  History:
00036 //    02 Dec. 1995, G.Cosmo : Structure created based on object model
00037 //    06 June 1996, K.Amako : The 1st version of implemented
00038 //    01 Jul. 1996, K.Amako : Cache mechanism and hidden bin from the 
00039 //                            user introduced
00040 //    26 Sep. 1996, K.Amako : Constructor with only 'bin size' added
00041 //    11 Nov. 2000, H.Kurashige : use STL vector for dataVector and binVector
00042 //    19 Jun. 2009, V.Ivanchenko : removed hidden bin 
00043 //
00044 //--------------------------------------------------------------------
00045 
00046 #include "G4PhysicsFreeVector.hh"
00047 
00048 
00049 G4PhysicsFreeVector::G4PhysicsFreeVector() 
00050   : G4PhysicsVector()
00051 {
00052   type = T_G4PhysicsFreeVector;
00053 }
00054 
00055 G4PhysicsFreeVector::G4PhysicsFreeVector(size_t theNbin)
00056   : G4PhysicsVector()
00057 {
00058   type = T_G4PhysicsFreeVector;
00059   numberOfNodes = theNbin;
00060 
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 G4PhysicsFreeVector::G4PhysicsFreeVector(const G4DataVector& theBinVector, 
00072                                          const G4DataVector& theDataVector)
00073 {
00074   type = T_G4PhysicsFreeVector;
00075   numberOfNodes = theBinVector.size();
00076 
00077   dataVector.reserve(numberOfNodes);
00078   binVector.reserve(numberOfNodes);
00079 
00080   for (size_t i=0; i<numberOfNodes; i++)
00081   {
00082      binVector.push_back(theBinVector[i]);
00083      dataVector.push_back(theDataVector[i]);
00084   }
00085 
00086   edgeMin = binVector[0];
00087   edgeMax = binVector[numberOfNodes-1];
00088 }  
00089 
00090 G4PhysicsFreeVector::~G4PhysicsFreeVector()
00091 {
00092 }
00093 
00094 void G4PhysicsFreeVector::PutValue( size_t theBinNumber, 
00095                                     G4double theBinValue, 
00096                                     G4double theDataValue )
00097 {
00098   binVector[theBinNumber]  = theBinValue;
00099   dataVector[theBinNumber] = theDataValue;
00100 
00101   if( theBinNumber == numberOfNodes-1 )
00102   {
00103      edgeMax = binVector[numberOfNodes-1];
00104   }
00105 
00106   if( theBinNumber == 0 )
00107   {
00108      edgeMin = binVector[0];
00109   }
00110 }
00111 
00112 size_t G4PhysicsFreeVector::FindBinLocation(G4double theEnergy) const
00113 {
00114   // For G4PhysicsFreeVector, FindBinLocation is implemented using
00115   // the binary search algorithm.
00116   //
00117   // Because this is a virtual function, it is accessed through a
00118   // pointer to the G4PhysicsVector object for most usages. In this
00119   // case, 'inline' will not be invoked. However, there is a possibility 
00120   // that the user access to the G4PhysicsFreeVector object directly and 
00121   // not through pointers or references. In this case, the 'inline' will
00122   // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
00123 
00124   size_t lowerBound = 0;
00125   size_t upperBound = numberOfNodes-2;
00126 
00127   while (lowerBound <= upperBound)
00128   {
00129     size_t midBin = (lowerBound + upperBound)/2;
00130     if( theEnergy < binVector[midBin] )
00131        { upperBound = midBin-1; }
00132     else
00133        { lowerBound = midBin+1; }
00134   }
00135 
00136   return upperBound;
00137 }

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