Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
CCalMaterialFactory Class Reference

#include <CCalMaterialFactory.hh>

Public Types

enum  MatDescription { byWeight, byVolume, byAtomic }
 

Public Member Functions

 ~CCalMaterialFactory ()
 
G4MaterialfindMaterial (const G4String &) const
 
G4ElementfindElement (const G4String &) const
 
G4ElementaddElement (const G4String &, const G4String &, G4double, G4double, G4double)
 
G4MaterialaddMaterial (const G4String &nam, G4double density, G4int nconst, G4String mats[], G4double prop[], MatDescription md=byWeight)
 
void readElements (const G4String &)
 
void readMaterials (const G4String &)
 

Static Public Member Functions

static CCalMaterialFactorygetInstance (const G4String &, const G4String &)
 
static CCalMaterialFactorygetInstance (const G4String &)
 
static CCalMaterialFactorygetInstance ()
 

Protected Member Functions

void readElements (std::ifstream &)
 
void readMaterials (std::ifstream &)
 

Detailed Description

Definition at line 47 of file CCalMaterialFactory.hh.

Member Enumeration Documentation

Constructor & Destructor Documentation

CCalMaterialFactory::~CCalMaterialFactory ( )

Definition at line 96 of file CCalMaterialFactory.cc.

96  {
97  CCalMaterialTable::iterator ite;
98  for(ite = theCCalMaterials.begin(); ite != theCCalMaterials.end(); ite++ ){
99  delete *ite;
100  }
101  theCCalMaterials.clear();
102  CCalAMaterialTable::iterator itea;
103  for(itea = theCCalAMaterials.begin(); itea != theCCalAMaterials.end();
104  itea++ ){
105  delete *itea;
106  }
107  theCCalAMaterials.clear();
108 }

Member Function Documentation

G4Element * CCalMaterialFactory::addElement ( const G4String name,
const G4String symbol,
G4double  Z,
G4double  A,
G4double  density 
)

Definition at line 160 of file CCalMaterialFactory.cc.

References g(), G4cout, G4endl, and python.hepunit::mole.

Referenced by readElements().

163  {
164 
165  G4Element* theEl = new G4Element(name, symbol, Z, A*g/mole);
166  //Make it also as a material.
167  CCalAMaterial* theMat = new CCalAMaterial(name,A,density);
168  theCCalAMaterials.push_back(theMat);
169 
170 #ifdef ddebug
171  G4cout << "Element " << name << " created!" << G4endl;
172 #endif
173  return theEl;
174 }
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4Material * CCalMaterialFactory::addMaterial ( const G4String nam,
G4double  density,
G4int  nconst,
G4String  mats[],
G4double  prop[],
MatDescription  md = byWeight 
)

Definition at line 177 of file CCalMaterialFactory.cc.

References findMaterial().

182  {
183  addCCalMaterial(name, density, nconst, mats, prop, md);
184  return findMaterial(name);
185 }
const XML_Char * name
G4double density
Definition: TRTMaterials.hh:39
G4Material * findMaterial(const G4String &) const
G4Element * CCalMaterialFactory::findElement ( const G4String mat) const

Definition at line 147 of file CCalMaterialFactory.cc.

References G4cout, G4endl, and G4Element::GetElementTable().

Referenced by findMaterial().

147  {
148  const G4ElementTable theElements = *(G4Element::GetElementTable());
149  for (unsigned int i=0; i<theElements.size(); i++)
150  if (theElements[i]->GetName()==mat){
151 #ifdef ddebug
152  G4cout << "Element " << mat << " found!" << G4endl;
153 #endif
154  return theElements[i];
155  }
156  return 0;
157 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
std::vector< G4Element * > G4ElementTable
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:395
G4Material * CCalMaterialFactory::findMaterial ( const G4String mat) const

Definition at line 111 of file CCalMaterialFactory.cc.

References G4Material::AddElement(), python.hepunit::cm3, CCalMaterial::Density(), CCalMaterial::Element(), findElement(), g(), G4cerr, G4cout, G4endl, CCalMaterial::Name(), CCalMaterial::NElements(), and CCalMaterial::Weight().

Referenced by addMaterial(), CCalG4Hcal::constructAbsorberLayer(), CCalG4Hall::constructIn(), CCalG4Hcal::constructIn(), and CCalG4Hcal::constructScintillatorLayer().

111  {
112  G4Material* theMat=findG4Material(mat);
113 
114  if (theMat) {
115 #ifdef ddebug
116  G4cout << "Material " << mat << " already defined. Returning previous "
117  << "instance." << G4endl;
118 #endif
119  return theMat;
120  } else {
121  CCalMaterial* CCalmat=findCCalMaterial(mat);
122  if (CCalmat){
123  G4Material* G4Mat = new G4Material(CCalmat->Name(),
124  CCalmat->Density()*g/cm3,
125  CCalmat->NElements());
126  for(G4int i=0; i<CCalmat->NElements(); i++) {
127  G4Element* elem = findElement(CCalmat->Element(i));
128  if (!elem) {
129  G4cerr << " Could not build material " << mat << "." << G4endl;
130  exit(-10);
131  }
132  G4Mat->AddElement(elem, CCalmat->Weight(i));
133  }
134 #ifdef ddebug
135  G4cout << "Material " << mat << " has been built successfully." << G4endl;
136 #endif
137  return G4Mat;
138  } else {
139  G4cerr << "ERROR: Material " << mat << " not found in CCal database!!!"
140  << G4endl;
141  return 0;
142  }
143  }
144 }
int NElements() const
Definition: CCalMaterial.hh:53
double Weight(int i) const
Definition: CCalMaterial.hh:55
G4String Name() const
Definition: CCalMaterial.hh:51
int G4int
Definition: G4Types.hh:78
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
double Density() const
Definition: CCalMaterial.hh:52
G4String Element(int i) const
Definition: CCalMaterial.hh:54
#define G4endl
Definition: G4ios.hh:61
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:345
G4Element * findElement(const G4String &) const
G4GLOB_DLL std::ostream G4cerr
CCalMaterialFactory * CCalMaterialFactory::getInstance ( const G4String matfile,
const G4String mixfile 
)
static

Definition at line 53 of file CCalMaterialFactory.cc.

References G4cerr, G4endl, and getInstance().

54  {
55  if ((matfile=="" || matfile==elementfile) &&
56  (mixfile=="" || mixfile==mixturefile))
57  return getInstance();
58  else if ((matfile != "" && elementfile != "" && matfile != elementfile) ||
59  (mixfile != "" && mixturefile != "" && mixfile != mixturefile)) {
60  G4cerr << "ERROR: Trying to get materials from " << matfile << " and "
61  << mixfile << " while previously were retrieved from "
62  << elementfile << " and " << mixturefile << "." << G4endl;
63  return 0;
64  } else {
65  if (elementfile == "")
66  elementfile=matfile;
67  if (mixturefile == "")
68  mixturefile=mixfile;
69  return getInstance();
70  }
71 }
#define G4endl
Definition: G4ios.hh:61
static CCalMaterialFactory * getInstance()
G4GLOB_DLL std::ostream G4cerr
CCalMaterialFactory * CCalMaterialFactory::getInstance ( const G4String matfile)
static

Definition at line 74 of file CCalMaterialFactory.cc.

References getInstance().

74  {
75  return getInstance(matfile,matfile);
76 }
static CCalMaterialFactory * getInstance()
CCalMaterialFactory * CCalMaterialFactory::getInstance ( )
static

Definition at line 79 of file CCalMaterialFactory.cc.

References G4cerr, and G4endl.

Referenced by CCalDetectorConstruction::Construct(), CCalG4Hcal::constructAbsorberLayer(), CCalG4Hall::constructIn(), CCalG4Hcal::constructIn(), CCalG4Hcal::constructScintillatorLayer(), and getInstance().

79  {
80  if (elementfile=="" || mixturefile=="") {
81  G4cerr << "ERROR: You haven't defined files to be used for materials in "
82  << "CCalMaterialFactory::getInstance(const G4String&,const G4String&)"
83  << G4endl;
84  return 0;
85  }
86 
87  if (instance==0) {
88  instance = new CCalMaterialFactory;
89  return instance;
90  }
91  else
92  return instance;
93 }
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalMaterialFactory::readElements ( const G4String matfile)

Definition at line 188 of file CCalMaterialFactory.cc.

References findDO(), G4cerr, G4cout, G4endl, and openGeomFile().

188  {
189 
190  G4String path = getenv("CCAL_GLOBALPATH");
191  G4cout << " ==> Opening file " << matfile << " to read elements..." << G4endl;
192  std::ifstream is;
193  bool ok = openGeomFile(is, path, matfile);
194  if (!ok) {
195  G4cerr << "ERROR: Could not open file " << matfile << G4endl;
196  return;
197  }
198 
199  // Find *DO GMAT
200  findDO(is, G4String("GMAT"));
201 
202  readElements(is);
203 
204  is.close();
205 }
void readElements(const G4String &)
bool openGeomFile(std::ifstream &is, const G4String &pathname, const G4String &filename)
Definition: CCalutils.cc:116
std::ifstream & findDO(std::ifstream &, const G4String &)
Definition: CCalutils.cc:72
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalMaterialFactory::readElements ( std::ifstream &  is)
protected

Definition at line 338 of file CCalMaterialFactory.cc.

References addElement(), density, G4cout, G4endl, G4Element::GetElementTable(), jump(), readName(), and symbol.

338  {
340 
341  G4cout << " ==> Reading elements... " << G4endl;
342 #ifdef debug
343  G4cout << " Element \tsymbol\tA\tZ\tdensity\tX_0 abs_l"<< G4endl;
344 #endif
345  //There should come the list of materials. #. Defines a comment
346  //*DO defines the beguining of the Mixes block.
347 
348  readName(is,name);
349  while (name != "*ENDDO") {
350  //It should be an element definition
351  G4double A, Z, density;
352  is >> symbol >> A >> Z >> density >> jump;
353 #ifdef debug
354  G4cout << " " << name << " \t" << symbol << "\t"
355  << A << "\t" << Z << "\t" << density << G4endl;
356 #endif
357  addElement(name, symbol, Z, A, density);
358  readName(is,name);
359  };
360  G4cout << " " << G4Element::GetElementTable()->size()
361  << " elements read from file" << G4endl << G4endl;
362 }
G4String symbol
Definition: TRTMaterials.hh:40
G4Element * addElement(const G4String &, const G4String &, G4double, G4double, G4double)
const XML_Char * name
std::istream & jump(std::istream &)
Definition: CCalutils.cc:95
G4double density
Definition: TRTMaterials.hh:39
std::ifstream & readName(std::ifstream &, G4String &)
Definition: CCalutils.cc:53
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:395
void CCalMaterialFactory::readMaterials ( const G4String matfile)

Definition at line 208 of file CCalMaterialFactory.cc.

References findDO(), G4cerr, G4cout, G4endl, and openGeomFile().

208  {
209 
210  G4String path = getenv("CCAL_GLOBALPATH");
211  G4cout << " ==> Opening file " << matfile << " to read materials..." << G4endl;
212  std::ifstream is;
213  bool ok = openGeomFile(is, path, matfile);
214  if (!ok) {
215  G4cerr << "ERROR: Could not open file " << matfile << G4endl;
216  return;
217  }
218 
219  // Find *DO GMIX
220  findDO(is, G4String("GMIX"));
221 
222  readMaterials(is);
223 
224  is.close();
225 }
bool openGeomFile(std::ifstream &is, const G4String &pathname, const G4String &filename)
Definition: CCalutils.cc:116
std::ifstream & findDO(std::ifstream &, const G4String &)
Definition: CCalutils.cc:72
G4GLOB_DLL std::ostream G4cout
void readMaterials(const G4String &)
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void CCalMaterialFactory::readMaterials ( std::ifstream &  is)
protected

Definition at line 365 of file CCalMaterialFactory.cc.

References byAtomic, byVolume, byWeight, g(), G4cout, G4endl, jump(), python.hepunit::kelvin, kStateGas, python.hepunit::mole, pascal, readName(), and python.hepunit::universe_mean_density.

365  {
366  G4String name, matname;
367 
368  G4cout << " ==> Reading materials... " << G4endl;
369 
370  //Take into account the special case of vacuum...
371 #ifdef debug
372  G4cout <<" \"Vacuum\"" << G4endl;
373 #endif
374  G4double density = universe_mean_density; //from PhysicalConstants.h
375  G4double pressure = 1.E-19*pascal;
376  G4double temperature = 0.1*kelvin;
377  new G4Material("Vacuum", /*Z=*/ 1., /*A=*/ 1.01*g/mole,
378  density, kStateGas, temperature, pressure);
379 
380  //There should come the list of materials. #. Defines a comment
381  //*ENDDO defines the block.
382  readName(is,name);
383  while (name != "*ENDDO") {
384  //It should be a material definition
385  matname=name;
386  G4int nElem;
387  G4double dens;
388  is >> nElem >> dens >> jump;
389 
390 #ifdef debug
391  G4cout <<" " << matname
392  << " made of " << nElem
393  << " elements. Density=" << dens
394  << G4endl;
395 #endif
396 
397  G4int absnelem = std::abs(nElem);
398 
399  G4String* mats = new G4String[absnelem];
400  G4double* weights = new G4double[absnelem];
401 
402  G4double prop;
403  for(int i=0; i<absnelem; i++) {
404  readName(is, name);
405  is >> prop >> jump;
406  mats[i]=name;
407  weights[i]=std::abs(prop);
408  } //for...
409  MatDescription md;
410  if (nElem>0 && prop<0)
411  md = byAtomic;
412  else if (nElem>0)
413  md = byWeight;
414  else
415  md = byVolume;
416 
417  addCCalMaterial(matname, dens, absnelem, mats, weights, md);
418  delete[] mats;
419  delete[] weights;
420 
421  readName(is,name);
422  }; //while
423 
424  G4cout << " " << theCCalMaterials.size() << " materials read from "
425  << mixturefile << G4endl << G4endl;
426 }
int universe_mean_density
Definition: hepunit.py:307
const XML_Char * name
std::istream & jump(std::istream &)
Definition: CCalutils.cc:95
int G4int
Definition: G4Types.hh:78
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
std::ifstream & readName(std::ifstream &, G4String &)
Definition: CCalutils.cc:53
G4GLOB_DLL std::ostream G4cout
#define pascal
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76

The documentation for this class was generated from the following files: