Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 09:11:52

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 (Univ. Buenos Aires), 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 #include "G4ios.hh"
0048 
0049 #include <atomic>
0050 #include <map>
0051 
0052 /**
0053  * @brief QSSStats contains functions for statistics on the QSS drivers.
0054  */
0055 
0056 struct QSSStats
0057 {
0058   G4double precision_dQMin;
0059   G4double precision_dQRel;
0060   G4int currentStep;
0061   G4int substeps;
0062   std::atomic<G4int> stepperSteps;
0063   std::map<G4int, std::map<G4int, G4int>> substepsByStepNumberByTrackID;
0064 
0065   G4double reset_time;
0066   G4double integration_time;
0067 
0068   G4int dqrel_changes[Qss_misc::VAR_IDX_END];
0069   G4int dqmin_changes[Qss_misc::VAR_IDX_END];
0070   G4double max_error[Qss_misc::VAR_IDX_END];
0071 
0072   QSSStats()
0073   {
0074     substeps = 0;
0075     reset_time = 0;
0076     integration_time = 0;
0077 
0078     for (std::size_t i = 0; i < Qss_misc::VAR_IDX_END; ++i)
0079     {
0080       dqrel_changes[i] = 0;
0081       dqmin_changes[i] = 0;
0082       max_error[i] = 0;
0083     }
0084   };
0085 
0086   void print() const
0087   {
0088     G4int steps = stepperSteps.load();
0089 
0090     std::vector<std::string> vars{"x", "y", "z", "vx", "vy", "vz"};
0091 
0092     G4double avg_substeps = (G4double)substeps / steps;
0093     G4double avg_integration_time = (G4double)integration_time / steps;
0094     G4double avg_substeps_integration_time = (G4double)integration_time / substeps;
0095     G4double avg_reset_time = (G4double)reset_time / steps;
0096 
0097     std::stringstream ss;
0098 
0099     ss << "QSS stats:" << std::endl;
0100     ss << "dQMin: " << precision_dQMin << std::endl;
0101     ss << "dQRel: " << precision_dQRel << std::endl;
0102 
0103     ss << " Total steps: " << steps << std::endl
0104        << " Total substeps: " << substeps << std::endl
0105        << " Substeps average per step: " << avg_substeps << std::endl;
0106 
0107     ss << " Substeps by track-step:" << std::endl;
0108     for (const auto& stp : substepsByStepNumberByTrackID)
0109     {
0110       ss << "  Track #" << stp.first << std::endl;
0111       for (const auto& stp2 : stp.second)
0112       {
0113         ss << "    Step " << stp2.first << " => " << stp2.second << " substeps" << std::endl;
0114       }
0115     }
0116 
0117     ss << " Integration time: " << integration_time << std::endl
0118        << " Integration time average (step): " << avg_integration_time << std::endl
0119        << " Integration time average (substep): " << avg_substeps_integration_time << std::endl;
0120 
0121     ss << " Reset time: " << reset_time << std::endl
0122        << " Reset time average: " << avg_reset_time << std::endl;
0123 
0124     for (std::size_t index = 0; index < Qss_misc::VAR_IDX_END; ++index)
0125     {
0126       ss << " Variable " << vars[index] << ":" << std::endl;
0127       ss << "  dQRel changes: " << dqrel_changes[index] << std::endl;
0128       ss << "  dQMin changes: " << dqmin_changes[index] << std::endl;
0129       ss << "  Max error: " << max_error[index] << std::endl;
0130     }
0131 
0132     G4cout << ss.rdbuf();
0133   };
0134 };
0135 
0136 #endif