17 #include "G4Element.hh" 18 #include "G4NistManager.hh" 19 #include "G4OpBoundaryProcess.hh" 25 string database = opts.
args[
"DATABASE"].args;
26 string dbhost = opts.
args[
"DBHOST"].args;
27 string dbUser = opts.
args[
"DBUSER"].args;
28 string dbPswd = opts.
args[
"DBPSWD"].args;
29 string hd_msg = opts.
args[
"LOG_MSG"].args +
" MYSQL Materials: >> ";
30 double verbos = opts.
args[
"MATERIAL_VERBOSITY"].arg;
34 QSqlDatabase db = QSqlDatabase::addDatabase(
"QMYSQL");
35 db.setHostName(dbhost.c_str());
36 db.setDatabaseName(database.c_str());
37 db.setUserName( dbUser.c_str() );
38 db.setPassword( dbPswd.c_str() );
43 cout << hd_msg <<
" Cannot connect to database " << database <<
". Exiting." << endl;
48 map<string, G4Material*> mats;
49 map<string, G4MaterialPropertiesTable*> optP;
51 G4NistManager* matman = G4NistManager::Instance();
55 map<string, G4Element*> elementsMap;
57 string dbexecute =
"select name, symbol, atomic_number, molar_mass from materials__elements" ;
60 if(!q.exec(dbexecute.c_str()))
62 cout << hd_msg <<
" Failed to access DB for table: materials__elements. Maybe the table doesn't exist? Exiting." << endl;
71 int atomic_number = q.value(2).toInt();
72 double molar_mass = q.value(3).toDouble();
74 elementsMap[ename] =
new G4Element(ename, esymbol, atomic_number, molar_mass*g/mole);
79 string dbtable = opts.
args[
"GT"].args;
81 if(runConditions.
gTab_Vec.size() == 0 && dbtable !=
"no")
82 runConditions.
gTab_Vec.push_back(dbtable);
87 for(
unsigned int sql_t=0; sql_t< runConditions.
gTab_Vec.size(); sql_t++)
89 string material_table = runConditions.
gTab_Vec[sql_t] +
"__materials";
90 dbexecute =
"select name, density, nelements, elements from " + material_table;
93 if(!q.exec(dbexecute.c_str()))
95 cout << hd_msg <<
" Failed to access DB for table: " << material_table <<
". Maybe the table doesn't exist? Exiting." << endl;
102 double density = q.value(1).toDouble();
103 int nelements = q.value(2).toInt();
104 mats[mname] =
new G4Material(mname, density*mg/cm3, nelements);
108 string *enamelist=
new string[nelements];
110 double eperc[nelements];
111 for(
int e=0; e<nelements; e++)
113 elements >> enamelist[e] >> eperc[e];
126 for(
int e=0; e<nelements; e++)
128 if(elementsMap.find(enamelist[e]) != elementsMap.end())
130 mats[mname]->AddElement(elementsMap[enamelist[e]], eperc[e]*perCent);
134 else if(matman->FindOrBuildMaterial(enamelist[e]) != 0)
135 mats[mname]->AddMaterial(matman->FindOrBuildMaterial(enamelist[e]), eperc[e]*perCent);
138 cout << hd_msg <<
" WARNING: Component " << enamelist[e] <<
" NOT FOUND!!" << endl;
143 for(
int e=0; e<nelements; e++)
144 sum += eperc[e]*perCent;
147 cout << hd_msg <<
" WARNING: Material " << mname <<
" components percentages add to " << sum*100 <<
" instead of 100." << endl;
153 string opt_properties_table = runConditions.
gTab_Vec[sql_t] +
"__opt_properties";
154 dbexecute =
"select property, plist from " + opt_properties_table +
" where mat_name='" + mname +
"' and property='PhotonEnergy'";
156 if(q2.exec(dbexecute.c_str()))
159 optP[mname] =
new G4MaterialPropertiesTable();
160 vector<string> pvalues;
170 unsigned int nentries = pvalues.size();
171 double penergy[nentries];
172 for(
unsigned int i=0; i<nentries; i++)
176 dbexecute =
"select property, plist from " + opt_properties_table +
" where mat_name='" + mname +
"' and property!='PhotonEnergy'";
177 if(q3.exec(dbexecute.c_str()))
186 if(dvalues.size() != nentries)
188 cout << hd_msg <<
" Number of entries for property " <<
property 189 <<
" of material " << mname
190 <<
" is " << dvalues.size() <<
" and does not match the photon energy entries of " << nentries << endl;
195 double this_values[nentries];
196 for(
unsigned int i=0; i<nentries; i++)
199 if(property ==
"IndexOfRefraction")
200 optP[mname]->AddProperty(
"RINDEX", penergy, this_values, nentries);
202 if(property ==
"AbsorptionLength")
203 optP[mname]->AddProperty(
"ABSLENGTH", penergy, this_values, nentries);
205 if(property ==
"Reflectivity")
206 optP[mname]->AddProperty(
"REFLECTIVITY", penergy, this_values, nentries);
208 if(property ==
"Efficiency")
209 optP[mname]->AddProperty(
"EFFICIENCY", penergy, this_values, nentries);
218 mats[mname]->SetMaterialPropertiesTable(optP[mname]);
221 cout << hd_msg <<
" Optical Properties for " << mname <<
":" << endl;
222 optP[mname]->DumpTable();
229 cout << hd_msg <<
" Material: " << mname <<
" with density " << density <<
" mg/cm3 loaded with " << nelements <<
" components: " << endl;
230 for(
int e=0; e<nelements; e++)
231 cout <<
" (" << e+1 <<
") " << enamelist[e] <<
" " << eperc[e] <<
"%" << endl;
243 db.removeDatabase(
"qt_sql_default_connection");
vector< string > get_strings(string input)
returns a vector of strings from a stringstream
vector< string > gTab_Vec
Vector of SQL tables names.
map< string, G4Material * > initMaterials(run_conditions, gemc_opts)
string gemc_tostring(QString input)
map< string, opts > args
Options map.
string TrimSpaces(string in)
Removes leading and trailing spaces.
double get_number(string)
Returns dimension from string, i.e. 100*cm.