-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathtext_materials.cc
More file actions
133 lines (108 loc) · 5.2 KB
/
Copy pathtext_materials.cc
File metadata and controls
133 lines (108 loc) · 5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// gemc headers
#include "material_factory.h"
#include "text_materials.h"
#include "string_utilities.h"
#include "gemcUtils.h"
// mlibrary
#include "gstring.h"
using namespace gstring;
// G4 headers
#include "G4Element.hh"
#include "G4NistManager.hh"
#include "G4OpBoundaryProcess.hh"
map<string, G4Material *> text_materials::initMaterials(runConditions rc, goptions opts) {
string hd_msg = opts.optMap["LOG_MSG"].args + " TEXT Materials Factory: >> ";
double verbosity = opts.optMap["MATERIAL_VERBOSITY"].arg;
map <string, material> mymats; // material map
// first check if there's at least one detector with TEXT factory
if (!check_if_factory_is_needed(rc.detectorConditionsMap, "TEXT"))
return materialsFromMap(mymats);
// Looping over detectorConditionsMap for detector names
// To each detector is associated a material and (optional) opt properties
for (map<string, detectorCondition>::iterator it = rc.detectorConditionsMap.begin(); it != rc.detectorConditionsMap.end(); it++) {
// building materials belonging to detectors that are tagged with MYSQL factory
if (it->second.get_factory() != "TEXT") {
continue;
}
if (verbosity) {
cout << hd_msg << " Initializing " << it->second.get_factory() << " for detector " << it->first << endl;
}
// only add "main" if it's the main variation
string dname = it->first;
string variation = get_variation(it->second.get_variation());
string filename = dname + "__materials_" + variation + ".txt";
ifstream IN(filename.c_str());
if (!IN) {
// if file is not found, maybe it's in the GEMC_DATA_DIR directory
if (getenv("GEMC_DATA_DIR") != nullptr) {
string maybeHere = (string) getenv("GEMC_DATA_DIR") + "/" + filename;
IN.open(maybeHere.c_str());
if (!IN) {
if (verbosity > 1)
cout << hd_msg << "Warning: The system >" << dname
<< "< does not have a material file associated with it. "
<< "Probably it's using default Geant4 parameters." << endl;
continue;
}
}
if (!IN) {
if (verbosity > 1)
cout << hd_msg << "Warning: The system >" << dname
<< "< does not have a material file associated with it. "
<< "Probably it's using default Geant4 parameters." << endl;
continue;
}
}
// else loading parameters from file
while (!IN.eof()) {
string dbline;
getline(IN, dbline);
if (!dbline.size())
continue;
gtable gt(getStringVectorFromStringWithDelimiter(dbline, "|"));
material thisMat(trimSpacesFromString(gt.data[0])); // name
thisMat.desc = gt.data[1]; // description
thisMat.density = get_number(gt.data[2]); // density
thisMat.ncomponents = get_number(gt.data[3]); // number of components
thisMat.componentsFromString(gt.data[4]); // component + quantity list
thisMat.opticalsFromString(gt.data[5], "photonEnergy");
thisMat.opticalsFromString(gt.data[6], "indexOfRefraction");
thisMat.opticalsFromString(gt.data[7], "absorptionLength");
thisMat.opticalsFromString(gt.data[8], "reflectivity");
thisMat.opticalsFromString(gt.data[9], "efficiency");
// this condition is for backward compatibility,
// scintillation was added with gemc 2.3
// 18 exact quantities
if (gt.data.size() > 10) {
thisMat.opticalsFromString(gt.data[10], "fastcomponent");
thisMat.opticalsFromString(gt.data[11], "slowcomponent");
thisMat.scintillationyield = get_number(gt.data[12]);
thisMat.resolutionscale = get_number(gt.data[13]);
thisMat.fasttimeconstant = get_number(gt.data[14]);
thisMat.slowtimeconstant = get_number(gt.data[15]);
thisMat.yieldratio = get_number(gt.data[16]);
thisMat.opticalsFromString(gt.data[17], "rayleigh");
}
// this condition is for backward compatibility,
// Birk Constant were added with gemc 2.6
// 19 exact quantities
if (gt.data.size() > 18) {
thisMat.birkConstant = get_number(gt.data[18]);
}
// this condition is for backward compatibility,
// Birk Constant were added with gemc 2.6
// 23 exact quantities
if (gt.data.size() > 19) {
thisMat.opticalsFromString(gt.data[19], "mie");
thisMat.mieforward = get_number(gt.data[20]);
thisMat.miebackward = get_number(gt.data[21]);
thisMat.mieratio = get_number(gt.data[22]);
}
mymats[thisMat.name] = thisMat;
}
}
cout << endl;
map < string, G4Material * > returnMap = materialsFromMap(mymats);
if (verbosity > 0) printMaterials(returnMap);
return returnMap;
}