ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Utilities
G4UserActions
src
G4SimTimer.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// Local includes
6
#include "
G4SimTimer.h
"
7
#include <G4Threading.hh>
8
9
// Infrastructure includes
10
11
namespace
G4UA
12
{
13
14
//---------------------------------------------------------------------------
15
// Constructor for timing results struct
16
//---------------------------------------------------------------------------
17
G4SimTimer::Report::Report
()
18
:
nEvent
(0),
eventTime
(0),
eventTimeSquared
(0)
19
{}
20
21
//---------------------------------------------------------------------------
22
// Calculate the mean and sample standard deviation
23
//---------------------------------------------------------------------------
24
std::pair<double, double>
G4SimTimer::Report::meanAndSigma
()
25
{
26
double
mean
=
nEvent
> 0 ?
eventTime
/
nEvent
: -1.;
27
double
sigma = -1.;
28
if
(
nEvent
> 1)
29
sigma = sqrt( (
eventTimeSquared
/
nEvent
-
mean
*
mean
) / (
nEvent
-1) );
30
return
std::make_pair(
mean
, sigma);
31
}
32
33
//---------------------------------------------------------------------------
34
// G4SimTimer constructor
35
//---------------------------------------------------------------------------
36
G4SimTimer::G4SimTimer
()
37
:
AthMessaging
(
"G4SimTimer"
),
38
m_firstEvent
(true)
39
{}
40
41
//---------------------------------------------------------------------------
42
// Begin-run action
43
//---------------------------------------------------------------------------
44
void
G4SimTimer::BeginOfRunAction
(
const
G4Run*)
45
{
46
if
(G4Threading::IsMasterThread()){
47
m_results
.runtime.Start();
48
}
49
}
50
51
//---------------------------------------------------------------------------
52
// End-run action
53
//---------------------------------------------------------------------------
54
void
G4SimTimer::EndOfRunAction
(
const
G4Run*)
55
{
56
if
(G4Threading::IsMasterThread()){
57
m_results
.runtime.Stop();
58
}
59
}
60
61
//---------------------------------------------------------------------------
62
// Begin-event action
63
//---------------------------------------------------------------------------
64
void
G4SimTimer::BeginOfEventAction
(
const
G4Event*
/*event*/
)
65
{
66
//ATH_MSG_INFO("beginOfEvent");
67
m_eventTimer
.Start();
68
}
69
70
//---------------------------------------------------------------------------
71
// End-event action
72
//---------------------------------------------------------------------------
73
void
G4SimTimer::EndOfEventAction
(
const
G4Event*
/*event*/
)
74
{
75
m_eventTimer
.Stop();
76
// We define time as user+system time.
77
auto
eventTime =
m_eventTimer
.GetUserElapsed() +
m_eventTimer
.GetSystemElapsed();
78
// Skip the first event
79
if
(!
m_firstEvent
) {
80
m_results
.nEvent++;
81
m_results
.eventTime += eventTime;
82
m_results
.eventTimeSquared += eventTime*eventTime;
83
auto
meanSigma =
m_results
.meanAndSigma();
84
ATH_MSG_INFO
(
"Event "
<<
m_results
.nEvent <<
" took "
<<
85
std::setprecision(4) << eventTime <<
" s. New average "
<<
86
std::setprecision(4) << meanSigma.first <<
" +- "
<<
87
std::setprecision(4) << meanSigma.second);
88
}
89
else
m_firstEvent
=
false
;
90
}
91
92
}
// namespace G4UA
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
G4SimTimer.h
AthMessaging::AthMessaging
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Definition
AthMessaging.cxx:13
G4UA::G4SimTimer::EndOfRunAction
virtual void EndOfRunAction(const G4Run *run) override final
End timing this Geant4 run.
Definition
G4SimTimer.cxx:54
G4UA::G4SimTimer::m_eventTimer
G4Timer m_eventTimer
My private instance of an event timer.
Definition
G4SimTimer.h:99
G4UA::G4SimTimer::EndOfEventAction
virtual void EndOfEventAction(const G4Event *event) override final
Finish timing this Geant4 event.
Definition
G4SimTimer.cxx:73
G4UA::G4SimTimer::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *run) override final
Start timing this Geant4 run.
Definition
G4SimTimer.cxx:44
G4UA::G4SimTimer::m_results
Report m_results
My timing results.
Definition
G4SimTimer.h:102
G4UA::G4SimTimer::G4SimTimer
G4SimTimer()
Constructor.
Definition
G4SimTimer.cxx:36
G4UA::G4SimTimer::BeginOfEventAction
virtual void BeginOfEventAction(const G4Event *event) override final
Start timing this Geant4 event.
Definition
G4SimTimer.cxx:64
G4UA::G4SimTimer::m_firstEvent
bool m_firstEvent
Used to skip the first event.
Definition
G4SimTimer.h:105
mean
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition
dependence.cxx:254
G4UA
for nSW
Definition
CalibrationDefaultProcessing.h:19
G4UA::G4SimTimer::Report::meanAndSigma
std::pair< double, double > meanAndSigma()
Calculate the mean and sample std dev.
Definition
G4SimTimer.cxx:24
G4UA::G4SimTimer::Report::eventTime
double eventTime
Accumulated event time.
Definition
G4SimTimer.h:59
G4UA::G4SimTimer::Report::Report
Report()
Initializes the variables.
Definition
G4SimTimer.cxx:17
G4UA::G4SimTimer::Report::nEvent
unsigned int nEvent
Number of timed G4 events (we skip the first).
Definition
G4SimTimer.h:57
G4UA::G4SimTimer::Report::eventTimeSquared
double eventTimeSquared
Accumulated squared event time.
Definition
G4SimTimer.h:61
Generated on
for ATLAS Offline Software by
1.17.0