8 G4int beamType = 0, modeType = 0;
9 G4bool boolLightGuide =
false;
16 size_t start = line.find(keyword);
19 if(start != G4String::npos)
21 start += keyword.length();
22 G4String value = line.substr(start);
32 void MC_summary(G4String macrofile, G4int seed, G4double duration,
const G4String& output_filename)
35 std::ofstream outfile(output_filename, std::ios::app);
38 outfile <<
"MonteCarlo serial number (Seed): " << seed << G4endl;
40 std::time_t now = std::time(0);
41 std::tm* current_time = std::localtime(&now);
42 outfile <<
"Date: " << std::asctime(current_time);
43 outfile <<
"User Name: " << getlogin() << G4endl;
44 outfile <<
"Duration of the simulation: " << duration <<
" s" << G4endl;
48 std::ifstream run_file(macrofile);
51 G4cerr <<
"Can't open run macro file!" << G4endl;
58 while(std::getline(run_file, line))
61 line = line.substr(line.find_first_not_of(
" \t"));
64 if(line.find(
"/MC_LYSO/Mode") != G4String::npos)
71 outfile <<
"Mode: Standard - Pointlike beam" << G4endl;
74 outfile <<
"Mode: Standard - Spread beam" << G4endl;
77 outfile <<
"Mode: Standard - Circle beam" << G4endl;
80 outfile <<
"Mode: 176Lu decay" << G4endl;
83 outfile <<
"Mode: 176Lu decay - Fixed position" << G4endl;
86 outfile <<
"Mode: 176Lu decay - Si Trigger" << G4endl;
89 outfile <<
"Mode: Cosmic rays" << G4endl;
92 outfile <<
"Mode: LED system" << G4endl;
96 else if(modeType == 11 && line.find(
"/MC_LYSO/myGun/radiusSpread") != G4String::npos)
98 G4String radius_value =
extract_value(line,
"/MC_LYSO/myGun/radiusSpread");
99 if(!radius_value.empty())
101 outfile <<
"RadiusSpread: " << radius_value << G4endl;
104 else if(modeType == 12 && line.find(
"/MC_LYSO/myGun/radiusCircle") != G4String::npos)
106 G4String radius_value =
extract_value(line,
"/MC_LYSO/myGun/radiusCircle");
107 if(!radius_value.empty())
109 outfile <<
"RadiusCircle: " << radius_value << G4endl;
112 else if((modeType == 10 || modeType == 11 || modeType == 12) && line.find(
"/MC_LYSO/myGun/meanEnergy") != G4String::npos)
114 G4String energy_value =
extract_value(line,
"/MC_LYSO/myGun/meanEnergy");
115 if(!energy_value.empty())
117 outfile <<
"Energy: " << energy_value << G4endl;
120 else if((modeType == 10 || modeType == 11 || modeType == 12) && line.find(
"/MC_LYSO/myGun/sigmaEnergy") != G4String::npos)
122 G4String sigma_value =
extract_value(line,
"/MC_LYSO/myGun/sigmaEnergy");
123 if(!sigma_value.empty())
125 outfile <<
"SigmaEnergy: " << sigma_value << G4endl;
128 else if(modeType == 21 && line.find(
"/MC_LYSO/myGun/posLuDecay") != G4String::npos)
130 G4String posdecay_value =
extract_value(line,
"/MC_LYSO/myGun/posLuDecay");
131 if(!posdecay_value.empty())
133 outfile <<
"176Lu isotope position: " << posdecay_value << G4endl;
136 else if(modeType == 40 && line.find(
"/MC_LYSO/myGun/LED-System/FrontOrBack F") != G4String::npos)
138 outfile <<
"LED of Front detector" << G4endl;
140 else if(modeType == 40 && line.find(
"/MC_LYSO/myGun/LED-System/FrontOrBack B") != G4String::npos)
142 outfile <<
"LED of Back detector" << G4endl;
144 else if(modeType == 40 && line.find(
"/MC_LYSO/myGun/LED-System/switchOnLED u") != G4String::npos)
146 outfile <<
"LED turned on: up" << G4endl;
148 else if(modeType == 40 && line.find(
"/MC_LYSO/myGun/LED-System/switchOnLED d") != G4String::npos)
150 outfile <<
"LED turned on: down" << G4endl;
152 else if(modeType == 40 && line.find(
"/MC_LYSO/myGun/LED-System/switchOnLED r") != G4String::npos)
154 outfile <<
"LED turned on: right" << G4endl;
156 else if(modeType == 40 && line.find(
"/MC_LYSO/myGun/LED-System/switchOnLED l") != G4String::npos)
158 outfile <<
"LED turned on: left" << G4endl;
160 else if(line.find(
"/run/beamOn") != G4String::npos)
163 if(!events_value.empty())
165 outfile <<
"Number of events: " << events_value << G4endl;
173 std::ifstream construction_file(
"construction.mac");
174 if(!construction_file)
176 G4cerr <<
"Can't open file 'construction.mac'" << G4endl;
181 while(std::getline(construction_file, line))
183 line = line.substr(line.find_first_not_of(
" \t"));
185 if(line.find(
"/MC_LYSO/myConstruction/isOpticalGrease true") != G4String::npos)
187 outfile <<
"Optical Grease: ON" << G4endl;
189 else if(line.find(
"/MC_LYSO/myConstruction/isOpticalGrease false") != G4String::npos)
191 outfile <<
"Optical Grease: OFF" << G4endl;
193 else if(line.find(
"/MC_LYSO/myConstruction/isLightGuide true") != G4String::npos)
195 outfile <<
"Light Guide: ON" << G4endl;
196 boolLightGuide =
true;
198 else if(line.find(
"/MC_LYSO/myConstruction/isLightGuide false") != G4String::npos)
200 outfile <<
"Light Guide: OFF" << G4endl;
201 boolLightGuide =
false;
203 else if(boolLightGuide && line.find(
"/MC_LYSO/myConstruction/MaterialOfLightGuide") != G4String::npos)
205 G4String material_value =
extract_value(line,
"/MC_LYSO/myConstruction/MaterialOfLightGuide");
206 if(!material_value.empty())
208 outfile <<
"Material of Light Guide: " << material_value << G4endl;
211 else if(line.find(
"/MC_LYSO/myConstruction/isPCB true") != G4String::npos)
213 outfile <<
"PCB: ON" << G4endl;
215 else if(line.find(
"/MC_LYSO/myConstruction/isPCB false") != G4String::npos)
217 outfile <<
"PCB: OFF" << G4endl;
219 else if(line.find(
"/MC_LYSO/myConstruction/isEndcap true") != G4String::npos)
221 outfile <<
"Endcap: ON" << G4endl;
223 else if(line.find(
"/MC_LYSO/myConstruction/isEndcap false") != G4String::npos)
225 outfile <<
"Endcap: OFF" << G4endl;
227 else if(line.find(
"/MC_LYSO/myConstruction/isCosmicRaysDetectors true") != G4String::npos)
229 outfile <<
"Cosmic rays detectors: ON" << G4endl;
231 else if(line.find(
"/MC_LYSO/myConstruction/isCosmicRaysDetectors false") != G4String::npos)
233 outfile <<
"Cosmic rays detectors: OFF" << G4endl;
237 construction_file.close();
240 outfile <<
"########################################################" << G4endl;
void MC_summary(G4String macrofile, G4int seed, G4double duration, const G4String &output_filename)
Writes the summary of the Monte Carlo to a text file, updating it at the end of every simulation.
G4String extract_value(const G4String &line, const G4String &keyword)
Auxiliary function called by MC_summary() to extract settings from the macro files used for the Monte...
Declaration of the function MC_summary() (and the auxiliary function extract_value())