Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

LCDG4MaterialMgr Class Reference

#include <LCDG4MaterialMgr.hh>

Collaboration diagram for LCDG4MaterialMgr:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 LCDG4MaterialMgr ()
 ~LCDG4MaterialMgr ()
void Init ()
G4Material * GetMaterial (const char *matname)
G4Material * SetMaterial (const char *matname)
G4Element * GetElement (const char *matname)
G4Element * SetElement (const char *matname)

Private Attributes

std::list< LCDG4Material * > m_material_array
std::list< LCDG4Element * > m_element_array

Constructor & Destructor Documentation

LCDG4MaterialMgr::LCDG4MaterialMgr  ) 
 

Definition at line 14 of file LCDG4MaterialMgr.cc.

00014                                    {
00015 }

LCDG4MaterialMgr::~LCDG4MaterialMgr  ) 
 

Definition at line 20 of file LCDG4MaterialMgr.cc.

References m_element_array, and m_material_array.

00020                                    {
00021   LCDG4Element* pel = 0;
00022   LCDG4Material* pmat = 0;
00023 
00024   // cleanup element array
00025   list<LCDG4Element*>::iterator iel = m_element_array.begin();
00026   for( ; iel != m_element_array.end(); ++iel ) {
00027     pel = *iel;
00028     if(pel) {
00029       delete pel;
00030       pel=0;
00031     }
00032   }
00033 //   m_element_array.clear();
00034 
00035   // cleanup material array
00036   list<LCDG4Material*>::iterator imat = m_material_array.begin();
00037   for( ; imat != m_material_array.end(); ++imat ) {
00038     pmat = *imat;
00039     if(pmat) {
00040       delete pmat;
00041       pmat=0;
00042     }
00043   }
00044 //   m_material_array.clear();  
00045 }


Member Function Documentation

G4Element * LCDG4MaterialMgr::GetElement const char *  matname  ) 
 

Definition at line 89 of file LCDG4MaterialMgr.cc.

References LCDG4Element::GetElement(), m_element_array, and SetElement().

Referenced by SetMaterial().

00090 {
00091   G4String elmname_given(elmname);
00092   if( elmname[1]==' ' ) elmname_given = elmname[0];
00093 //   G4cout<< "GetElement: elmname-given = <"<< elmname_given.data() <<">\n";
00094 
00095   G4Element*    g4elm = 0;
00096   LCDG4Element* lcdelm = 0;
00097 
00098   list<LCDG4Element*>::iterator elm_iter;
00099 
00100   for(elm_iter=m_element_array.begin();
00101       elm_iter!=m_element_array.end(); ++elm_iter)
00102     {
00103       lcdelm = *elm_iter;
00104       G4Element* test = lcdelm->GetElement();
00105       G4String name = test->GetSymbol();
00106       if(name == elmname_given) {
00107         g4elm = lcdelm->GetElement();
00108         break;
00109       }
00110     }
00111   if(g4elm == 0) { g4elm = SetElement(elmname_given.data()); }
00112 
00113   return g4elm;
00114 }

G4Material * LCDG4MaterialMgr::GetMaterial const char *  matname  ) 
 

Definition at line 57 of file LCDG4MaterialMgr.cc.

References LCDG4Material::GetMaterial(), m_material_array, and SetMaterial().

Referenced by LCDXML2G4DetConst::Construct().

00058 {
00059   G4String matname_given(matname);
00060 //   G4cout<< "GetMaterial: matname-given = "<< matname << G4endl;
00061 
00062   G4Material*   g4mat = 0;
00063   LCDG4Material*        lcdmat = 0;
00064 
00065   list<LCDG4Material*>::iterator        mat_iter;
00066 
00067   for(mat_iter=m_material_array.begin(); mat_iter!=m_material_array.end(); ++mat_iter)
00068     {
00069       lcdmat = *mat_iter;
00070       G4Material* test = lcdmat->GetMaterial();
00071       G4String name = test->GetName();
00072 
00073 //       G4cout << "Searching for material-->" << name << endl;
00074       if(name == matname_given) {
00075 //      G4cout << "Material:" << name << " has been found!" << endl;
00076         g4mat = lcdmat->GetMaterial();
00077         break;
00078       }
00079     }
00080   if(g4mat == 0) { g4mat = SetMaterial(matname); }
00081 
00082   return g4mat;
00083 }

void LCDG4MaterialMgr::Init  ) 
 

Definition at line 50 of file LCDG4MaterialMgr.cc.

Referenced by LCDXML2G4DetConst::Construct().

00050                             {
00051 }

G4Element * LCDG4MaterialMgr::SetElement const char *  matname  ) 
 

Definition at line 230 of file LCDG4MaterialMgr.cc.

References m_element_array.

Referenced by GetElement().

00230                                                            {
00231 
00232   G4String elmname_given(elmname);
00233 //   G4cout << "Setting element--> <" << elmname_given.data()<< '>'<< endl;
00234 
00235   G4double a, iz;
00236   G4String name, symbol;
00237 
00238   G4Element*    g4elm=0;
00239   LCDG4Element* lcdelm=0;
00240 
00241   if ( elmname_given=="H" ) {
00242     a=1.00794*g/mole;
00243     g4elm  = new G4Element(name="Hydrogen",symbol="H",iz=1.,a);
00244     lcdelm = new LCDG4Element(g4elm);
00245     m_element_array.push_back(lcdelm);
00246   }
00247 
00248   else if ( elmname_given=="C" ) {
00249     a=12.0107*g/mole;
00250     g4elm  = new G4Element(name="Carbon",symbol="C",iz=6.,a);
00251     lcdelm = new LCDG4Element(g4elm);
00252     m_element_array.push_back(lcdelm);
00253   }
00254 
00255   else if ( elmname_given=="N" ) {
00256     a=14.00674*g/mole;
00257     g4elm  = new G4Element(name="Nitrogen",symbol="N",iz=7.,a);
00258     lcdelm = new LCDG4Element(g4elm);
00259     m_element_array.push_back(lcdelm);
00260   }
00261 
00262   else if ( elmname_given=="O" ) {
00263     a=15.9994*g/mole;
00264     g4elm  = new G4Element(name="Oxygen",symbol="O",iz=8.,a);
00265     lcdelm = new LCDG4Element(g4elm);
00266     m_element_array.push_back(lcdelm);
00267   }
00268 
00269   else if ( elmname_given=="B") {
00270     a=10.8110*g/mole;
00271     g4elm  = new G4Element(name="Boron",symbol="B",iz=5.,a);
00272     lcdelm = new LCDG4Element(g4elm);
00273     m_element_array.push_back(lcdelm);
00274   }
00275 
00276   else if ( (elmname_given=="NA") || (elmname_given=="Na")) {
00277     a=22.9898*g/mole;
00278     g4elm  = new G4Element(name="Sodium",symbol="Na",iz=11.,a);
00279     lcdelm = new LCDG4Element(g4elm);
00280     m_element_array.push_back(lcdelm);
00281   }
00282 
00283   else if ( elmname_given=="F") {
00284     a=18.9984*g/mole;
00285     g4elm  = new G4Element(name="Fluorine",symbol="F",iz=9.,a);
00286     lcdelm = new LCDG4Element(g4elm);
00287     m_element_array.push_back(lcdelm);
00288   }
00289 
00290   else if ( elmname_given=="Cl") {
00291     a=35.4527*g/mole;
00292     g4elm  = new G4Element(name="Chlorine",symbol="Cl",iz=17.,a);
00293     lcdelm = new LCDG4Element(g4elm);
00294     m_element_array.push_back(lcdelm);
00295   }
00296 
00297   else if ( elmname_given == "Ne" || elmname_given == "NE" ) {
00298     a=20.1797*g/mole;
00299     g4elm  = new G4Element(name="Neon",symbol="Ne",iz=10.,a);
00300     lcdelm = new LCDG4Element(g4elm);
00301     m_element_array.push_back(lcdelm);
00302   }
00303 
00304   else if (elmname_given == "Al" || elmname_given == "AL") {
00305     a=26.981538*g/mole;
00306     g4elm  = new G4Element(name="Aluminum",symbol="Al",iz=13.,a);
00307     lcdelm = new LCDG4Element(g4elm);
00308     m_element_array.push_back(lcdelm);
00309   }
00310 
00311   else if (elmname_given == "Si" || elmname_given == "SI") {
00312     a=28.0855*g/mole;
00313     g4elm  = new G4Element(name="Silicon",symbol="Si",iz=14.,a);
00314     lcdelm = new LCDG4Element(g4elm);
00315     m_element_array.push_back(lcdelm);
00316   }
00317 
00318   else if (elmname_given == "Ar" || elmname_given == "AR") {
00319     a=39.948*g/mole;
00320     g4elm  = new G4Element(name="Argon",symbol="Ar",iz=18.,a);
00321     lcdelm = new LCDG4Element(g4elm);
00322     m_element_array.push_back(lcdelm);
00323   }
00324 
00325   else if (elmname_given == "Ti" || elmname_given == "TI") {
00326     a=47.867*g/mole;
00327     g4elm  = new G4Element(name="Titanium",symbol="Ti",iz=22.,a);
00328     lcdelm = new LCDG4Element(g4elm);
00329     m_element_array.push_back(lcdelm);
00330   }
00331 
00332   else if (elmname_given == "Cr" || elmname_given == "CR") {
00333     a       = 51.9961*g/mole;
00334     g4elm  = new G4Element(name="Chromium",symbol="Cr",iz=24.0,a);
00335     lcdelm = new LCDG4Element(g4elm);
00336     m_element_array.push_back(lcdelm);
00337   }
00338 
00339   else if (elmname_given == "Fe" || elmname_given == "FE") {
00340     a       = 55.845*g/mole;
00341     g4elm  = new G4Element(name="Iron",symbol="Fe",iz=26.0,a);
00342     lcdelm = new LCDG4Element(g4elm);
00343     m_element_array.push_back(lcdelm);
00344   }
00345 
00346   else if (elmname_given == "Ni" || elmname_given == "NI") {
00347     a       = 58.6934*g/mole;
00348     g4elm  = new G4Element(name="Nickel",symbol="Ni",iz=28.0,a);
00349     lcdelm = new LCDG4Element(g4elm);
00350     m_element_array.push_back(lcdelm);
00351   }
00352 
00353   else if (elmname_given == "Xe" || elmname_given == "XE") {
00354     a=131.29*g/mole;
00355     g4elm  = new G4Element(name="Xenon",symbol="Xe",iz=54.,a);
00356     lcdelm = new LCDG4Element(g4elm);
00357     m_element_array.push_back(lcdelm);
00358   }
00359 
00360   else {
00361     /* Comment out now for DEBUGging */
00362     fprintf(stderr,"LCDG4MaterialMgr::SetElement error!!! elmname=%s\n",
00363             elmname);
00364     g4elm = 0;
00365     exit(-1);
00366   }
00367 
00368 //   G4cout<< "picked Element: "<< g4elm->GetName() << G4endl;
00369   return g4elm;
00370 }

G4Material * LCDG4MaterialMgr::SetMaterial const char *  matname  ) 
 

Definition at line 121 of file LCDG4MaterialMgr.cc.

References GetElement(), and m_material_array.

Referenced by GetMaterial().

00122 {
00123 //   G4cout << "Setting material-->" << matname << endl;
00124   G4String matname_given(matname);
00125 
00126   G4int nel;
00127   G4double a, z, density, fractionmass;
00128   G4String name;
00129 
00130   G4Material* g4mat = 0;
00131   LCDG4Material* lcdmat = 0;
00132 
00133   const char* env = getenv("PEGS4PATH");
00134   G4String matfile(env);
00135 
00136   matfile += "/ParFiles/";
00137   matfile += matname;
00138   matfile += ".mat";
00139   FILE *fp=fopen(matfile,"r");
00140 
00141   // Read First line
00142   char linebuf[90];
00143   fgets(linebuf,90,fp);
00144   char type[7],materialName[32];
00145   sscanf(linebuf," %6s=%15s",type,materialName);
00146   if (strcmp("MEDIUM",type) != 0) {
00147     //   fprintf(stderr,"LCDG4MaterialMgr::SetMaterial "
00148     //   " Material file format for %s is unrecongnizable:\n"
00149     //   "     should start MEDIUM=\n"
00150     //   "Material File = %s\n",matfile);
00151     G4cerr << "LCDG4MaterialMgr::SetMaterial: Material file format for "
00152            << matfile << " is unrecognizable:" << endl;
00153     G4cerr << "     should start MEDIUM=\nMaterial File = " << matfile << endl;
00154     exit(-1);
00155   }
00156 
00157   // Read # of element
00158   double rho;
00159   fgets(linebuf,90,fp);
00160   sscanf(linebuf," %4s,RHO=%lf,NE=%i", type, &rho, &nel);
00161   if(nel < 0 || nel > 10)  {
00162     //  fprintf(stderr,"LCDG4MaterialMgr::SetMaterial "
00163     //  "Material file format problem: bad number of elements\n"
00164     //  "Material File = %s\n",matfile);
00165     G4cerr << "LCDG4MaterialMgr::SetMaterial:\n"
00166            << "   Material file format problem: Bad number of elements\n"
00167            << "   Material file = " << matfile << endl;
00168     exit(-1);
00169   }
00170 
00171   // Here loop over nel
00172   double pznorm=0;
00173   int ie=0;
00174   char ename[3];
00175   double f,d;
00176   for (ie=0 ; ie < nel ; ie++) {
00177     fgets(linebuf,90,fp);
00178     sscanf(linebuf," ASYM=%2c, Z=%lf, A=%lf, PZ=%lf, RHOZ=%lf",
00179            ename,&z,&a,&f,&d);
00180     pznorm += a*f;
00181   }
00182   fclose(fp);
00183 
00184   fp=fopen(matfile,"r");
00185   fgets(linebuf,90,fp);
00186   fgets(linebuf,90,fp);
00187 
00188   if (nel == 1) {
00189     fgets(linebuf,90,fp);
00190     sscanf(linebuf," ASYM=%2c, Z=%lf, A=%lf, PZ=%lf, RHOZ=%lf",
00191            ename,&z,&a,&f,&d);
00192     ename[2]='\0';
00193     a      *= g/mole;
00194     density = rho*g/cm3;
00195     g4mat  = new G4Material(name=matname,z,a,density);
00196     lcdmat = new LCDG4Material(g4mat);
00197     // m_material_array->Add(lcdmat);
00198 //     G4cout <<" nel==1, adding material: "<< g4mat->GetName() << G4endl;
00199     m_material_array.push_back(lcdmat);
00200   }
00201 
00202   else if (nel > 1) {
00203     density = rho*g/cm3;
00204     G4cout << "Creating new material:" << matname << G4endl;
00205     g4mat  = new G4Material(name=matname,density,nel);
00206 
00207     for (ie=0 ; ie < nel ; ie++) {
00208       fgets(linebuf,90,fp);
00209       sscanf(linebuf," ASYM=%2c, Z=%lf, A=%lf, PZ=%lf, RHOZ=%lf",
00210              ename,&z,&a,&f,&d);
00211       fractionmass=a*f/pznorm;
00212       ename[2]='\0';
00213       G4Element* elem = GetElement(ename);
00214       G4cout<<"Element="<< elem->GetName()<<", frac="<< fractionmass <<G4endl;
00215       g4mat->AddElement(elem,fractionmass);
00216     }
00217     lcdmat = new LCDG4Material(g4mat);
00218     m_material_array.push_back(lcdmat);
00219   }
00220 
00221   // close file
00222   fclose(fp);
00223 
00224   return g4mat;
00225 }


Member Data Documentation

std::list<LCDG4Element*> LCDG4MaterialMgr::m_element_array [private]
 

Definition at line 29 of file LCDG4MaterialMgr.hh.

Referenced by GetElement(), SetElement(), and ~LCDG4MaterialMgr().

std::list<LCDG4Material*> LCDG4MaterialMgr::m_material_array [private]
 

Definition at line 28 of file LCDG4MaterialMgr.hh.

Referenced by GetMaterial(), SetMaterial(), and ~LCDG4MaterialMgr().


The documentation for this class was generated from the following files:
Generated on Thu Oct 7 18:45:05 2004 for LCDG4 by doxygen 1.3.4