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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/src/G4PhysicsFreeVector.cc (Version 11.3.0) and /global/management/src/G4PhysicsFreeVector.cc (Version 9.2)


  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 // G4PhysicsFreeVector class implementation    << 
 27 //                                                 26 //
 28 // Authors:                                    <<  27 // $Id: G4PhysicsFreeVector.cc,v 1.12 2008/09/22 14:49:57 gcosmo Exp $
 29 // - 02 Dec. 1995, G.Cosmo: Structure created  <<  28 // GEANT4 tag $Name: geant4-09-02 $
 30 // - 06 Jun. 1996, K.Amako: Implemented the 1s <<  29 //
 31 // Revisions:                                  <<  30 // 
 32 // - 11 Nov. 2000, H.Kurashige: Use STL vector <<  31 //--------------------------------------------------------------------
 33 // - 25 Aug. 2021, V.Ivanchenko updated for Ge <<  32 //      GEANT 4 class implementation file
 34 // ------------------------------------------- <<  33 //
                                                   >>  34 //  G4PhysicsFreeVector.cc
                                                   >>  35 //
                                                   >>  36 //  History:
                                                   >>  37 //    02 Dec. 1995, G.Cosmo : Structure created based on object model
                                                   >>  38 //    06 June 1996, K.Amako : The 1st version of implemented
                                                   >>  39 //    01 Jul. 1996, K.Amako : Cache mechanism and hidden bin from the 
                                                   >>  40 //                            user introduced
                                                   >>  41 //    26 Sep. 1996, K.Amako : Constructor with only 'bin size' added
                                                   >>  42 //    11 Nov. 2000, H.Kurashige : use STL vector for dataVector and binVector
                                                   >>  43 //
                                                   >>  44 //--------------------------------------------------------------------
 35                                                    45 
 36 #include "G4PhysicsFreeVector.hh"                  46 #include "G4PhysicsFreeVector.hh"
 37 #include "G4Exp.hh"                            << 
 38                                                    47 
 39 // ------------------------------------------- << 
 40 G4PhysicsFreeVector::G4PhysicsFreeVector(G4boo << 
 41   : G4PhysicsVector(spline)                    << 
 42 {}                                             << 
 43                                                << 
 44 // ------------------------------------------- << 
 45 G4PhysicsFreeVector::G4PhysicsFreeVector(G4int << 
 46   : G4PhysicsFreeVector(static_cast<std::size_ << 
 47 {}                                             << 
 48                                                << 
 49 // ------------------------------------------- << 
 50 G4PhysicsFreeVector::G4PhysicsFreeVector(std:: << 
 51   : G4PhysicsVector(spline)                    << 
 52 {                                              << 
 53   numberOfNodes = length;                      << 
 54                                                    48 
 55   if (0 < length) {                            <<  49 G4PhysicsFreeVector::G4PhysicsFreeVector() 
 56     binVector.resize(numberOfNodes, 0.0);      <<  50   : G4PhysicsVector()
 57     dataVector.resize(numberOfNodes, 0.0);     <<  51 {
 58   }                                            <<  52   type = T_G4PhysicsFreeVector;
 59   Initialise();                                << 
 60 }                                                  53 }
 61                                                    54 
 62 // ------------------------------------------- <<  55 G4PhysicsFreeVector::G4PhysicsFreeVector(size_t theNbin)
 63 G4PhysicsFreeVector::G4PhysicsFreeVector(std:: <<  56   : G4PhysicsVector()
 64                                          G4dou << 
 65   : G4PhysicsFreeVector(length, spline)        << 
 66 {}                                             << 
 67                                                << 
 68 // ------------------------------------------- << 
 69 G4PhysicsFreeVector::G4PhysicsFreeVector(const << 
 70                                          const << 
 71                                          G4boo << 
 72   : G4PhysicsVector(spline)                    << 
 73 {                                                  57 {
 74   numberOfNodes = energies.size();             <<  58   type = T_G4PhysicsFreeVector;
                                                   >>  59   numberOfBin = theNbin;
                                                   >>  60 
                                                   >>  61   // Add extra one bin (hidden to user) to handle correctly when 
                                                   >>  62   // Energy=theEmax in getValue.
                                                   >>  63   dataVector.reserve(numberOfBin+1);
                                                   >>  64   binVector.reserve(numberOfBin+1);
 75                                                    65 
 76   if (numberOfNodes != values.size())          <<  66   for (size_t i=0; i<=numberOfBin; i++)
 77   {                                                67   {
 78     G4ExceptionDescription ed;                 <<  68      binVector.push_back(0.0);
 79     ed << "The size of energy vector " << numb <<  69      dataVector.push_back(0.0);
 80     G4Exception("G4PhysicsFreeVector construct << 
 81   }                                                70   }
                                                   >>  71 }  
 82                                                    72 
 83   binVector = energies;                        <<  73 G4PhysicsFreeVector::G4PhysicsFreeVector(const G4DataVector& theBinVector, 
 84   dataVector = values;                         <<  74                                          const G4DataVector& theDataVector)
 85   Initialise();                                << 
 86 }                                              << 
 87                                                << 
 88 // ------------------------------------------- << 
 89 G4PhysicsFreeVector::G4PhysicsFreeVector(const << 
 90                                          const << 
 91                                          std:: << 
 92                                          G4boo << 
 93   : G4PhysicsVector(spline)                    << 
 94 {                                                  75 {
 95   numberOfNodes = length;                      <<  76   type = T_G4PhysicsFreeVector;
                                                   >>  77   numberOfBin = theBinVector.size();
 96                                                    78 
 97   if (0 < numberOfNodes)                       <<  79   // Add extra one bin (hidden to user) to handle correctly when 
 98   {                                            <<  80   // Energy=theEmax in getValue.
 99     binVector.resize(numberOfNodes);           <<  81   dataVector.reserve(numberOfBin+1);
100     dataVector.resize(numberOfNodes);          <<  82   binVector.reserve(numberOfBin+1);
101                                                    83 
102     for(std::size_t i = 0; i < numberOfNodes;  <<  84   for (size_t i=0; i<numberOfBin; i++)
103     {                                          << 
104       binVector[i] = energies[i];              << 
105       dataVector[i] = values[i];               << 
106     }                                          << 
107   }                                            << 
108   Initialise();                                << 
109 }                                              << 
110                                                << 
111 // ------------------------------------------- << 
112 void G4PhysicsFreeVector::PutValues(const std: << 
113                                     const G4do << 
114                                     const G4do << 
115 {                                              << 
116   if (index >= numberOfNodes)                  << 
117   {                                                85   {
118     PrintPutValueError(index, value, "G4Physic <<  86      binVector.push_back(theBinVector[i]);
119     return;                                    <<  87      dataVector.push_back(theDataVector[i]);
120   }                                                88   }
121   binVector[index]  = e;                       << 
122   dataVector[index] = value;                   << 
123   if(index == 0)                               << 
124   {                                            << 
125     edgeMin = e;                               << 
126   }                                            << 
127   else if(numberOfNodes == index + 1)          << 
128   {                                            << 
129     edgeMax = e;                               << 
130   }                                            << 
131 }                                              << 
132                                                    89 
133 // ------------------------------------------- <<  90   // Put values to extra hidden bin. For 'binVector', the 'edgeMin' of the
134 void G4PhysicsFreeVector::InsertValues(const G <<  91   // extra hidden bin is assumed to have the following value. For binary
135                                        const G <<  92   // search, this value is completely arbitrary if it is greater than
136 {                                              <<  93   // the 'edgeMin' at 'numberOfBin-1'. 
137   auto binLoc = std::lower_bound(binVector.cbe <<  94   binVector.push_back ( theBinVector[numberOfBin-1] + 1.0 );
138   auto dataLoc = dataVector.cbegin();          <<  95 
139   dataLoc += binLoc - binVector.cbegin();      << 
140                                                    96 
141   binVector.insert(binLoc, energy);            <<  97   // Put values to extra hidden bin. For 'dataVector', the 'value' of the
142   dataVector.insert(dataLoc, value);           <<  98   // extra hidden bin is assumed to have the same as the one at 'numberBin-1'. 
                                                   >>  99   dataVector.push_back( theDataVector[numberOfBin-1] );
143                                                   100 
144   ++numberOfNodes;                             << 101   edgeMin = binVector[0];
145   Initialise();                                << 102   edgeMax = binVector[numberOfBin-1];
                                                   >> 103 }  
                                                   >> 104 
                                                   >> 105 G4PhysicsFreeVector::~G4PhysicsFreeVector()
                                                   >> 106 {
146 }                                                 107 }
147                                                   108 
148 // ------------------------------------------- << 109 void G4PhysicsFreeVector::PutValue( size_t theBinNumber, G4double theBinValue, 
149 void G4PhysicsFreeVector::EnableLogBinSearch(c << 110                                     G4double theDataValue )
150 {                                                 111 {
151   // check if log search is applicable         << 112   binVector[theBinNumber]  = theBinValue;
152   if (0 >= n || edgeMin <= 0.0 || edgeMin == e << 113   dataVector[theBinNumber] = theDataValue;
                                                   >> 114 
                                                   >> 115   if( theBinNumber == numberOfBin-1 )
153   {                                               116   {
154     return;                                    << 117      edgeMax = binVector[numberOfBin-1];
                                                   >> 118 
                                                   >> 119      // Put values to extra hidden bin. For 'binVector', the 'edgeMin' 
                                                   >> 120      // of the extra hidden bin is assumed to have the following value. 
                                                   >> 121      // For binary search, this value is completely arbitrary if it is 
                                                   >> 122      // greater than the 'edgeMin' at 'numberOfBin-1'. 
                                                   >> 123      binVector[numberOfBin] = theBinValue + 1.0;
                                                   >> 124 
                                                   >> 125      // Put values to extra hidden bin. For 'dataVector', the 'value' 
                                                   >> 126      // of the extra hidden bin is assumed to have the same as the one 
                                                   >> 127      // at 'numberBin-1'. 
                                                   >> 128      dataVector[numberOfBin] = theDataValue;
155   }                                               129   }
156   nLogNodes = static_cast<std::size_t>(static_ << 130 
157   if (nLogNodes < 3) { nLogNodes = 3; }        << 131   if( theBinNumber == 0 )
158   scale.resize(nLogNodes, 0);                  << 
159   imax1 = nLogNodes - 2;                       << 
160   iBin1 = (imax1 + 1) / G4Log(edgeMax/edgeMin) << 
161   lmin1 = G4Log(edgeMin);                      << 
162   scale[0] = 0;                                << 
163   scale[imax1 + 1] = idxmax;                   << 
164   std::size_t j = 0;                           << 
165   for (std::size_t i = 1; i <= imax1; ++i)     << 
166   {                                               132   {
167     G4double e = edgeMin*G4Exp(i/iBin1);       << 133      edgeMin = binVector[0];
168     for (; j <= idxmax; ++j)                   << 
169     {                                          << 
170       if (binVector[j] <= e && e < binVector[j << 
171       {                                        << 
172         scale[i] = j;                          << 
173         break;                                 << 
174       }                                        << 
175     }                                          << 
176   }                                               134   }
177 }                                                 135 }
178                                                << 
179 // ------------------------------------------- << 
180                                                   136