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

#include <CCalMaterial.hh>

Inheritance diagram for CCalMaterial:
CCalAMaterial

Public Types

enum  FractionType { FTWeight, FTVolume }
 

Public Member Functions

 CCalMaterial (G4String mat, double dens, int nelem, CCalMaterial **constituents, double *weights, FractionType=FTWeight)
 
 CCalMaterial (const CCalMaterial &)
 
virtual ~CCalMaterial ()
 
G4String Name () const
 
double Density () const
 
int NElements () const
 
G4String Element (int i) const
 
double Weight (int i) const
 
G4bool operator== (const CCalMaterial &) const
 
G4bool operator!= (const CCalMaterial &) const
 
CCalMaterialoperator= (const CCalMaterial &)
 

Protected Member Functions

 CCalMaterial ()
 
void computeDensity (int nconst, CCalMaterial **constituents, double *weights, FractionType ft)
 
void closeMaterial ()
 

Protected Attributes

G4String name
 
double density
 
int nElem
 
G4StringtheElements
 
double * theWeights
 

Friends

std::ostream & operator<< (std::ostream &, const CCalMaterial &)
 

Detailed Description

Definition at line 36 of file CCalMaterial.hh.

Member Enumeration Documentation

Enumerator
FTWeight 
FTVolume 

Definition at line 41 of file CCalMaterial.hh.

Constructor & Destructor Documentation

CCalMaterial::CCalMaterial ( G4String  mat,
double  dens,
int  nelem,
CCalMaterial **  constituents,
double *  weights,
FractionType  ft = FTWeight 
)

Definition at line 35 of file CCalMaterial.cc.

References closeMaterial(), computeDensity(), Density(), density, Element(), FTWeight, nElem, NElements(), theElements, theWeights, and Weight().

37  : name(mat), density(dens) {
38  nElem = 0;
39 
40  int i=0;
41  for (i=0; i<nconst; i++)
42  nElem += constituents[i]->NElements();
43 
44  theElements = new G4String[nElem];
45  theWeights = new double[nElem];
46 
47  double factor;
48  int nelem=0;
49  for (i=0; i<nconst; i++) {
50  if (ft==FTWeight)
51  factor=1.0;
52  else
53  factor=constituents[i]->Density();
54  for (int j=0; j<constituents[i]->NElements(); j++) {
55  theElements[nelem] = constituents[i]->Element(j);
56  theWeights[nelem] = constituents[i]->Weight(j)* weights[i] * factor;
57  nelem++;
58  }
59  }
60 
61  if (density<0) { //Let's compute density
62  computeDensity(nconst, constituents, weights, ft);
63  }
64  closeMaterial();
65 }
int NElements() const
Definition: CCalMaterial.hh:53
double Weight(int i) const
Definition: CCalMaterial.hh:55
G4String name
Definition: CCalMaterial.hh:70
G4String * theElements
Definition: CCalMaterial.hh:73
void computeDensity(int nconst, CCalMaterial **constituents, double *weights, FractionType ft)
Definition: CCalMaterial.cc:84
double Density() const
Definition: CCalMaterial.hh:52
G4String Element(int i) const
Definition: CCalMaterial.hh:54
void closeMaterial()
double density
Definition: CCalMaterial.hh:71
double * theWeights
Definition: CCalMaterial.hh:74
CCalMaterial::CCalMaterial ( const CCalMaterial mat)

Definition at line 67 of file CCalMaterial.cc.

References nElem, theElements, and theWeights.

67  :
68  name(mat.name), density(mat.density), nElem(mat.nElem) {
69  theElements = new G4String[nElem];
70  theWeights = new double[nElem];
71  for (int i=0; i<nElem; i++){
72  theElements[i]=mat.theElements[i];
73  theWeights[i]=mat.theWeights[i];
74  }
75 }
G4String name
Definition: CCalMaterial.hh:70
G4String * theElements
Definition: CCalMaterial.hh:73
double density
Definition: CCalMaterial.hh:71
double * theWeights
Definition: CCalMaterial.hh:74
CCalMaterial::~CCalMaterial ( )
virtual

Definition at line 77 of file CCalMaterial.cc.

References theElements, and theWeights.

77  {
78  if (theElements)
79  delete[] theElements;
80  if (theWeights)
81  delete[] theWeights;
82 }
G4String * theElements
Definition: CCalMaterial.hh:73
double * theWeights
Definition: CCalMaterial.hh:74
CCalMaterial::CCalMaterial ( )
inlineprotected

Definition at line 63 of file CCalMaterial.hh.

63 {} //Default constructor

Member Function Documentation

void CCalMaterial::closeMaterial ( )
protected

Definition at line 129 of file CCalMaterial.cc.

References G4cout, G4endl, nElem, theElements, and theWeights.

Referenced by CCalAMaterial::CCalAMaterial(), and CCalMaterial().

129  {
130  int trueConst=0;
131 
132  double norm=0;
133 
134  for (int i=0; i<nElem; i++) {
135  norm+=theWeights[i];
136  if (theElements[i]!="") {
137  trueConst++;
138  for (int j=i+1; j<nElem; j++) {
139  if(theElements[i]==theElements[j]){
140  theWeights[i]+=theWeights[j];
141  theElements[j]="";
142  }
143  }//for j
144  } //if
145  }//for i
146 
147  if (trueConst != nElem) {
148  G4String* newConst = new G4String[trueConst];
149  double* newWeight = new double[trueConst];
150 
151  int newi=0;
152  for(int i=0; i<nElem; i++){
153  if (theElements[i]!="") {
154  newConst[newi] = theElements[i];
155  newWeight[newi] = theWeights[i]/norm;
156  newi++;
157  }
158  }
159 
160 #ifdef debug
161  G4cout << "\tGoing from " << nElem <<" constituents to " << trueConst << G4endl;
162 #endif
163  nElem=trueConst;
164 
165  delete[] theElements;
166  delete[] theWeights;
167 
168  theElements=newConst;
169  theWeights=newWeight;
170  }
171  else { //Let's normalize the weights
172  for (int i=0; i<nElem; i++)
173  theWeights[i] = theWeights[i]/norm;
174  }
175 }
G4String * theElements
Definition: CCalMaterial.hh:73
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
double * theWeights
Definition: CCalMaterial.hh:74
void CCalMaterial::computeDensity ( int  nconst,
CCalMaterial **  constituents,
double *  weights,
FractionType  ft 
)
protected

Definition at line 84 of file CCalMaterial.cc.

References Density(), density, and FTWeight.

Referenced by CCalAMaterial::CCalAMaterial(), and CCalMaterial().

86  {
87  double mass=0;
88  double volume=0;
89  for (int i=0; i<nconst; i++) {
90  if (ft==FTWeight) {
91  mass+=weights[i];
92  volume+=(weights[i]/constituents[i]->Density());
93  }
94  else { //by volume
95  mass+=(weights[i]*constituents[i]->Density());
96  volume+=weights[i];
97  }
98  }
99  density=mass/volume;
100 }
double Density() const
Definition: CCalMaterial.hh:52
double density
Definition: CCalMaterial.hh:71
double CCalMaterial::Density ( ) const
inline

Definition at line 52 of file CCalMaterial.hh.

References density.

Referenced by CCalMaterial(), computeDensity(), and CCalMaterialFactory::findMaterial().

52 {return density;} //Density in g/cm3.
double density
Definition: CCalMaterial.hh:71
G4String CCalMaterial::Element ( int  i) const
inline

Definition at line 54 of file CCalMaterial.hh.

References theElements.

Referenced by CCalAMaterial::CCalAMaterial(), CCalMaterial(), and CCalMaterialFactory::findMaterial().

54 {return theElements[i];} //Should be protected.
G4String * theElements
Definition: CCalMaterial.hh:73
G4String CCalMaterial::Name ( ) const
inline

Definition at line 51 of file CCalMaterial.hh.

References name.

Referenced by CCalMaterialFactory::findMaterial().

51 {return name;} //Material name.
G4String name
Definition: CCalMaterial.hh:70
int CCalMaterial::NElements ( ) const
inline

Definition at line 53 of file CCalMaterial.hh.

References nElem.

Referenced by CCalAMaterial::CCalAMaterial(), CCalMaterial(), and CCalMaterialFactory::findMaterial().

53 {return nElem;} //Number of Elements.
G4bool CCalMaterial::operator!= ( const CCalMaterial mat) const

Definition at line 125 of file CCalMaterial.cc.

References name.

125  {
126  return (name!=mat.name);
127 }
G4String name
Definition: CCalMaterial.hh:70
const XML_Char * name
CCalMaterial & CCalMaterial::operator= ( const CCalMaterial mat)

Definition at line 102 of file CCalMaterial.cc.

References density, name, nElem, theElements, and theWeights.

102  {
103  if(theElements)
104  delete[] theElements;
105  if(theWeights)
106  delete[] theWeights;
107 
108  name=mat.name;
109  density=mat.density;
110  nElem=mat.nElem;
111 
112  theElements = new G4String[nElem];
113  theWeights = new double[nElem];
114  for (int i=0; i<nElem; i++){
115  theElements[i]=mat.theElements[i];
116  theWeights[i]=mat.theWeights[i];
117  }
118  return *this;
119 }
G4String name
Definition: CCalMaterial.hh:70
const XML_Char * name
G4String * theElements
Definition: CCalMaterial.hh:73
double density
Definition: CCalMaterial.hh:71
double * theWeights
Definition: CCalMaterial.hh:74
G4bool CCalMaterial::operator== ( const CCalMaterial mat) const

Definition at line 121 of file CCalMaterial.cc.

References name.

121  {
122  return (name==mat.name);
123 }
G4String name
Definition: CCalMaterial.hh:70
const XML_Char * name
double CCalMaterial::Weight ( int  i) const
inline

Definition at line 55 of file CCalMaterial.hh.

References theWeights.

Referenced by CCalAMaterial::CCalAMaterial(), CCalMaterial(), and CCalMaterialFactory::findMaterial().

55 {return theWeights[i];} //Should be protected.
double * theWeights
Definition: CCalMaterial.hh:74

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const CCalMaterial mat 
)
friend

Definition at line 177 of file CCalMaterial.cc.

177  {
178  os << mat.name << G4endl;
179  os << "Density= " << mat.density << " g/cm3. Number of Elements: "
180  << mat.nElem << G4endl;
181  for (int i=0; i<mat.nElem; i++)
182  os << '\t' << mat.theElements[i] << '\t' << mat.theWeights[i] << G4endl;
183  return os;
184 }
G4String name
Definition: CCalMaterial.hh:70
G4String * theElements
Definition: CCalMaterial.hh:73
#define G4endl
Definition: G4ios.hh:61
double density
Definition: CCalMaterial.hh:71
double * theWeights
Definition: CCalMaterial.hh:74

Field Documentation

double CCalMaterial::density
protected
G4String CCalMaterial::name
protected
int CCalMaterial::nElem
protected
G4String* CCalMaterial::theElements
protected
double* CCalMaterial::theWeights
protected

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