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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/G4PhysicsTable.cc (Version 11.3.0) and /global/management/src/G4PhysicsTable.cc (Version 9.1.p2)


  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 // G4PhysicsTable class implementation         << 
 27 //                                                 26 //
 28 // Author: G.Cosmo, 2 December 1995            <<  27 // $Id: G4PhysicsTable.cc,v 1.15 2007/11/13 17:35:06 gcosmo Exp $
 29 //         First implementation based on objec <<  28 // GEANT4 tag $Name: geant4-09-01-patch-02 $
 30 // Revisions:                                  <<  29 //
 31 // - 1st March 1996, K.Amako: modified         <<  30 // 
 32 // - 24th February 2001, H.Kurashige: migratio <<  31 // ------------------------------------------------------------
 33 // ------------------------------------------- <<  32 //      GEANT 4 class implementation
                                                   >>  33 //
                                                   >>  34 //      G4PhysicsTable
                                                   >>  35 //
                                                   >>  36 // ------------------------------------------------------------
 34                                                    37 
                                                   >>  38 #include "G4PhysicsVector.hh"
                                                   >>  39 #include "G4PhysicsTable.hh"
                                                   >>  40 #include <iostream>
 35 #include <fstream>                                 41 #include <fstream>
 36 #include <iomanip>                                 42 #include <iomanip>
 37 #include <iostream>                            << 
 38                                                    43 
 39 #include "G4PhysicsFreeVector.hh"              <<  44 G4PhysicsTable::G4PhysicsTable()
 40 #include "G4PhysicsLinearVector.hh"            <<  45   : G4PhysCollection()
 41 #include "G4PhysicsLogVector.hh"               <<  46 {
 42 #include "G4PhysicsTable.hh"                   <<  47 }
 43 #include "G4PhysicsVector.hh"                  << 
 44 #include "G4PhysicsVectorType.hh"              << 
 45                                                    48 
 46 // ------------------------------------------- <<  49 G4PhysicsTable::G4PhysicsTable(size_t cap)
 47 G4PhysicsTable::G4PhysicsTable(std::size_t cap <<  50   : G4PhysCollection()
 48 {                                                  51 {
 49   reserve(cap);                                    52   reserve(cap);
 50   vecFlag.reserve(cap);                            53   vecFlag.reserve(cap);
 51 }                                                  54 }
 52                                                    55 
 53 // ------------------------------------------- <<  56 G4PhysicsTable::G4PhysicsTable(const G4PhysicsTable& right)
                                                   >>  57   : G4PhysCollection()
                                                   >>  58 {
                                                   >>  59   *this = right;
                                                   >>  60 }
                                                   >>  61 
                                                   >>  62 G4PhysicsTable& G4PhysicsTable::operator=(const G4PhysicsTable& right)
                                                   >>  63 {
                                                   >>  64   if (this != &right)
                                                   >>  65   {
                                                   >>  66     size_t idx = 0;
                                                   >>  67     for (G4PhysCollection::const_iterator itr=right.begin();
                                                   >>  68          itr!=right.end(); ++itr )
                                                   >>  69     {
                                                   >>  70       G4PhysCollection::push_back(*itr);
                                                   >>  71       vecFlag.push_back(right.GetFlag(idx));
                                                   >>  72       idx +=1;
                                                   >>  73     }
                                                   >>  74   }
                                                   >>  75   return *this;
                                                   >>  76 }
                                                   >>  77 
 54 G4PhysicsTable::~G4PhysicsTable()                  78 G4PhysicsTable::~G4PhysicsTable()
 55 {                                                  79 {
 56   G4PhysCollection::clear();                       80   G4PhysCollection::clear();
 57   vecFlag.clear();                                 81   vecFlag.clear();
 58 }                                                  82 }
 59                                                <<  83  
 60 // ------------------------------------------- <<  84 void   G4PhysicsTable::resize(size_t siz, G4PhysicsVector* vec)
 61 void G4PhysicsTable::resize(std::size_t siz, G << 
 62 {                                                  85 {
 63   G4PhysCollection::resize(siz, vec);              86   G4PhysCollection::resize(siz, vec);
 64   vecFlag.resize(siz, true);                       87   vecFlag.resize(siz, true);
 65 }                                                  88 }
 66                                                    89 
 67 // ------------------------------------------- <<  90 G4bool G4PhysicsTable::StorePhysicsTable(const G4String& fileName,
 68 G4bool G4PhysicsTable::StorePhysicsTable(const <<  91                                          G4bool          ascii)
 69 {                                                  92 {
 70   std::ofstream fOut;                          <<  93   std::ofstream fOut;  
 71                                                <<  94   
 72   // open output file                          <<  95   // open output file //
 73   if(!ascii)                                   <<  96   if (!ascii)
 74   {                                            <<  97     { fOut.open(fileName, std::ios::out|std::ios::binary); }
 75     fOut.open(fileName, std::ios::out | std::i << 
 76   }                                            << 
 77   else                                             98   else
 78   {                                            <<  99     { fOut.open(fileName, std::ios::out); }
 79     fOut.open(fileName, std::ios::out);        << 
 80   }                                            << 
 81                                                   100 
 82   // check if the file has been opened success << 101   // check if the file has been opened successfully 
 83   if(!fOut.is_open())                          << 102   if (!fOut)
 84   {                                               103   {
 85 #ifdef G4VERBOSE                               << 104 #ifdef G4VERBOSE  
 86     G4cerr << "G4PhysicsTable::StorePhysicsTab << 105     G4cerr << "G4PhysicsTable::StorePhysicsTable  ";
 87     G4cerr << " Cannot open file: " << fileNam << 106     G4cerr << " Can not open file " << fileName << G4endl;
 88 #endif                                            107 #endif
 89     fOut.close();                                 108     fOut.close();
 90     return false;                                 109     return false;
 91   }                                               110   }
 92                                                   111 
 93   // Number of elements                           112   // Number of elements
 94   std::size_t tableSize = size();              << 113   size_t tableSize = size(); 
 95   if(!ascii)                                   << 114   if (!ascii)
 96   {                                               115   {
 97     fOut.write((char*) (&tableSize), sizeof ta << 116     fOut.write( (char*)(&tableSize), sizeof tableSize); 
 98   }                                               117   }
 99   else                                            118   else
100   {                                               119   {
101     fOut << tableSize << G4endl;                  120     fOut << tableSize << G4endl;
102   }                                               121   }
103                                                   122 
104   // Physics Vector                               123   // Physics Vector
105   for(const auto itr : *this)                  << 124   for (G4PhysicsTableIterator itr=begin(); itr!=end(); ++itr)
106   {                                               125   {
107     G4int vType = itr->GetType();              << 126     G4int vType = (*itr)->GetType();
108     if(!ascii)                                 << 127     if (!ascii)
109     {                                             128     {
110       fOut.write((char*) (&vType), sizeof vTyp << 129       fOut.write( (char*)(&vType), sizeof vType); 
111     }                                             130     }
112     else                                          131     else
113     {                                             132     {
114       fOut << vType << G4endl;                    133       fOut << vType << G4endl;
115     }                                             134     }
116     itr->Store(fOut, ascii);                   << 135     (*itr)->Store(fOut,ascii);
117   }                                               136   }
118   fOut.close();                                   137   fOut.close();
119   return true;                                    138   return true;
120 }                                                 139 }
121                                                   140 
122 // ------------------------------------------- << 141 
123 G4bool G4PhysicsTable::ExistPhysicsTable(const    142 G4bool G4PhysicsTable::ExistPhysicsTable(const G4String& fileName) const
124 {                                                 143 {
125   std::ifstream fIn;                           << 144   std::ifstream fIn;  
126   G4bool value = true;                         << 145   G4bool value=true;
127   // open input file                              146   // open input file
128   fIn.open(fileName, std::ios::in);            << 147   fIn.open(fileName,std::ios::in);
129                                                   148 
130   // check if the file has been opened success << 149   // check if the file has been opened successfully 
131   if(!fIn)                                     << 150   if (!fIn)
132   {                                               151   {
133     value = false;                                152     value = false;
134   }                                               153   }
135   fIn.close();                                    154   fIn.close();
136   return value;                                   155   return value;
137 }                                                 156 }
138                                                << 157     
139 // ------------------------------------------- << 
140 G4bool G4PhysicsTable::RetrievePhysicsTable(co    158 G4bool G4PhysicsTable::RetrievePhysicsTable(const G4String& fileName,
141                                             G4 << 159                                             G4bool          ascii)
142 {                                                 160 {
143   std::ifstream fIn;                           << 161   std::ifstream fIn;  
144   // open input file                              162   // open input file
145   if(ascii)                                    << 163   if (ascii)
146   {                                            << 164     { fIn.open(fileName,std::ios::in|std::ios::binary); }
147     fIn.open(fileName, std::ios::in | std::ios << 
148   }                                            << 
149   else                                            165   else
150   {                                            << 166     { fIn.open(fileName,std::ios::in);} 
151     fIn.open(fileName, std::ios::in);          << 
152   }                                            << 
153                                                   167 
154   // check if the file has been opened success << 168   // check if the file has been opened successfully 
155   if(!fIn.is_open())                           << 169   if (!fIn)
156   {                                               170   {
157 #ifdef G4VERBOSE                               << 171 #ifdef G4VERBOSE  
158     G4cerr << "G4PhysicsTable::RetrievePhysics << 172     G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
159     G4cerr << " Cannot open file: " << fileNam << 173     G4cerr << " Can not open file " << fileName << G4endl;
160 #endif                                            174 #endif
161     fIn.close();                                  175     fIn.close();
162     return false;                                 176     return false;
163   }                                               177   }
164                                                   178 
165   // clear                                     << 179   // clear 
166   clearAndDestroy();                              180   clearAndDestroy();
167                                                << 181   
168   // Number of elements                           182   // Number of elements
169   std::size_t tableSize = 0;                   << 183   size_t tableSize=0; 
170   if(!ascii)                                   << 184   if (!ascii)
171   {                                               185   {
172     fIn.read((char*) (&tableSize), sizeof tabl << 186     fIn.read((char*)(&tableSize), sizeof tableSize); 
173   }                                               187   }
174   else                                            188   else
175   {                                               189   {
176     fIn >> tableSize;                             190     fIn >> tableSize;
177   }                                               191   }
178   reserve(tableSize);                          << 192   reserve(tableSize); 
179   vecFlag.clear();                                193   vecFlag.clear();
180                                                   194 
181   // Physics Vector                               195   // Physics Vector
182   for(std::size_t idx = 0; idx < tableSize; ++ << 196   for (size_t idx=0; idx<tableSize; ++idx)
183   {                                               197   {
184     G4int vType = 0;                           << 198     G4int vType=0;
185     if(!ascii)                                 << 199     if (!ascii)
186     {                                             200     {
187       fIn.read((char*) (&vType), sizeof vType) << 201       fIn.read( (char*)(&vType), sizeof vType); 
188     }                                             202     }
189     else                                          203     else
190     {                                             204     {
191       fIn >> vType;                            << 205       fIn >>  vType;
192     }                                             206     }
193     G4PhysicsVector* pVec = CreatePhysicsVecto << 207     G4PhysicsVector* pVec = CreatePhysicsVector(vType);
194     if(pVec == nullptr)                        << 208     if (pVec==0)
195     {                                             209     {
196 #ifdef G4VERBOSE                               << 210 #ifdef G4VERBOSE  
197       G4cerr << "G4PhysicsTable::RetrievePhysi << 211       G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
198       G4cerr << " Illegal Physics Vector type: << 212       G4cerr << " illegal Physics Vector type " << vType << " in  ";
199       G4cerr << fileName << G4endl;               213       G4cerr << fileName << G4endl;
200 #endif                                         << 214 #endif          
201       fIn.close();                                215       fIn.close();
202       return false;                               216       return false;
203     }                                             217     }
204                                                   218 
205     if(!(pVec->Retrieve(fIn, ascii)))          << 219     if (! (pVec->Retrieve(fIn,ascii)) )
206     {                                             220     {
207 #ifdef G4VERBOSE                               << 221 #ifdef G4VERBOSE  
208       G4cerr << "G4PhysicsTable::RetrievePhysi << 222       G4cerr << "G4PhysicsTable::RetrievePhysicsTable  ";
209       G4cerr << " Rrror in retreiving " << idx << 223       G4cerr << " error in retreiving " << idx << "-th Physics Vector from file ";
210              << "-th Physics Vector from file: << 
211       G4cerr << fileName << G4endl;               224       G4cerr << fileName << G4endl;
212 #endif                                         << 225 #endif          
213       fIn.close();                                226       fIn.close();
214       return false;                               227       return false;
215     }                                             228     }
216                                                   229 
217     // add a PhysicsVector to this PhysicsTabl    230     // add a PhysicsVector to this PhysicsTable
218     G4PhysCollection::push_back(pVec);            231     G4PhysCollection::push_back(pVec);
219     vecFlag.push_back(true);                      232     vecFlag.push_back(true);
220   }                                            << 233     
                                                   >> 234   } 
221   fIn.close();                                    235   fIn.close();
222   return true;                                    236   return true;
223 }                                                 237 }
224                                                   238 
225 // ------------------------------------------- << 239 std::ostream& operator<<(std::ostream& out, 
226 std::ostream& operator<<(std::ostream& out, G4 << 240                          G4PhysicsTable& right)
227 {                                                 241 {
228   // Printout Physics Vector                      242   // Printout Physics Vector
229   std::size_t i = 0;                           << 243   size_t i=0;
230   for(auto itr = right.cbegin(); itr != right. << 244   for (G4PhysicsTableIterator itr=right.begin(); itr!=right.end(); ++itr)
231   {                                               245   {
232     out << std::setw(8) << i << "-th Vector       246     out << std::setw(8) << i << "-th Vector   ";
233     if (nullptr == (*itr)) {                   << 247     out << ": Type    " << G4int((*itr)->GetType()) ;
234       out << "empty" << G4endl;                << 
235       ++i;                                     << 
236       continue;                                << 
237     }                                          << 
238     out << ": Type    " << G4int((*itr)->GetTy << 
239     out << ": Flag    ";                          248     out << ": Flag    ";
240     if(right.GetFlag(i))                       << 249     if (right.GetFlag(i))
241     {                                             250     {
242       out << " T";                                251       out << " T";
243     }                                          << 252     } 
244     else                                          253     else
245     {                                             254     {
246       out << " F";                                255       out << " F";
247     }                                          << 256     } 
248     out << G4endl;                                257     out << G4endl;
249     out << *(*itr);                               258     out << *(*itr);
250     ++i;                                       << 259     i +=1;
251   }                                               260   }
252   out << G4endl;                                  261   out << G4endl;
253   return out;                                  << 262   return out; 
254 }                                                 263 }
255                                                   264 
256 // ------------------------------------------- << 
257 void G4PhysicsTable::ResetFlagArray()             265 void G4PhysicsTable::ResetFlagArray()
258 {                                                 266 {
259   size_t tableSize = G4PhysCollection::size(); << 267   size_t tableSize = G4PhysCollection::size(); 
260   vecFlag.clear();                                268   vecFlag.clear();
261   for(std::size_t idx = 0; idx < tableSize; ++ << 269   for (size_t idx=0; idx<tableSize; idx++)
262   {                                               270   {
263     vecFlag.push_back(true);                      271     vecFlag.push_back(true);
264   }                                               272   }
265 }                                                 273 }
266                                                   274 
267 // ------------------------------------------- << 275 #include "G4PhysicsVectorType.hh"
268 G4PhysicsVector* G4PhysicsTable::CreatePhysics << 276 #include "G4LPhysicsFreeVector.hh"
                                                   >> 277 #include "G4PhysicsLogVector.hh"
                                                   >> 278 #include "G4PhysicsFreeVector.hh"
                                                   >> 279 #include "G4PhysicsOrderedFreeVector.hh"
                                                   >> 280 #include "G4PhysicsLinearVector.hh"
                                                   >> 281 #include "G4PhysicsLnVector.hh"
                                                   >> 282  
                                                   >> 283 G4PhysicsVector* G4PhysicsTable::CreatePhysicsVector(G4int type)
269 {                                                 284 {
270   G4PhysicsVector* pVector = nullptr;          << 285   G4PhysicsVector* pVector=0;
271   switch(type)                                 << 286   switch (type)
272   {                                               287   {
273     case T_G4PhysicsLinearVector:              << 288   case T_G4PhysicsLinearVector: 
274       pVector = new G4PhysicsLinearVector(spli << 289     pVector = new G4PhysicsLinearVector();
275       break;                                   << 290     break;
276                                                << 291 
277     case T_G4PhysicsLogVector:                 << 292   case T_G4PhysicsLogVector: 
278       pVector = new G4PhysicsLogVector(spline) << 293     pVector = new G4PhysicsLogVector();
279       break;                                   << 294     break;
280                                                << 295 
281     default:                                   << 296   case T_G4PhysicsLnVector: 
282       pVector = new G4PhysicsVector(spline);   << 297     pVector = new G4PhysicsLnVector();
283       break;                                   << 298     break;
                                                   >> 299 
                                                   >> 300   case T_G4PhysicsFreeVector: 
                                                   >> 301     pVector = new G4PhysicsFreeVector();
                                                   >> 302     break;
                                                   >> 303 
                                                   >> 304   case T_G4PhysicsOrderedFreeVector: 
                                                   >> 305     pVector = new G4PhysicsOrderedFreeVector();
                                                   >> 306     break;
                                                   >> 307 
                                                   >> 308   case T_G4LPhysicsFreeVector: 
                                                   >> 309     pVector = new G4LPhysicsFreeVector();
                                                   >> 310     break;
                                                   >> 311   
                                                   >> 312   default:
                                                   >> 313     break;
284   }                                               314   }
285   return pVector;                                 315   return pVector;
286 }                                                 316 }
287                                                   317