ATLAS Offline Software
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 
33 using std::map;
34 using std::max;
35 using std::string;
36 using std::setw;
37 using std::ios;
38 using std::make_pair;
39 using std::pair;
40 using std::find;
41 using std::vector;
42 
43 // #define _myDebug
44 
45 namespace G4UA
46 {
47 
49  : m_config(config), m_runTimer(0), m_eventTimer(0), m_eventTime(0.)
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
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
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
G4UA::TestActionVPTimer::Config::dBeam
int dBeam
Definition: TestActionVPTimer.h:60
G4UA::TestActionVPTimer::m_eventTimer
G4Timer * m_eventTimer
Timer for this event.
Definition: TestActionVPTimer.h:155
G4UA::TestActionVPTimer::m_report
Report m_report
Definition: TestActionVPTimer.h:152
VolumeTreeNavigator::SetDepthCutSimple
void SetDepthCutSimple(const int, const int, const int, const int)
Definition: VolumeTreeNavigator.cxx:65
max
#define max(a, b)
Definition: cfImp.cxx:41
G4UA::TestActionVPTimer::v_timer
G4Timer * v_timer
Timer activated for each volume.
Definition: TestActionVPTimer.h:156
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
G4UA::TestActionVPTimer::EndOfRunAction
virtual void EndOfRunAction(const G4Run *) override
Definition: TestActionVPTimer.cxx:82
VolumeTreeNavigator
Definition: VolumeTreeNavigator.h:39
G4UA::TestActionVPTimer::Config::dIDET
int dIDET
Definition: TestActionVPTimer.h:61
G4UA::TestActionVPTimer::BeginOfRunAction
virtual void BeginOfRunAction(const G4Run *) override
Definition: TestActionVPTimer.cxx:77
G4UA::TestActionVPTimer::Config::dMUON
int dMUON
Used for setting depths in jobOptions file.
Definition: TestActionVPTimer.h:62
G4UA::TestActionVPTimer::m_config
Config m_config
Definition: TestActionVPTimer.h:151
G4UA::TestActionVPTimer::Config
Definition: TestActionVPTimer.h:58
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
TestActionVPTimer.h
G4UA::TestActionVPTimer::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition: TestActionVPTimer.cxx:88
G4UA::TestActionVPTimer::Config::dCALO
int dCALO
Definition: TestActionVPTimer.h:59
G4UA::TestActionVPTimer::m_eventTime
double m_eventTime
Double for storing this event time.
Definition: TestActionVPTimer.h:157
G4UA::TestActionVPTimer::Report::time_index
VolMap time_index
Definition: TestActionVPTimer.h:107
G4UA::TestActionVPTimer::Report::nev
int nev
number of processed events
Definition: TestActionVPTimer.h:108
G4UA::TestActionVPTimer::TestActionVPTimer
TestActionVPTimer(const Config &config)
Definition: TestActionVPTimer.cxx:48
G4UA::TestActionVPTimer::m_runTimer
G4Timer * m_runTimer
Timer for the entire run.
Definition: TestActionVPTimer.h:154
G4UA::TestActionVPTimer::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition: TestActionVPTimer.cxx:71
VolumeTreeNavigator::SetDepthCutDetail
void SetDepthCutDetail(const char *)
Definition: VolumeTreeNavigator.cxx:88
VolumeTreeNavigator::GetTrack
const G4Track * GetTrack() const
VolTree
std::vector< VolID > VolTree
Definition: VolumeTreeNavigator.h:36
VolumeTreeNavigator::Ascend
bool Ascend(int levels=1)
Definition: VolumeTreeNavigator.cxx:133
G4UA::TestActionVPTimer::TimerSum
double TimerSum(G4Timer *timer) const
Gets the time from the timer for summation.
Definition: TestActionVPTimer.h:166
VolumeTreeNavigator::Extract
VolTree Extract()
Definition: VolumeTreeNavigator.cxx:122
G4UA::TestActionVPTimer::Config::dDetail
std::string dDetail
Path to set detailed depth in jobOptions file.
Definition: TestActionVPTimer.h:63
G4UA::TestActionVPTimer::BeginOfEventAction
virtual void BeginOfEventAction(const G4Event *) override
Definition: TestActionVPTimer.cxx:65
G4UA::TestActionVPTimer::Report::runTime
double runTime
Double for storing this run time.
Definition: TestActionVPTimer.h:109