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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 1.0)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 // G4VelocityTable class implementation           
 27 //                                                
 28 // Author: Hisaya Kurashige,  17 August 2011      
 29 // -------------------------------------------    
 30                                                   
 31 #include "G4VelocityTable.hh"                     
 32 #include "G4PhysicalConstants.hh"                 
 33 #include "G4StateManager.hh"                      
 34 #include "G4ApplicationState.hh"                  
 35 #include "G4Log.hh"                               
 36 #include "G4Exp.hh"                               
 37                                                   
 38 #include "G4ios.hh"                               
 39                                                   
 40 G4ThreadLocal G4VelocityTable* G4VelocityTable    
 41                                                   
 42 // -------------------------------------------    
 43 G4VelocityTable::G4VelocityTable()                
 44 {                                                 
 45   PrepareVelocityTable();                         
 46 }                                                 
 47                                                   
 48 // -------------------------------------------    
 49 G4VelocityTable::~G4VelocityTable()               
 50 {                                                 
 51   dataVector.clear();                             
 52   binVector.clear();                              
 53 }                                                 
 54                                                   
 55 // -------------------------------------------    
 56 void G4VelocityTable::PrepareVelocityTable()      
 57 {                                                 
 58   // const G4double g4log10 = std::log(10.);      
 59                                                   
 60   dataVector.clear();                             
 61   binVector.clear();                              
 62   dBin    = G4Log(maxT / minT) / NbinT;           
 63   baseBin = G4Log(minT) / dBin;                   
 64                                                   
 65   numberOfNodes = NbinT + 1;                      
 66   dataVector.reserve(numberOfNodes);              
 67   binVector.reserve(numberOfNodes);               
 68                                                   
 69   binVector.push_back(minT);                      
 70   dataVector.push_back(0.0);                      
 71                                                   
 72   for(std::size_t i = 1; i < numberOfNodes - 1    
 73   {                                               
 74     binVector.push_back(G4Exp((baseBin + i) *     
 75     dataVector.push_back(0.0);                    
 76   }                                               
 77   binVector.push_back(maxT);                      
 78   dataVector.push_back(0.0);                      
 79                                                   
 80   edgeMin = binVector[0];                         
 81   edgeMax = binVector[numberOfNodes - 1];         
 82                                                   
 83   for(G4int i = 0; i <= NbinT; ++i)               
 84   {                                               
 85     G4double T    = binVector[i];                 
 86     dataVector[i] = c_light * std::sqrt(T * (T    
 87   }                                               
 88                                                   
 89   return;                                         
 90 }                                                 
 91                                                   
 92 // -------------------------------------------    
 93 std::size_t G4VelocityTable::FindBinLocation(G    
 94 {                                                 
 95   // For G4PhysicsLogVector, FindBinLocation i    
 96   // a simple arithmetic calculation.             
 97   //                                              
 98   // Because this is a virtual function, it is    
 99   // pointer to the G4PhysicsVector object for    
100   // case, 'inline' will not be invoked. Howev    
101   // that the user access to the G4PhysicsLogV    
102   // not through pointers or references. In th    
103   // be invoked. (See R.B.Murray, "C++ Strateg    
104                                                   
105   // const G4double g4log10 = G4Log(10.);         
106   return std::size_t(G4Log(theEnergy) / dBin -    
107 }                                                 
108                                                   
109 // -------------------------------------------    
110 G4double G4VelocityTable::Value(G4double theEn    
111 {                                                 
112   // Use cache for speed up - check if the val    
113   // last call. If it is same, then use the la    
114   // value 'theEnergy' lies between the last e    
115   // bin of last call, then the last bin locat    
116                                                   
117   if(theEnergy == lastEnergy)                     
118   {                                               
119   }                                               
120   else if(theEnergy < lastEnergy && theEnergy     
121   {                                               
122     lastEnergy = theEnergy;                       
123     lastValue  = Interpolation();                 
124   }                                               
125   else if(theEnergy <= edgeMin)                   
126   {                                               
127     lastBin    = 0;                               
128     lastEnergy = edgeMin;                         
129     lastValue  = dataVector[0];                   
130   }                                               
131   else if(theEnergy >= edgeMax)                   
132   {                                               
133     lastBin    = numberOfNodes - 1;               
134     lastEnergy = edgeMax;                         
135     lastValue  = dataVector[lastBin];             
136   }                                               
137   else                                            
138   {                                               
139     lastBin = (std::size_t)(G4Log(theEnergy) /    
140     if(lastBin == numberOfNodes)                  
141     {                                             
142       --lastBin;                                  
143     }  // VI: fix possible precision lost         
144     lastEnergy = theEnergy;                       
145     lastValue  = Interpolation();                 
146   }                                               
147   return lastValue;                               
148 }                                                 
149                                                   
150 // -------------------------------------------    
151 G4VelocityTable* G4VelocityTable::GetVelocityT    
152 {                                                 
153   if(theInstance == nullptr)                      
154   {                                               
155     static G4ThreadLocalSingleton<G4VelocityTa    
156     theInstance = inst.Instance();                
157   }                                               
158   return theInstance;                             
159 }                                                 
160                                                   
161 // -------------------------------------------    
162 void G4VelocityTable::                            
163 SetVelocityTableProperties(G4double t_max, G4d    
164 {                                                 
165   if(theInstance == nullptr)                      
166   {                                               
167     GetVelocityTable();                           
168   }                                               
169                                                   
170   G4StateManager* stateManager    = G4StateMan    
171   G4ApplicationState currentState = stateManag    
172                                                   
173   // check if state is outside event loop         
174   if(!(currentState == G4State_Idle || current    
175   {                                               
176     G4Exception("G4VelocityTable::SetVelocityT    
177                 JustWarning,                      
178                 "Can modify only in PreInit or    
179     return;                                       
180   }                                               
181                                                   
182   if(nbin > 100)                                  
183     theInstance->NbinT = nbin;                    
184   if((t_min < t_max) && (t_min > 0.))             
185   {                                               
186     theInstance->minT = t_min;                    
187     theInstance->maxT = t_max;                    
188   }                                               
189   theInstance->PrepareVelocityTable();            
190 }                                                 
191                                                   
192 // -------------------------------------------    
193 G4double G4VelocityTable::GetMaxTOfVelocityTab    
194 {                                                 
195   return GetVelocityTable()->maxT;                
196 }                                                 
197                                                   
198 // -------------------------------------------    
199 G4double G4VelocityTable::GetMinTOfVelocityTab    
200 {                                                 
201   return GetVelocityTable()->minT;                
202 }                                                 
203                                                   
204 // -------------------------------------------    
205 G4int G4VelocityTable::GetNbinOfVelocityTable(    
206 {                                                 
207   return GetVelocityTable()->NbinT;               
208 }                                                 
209