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