| [833] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4PhysicsTable.cc,v 1.15 2007/11/13 17:35:06 gcosmo Exp $
|
|---|
| [1228] | 28 | // GEANT4 tag $Name: geant4-09-03 $
|
|---|
| [833] | 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // ------------------------------------------------------------
|
|---|
| 32 | // GEANT 4 class implementation
|
|---|
| 33 | //
|
|---|
| 34 | // G4PhysicsTable
|
|---|
| 35 | //
|
|---|
| 36 | // ------------------------------------------------------------
|
|---|
| 37 |
|
|---|
| 38 | #include "G4PhysicsVector.hh"
|
|---|
| 39 | #include "G4PhysicsTable.hh"
|
|---|
| 40 | #include <iostream>
|
|---|
| 41 | #include <fstream>
|
|---|
| 42 | #include <iomanip>
|
|---|
| 43 |
|
|---|
| 44 | G4PhysicsTable::G4PhysicsTable()
|
|---|
| 45 | : G4PhysCollection()
|
|---|
| 46 | {
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | G4PhysicsTable::G4PhysicsTable(size_t cap)
|
|---|
| 50 | : G4PhysCollection()
|
|---|
| 51 | {
|
|---|
| 52 | reserve(cap);
|
|---|
| 53 | vecFlag.reserve(cap);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 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 |
|
|---|
| 78 | G4PhysicsTable::~G4PhysicsTable()
|
|---|
| 79 | {
|
|---|
| 80 | G4PhysCollection::clear();
|
|---|
| 81 | vecFlag.clear();
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | void G4PhysicsTable::resize(size_t siz, G4PhysicsVector* vec)
|
|---|
| 85 | {
|
|---|
| 86 | G4PhysCollection::resize(siz, vec);
|
|---|
| 87 | vecFlag.resize(siz, true);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | G4bool G4PhysicsTable::StorePhysicsTable(const G4String& fileName,
|
|---|
| 91 | G4bool ascii)
|
|---|
| 92 | {
|
|---|
| 93 | std::ofstream fOut;
|
|---|
| 94 |
|
|---|
| 95 | // open output file //
|
|---|
| 96 | if (!ascii)
|
|---|
| 97 | { fOut.open(fileName, std::ios::out|std::ios::binary); }
|
|---|
| 98 | else
|
|---|
| 99 | { fOut.open(fileName, std::ios::out); }
|
|---|
| 100 |
|
|---|
| 101 | // check if the file has been opened successfully
|
|---|
| 102 | if (!fOut)
|
|---|
| 103 | {
|
|---|
| 104 | #ifdef G4VERBOSE
|
|---|
| 105 | G4cerr << "G4PhysicsTable::StorePhysicsTable ";
|
|---|
| 106 | G4cerr << " Can not open file " << fileName << G4endl;
|
|---|
| 107 | #endif
|
|---|
| 108 | fOut.close();
|
|---|
| 109 | return false;
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | // Number of elements
|
|---|
| 113 | size_t tableSize = size();
|
|---|
| 114 | if (!ascii)
|
|---|
| 115 | {
|
|---|
| 116 | fOut.write( (char*)(&tableSize), sizeof tableSize);
|
|---|
| 117 | }
|
|---|
| 118 | else
|
|---|
| 119 | {
|
|---|
| 120 | fOut << tableSize << G4endl;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | // Physics Vector
|
|---|
| 124 | for (G4PhysicsTableIterator itr=begin(); itr!=end(); ++itr)
|
|---|
| 125 | {
|
|---|
| 126 | G4int vType = (*itr)->GetType();
|
|---|
| 127 | if (!ascii)
|
|---|
| 128 | {
|
|---|
| 129 | fOut.write( (char*)(&vType), sizeof vType);
|
|---|
| 130 | }
|
|---|
| 131 | else
|
|---|
| 132 | {
|
|---|
| 133 | fOut << vType << G4endl;
|
|---|
| 134 | }
|
|---|
| 135 | (*itr)->Store(fOut,ascii);
|
|---|
| 136 | }
|
|---|
| 137 | fOut.close();
|
|---|
| 138 | return true;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 | G4bool G4PhysicsTable::ExistPhysicsTable(const G4String& fileName) const
|
|---|
| 143 | {
|
|---|
| 144 | std::ifstream fIn;
|
|---|
| 145 | G4bool value=true;
|
|---|
| 146 | // open input file
|
|---|
| 147 | fIn.open(fileName,std::ios::in);
|
|---|
| 148 |
|
|---|
| 149 | // check if the file has been opened successfully
|
|---|
| 150 | if (!fIn)
|
|---|
| 151 | {
|
|---|
| 152 | value = false;
|
|---|
| 153 | }
|
|---|
| 154 | fIn.close();
|
|---|
| 155 | return value;
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | G4bool G4PhysicsTable::RetrievePhysicsTable(const G4String& fileName,
|
|---|
| 159 | G4bool ascii)
|
|---|
| 160 | {
|
|---|
| 161 | std::ifstream fIn;
|
|---|
| 162 | // open input file
|
|---|
| 163 | if (ascii)
|
|---|
| 164 | { fIn.open(fileName,std::ios::in|std::ios::binary); }
|
|---|
| 165 | else
|
|---|
| 166 | { fIn.open(fileName,std::ios::in);}
|
|---|
| 167 |
|
|---|
| 168 | // check if the file has been opened successfully
|
|---|
| 169 | if (!fIn)
|
|---|
| 170 | {
|
|---|
| 171 | #ifdef G4VERBOSE
|
|---|
| 172 | G4cerr << "G4PhysicsTable::RetrievePhysicsTable ";
|
|---|
| 173 | G4cerr << " Can not open file " << fileName << G4endl;
|
|---|
| 174 | #endif
|
|---|
| 175 | fIn.close();
|
|---|
| 176 | return false;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | // clear
|
|---|
| 180 | clearAndDestroy();
|
|---|
| 181 |
|
|---|
| 182 | // Number of elements
|
|---|
| 183 | size_t tableSize=0;
|
|---|
| 184 | if (!ascii)
|
|---|
| 185 | {
|
|---|
| 186 | fIn.read((char*)(&tableSize), sizeof tableSize);
|
|---|
| 187 | }
|
|---|
| 188 | else
|
|---|
| 189 | {
|
|---|
| 190 | fIn >> tableSize;
|
|---|
| 191 | }
|
|---|
| 192 | reserve(tableSize);
|
|---|
| 193 | vecFlag.clear();
|
|---|
| 194 |
|
|---|
| 195 | // Physics Vector
|
|---|
| 196 | for (size_t idx=0; idx<tableSize; ++idx)
|
|---|
| 197 | {
|
|---|
| 198 | G4int vType=0;
|
|---|
| 199 | if (!ascii)
|
|---|
| 200 | {
|
|---|
| 201 | fIn.read( (char*)(&vType), sizeof vType);
|
|---|
| 202 | }
|
|---|
| 203 | else
|
|---|
| 204 | {
|
|---|
| 205 | fIn >> vType;
|
|---|
| 206 | }
|
|---|
| 207 | G4PhysicsVector* pVec = CreatePhysicsVector(vType);
|
|---|
| 208 | if (pVec==0)
|
|---|
| 209 | {
|
|---|
| 210 | #ifdef G4VERBOSE
|
|---|
| 211 | G4cerr << "G4PhysicsTable::RetrievePhysicsTable ";
|
|---|
| 212 | G4cerr << " illegal Physics Vector type " << vType << " in ";
|
|---|
| 213 | G4cerr << fileName << G4endl;
|
|---|
| 214 | #endif
|
|---|
| 215 | fIn.close();
|
|---|
| 216 | return false;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | if (! (pVec->Retrieve(fIn,ascii)) )
|
|---|
| 220 | {
|
|---|
| 221 | #ifdef G4VERBOSE
|
|---|
| 222 | G4cerr << "G4PhysicsTable::RetrievePhysicsTable ";
|
|---|
| 223 | G4cerr << " error in retreiving " << idx << "-th Physics Vector from file ";
|
|---|
| 224 | G4cerr << fileName << G4endl;
|
|---|
| 225 | #endif
|
|---|
| 226 | fIn.close();
|
|---|
| 227 | return false;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | // add a PhysicsVector to this PhysicsTable
|
|---|
| 231 | G4PhysCollection::push_back(pVec);
|
|---|
| 232 | vecFlag.push_back(true);
|
|---|
| 233 |
|
|---|
| 234 | }
|
|---|
| 235 | fIn.close();
|
|---|
| 236 | return true;
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | std::ostream& operator<<(std::ostream& out,
|
|---|
| 240 | G4PhysicsTable& right)
|
|---|
| 241 | {
|
|---|
| 242 | // Printout Physics Vector
|
|---|
| 243 | size_t i=0;
|
|---|
| 244 | for (G4PhysicsTableIterator itr=right.begin(); itr!=right.end(); ++itr)
|
|---|
| 245 | {
|
|---|
| 246 | out << std::setw(8) << i << "-th Vector ";
|
|---|
| 247 | out << ": Type " << G4int((*itr)->GetType()) ;
|
|---|
| 248 | out << ": Flag ";
|
|---|
| 249 | if (right.GetFlag(i))
|
|---|
| 250 | {
|
|---|
| 251 | out << " T";
|
|---|
| 252 | }
|
|---|
| 253 | else
|
|---|
| 254 | {
|
|---|
| 255 | out << " F";
|
|---|
| 256 | }
|
|---|
| 257 | out << G4endl;
|
|---|
| 258 | out << *(*itr);
|
|---|
| 259 | i +=1;
|
|---|
| 260 | }
|
|---|
| 261 | out << G4endl;
|
|---|
| 262 | return out;
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | void G4PhysicsTable::ResetFlagArray()
|
|---|
| 266 | {
|
|---|
| 267 | size_t tableSize = G4PhysCollection::size();
|
|---|
| 268 | vecFlag.clear();
|
|---|
| 269 | for (size_t idx=0; idx<tableSize; idx++)
|
|---|
| 270 | {
|
|---|
| 271 | vecFlag.push_back(true);
|
|---|
| 272 | }
|
|---|
| 273 | }
|
|---|
| 274 |
|
|---|
| 275 | #include "G4PhysicsVectorType.hh"
|
|---|
| 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)
|
|---|
| 284 | {
|
|---|
| 285 | G4PhysicsVector* pVector=0;
|
|---|
| 286 | switch (type)
|
|---|
| 287 | {
|
|---|
| 288 | case T_G4PhysicsLinearVector:
|
|---|
| 289 | pVector = new G4PhysicsLinearVector();
|
|---|
| 290 | break;
|
|---|
| 291 |
|
|---|
| 292 | case T_G4PhysicsLogVector:
|
|---|
| 293 | pVector = new G4PhysicsLogVector();
|
|---|
| 294 | break;
|
|---|
| 295 |
|
|---|
| 296 | case T_G4PhysicsLnVector:
|
|---|
| 297 | pVector = new G4PhysicsLnVector();
|
|---|
| 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;
|
|---|
| 314 | }
|
|---|
| 315 | return pVector;
|
|---|
| 316 | }
|
|---|