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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 /track/src/G4VelocityTable.cc (Version 11.3.0) and /track/src/G4VelocityTable.cc (Version 10.5.p1)


  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 // G4VelocityTable class implementation        << 
 27 //                                                 26 //
 28 // Author: Hisaya Kurashige,  17 August 2011   <<  27 //
 29 // ------------------------------------------- <<  28 //
                                                   >>  29 //---------------------------------------------------------------
                                                   >>  30 //
                                                   >>  31 //  G4VelocityTable.cc
                                                   >>  32 //
                                                   >>  33 //  class description:
                                                   >>  34 //    This class keeps a table of velocity as a function of
                                                   >>  35 //    the ratio kinetic erngy and mass
                                                   >>  36 //
                                                   >>  37 //---------------------------------------------------------------
                                                   >>  38 //   created                     17.Aug.  2011 H.Kurashige
                                                   >>  39 //
 30                                                    40 
 31 #include "G4VelocityTable.hh"                      41 #include "G4VelocityTable.hh"
 32 #include "G4PhysicalConstants.hh"                  42 #include "G4PhysicalConstants.hh"
 33 #include "G4StateManager.hh"                       43 #include "G4StateManager.hh"
 34 #include "G4ApplicationState.hh"                   44 #include "G4ApplicationState.hh"
 35 #include "G4Log.hh"                                45 #include "G4Log.hh"
 36 #include "G4Exp.hh"                                46 #include "G4Exp.hh"
 37                                                    47 
 38 #include "G4ios.hh"                            <<  48 #include "G4ios.hh" 
 39                                                    49 
 40 G4ThreadLocal G4VelocityTable* G4VelocityTable     50 G4ThreadLocal G4VelocityTable* G4VelocityTable::theInstance = nullptr;
 41                                                    51 
 42 // ------------------------------------------- <<  52 ////////////////
 43 G4VelocityTable::G4VelocityTable()                 53 G4VelocityTable::G4VelocityTable()
                                                   >>  54 ////////////////
                                                   >>  55   : edgeMin(0.), edgeMax(0.), numberOfNodes(0),
                                                   >>  56     dBin(0.), baseBin(0.),
                                                   >>  57     lastEnergy(-DBL_MAX), lastValue(0.), lastBin(0),
                                                   >>  58     maxT( 1000.0 ), minT( 0.0001 ), NbinT( 500 )
 44 {                                                  59 {
 45   PrepareVelocityTable();                          60   PrepareVelocityTable();
 46 }                                              <<  61 } 
 47                                                    62 
 48 // ------------------------------------------- <<  63 /////////////////
 49 G4VelocityTable::~G4VelocityTable()                64 G4VelocityTable::~G4VelocityTable()
                                                   >>  65 /////////////////
 50 {                                                  66 {
 51   dataVector.clear();                              67   dataVector.clear();
 52   binVector.clear();                               68   binVector.clear();
 53 }                                                  69 }
 54                                                    70 
 55 // ------------------------------------------- <<  71 
                                                   >>  72 ///////////////////
 56 void G4VelocityTable::PrepareVelocityTable()       73 void G4VelocityTable::PrepareVelocityTable()
                                                   >>  74 ///////////////////
 57 {                                                  75 {
 58   // const G4double g4log10 = std::log(10.);   <<  76   //const G4double g4log10 = std::log(10.); 
 59                                                <<  77   
 60   dataVector.clear();                              78   dataVector.clear();
 61   binVector.clear();                               79   binVector.clear();
 62   dBin    = G4Log(maxT / minT) / NbinT;        <<  80   dBin     =  G4Log(maxT/minT)/NbinT;
 63   baseBin = G4Log(minT) / dBin;                <<  81   baseBin  =  G4Log(minT)/dBin;
 64                                                    82 
 65   numberOfNodes = NbinT + 1;                       83   numberOfNodes = NbinT + 1;
 66   dataVector.reserve(numberOfNodes);               84   dataVector.reserve(numberOfNodes);
 67   binVector.reserve(numberOfNodes);                85   binVector.reserve(numberOfNodes);
 68                                                    86 
 69   binVector.push_back(minT);                       87   binVector.push_back(minT);
 70   dataVector.push_back(0.0);                       88   dataVector.push_back(0.0);
 71                                                    89 
 72   for(std::size_t i = 1; i < numberOfNodes - 1 <<  90   for (size_t i=1; i<numberOfNodes-1; i++){
 73   {                                            <<  91     binVector.push_back(G4Exp((baseBin+i)*dBin));
 74     binVector.push_back(G4Exp((baseBin + i) *  << 
 75     dataVector.push_back(0.0);                     92     dataVector.push_back(0.0);
 76   }                                                93   }
 77   binVector.push_back(maxT);                       94   binVector.push_back(maxT);
 78   dataVector.push_back(0.0);                       95   dataVector.push_back(0.0);
 79                                                <<  96   
 80   edgeMin = binVector[0];                          97   edgeMin = binVector[0];
 81   edgeMax = binVector[numberOfNodes - 1];      <<  98   edgeMax = binVector[numberOfNodes-1];
 82                                                    99 
 83   for(G4int i = 0; i <= NbinT; ++i)            << 100   for (G4int i=0; i<=NbinT; i++){
 84   {                                            << 101     G4double T = binVector[i];
 85     G4double T    = binVector[i];              << 102     dataVector[i]= c_light*std::sqrt(T*(T+2.))/(T+1.0);    
 86     dataVector[i] = c_light * std::sqrt(T * (T << 
 87   }                                               103   }
 88                                                   104 
 89   return;                                         105   return;
 90 }                                              << 106 } 
 91                                                   107 
 92 // ------------------------------------------- << 108 size_t G4VelocityTable::FindBinLocation(G4double theEnergy) const
 93 std::size_t G4VelocityTable::FindBinLocation(G << 
 94 {                                                 109 {
 95   // For G4PhysicsLogVector, FindBinLocation i    110   // For G4PhysicsLogVector, FindBinLocation is implemented using
 96   // a simple arithmetic calculation.             111   // a simple arithmetic calculation.
 97   //                                              112   //
 98   // Because this is a virtual function, it is    113   // Because this is a virtual function, it is accessed through a
 99   // pointer to the G4PhysicsVector object for << 114   // pointer to the G4PhyiscsVector object for most usages. In this
100   // case, 'inline' will not be invoked. Howev << 115   // case, 'inline' will not be invoked. However, there is a possibility 
101   // that the user access to the G4PhysicsLogV << 116   // that the user access to the G4PhysicsLogVector object directly and 
102   // not through pointers or references. In th    117   // not through pointers or references. In this case, the 'inline' will
103   // be invoked. (See R.B.Murray, "C++ Strateg    118   // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
104                                                   119 
105   // const G4double g4log10 = G4Log(10.);      << 120   //const G4double g4log10 = G4Log(10.); 
106   return std::size_t(G4Log(theEnergy) / dBin - << 121   return size_t( G4Log(theEnergy)/dBin - baseBin );
107 }                                                 122 }
108                                                   123 
109 // ------------------------------------------- << 124 G4double G4VelocityTable::Value(G4double theEnergy) 
110 G4double G4VelocityTable::Value(G4double theEn << 
111 {                                                 125 {
112   // Use cache for speed up - check if the val << 126   // Use cache for speed up - check if the value 'theEnergy' is same as the 
113   // last call. If it is same, then use the la    127   // last call. If it is same, then use the last bin location. Also the
114   // value 'theEnergy' lies between the last e << 128   // value 'theEnergy' lies between the last energy and low edge of of the 
115   // bin of last call, then the last bin locat << 129   // bin of last call, then the last bin location is used.
116                                                   130 
117   if(theEnergy == lastEnergy)                  << 131   if( theEnergy == lastEnergy ) {
118   {                                            << 132 
119   }                                            << 133   } else if( theEnergy < lastEnergy
120   else if(theEnergy < lastEnergy && theEnergy  << 134         &&   theEnergy >= binVector[lastBin]) {
121   {                                            << 135      lastEnergy = theEnergy;
122     lastEnergy = theEnergy;                    << 136      lastValue = Interpolation();
123     lastValue  = Interpolation();              << 137 
124   }                                            << 138   } else if( theEnergy <= edgeMin ) {
125   else if(theEnergy <= edgeMin)                << 139      lastBin = 0;
126   {                                            << 140      lastEnergy = edgeMin;
127     lastBin    = 0;                            << 141      lastValue  = dataVector[0];
128     lastEnergy = edgeMin;                      << 142 
129     lastValue  = dataVector[0];                << 143   } else if( theEnergy >= edgeMax ){
130   }                                            << 144      lastBin = numberOfNodes-1;
131   else if(theEnergy >= edgeMax)                << 145      lastEnergy = edgeMax;
132   {                                            << 146      lastValue  = dataVector[lastBin];
133     lastBin    = numberOfNodes - 1;            << 147 
134     lastEnergy = edgeMax;                      << 148   } else {
135     lastValue  = dataVector[lastBin];          << 149      lastBin = (size_t)( G4Log(theEnergy)/dBin - baseBin ); 
136   }                                            << 150      if(lastBin == numberOfNodes) { --lastBin; } // VI: fix possible precision lost
137   else                                         << 151      lastEnergy = theEnergy;
138   {                                            << 152      lastValue = Interpolation();
139     lastBin = (std::size_t)(G4Log(theEnergy) / << 153      
140     if(lastBin == numberOfNodes)               << 
141     {                                          << 
142       --lastBin;                               << 
143     }  // VI: fix possible precision lost      << 
144     lastEnergy = theEnergy;                    << 
145     lastValue  = Interpolation();              << 
146   }                                               154   }
147   return lastValue;                            << 155   return lastValue;        
148 }                                                 156 }
149                                                   157 
150 // ------------------------------------------- << 158 ///////////////////////////////////////////////////////
                                                   >> 159 // Static methods
                                                   >> 160 
                                                   >> 161 ///////////////////
151 G4VelocityTable* G4VelocityTable::GetVelocityT    162 G4VelocityTable* G4VelocityTable::GetVelocityTable()
                                                   >> 163 ///////////////////
152 {                                                 164 {
153   if(theInstance == nullptr)                   << 165   if (!theInstance)  { 
154   {                                            << 
155     static G4ThreadLocalSingleton<G4VelocityTa    166     static G4ThreadLocalSingleton<G4VelocityTable> inst;
156     theInstance = inst.Instance();                167     theInstance = inst.Instance();
157   }                                               168   }
158   return theInstance;                             169   return theInstance;
159 }                                                 170 }
160                                                   171 
161 // ------------------------------------------- << 172 ///////////////////
162 void G4VelocityTable::                         << 173 void G4VelocityTable::SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
163 SetVelocityTableProperties(G4double t_max, G4d << 174 ///////////////////
164 {                                              << 175 {
165   if(theInstance == nullptr)                   << 176   if (theInstance == nullptr)  { GetVelocityTable(); }
166   {                                            << 
167     GetVelocityTable();                        << 
168   }                                            << 
169                                                   177 
170   G4StateManager* stateManager    = G4StateMan << 178   G4StateManager*    stateManager = G4StateManager::GetStateManager();
171   G4ApplicationState currentState = stateManag    179   G4ApplicationState currentState = stateManager->GetCurrentState();
172                                                << 180   
173   // check if state is outside event loop         181   // check if state is outside event loop
174   if(!(currentState == G4State_Idle || current << 182   if(!(currentState==G4State_Idle||currentState==G4State_PreInit)){ 
175   {                                            << 183     G4Exception("G4VelocityTable::SetVelocityTableProperties",
176     G4Exception("G4VelocityTable::SetVelocityT << 184                 "Track101", JustWarning,
177                 JustWarning,                   << 
178                 "Can modify only in PreInit or    185                 "Can modify only in PreInit or Idle state : Method ignored.");
179     return;                                       186     return;
180   }                                               187   }
181                                                   188 
182   if(nbin > 100)                               << 189   if (nbin > 100 )  theInstance->NbinT = nbin;
183     theInstance->NbinT = nbin;                 << 190   if ((t_min < t_max)&&(t_min>0.))  {
184   if((t_min < t_max) && (t_min > 0.))          << 191     theInstance->minT = t_min; 
185   {                                            << 
186     theInstance->minT = t_min;                 << 
187     theInstance->maxT = t_max;                    192     theInstance->maxT = t_max;
188   }                                            << 193   } 
189   theInstance->PrepareVelocityTable();            194   theInstance->PrepareVelocityTable();
190 }                                                 195 }
191                                                   196 
192 // ------------------------------------------- << 197 ///////////////////
193 G4double G4VelocityTable::GetMaxTOfVelocityTab    198 G4double G4VelocityTable::GetMaxTOfVelocityTable()
                                                   >> 199 ///////////////////
194 {                                                 200 {
195   return GetVelocityTable()->maxT;             << 201   return GetVelocityTable()->maxT; 
196 }                                                 202 }
197                                                   203 
198 // ------------------------------------------- << 204 ///////////////////
199 G4double G4VelocityTable::GetMinTOfVelocityTab << 205 G4double G4VelocityTable::GetMinTOfVelocityTable() 
                                                   >> 206 ///////////////////
200 {                                                 207 {
201   return GetVelocityTable()->minT;             << 208   return GetVelocityTable()->minT; 
202 }                                                 209 }
203                                                   210 
204 // ------------------------------------------- << 211 ///////////////////
205 G4int G4VelocityTable::GetNbinOfVelocityTable( << 212 G4int    G4VelocityTable::GetNbinOfVelocityTable() 
                                                   >> 213 ///////////////////
206 {                                                 214 {
207   return GetVelocityTable()->NbinT;            << 215   return GetVelocityTable()->NbinT; 
208 }                                                 216 }
209                                                   217