Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4QSS_CustomStats.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// QSSStats
27//
28// QSS statistics
29
30// Authors: Lucio Santi, Rodrigo Castro - 2018-2021
31// --------------------------------------------------------------------
32#ifndef _QSS_CUSTOM_STATS_HH_
33#define _QSS_CUSTOM_STATS_HH_
34
35#include <time.h>
36
37#define GET_TIME(t0) (clock_gettime(CLOCK_MONOTONIC, &t0))
38#define TIME_SECS(t0, t1) ((t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1e9)
39
40// #define INTERPOLATE_ITERATIONS 1e2
41// #define ESTIMATE_ITERATIONS 2
42// #define ON_COMPUTE_STEP_ITERATIONS 20
43// #define ON_COMPUTE_STEP_ITERATIONS_G4 2e3
44
45#include "G4qss_misc.hh"
46#include "G4Types.hh"
47
48#include <atomic>
49
51{
56 std::atomic<G4int> stepperSteps;
57 std::map<G4int, std::map<G4int, G4int>> substepsByStepNumberByTrackID;
58
61
65
67 {
68 substeps = 0;
69 reset_time = 0;
71
72 for (size_t i = 0; i < Qss_misc::VAR_IDX_END; i++) {
73 dqrel_changes[i] = 0;
74 dqmin_changes[i] = 0;
75 max_error[i] = 0;
76 }
77 };
78
79 void print() const
80 {
81 G4int steps = stepperSteps.load();
82
83 std::vector<std::string> vars{"x", "y", "z", "vx", "vy", "vz"};
84
85 G4double avg_substeps = (G4double)substeps / steps;
86 G4double avg_integration_time = (G4double)integration_time / steps;
87 G4double avg_substeps_integration_time = (G4double)integration_time / substeps;
88 G4double avg_reset_time = (G4double)reset_time / steps;
89
90 std::stringstream ss;
91
92 ss << "QSS stats:" << std::endl;
93 ss << "dQMin: " << precision_dQMin << std::endl;
94 ss << "dQRel: " << precision_dQRel << std::endl;
95
96 ss << " Total steps: " << steps << std::endl
97 << " Total substeps: " << substeps << std::endl
98 << " Substeps average per step: " << avg_substeps << std::endl;
99
100 ss << " Substeps by track-step:" << std::endl;
101 for (auto it = substepsByStepNumberByTrackID.begin(); it != substepsByStepNumberByTrackID.end();
102 ++it)
103 {
104 ss << " Track #" << it->first << std::endl;
105 for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
106 ss << " Step " << it2->first << " => " << it2->second << " substeps" << std::endl;
107 }
108 }
109
110 ss << " Integration time: " << integration_time << std::endl
111 << " Integration time average (step): " << avg_integration_time << std::endl
112 << " Integration time average (substep): " << avg_substeps_integration_time << std::endl;
113
114 ss << " Reset time: " << reset_time << std::endl
115 << " Reset time average: " << avg_reset_time << std::endl;
116
117 for (G4int index = 0; index < Qss_misc::VAR_IDX_END; index++) {
118 ss << " Variable " << vars[index] << ":" << std::endl;
119 ss << " dQRel changes: " << dqrel_changes[index] << std::endl;
120 ss << " dQMin changes: " << dqmin_changes[index] << std::endl;
121 ss << " Max error: " << max_error[index] << std::endl;
122 }
123
124 std::cout << ss.rdbuf();
125 };
126};
127
128#endif
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
constexpr unsigned int VAR_IDX_END
Definition G4qss_misc.hh:46
G4int dqmin_changes[Qss_misc::VAR_IDX_END]
G4double precision_dQRel
G4int dqrel_changes[Qss_misc::VAR_IDX_END]
G4double reset_time
G4double integration_time
void print() const
std::atomic< G4int > stepperSteps
std::map< G4int, std::map< G4int, G4int > > substepsByStepNumberByTrackID
G4double max_error[Qss_misc::VAR_IDX_END]
G4double precision_dQMin