81 G4cout <<
" ###### EndOfTSRunAction ###### " << G4endl;
83 aRun->GetNumberOfEvent();
84 std::ofstream fileout;
86 std::stringstream separator;
88 separator <<
"============================================================";
90 typedef std::set<G4int> IDSet_t;
94 const TSRun* tsRun =
static_cast<const TSRun*
>(aRun);
100 std::vector<G4String> primScorerNames{
"EnergyDeposit",
"NumberOfSteps" };
101 std::vector<G4String> fnames{
"mfd_tl",
"mfd_tg" };
102 std::vector<G4double> units{ CLHEP::eV, CLHEP::keV, 1, 1 };
103 std::vector<G4String> unitstr{
"keV",
"steps" };
107 auto print = [](std::ostream& fout, G4int first, G4double second,
108 G4double unit1, G4double unit2,
G4String unit2str) {
110 fout << first <<
" " << second / unit1 << G4endl;
112 G4cout <<
" " << std::setw(10) << first <<
" " << std::setw(15)
113 << std::setprecision(6) << std::fixed << second / unit2 <<
" "
114 << unit2str << G4endl;
115 G4cout.unsetf(std::ios::fixed);
119 auto stat_print = [](std::ostream& fout, G4int first,
G4StatAnalysis* stat,
121 G4double unit2,
G4String unit2str) {
124 auto fsecond = (*stat);
125 auto psecond = (*stat);
130 fout << first <<
" " << fsecond << G4endl;
131 conv->ShowResult(fout);
133 std::stringstream ss;
134 ss <<
" " << std::setw(10) << first <<
" " << std::setw(15)
135 << std::setprecision(6) << std::fixed << psecond <<
" " << unit2str;
137 G4cout << ss.str() << G4endl;
141 for(
unsigned i = 0; i < primScorerNames.size(); ++i)
143 for(
unsigned j = 0; j < fnames.size(); ++j)
145 fname = fnames.at(j) +
"_" + primScorerNames.at(i) +
".out";
147 G4cout << separator.str() << G4endl;
148 G4cout <<
" opened file " << fname <<
" for output" << G4endl;
149 G4cout << separator.str() << G4endl;
161 if(hitmap && hitmap->size() != 0)
163 for(
auto itr = hitmap->begin(); itr != hitmap->end(); itr++)
165 if(!hitmap->GetObject(itr))
167 IDs.insert(itr->first);
168 std::get<0>(
fTypeCompare[primScorerNames.at(i)][itr->first]) =
169 *itr->second / units.at(i);
170 print(fileout, itr->first, *itr->second, units.at(i),
171 units.at(i + 1), unitstr.at(i));
179 if(statmap && statmap->size() != 0 && convmap && convmap->size() != 0)
181 auto stat_fname =
"stat_" + fname;
182 std::ofstream statout;
183 statout.open(stat_fname);
184 for(
auto itr = statmap->begin(); itr != statmap->end(); itr++)
186 G4int _f = statmap->GetIndex(itr);
189 stat_print(statout, _f, _s, _c, units.at(i), units.at(i + 1),
196 std::stringstream ss;
197 ss <<
" StatMap/ConvMap is either not "
198 <<
"created or the StatMap/ConvMap was empty";
200 ss <<
" (StatMap size == " << statmap->size() <<
")";
202 ss <<
" (ConvMap size == " << convmap->size() <<
")";
204 G4Exception(
"TSRunAction",
"002", JustWarning,
205 G4String(primScorerNames.at(i) + ss.str()).c_str());
210 G4Exception(
"TSRunAction",
"000", JustWarning,
212 " HitsMap is either not "
213 "created or the HitsMap was empty")
221 if(hitmap && hitmap->
size() != 0)
223 for(
auto itr = hitmap->
begin(); itr != hitmap->
end(); itr++)
225 IDs.insert(itr->first);
226 std::get<1>(
fTypeCompare[primScorerNames.at(i)][itr->first]) =
227 *itr->second / units.at(i);
228 print(fileout, itr->first, *itr->second, units.at(i),
229 units.at(i + 1), unitstr.at(i));
239 G4Exception(
"TSRunAction",
"001", JustWarning,
241 " HitsMap is either not "
242 "created or the HitsMap was empty")
248 G4cout << separator.str() << G4endl;
249 G4cout <<
" closed file " << fname <<
" for output" << G4endl;
254 if(hitmap && hitmap->size() != 0)
256 for(
auto itr = hitmap->begin(); itr != hitmap->end(); itr++)
258 IDs.insert(itr->first);
259 std::get<2>(
fTypeCompare[primScorerNames.at(i)][itr->first]) =
260 itr->second / units.at(i);
270 fname =
"mfd_diff.out";
273 G4cout << separator.str() << G4endl;
274 G4cout <<
" opened file " << fname <<
" for difference output" << G4endl;
275 G4cout << separator.str() << G4endl;
277 fileout <<
" " << std::setw(10) <<
"ID"
278 <<
" " << std::setw(30) << std::setprecision(12) << std::fixed
280 <<
" " << std::setw(30) << std::setprecision(12) << std::fixed
281 <<
"Atomic Hits Map value"
282 <<
" " << std::setw(30) << std::setprecision(8)
283 << std::scientific <<
"Difference"
284 <<
" " << std::setw(30) << std::setprecision(8)
285 << std::scientific <<
"Diff (MFD - MUTEXED)"
286 <<
" " << std::setw(30) << std::setprecision(8)
287 << std::scientific <<
"Diff (ATOM_HIT_MAP - MUTEXED)" << G4endl
305 auto tp = (tm) ? tm->GetThreadPool() :
nullptr;
307 auto join_output = [](std::string& lhs, std::string&& rhs) {
312 auto report_type_comparison = [=](
const G4String& id,
315 auto report_subtype_comparison = [](
const G4int& idx,
317 std::stringstream streamout;
318 G4double d01 = std::fabs(std::get<0>(value) - std::get<1>(value));
319 G4double d02 = std::fabs(std::get<0>(value) - std::get<2>(value));
320 G4double d03 = std::fabs(std::get<1>(value) - std::get<2>(value));
322 auto _print_diff = [&](
const G4double& _dval) {
324 streamout << std::setprecision(8) << std::scientific
325 << std::setw(30) << _dval <<
" ";
327 streamout << std::setprecision(1) << std::fixed << std::setw(30)
331 streamout <<
" " << std::setw(10) << idx <<
" " << std::setw(30)
332 << std::setprecision(12) << std::fixed << std::get<0>(value)
333 <<
" " << std::setw(30) << std::setprecision(12)
334 << std::fixed << std::get<1>(value) <<
" ";
341 return streamout.str();
344 std::stringstream streamout;
345 streamout <<
"\n\nType = " <<
id <<
"\n" << G4endl;
349 G4TaskGroup<std::string> tg(join_output, tp);
351 for(
auto titr = comp.begin(); titr != comp.end(); ++titr)
352 tg.exec(report_subtype_comparison, titr->first, titr->second);
356 streamout << tg.join();
362 for(
auto titr = comp.begin(); titr != comp.end(); ++titr)
363 streamout << report_subtype_comparison(titr->first, titr->second);
366 return streamout.str();
372 G4cout <<
"\n\nGenerating diff output via tasking... ";
374 G4TaskGroup<std::string> tg(join_output, tp);
376 tg.exec(report_type_comparison, itr->first, itr->second);
378 tasking_result = tg.join();
388 serial_result += report_type_comparison(itr->first, itr->second);
391 fileout << tasking_result;
394 if(serial_result != tasking_result)
396 G4Exception(
"TSRunAction",
"003", JustWarning,
397 "Output written via tasking did not match output written "
398 "serially. Appending serial result to output file");
400 <<
"\n\n#================CORRECT_SERIAL_OUTPUT================#\n\n";
401 fileout << serial_result;
408 fileout << report_type_comparison(itr->first, itr->second);
412 G4cout <<
" closed file " << fname <<
" for difference output" << G4endl;
413 G4cout << separator.str() << G4endl;