ATLAS Offline Software
Loading...
Searching...
No Matches
TestActionVPTimer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
6// //
7// TestActionVPTimer //
8// Code for text output (into the athena.out files) //
9// of information about the time spent simulating //
10// various pieces of the detector and particles. //
11// //
12// Written by Kevin Sapp //
13// University of Pittsburgh //
14// kcs34@pitt.edu //
15// Last update 10.13.09 //
16// //
18
19
20#include "TestActionVPTimer.h"
21
22#include <G4Track.hh>
23#include <G4Electron.hh>
24#include <G4Gamma.hh>
25#include <G4Positron.hh>
26#include <G4TouchableHistory.hh>
27#include <G4ParticleDefinition.hh>
28
29#include <algorithm>
30#include <iomanip>
31#include <ios>
32
33using std::map;
34using std::max;
35using std::string;
36using std::setw;
37using std::ios;
38using std::make_pair;
39using std::pair;
40using std::find;
41using std::vector;
42
43// #define _myDebug
44
45namespace G4UA
46{
47
50 {
51 // create event & run timers
52 m_runTimer = new G4Timer();
53 m_runTimer->Start();
54 m_runTimer->Stop();
55 m_eventTimer = new G4Timer();
56 m_eventTimer->Start();
57 m_eventTimer->Stop();
58
59 // create step timer
60 v_timer = new G4Timer();
61 v_timer->Start();
62 v_timer->Stop();
63 }
64
66 {
67 m_report.nev++;
68 m_eventTimer->Start();
69 }
70
72 {
73 // this function also stops the timer. it will be restarted at BoE
75 }
76
78 {
79 m_runTimer->Start();
80 }
81
83 {
84 // this also stops the timer
85 m_report.runTime += TimerSum(m_runTimer);
86 }
87
88 void TestActionVPTimer::UserSteppingAction(const G4Step* aStep)
89 {
90 // HERE IS WHERE WE BEGIN OUR CLOCKING -- ONLY IF
91 // TIMERS ARE NOT VALID
92
93 if (!v_timer->IsValid()) {
94
95 // Collect the total time before processing anything else
96 // this stops the timer
97 double vtime = TimerSum(v_timer);
98
99 // CHECKIN' OUT THA NAVIGATA
100 VolumeTreeNavigator currentTree( aStep );
101
102 // Set depth cuts here
103 currentTree.SetDepthCutSimple(m_config.dCALO, m_config.dBeam, m_config.dIDET, m_config.dMUON);
104 if ( !m_config.dDetail.empty() ) {
105 currentTree.SetDepthCutDetail( m_config.dDetail.c_str() );
106 }
107
108 // Store time generated in current volume, remove deepest entry in v_history, then
109 // repeat for the resulting VolTree (one level higher)
110 G4ParticleDefinition* PDef = currentTree.GetTrack()->GetDefinition();
111 while ( true ) {
112 VolTree VHistory = currentTree.Extract();
113 m_report.time_index[VHistory].tTotal += vtime;
114 //std::cout<<"filling "<<m_report.time_index[VHistory].tTotal<<std::endl;
115 if (PDef->GetParticleName() == "neutron") { m_report.time_index[VHistory].tNeutron += vtime; }
116 else if (PDef->GetParticleSubType() == "e") { m_report.time_index[VHistory].tElectron += vtime; }
117 else if (PDef->GetParticleSubType() == "pi") { m_report.time_index[VHistory].tPion += vtime; }
118 else if (PDef->GetParticleType() == "gamma") { m_report.time_index[VHistory].tPhoton += vtime; }
119 else if (PDef->GetParticleType() == "baryon") { m_report.time_index[VHistory].tBaryon += vtime; }
120 else if (PDef->GetParticleType() == "lepton") { m_report.time_index[VHistory].tLepton += vtime; }
121 else if (PDef->GetParticleType() == "meson") { m_report.time_index[VHistory].tMeson += vtime; }
122 else { m_report.time_index[VHistory].tOther += vtime; }
123 //ATH_MSG_DEBUG("Time stored in "<<VHistory.back().first->GetName());
124 if ( !currentTree.Ascend() ) break;
125 }
126 }
127
128 // Restart timer
129 v_timer->Start();
130 }
131
132} // namespace G4UA
std::vector< VolID > VolTree
virtual void BeginOfRunAction(const G4Run *) override
double m_eventTime
Double for storing this event time.
double TimerSum(G4Timer *timer) const
Gets the time from the timer for summation.
TestActionVPTimer(const Config &config)
G4Timer * m_eventTimer
Timer for this event.
virtual void EndOfEventAction(const G4Event *) override
virtual void BeginOfEventAction(const G4Event *) override
virtual void UserSteppingAction(const G4Step *) override
G4Timer * v_timer
Timer activated for each volume.
virtual void EndOfRunAction(const G4Run *) override
G4Timer * m_runTimer
Timer for the entire run.
bool Ascend(int levels=1)
const G4Track * GetTrack() const
void SetDepthCutDetail(const char *)
void SetDepthCutSimple(const int, const int, const int, const int)