GEMC  2.3
Geant4 Monte-Carlo Framework
text_materials.cc
Go to the documentation of this file.
1 // gemc headers
2 #include "material_factory.h"
3 #include "text_materials.h"
4 #include "string_utilities.h"
5 #include "utils.h"
6 
7 // G4 headers
8 #include "G4Element.hh"
9 #include "G4NistManager.hh"
10 #include "G4OpBoundaryProcess.hh"
11 
12 
13 map<string, G4Material*> text_materials::initMaterials(runConditions rc, goptions opts)
14 {
15 
16  string hd_msg = opts.optMap["LOG_MSG"].args + " TEXT Materials Factory: >> ";
17  double verbosity = opts.optMap["MATERIAL_VERBOSITY"].arg;
18 
19  map<string, material> mymats; // material map
20 
21  // first check if there's at least one detector with TEXT factory
23  return materialsFromMap(mymats);
24 
25 
26  // Looping over detectorConditionsMap for detector names
27  // To each detector is associated a material and (optional) opt properties
28  for(map<string, detectorCondition>::iterator it=rc.detectorConditionsMap.begin(); it != rc.detectorConditionsMap.end(); it++)
29  {
30  // building materials belonging to detectors that are tagged with MYSQL factory
31  if(it->second.get_factory() != "TEXT")
32  continue;
33 
34  if(verbosity)
35  cout << hd_msg << " Initializing " << it->second.get_factory() << " for detector " << it->first << endl;
36 
37  // only add "main" if it's the main variation
38  string dname = it->first ;
39  string variation = get_variation(it->second.get_variation());
40  string filename = dname + "__materials_" + variation + ".txt";
41 
42  ifstream IN(filename.c_str());
43  if(!IN)
44  {
45  // if file is not found, maybe it's in the GEMC_DATA_DIR directory
46  if(getenv("GEMC_DATA_DIR") != NULL)
47  {
48 
49  string maybeHere = (string) getenv("GEMC_DATA_DIR") + "/" + filename;
50 
51  IN.open(maybeHere.c_str());
52  if(!IN)
53  {
54  if(verbosity>1)
55  cout << hd_msg << "Warning: The system >" << dname
56  << "< does not have a material file associated with it. "
57  << "Probably it's using default Geant4 parameters." << endl;
58  continue;
59  }
60  }
61 
62 
63  if(!IN)
64  {
65  if(verbosity>1)
66  cout << hd_msg << "Warning: The system >" << dname
67  << "< does not have a material file associated with it. "
68  << "Probably it's using default Geant4 parameters." << endl;
69  continue;
70  }
71  }
72 
73  // else loading parameters from file
74  while(!IN.eof())
75  {
76  string dbline;
77  getline(IN, dbline);
78 
79  if(!dbline.size())
80  continue;
81 
82  gtable gt(get_strings(dbline, "|"));
83 
84  material thisMat(TrimSpaces( gt.data[0])); // name
85  thisMat.desc = gt.data[1]; // description
86  thisMat.density = get_number(gt.data[2]); // density
87  thisMat.ncomponents = get_number(gt.data[3]); // number of components
88  thisMat.componentsFromString( gt.data[4]); // component + quantity list
89  thisMat.opticalsFromString( gt.data[5], "photonEnergy");
90  thisMat.opticalsFromString( gt.data[6], "indexOfRefraction");
91  thisMat.opticalsFromString( gt.data[7], "absorptionLength");
92  thisMat.opticalsFromString( gt.data[8], "reflectivity");
93  thisMat.opticalsFromString( gt.data[9], "efficiency");
94 
95  // scintillation
96  // this condition is for backward compatibility,
97  // scintillation was added with gemc 2.3
98  if( gt.data.size() == 18)
99  {
100  thisMat.opticalsFromString( gt.data[10], "fastcomponent");
101  thisMat.opticalsFromString( gt.data[11], "slowcomponent");
102  thisMat.scintillationyield = get_number(gt.data[12]);
103  thisMat.resolutionscale = get_number(gt.data[13]);
104  thisMat.fasttimeconstant = get_number(gt.data[14]);
105  thisMat.slowtimeconstant = get_number(gt.data[15]);
106  thisMat.yieldratio = get_number(gt.data[16]);
107  thisMat.opticalsFromString( gt.data[17], "rayleigh");
108  }
109  mymats[thisMat.name] = thisMat;
110 
111  }
112  }
113  cout << endl;
114 
115  map<string, G4Material*> returnMap = materialsFromMap(mymats);
116  if(verbosity>0) printMaterials(returnMap);
117 
118  return returnMap;
119 }
120 
121 
122 
123 
map< string, G4Material * > initMaterials(runConditions, goptions)
vector< string > get_strings(string input)
returns a vector of strings from a stringstream, space is delimiter
int check_if_factory_is_needed(map< string, detectorCondition > dcon, string factory)
double slowtimeconstant
double fasttimeconstant
vector< string > data
Definition: utils.h:76
Definition: utils.h:65
double verbosity
map< string, G4Material * > materialsFromMap(map< string, material >)
string get_variation(string var)
parse variation name from string
map< string, detectorCondition > detectorConditionsMap
double get_number(string v, int warn_no_unit)
Returns number with dimension from string, i.e. 100*cm.
void printMaterials(map< string, G4Material * > matMap)
map< string, aopt > optMap
Options map.
Definition: options.h:75
double density
double scintillationyield
void componentsFromString(string)
double resolutionscale
string TrimSpaces(string in)
Removes leading and trailing spaces.
void opticalsFromString(string, string)
double yieldratio