ATLAS Offline Software
Loading...
Searching...
No Matches
TestActionTimerTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "GaudiKernel/ITHistSvc.h"
7#include "TH1D.h"
8
9namespace G4UA
10{
11
13 const std::string& name,
14 const IInterface* parent)
15 : UserActionToolBase<TestActionTimer>(type, name, parent),
16 m_histSvc("THistSvc", name)
17 {
18 }
19
21 {
22 ATH_CHECK(m_histSvc.retrieve());
23 return StatusCode::SUCCESS;
24 }
25
26 std::unique_ptr<TestActionTimer>
28 {
29 ATH_MSG_DEBUG("Constructing a TestActionTimer");
30 auto action = std::make_unique<TestActionTimer>();
31 actionList.runActions.push_back( action.get() );
32 actionList.eventActions.push_back( action.get() );
33 actionList.steppingActions.push_back( action.get() );
34 return action;
35 }
36
38 {
39 // Accumulate results across threads
41 m_actions.accumulate(report, &TestActionTimer::getReport,
43
44 if(!report.time.empty()){
45 G4double sumVTime = 0.;
46 G4double sumPTime = 0.;
47 for (int i(0); i <= TestActionTimer::eOther; ++i) sumVTime += report.time[i];
48 for (int i(TestActionTimer::eElec); i < TestActionTimer::eMax; ++i) sumPTime += report.time[i];
49
50 if (report.nev>0){
51 ATH_MSG_INFO("****** TestActionTimer: Beginning timer dump ******");
52
53 G4double DeadTime = report.runTime - sumVTime;
54 G4double OtherPart = report.runTime - DeadTime - sumPTime;
55
56 ATH_MSG_INFO("Timer\tEvent\tFraction");
57 ATH_MSG_INFO("EvtAve\t"<<report.runTime/report.nev<<"\t100");
58
59 for (int i(0);i <= TestActionTimer::eOther; i++) {
60 ATH_MSG_INFO(report.timeName[i] << "\t" << report.time[i]/report.nev << "\t" << report.time[i]/report.runTime);
61 }
62 ATH_MSG_INFO("Dead\t" << DeadTime/report.nev << "\t" << DeadTime/report.runTime);
63 for (int i(TestActionTimer::eElec);i < TestActionTimer::eMax; i++) {
64 ATH_MSG_INFO(report.timeName[i] << "\t" << report.time[i]/report.nev << "\t" << report.time[i]/report.runTime);
65 }
66 ATH_MSG_INFO("OtherPart\t" << OtherPart/report.nev << "\t" << OtherPart/report.runTime);
67
68 ATH_MSG_INFO("****** TestActionTimer: Major Subdet Times per Event *********");
69 ATH_MSG_INFO("EMB\t" << (report.time[TestActionTimer::eEMB])/report.nev);
70 ATH_MSG_INFO("EMEC\t" << (report.time[TestActionTimer::eEMEC])/report.nev);
71 ATH_MSG_INFO("FCAL\t" << (report.time[TestActionTimer::eFC1]+report.time[TestActionTimer::eFC23]+report.time[TestActionTimer::eFCO])/report.nev);
72 ATH_MSG_INFO("HEC\t" << (report.time[TestActionTimer::eHEC])/report.nev);
73 ATH_MSG_INFO("Tile\t" << (report.time[TestActionTimer::eHCB])/report.nev);
74 ATH_MSG_INFO("Tracker\t" << (report.time[TestActionTimer::ePx]+report.time[TestActionTimer::eSct]+report.time[TestActionTimer::eITkPix]+report.time[TestActionTimer::eITkStrip]+report.time[TestActionTimer::eTrt]+report.time[TestActionTimer::eSev])/report.nev);
75 ATH_MSG_INFO("Muons\t" << (report.time[TestActionTimer::eMu])/report.nev);
76 ATH_MSG_INFO("Oth.LAr\t" << (report.time[TestActionTimer::ePre]+report.time[TestActionTimer::TestActionTimer::eCry]+report.time[TestActionTimer::eLAr])/report.nev);
77 ATH_MSG_INFO("Other\t" << (report.time[TestActionTimer::eOther])/report.nev);
78 ATH_MSG_INFO("EvtAve\t" << (report.runTime)/report.nev);
79 ATH_MSG_INFO("******* TestActionTimer: Major Subdet Frac per Event *********");
80 ATH_MSG_INFO("EMB\t" << (report.time[TestActionTimer::eEMB])/report.runTime*100.);
81 ATH_MSG_INFO("EMEC\t" << (report.time[TestActionTimer::eEMEC])/report.runTime*100.);
82 ATH_MSG_INFO("FCAL\t" << (report.time[TestActionTimer::eFC1]+report.time[TestActionTimer::eFC23]+report.time[TestActionTimer::eFCO])/report.runTime*100.);
83 ATH_MSG_INFO("HEC\t" << (report.time[TestActionTimer::eHEC])/report.runTime*100.);
84 ATH_MSG_INFO("Tile\t" << (report.time[TestActionTimer::eHCB])/report.runTime*100.);
85 ATH_MSG_INFO("Tracker\t" << (report.time[TestActionTimer::ePx]+report.time[TestActionTimer::eSct]+report.time[TestActionTimer::eITkPix]+report.time[TestActionTimer::eITkStrip]+report.time[TestActionTimer::eTrt]+report.time[TestActionTimer::eSev])/report.runTime*100.);
86 ATH_MSG_INFO("Muons\t" << (report.time[TestActionTimer::eMu])/report.runTime*100.);
87 ATH_MSG_INFO("Oth.LAr\t" << (report.time[TestActionTimer::ePre]+report.time[TestActionTimer::eCry]+report.time[TestActionTimer::eLAr])/report.runTime*100.);
88 ATH_MSG_INFO("Other\t" << (report.time[TestActionTimer::eOther])/report.runTime*100.);
89 ATH_MSG_INFO("EvtAve\t" << (report.runTime)/report.nev);
90 ATH_MSG_INFO("******* TestActionTimer: Timer Information *********");
91 ATH_MSG_INFO("NOTE: in case of MT runs, the timings for the individual threads are added, i.e. it is");
92 ATH_MSG_INFO(" equivalent to running the N threads sequentially instead of in parallel.");
93 ATH_MSG_INFO("Timers were run over " << report.nev << " events, and the averages were taken by");
94 ATH_MSG_INFO("detector portion. Detectors are determined by volume name. Pieces include:");
95 ATH_MSG_INFO("EMB, EMEC, FCAL, HEC, Tile - the sampling portions of the calorimeters.");
96 ATH_MSG_INFO("Pixel, SCT, TRT - the sensitive portions of the tracker only");
97 ATH_MSG_INFO("InDetSvc - all remaining portions of the inner detector");
98 ATH_MSG_INFO("Oth.LAr - all remaining portions of the LAr, including preshower, solenoid,");
99 ATH_MSG_INFO("\tcryostats, and services.");
100 ATH_MSG_INFO("Other - volumes not listed, including ATLAS::ATLAS and CALO::CALO");
101 ATH_MSG_INFO("");
102 ATH_MSG_INFO("Dead time includes overhead per event (file i/o, event loading, timing overhead)");
103 ATH_MSG_INFO("");
104 ATH_MSG_INFO("All times are user+system time on your processor");
105 ATH_MSG_INFO("******* TestActionTimer: End of timer dump *********");
106
107 TH1D * r_geo = new TH1D("GeoResults","GeoResults",TestActionTimer::eOther-TestActionTimer::eEMB+1,-0.5,float(TestActionTimer::eOther-TestActionTimer::eEMB+1)-0.5);
108 TH1D * r_part = new TH1D("ParticleResults","ParticleResults",TestActionTimer::eMax-TestActionTimer::eElec+1,-0.5,float(TestActionTimer::eMax-TestActionTimer::eElec+1)-0.5);
109
110 report.runTime -= DeadTime;
111 for (int i(0); i <= TestActionTimer::eOther; ++i){
112 r_geo->Fill( i , report.time[i] / report.runTime*100. );
113 r_geo->GetXaxis()->SetBinLabel( i+1 , report.timeName[i].c_str() );
114 }
115 for (int i(TestActionTimer::eElec); i < TestActionTimer::eMax; ++i){
116 r_part->Fill( i-TestActionTimer::eElec , report.time[i] / report.runTime*100. );
117 r_part->GetXaxis()->SetBinLabel( i-TestActionTimer::eElec+1 , report.timeName[i].c_str() );
118 }
119 r_part->Fill( TestActionTimer::eMax-TestActionTimer::eElec , OtherPart / report.runTime*100. ); // Other particles don't get their own timer
120 r_part->GetXaxis()->SetBinLabel( TestActionTimer::eMax-TestActionTimer::eElec+1 , "Others" );
121 r_geo->SetXTitle("Detector Region");
122 r_part->SetXTitle("Particle Type");
123 r_geo->SetYTitle("Percent of Event Time");
124 r_part->SetYTitle("Percent of Event Time");
125
126 if (m_histSvc){
127 if ( m_histSvc->regHist("/simTime/GeoResults",r_geo).isFailure() ||
128 m_histSvc->regHist("/simTime/ParticleResults",r_part).isFailure() ){
129 ATH_MSG_ERROR("Could not register histograms!");
130 }
131 }
132
133 } else {
134
135 ATH_MSG_INFO("******* TestActionTimer: Nothing to report, no events timed! *********");
136 }
137 } else {ATH_MSG_INFO("******* TestActionTimer: No timing information recoreded! *********");}
138 return StatusCode::SUCCESS;
139 }
140
141} // namespace G4UA
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
virtual StatusCode finalize() override
Finalize the tool.
virtual StatusCode initialize() override
Initialize the tool.
virtual std::unique_ptr< TestActionTimer > makeAndFillAction(G4AtlasUserActions &) override final
Create action for this thread.
ServiceHandle< ITHistSvc > m_histSvc
HistSvc to record timing histograms.
TestActionTimerTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
User action to measure time spent in subdetectors.
const Report & getReport() const
ThreadSpecificUserAction< TestActionTimer > m_actions
UserActionToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Struct for passing around user actions.
std::vector< G4UserSteppingAction * > steppingActions
std::vector< G4UserEventAction * > eventActions
std::vector< G4UserRunAction * > runActions
this holds all the data from individual threads that needs to be merged at EoR
void merge(const Report &rep)