Geant4 11.4.0
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 (Univ. Buenos Aires), 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#include "G4ios.hh"
48
49#include <atomic>
50#include <map>
51
52/**
53 * @brief QSSStats contains functions for statistics on the QSS drivers.
54 */
55
57{
62 std::atomic<G4int> stepperSteps;
63 std::map<G4int, std::map<G4int, G4int>> substepsByStepNumberByTrackID;
64
67
71
73 {
74 substeps = 0;
75 reset_time = 0;
77
78 for (std::size_t i = 0; i < Qss_misc::VAR_IDX_END; ++i)
79 {
80 dqrel_changes[i] = 0;
81 dqmin_changes[i] = 0;
82 max_error[i] = 0;
83 }
84 };
85
86 void print() const
87 {
88 G4int steps = stepperSteps.load();
89
90 std::vector<std::string> vars{"x", "y", "z", "vx", "vy", "vz"};
91
92 G4double avg_substeps = (G4double)substeps / steps;
93 G4double avg_integration_time = (G4double)integration_time / steps;
94 G4double avg_substeps_integration_time = (G4double)integration_time / substeps;
95 G4double avg_reset_time = (G4double)reset_time / steps;
96
97 std::stringstream ss;
98
99 ss << "QSS stats:" << std::endl;
100 ss << "dQMin: " << precision_dQMin << std::endl;
101 ss << "dQRel: " << precision_dQRel << std::endl;
102
103 ss << " Total steps: " << steps << std::endl
104 << " Total substeps: " << substeps << std::endl
105 << " Substeps average per step: " << avg_substeps << std::endl;
106
107 ss << " Substeps by track-step:" << std::endl;
108 for (const auto& stp : substepsByStepNumberByTrackID)
109 {
110 ss << " Track #" << stp.first << std::endl;
111 for (const auto& stp2 : stp.second)
112 {
113 ss << " Step " << stp2.first << " => " << stp2.second << " substeps" << std::endl;
114 }
115 }
116
117 ss << " Integration time: " << integration_time << std::endl
118 << " Integration time average (step): " << avg_integration_time << std::endl
119 << " Integration time average (substep): " << avg_substeps_integration_time << std::endl;
120
121 ss << " Reset time: " << reset_time << std::endl
122 << " Reset time average: " << avg_reset_time << std::endl;
123
124 for (std::size_t index = 0; index < Qss_misc::VAR_IDX_END; ++index)
125 {
126 ss << " Variable " << vars[index] << ":" << std::endl;
127 ss << " dQRel changes: " << dqrel_changes[index] << std::endl;
128 ss << " dQMin changes: " << dqmin_changes[index] << std::endl;
129 ss << " Max error: " << max_error[index] << std::endl;
130 }
131
132 G4cout << ss.rdbuf();
133 };
134};
135
136#endif
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
constexpr unsigned int VAR_IDX_END
Definition G4qss_misc.hh:57
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