Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4QSS_CustomStats.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // QSSStats
0027 //
0028 // QSS statistics
0029 
0030 // Authors:  Lucio Santi, Rodrigo Castro - 2018-2021
0031 // --------------------------------------------------------------------
0032 #ifndef _QSS_CUSTOM_STATS_HH_
0033 #define _QSS_CUSTOM_STATS_HH_
0034 
0035 #include <time.h>
0036 
0037 #define GET_TIME(t0) (clock_gettime(CLOCK_MONOTONIC, &t0))
0038 #define TIME_SECS(t0, t1) ((t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1e9)
0039 
0040 // #define INTERPOLATE_ITERATIONS 1e2
0041 // #define ESTIMATE_ITERATIONS 2
0042 // #define ON_COMPUTE_STEP_ITERATIONS 20
0043 // #define ON_COMPUTE_STEP_ITERATIONS_G4 2e3
0044 
0045 #include "G4qss_misc.hh"
0046 #include "G4Types.hh"
0047 
0048 #include <atomic>
0049 
0050 struct QSSStats
0051 {
0052   G4double precision_dQMin;
0053   G4double precision_dQRel;
0054   G4int currentStep;
0055   G4int substeps;
0056   std::atomic<G4int> stepperSteps;
0057   std::map<G4int, std::map<G4int, G4int>> substepsByStepNumberByTrackID;
0058 
0059   G4double reset_time;
0060   G4double integration_time;
0061 
0062   G4int dqrel_changes[Qss_misc::VAR_IDX_END];
0063   G4int dqmin_changes[Qss_misc::VAR_IDX_END];
0064   G4double max_error[Qss_misc::VAR_IDX_END];
0065 
0066   QSSStats()
0067   {
0068     substeps = 0;
0069     reset_time = 0;
0070     integration_time = 0;
0071 
0072     for (size_t i = 0; i < Qss_misc::VAR_IDX_END; i++) {
0073       dqrel_changes[i] = 0;
0074       dqmin_changes[i] = 0;
0075       max_error[i] = 0;
0076     }
0077   };
0078 
0079   void print() const
0080   {
0081     G4int steps = stepperSteps.load();
0082 
0083     std::vector<std::string> vars{"x", "y", "z", "vx", "vy", "vz"};
0084 
0085     G4double avg_substeps = (G4double)substeps / steps;
0086     G4double avg_integration_time = (G4double)integration_time / steps;
0087     G4double avg_substeps_integration_time = (G4double)integration_time / substeps;
0088     G4double avg_reset_time = (G4double)reset_time / steps;
0089 
0090     std::stringstream ss;
0091 
0092     ss << "QSS stats:" << std::endl;
0093     ss << "dQMin: " << precision_dQMin << std::endl;
0094     ss << "dQRel: " << precision_dQRel << std::endl;
0095 
0096     ss << " Total steps: " << steps << std::endl
0097        << " Total substeps: " << substeps << std::endl
0098        << " Substeps average per step: " << avg_substeps << std::endl;
0099 
0100     ss << " Substeps by track-step:" << std::endl;
0101     for (auto it = substepsByStepNumberByTrackID.begin(); it != substepsByStepNumberByTrackID.end();
0102          ++it)
0103     {
0104       ss << "  Track #" << it->first << std::endl;
0105       for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2) {
0106         ss << "    Step " << it2->first << " => " << it2->second << " substeps" << std::endl;
0107       }
0108     }
0109 
0110     ss << " Integration time: " << integration_time << std::endl
0111        << " Integration time average (step): " << avg_integration_time << std::endl
0112        << " Integration time average (substep): " << avg_substeps_integration_time << std::endl;
0113 
0114     ss << " Reset time: " << reset_time << std::endl
0115        << " Reset time average: " << avg_reset_time << std::endl;
0116 
0117     for (G4int index = 0; index < Qss_misc::VAR_IDX_END; index++) {
0118       ss << " Variable " << vars[index] << ":" << std::endl;
0119       ss << "  dQRel changes: " << dqrel_changes[index] << std::endl;
0120       ss << "  dQMin changes: " << dqmin_changes[index] << std::endl;
0121       ss << "  Max error: " << max_error[index] << std::endl;
0122     }
0123 
0124     std::cout << ss.rdbuf();
0125   };
0126 };
0127 
0128 #endif