Geant4.10
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
exrdmMaterial Class Reference

#include <exrdmMaterial.hh>

Public Member Functions

 exrdmMaterial ()
 
 ~exrdmMaterial ()
 
void AddMaterial (G4String, G4String, G4double, G4String, G4double tem=CLHEP::STP_Temperature, G4double pres=CLHEP::STP_Pressure)
 
G4MaterialGetMaterial (G4int i)
 
G4MaterialGetMaterial (G4String name)
 
G4int GetMaterialIndex (G4String)
 
G4int GetNbOfMaterial ()
 
void DeleteMaterial (G4int)
 
void DeleteMaterial (G4String)
 
void ListMaterial ()
 

Detailed Description

Definition at line 41 of file exrdmMaterial.hh.

Constructor & Destructor Documentation

exrdmMaterial::exrdmMaterial ( )

Definition at line 46 of file exrdmMaterial.cc.

References AddMaterial(), python.hepunit::cm3, density, g(), python.hepunit::kelvin, python.hepunit::mg, pascal, and python.hepunit::universe_mean_density.

47  : fMaterialMessenger(0)
48 {
49  fMaterial.clear();
50  fElement.clear();
51  fIsotope.clear();
52  // some default materials vacuum (0), air (1) and aluminium (2) defined here
53  // examples of vacuum
54  //
55  // G4double a,z;
56 
57  static G4bool bmat = false ;
58 
59  if (!bmat) {
60 
61  // vacuum
62  G4double density = universe_mean_density; //from PhysicalConstants.h
63  G4double pressure = 3.e-18*pascal;
64  G4double temperature = 2.73*kelvin;
65  AddMaterial("Vacuum", "H", density,"gas",temperature,pressure);
66  // air
67  density = 1.290*mg/cm3;
68  AddMaterial("Air", "N0.78-O0.22", density, "gas");
69 
70  // aluminium
71  density=2.700*g/cm3 ;
72  AddMaterial ("Aluminium", "Al", density,"");
73 
74  //silicon
75  density=2.3290*g/cm3 ;
76  AddMaterial ("Silicon", "Si", density,"");
77 
78  bmat = true;
79  }
80  // create commands for interactive definition of the geometry
81  fMaterialMessenger = new exrdmMaterialMessenger(this);
82 }
int universe_mean_density
Definition: hepunit.py:307
void AddMaterial(G4String, G4String, G4double, G4String, G4double tem=CLHEP::STP_Temperature, G4double pres=CLHEP::STP_Pressure)
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
bool G4bool
Definition: G4Types.hh:79
#define pascal
double G4double
Definition: G4Types.hh:76
exrdmMaterial::~exrdmMaterial ( )

Definition at line 85 of file exrdmMaterial.cc.

86 {
87  delete fMaterialMessenger;
88 }

Member Function Documentation

void exrdmMaterial::AddMaterial ( G4String  name,
G4String  formula,
G4double  density,
G4String  state,
G4double  tem = CLHEP::STP_Temperature,
G4double  pres = CLHEP::STP_Pressure 
)

Definition at line 91 of file exrdmMaterial.cc.

References G4Material::AddElement(), G4Element::AddIsotope(), python.hepunit::cm3, g(), G4cerr, G4cout, G4endl, G4Element::GetElement(), G4Isotope::GetIsotope(), kStateGas, kStateSolid, python.hepunit::mole, python.hepunit::perCent, and G4InuclParticleNames::s0.

Referenced by exrdmMaterial(), and exrdmMaterialMessenger::SetNewValue().

93 {
94  G4int isotope, Z;
95  size_t i;
96  for (i = 0; i<fMaterial.size(); i++) {
97  if (fMaterial[i]->GetName() == name) {
98  G4cerr <<" AddMaterial : material " <<name
99  <<" already exists." <<G4endl;
100  G4cerr <<"--> Command rejected." <<G4endl;
101  return;
102  }
103  }
104 
105  char *tokenPtr1 = NULL;
106  char *sname = NULL;
107  G4String s0, s1("0123456789");
108  G4String element, isotopename;
109  G4int ncomponents, natoms;
110  G4double fatoms = 0.;
111  size_t ls, id=0, ll, lr;
112  ncomponents = 0;
113 
114  sname = new char[strlen(formula)+1];
115  strcpy(sname,formula);
116  tokenPtr1 = strtok(sname,"-");
117 
118  while (tokenPtr1 != NULL) {
119  ncomponents++;
120  tokenPtr1 = strtok( NULL, "-");
121  }
122  delete[] sname;
123 
124  G4Material* aMaterial = 0;
125  G4cout << name <<" "<< formula << " " << density/(g/cm3) << " " << tem <<" "
126  <<pres << G4endl;
127 
128  if (state == "") {
129  aMaterial = new G4Material(name, density, ncomponents);
130  } else if (state == "solid" && tem > 0.) {
131  aMaterial = new G4Material(name, density, ncomponents,
132  kStateSolid, tem );
133  } else if (state == "gas" && pres > 0.) {
134  aMaterial = new G4Material(name, density, ncomponents,
135  kStateGas, tem, pres );
136  }
137  if (aMaterial == 0) {
138  G4cerr <<" AddMaterial : Name " <<name <<"." <<G4endl;
139  G4cerr <<"--> Command failed." <<G4endl;
140  return;
141  }
142 
143  sname=new char[strlen(formula)+1];
144  strcpy(sname,formula);
145  tokenPtr1 = strtok(sname,"-");
146 
147  while (tokenPtr1 != NULL) {
148  isotope = 0;
149  // G4cout << tokenPtr1 << G4endl;
150  s0 = G4String(tokenPtr1);
151  ls = s0.length();
152  ll = s0.find("(");
153  lr = s0.find(")");
154  if (ll == lr) {
155  id = s0.find_first_of(s1);
156  element = s0.substr(0,id);
157 
158  if (element.length() == 1) element.insert(0," ");
159  for (i = 0; i<110; i++) {
160  if (element == fELU[i]) break;
161  }
162  if (i == 110) {
163  for (i = 0; i<110; i++) {
164  if (element == fELL[i]) break;
165  }
166  if (i == 110) {
167  for (i = 0; i<110; i++) {
168  if (element == fEUU[i]) break;
169  }
170  }
171  }
172 
173  if (i == 110) {
174  G4cerr <<"AddMaterial : Invalid element in material formula."
175  <<element <<G4endl;
176  G4cerr <<"--> Command rejected." <<G4endl;
177 // delete aMaterial;
178 // fMaterial[NbMat] = NULL;
179  return;
180  }
181 
182  Z = i+1;
183  element = fELU[i];
184  if (id == std::string::npos) {
185  natoms = 1;
186  } else {
187  natoms = atoi((s0.substr(id,ls-id)).c_str());
188  }
189  if (natoms < 1) fatoms = atof((s0.substr(id,ls-id)).c_str());
190  // G4cout << " Elements = " << element << G4endl;
191  //G4cout << " Nb of atoms = " << natoms << G4endl;
192  } else {
193  element = s0.substr(0,ll);
194  isotope = atoi((s0.substr(ll+1,lr-ll)).c_str());
195  if (element.length() == 1) element.insert(0," ");
196  for (i = 0; i<110; i++) {
197  if (element == fELU[i]) break;
198  }
199  if (i == 110) {
200  for (i = 0; i<110; i++) {
201  if (element == fELL[i]) break;
202  }
203  if (i == 110) {
204  for (i = 0; i<110; i++) {
205  if (element == fEUU[i]) break;
206  }
207  }
208  }
209  if (i == 110) {
210  G4cerr <<"AddMaterial : Invalid element in material formula."
211  <<element <<G4endl;
212  G4cerr <<"--> Command rejected." <<G4endl;
213 // delete aMaterial;
214 // fMaterial[NbMat] = NULL;
215  return;
216  }
217 
218  Z = i+1;
219  element = fELU[i];
220  isotopename = element+s0.substr(ll+1,lr-ll-1);
221  if (lr == std::string::npos ) {
222  natoms = 1;
223  } else {
224  natoms = atoi((s0.substr(lr+1,ls-lr)).c_str());
225  }
226  if (natoms < 1) fatoms = atof((s0.substr(id,ls-id)).c_str());
227  if (fatoms == 0.) natoms = 1;
228  //
229  // G4cout << " Elements = " << element << G4endl;
230  // G4cout << " fIsotope Nb = " << isotope << G4endl;
231  // G4cout << " Nb of atoms = " << natoms << G4endl;
232  }
233  if (isotope != 0) {
234  if (G4Isotope::GetIsotope(isotopename) == NULL) {
235  G4Isotope* aIsotope = new G4Isotope(isotopename, Z, isotope, isotope*g/mole);
236  G4Element* aElement = new G4Element(isotopename, element, 1);
237  aElement->AddIsotope(aIsotope, 100.*perCent);
238  fIsotope.push_back(aIsotope);
239  if (natoms>0) {
240  aMaterial->AddElement(aElement, natoms);
241  } else {
242  aMaterial->AddElement(aElement, fatoms);
243  }
244  fElement.push_back(aElement);
245  } else {
246  if (natoms>0) {
247  aMaterial->AddElement( G4Element::GetElement(isotopename,false) , natoms);
248  } else {
249  aMaterial->AddElement( G4Element::GetElement(isotopename,false) , fatoms);
250  }
251  }
252  } else {
253  if ( G4Element::GetElement(element,false) == NULL) {
254  G4Element* aElement = new G4Element(element, element, Z, fA[Z-1]*g/mole);
255  if (natoms>0) {
256  aMaterial->AddElement(aElement, natoms);
257  } else {
258  aMaterial->AddElement(aElement, fatoms);
259  }
260  fElement.push_back(aElement);
261  } else {
262  if (natoms>0) {
263  aMaterial->AddElement( G4Element::GetElement(element,false) , natoms);
264  } else {
265  aMaterial->AddElement( G4Element::GetElement(element,false) , fatoms);
266  }
267  }
268  }
269  tokenPtr1 = strtok( NULL, "-");
270  // s0.empty();
271  //element.erase();
272  //
273  }
274 
275  delete[] sname;
276  fMaterial.push_back(aMaterial);
277  G4cout <<" fMaterial:" <<name <<" with formula: " <<formula <<" added! "
278  <<G4endl;
279  G4cout <<" Nb of fMaterial = " <<fMaterial.size() <<G4endl;
280  G4cout <<" Nb of fIsotope = " <<fIsotope.size() <<G4endl;
281  G4cout <<" Nb of fElement = " <<fElement.size() <<G4endl;
282 }
static G4Element * GetElement(G4String name, G4bool warning=true)
Definition: G4Element.cc:409
const XML_Char * name
int G4int
Definition: G4Types.hh:78
static G4Isotope * GetIsotope(const G4String &name, G4bool warning=false)
Definition: G4Isotope.cc:196
G4double density
Definition: TRTMaterials.hh:39
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
void AddIsotope(G4Isotope *isotope, G4double RelativeAbundance)
Definition: G4Element.cc:151
float perCent
Definition: hepunit.py:239
#define G4endl
Definition: G4ios.hh:61
void AddElement(G4Element *element, G4int nAtoms)
Definition: G4Material.cc:345
double G4double
Definition: G4Types.hh:76
G4GLOB_DLL std::ostream G4cerr
void exrdmMaterial::DeleteMaterial ( G4int  j)

Definition at line 285 of file exrdmMaterial.cc.

References G4cerr, and G4endl.

Referenced by exrdmMaterialMessenger::SetNewValue().

286 {
287  size_t i(j-1);
288  if (i > fMaterial.size()) {
289  G4cerr <<"DeleteMaterial : Invalid material index " <<j <<"." <<G4endl;
290  G4cerr <<"--> Command rejected." <<G4endl;
291  } else {
292  G4cerr <<"It seems there is no mechanism in G4 for deleting a material yet!"
293  <<G4endl;
294  G4cerr <<"--> Command rejected." <<G4endl;
295  }
296 }
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void exrdmMaterial::DeleteMaterial ( G4String  )

Definition at line 299 of file exrdmMaterial.cc.

References G4cerr, and G4endl.

300 {
301  G4cerr <<"It seems there is no mechanism in G4 for deleting a material yet!"
302  <<G4endl;
303  G4cerr <<"--> Command rejected." <<G4endl;
304 }
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
G4Material* exrdmMaterial::GetMaterial ( G4int  i)
inline

Definition at line 53 of file exrdmMaterial.hh.

53 {return fMaterial[i];};
G4Material* exrdmMaterial::GetMaterial ( G4String  name)
inline

Definition at line 54 of file exrdmMaterial.hh.

References G4Material::GetMaterial().

55  {return G4Material::GetMaterial(name);} ;
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:578
G4int exrdmMaterial::GetMaterialIndex ( G4String  name)

Definition at line 307 of file exrdmMaterial.cc.

308 {
309  size_t i ;
310  for (i = 0; i < fMaterial.size(); i++) {
311  if (fMaterial[i]->GetName() == name) break;
312  }
313  G4int k = G4int(i);
314  if (i == fMaterial.size()) k = -1;
315  return k;
316 }
const XML_Char * name
int G4int
Definition: G4Types.hh:78
G4int exrdmMaterial::GetNbOfMaterial ( )
inline

Definition at line 57 of file exrdmMaterial.hh.

57 {return fMaterial.size();};
void exrdmMaterial::ListMaterial ( )

Definition at line 319 of file exrdmMaterial.cc.

References G4BestUnit, G4cout, and G4endl.

Referenced by exrdmMaterialMessenger::SetNewValue().

320 {
321  G4cout <<" There are" <<std::setw(3) <<fMaterial.size()
322  <<" materials defined." <<G4endl;
323  for (size_t i = 0; i< fMaterial.size(); i++)
324  G4cout <<" fMaterial Index " <<std::setw(3) <<i+1 <<" "
325  <<std::setw(14) <<fMaterial[i]->GetName()
326  <<" density: " <<std::setw(6) <<std::setprecision(3)
327  <<G4BestUnit(fMaterial[i]->GetDensity(),"Volumic Mass") <<G4endl;
328  G4cout <<G4endl;
329 
330 }
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

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