Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnalyzeTime.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AnalyzeTime.C
1 #include "../CommonTools.h"
2 
3 void initializeModules(std::map<std::string,std::vector<double>>& modules);
4 void collectData(std::map<std::string,std::vector<double>>& modules,
6 void plotTimes(std::map<std::string, std::vector<double>>& modules, std::string& filename);
7 
8 
9 
10 /*
11  * This root macro analyzes the output from parseTimers.csh
12  * The input is a filename to the text file created from parseTimers.csh, e.g.
13  * root -l -b -q AnalyzeTime.C'("time.txt")'
14  * The output is a root file which contains the time of each tracking module
15  * The output also produces a .png with each module's individual contribution
16  * to the total time. The output rootfile has a total time graph which
17  * sums the contributions
18  */
20 {
21 
22  std::map<std::string,std::vector<double>> modules;
23  initializeModules(modules);
24 
25  collectData(modules,infile);
26 
27  plotTimes(modules, outfile);
28 }
29 
30 void plotTimes(std::map<std::string, std::vector<double>>& modules,
32 {
33  ostringstream canname;
34  int nbins = 200;
35  double bins[nbins+1];
36  double stepsize = 1.07;
37  bins[0] = 1.;
38 
39  for(int i=1;i <nbins+1; i++)
40  {
41  bins[i]=bins[i-1]*stepsize;
42  }
43 
44 
45  std::vector<double> totalTime;
46  const int totentries = modules.at("MvtxClusterizer").size();
47 
48  for(int i=0; i<totentries; i++)
49  { totalTime.push_back(0); }
50 
51  TFile *outfile = new TFile(filename.c_str(),"recreate");
52  for(const auto& [moduleName, values] : modules)
53  {
54  canname.str("");
55  canname<<"can_"<<moduleName.c_str();
56  TCanvas *can = new TCanvas(canname.str().c_str(),canname.str().c_str(),
57  200,200,800,600);
58  //gStyle->SetOptStat(0);
59  TH1F *histo = new TH1F(moduleName.c_str(),moduleName.c_str(),
60  nbins,bins);
61 
62  for(int i=0; i<values.size(); i++)
63  {
64  histo->Fill(values.at(i));
65  if(i<totentries)
66  totalTime.at(i) += values.at(i);
67  }
68 
69  histo->GetXaxis()->SetTitle("time [ms]");
70  can->cd();
71 
72  gPad->SetLogx();
73 
74  histo->Draw();
75  outfile->cd();
76  histo->Write();
77  myText(0.2,0.96,kBlack,moduleName.c_str());
78  canname<<".png";
79  //can->Print(canname.str().c_str());
80  }
81 
82  TH1F *totalTimes = new TH1F("totalTime",";time [ms]",nbins,bins);
83  for(const auto& val : totalTime)
84  { totalTimes->Fill(val); }
85 
86  totalTimes->Write();
87  outfile->Write();
88  outfile->Close();
89 
90 }
91 
92 void collectData(std::map<std::string,std::vector<double>>& modules,
94 {
95 
96  ifstream file;
97  file.open(filename.c_str());
99 
100  if(file.is_open()) {
101  while(getline(file,line)) {
102  for(auto& [module, values] : modules) {
103  if(line.find(module) != std::string::npos) {
104  if(line.find("TOP") != std::string::npos) {
105  const auto pos = line.find("(ms): ");
106  const auto val = line.substr(pos+7,11);
107  values.push_back(atof(val.c_str()));
108  }
109  else if(line.find("Acts seed time") != std::string::npos) {
110  const auto apos = line.find("time ");
111  const auto aval = line.substr(apos+5,6);
112  values.push_back(atof(aval.c_str()));
113  }
114  }
115  }
116  }
117  }
118 }
119 
120 
121 void initializeModules(std::map<std::string,std::vector<double>>& modules)
122 {
123  std::vector<double> mvtx, intt, tpc, tpclean, silseed, caseed, preprop, kfprop, circlefit, clusterMover, tpcresiduals, secondtrkfit, trackmatch, trackfit, vtxfinder, vertexprop, actsseed, mm, mmmatch, dzcor;
124  modules.insert(std::make_pair("MvtxClusterizer",mvtx));
125  modules.insert(std::make_pair("InttClusterizer",intt));
126  modules.insert(std::make_pair("TpcClusterizer",tpc));
127  modules.insert(std::make_pair("MicromegasClusterizer",mm));
128  modules.insert(std::make_pair("PHMicromegasTpcTrackMatching",mmmatch));
129  modules.insert(std::make_pair("TpcClusterCleaner",tpclean));
130  modules.insert(std::make_pair("PHActsSiliconSeeding",silseed));
131  modules.insert(std::make_pair("Acts seed time",actsseed));
132  modules.insert(std::make_pair("PHCASeeding",caseed));
133  modules.insert(std::make_pair("PrePropagatorPHTpcTrackSeedCircleFit",preprop));
134  modules.insert(std::make_pair("PHSimpleKFProp",kfprop));
135  modules.insert(std::make_pair("PHTpcTrackSeedCircleFit",circlefit));
136  modules.insert(std::make_pair("PHSiliconTpcTrackMatching",trackmatch));
137  modules.insert(std::make_pair("PHActsFirstTrkFitter",trackfit));
138  modules.insert(std::make_pair("PHSimpleVertexFinder",vtxfinder));
139  modules.insert(std::make_pair("PHActsVertexPropagator",vertexprop));
140  modules.insert(std::make_pair("PHTpcClusterMover",clusterMover));
141  modules.insert(std::make_pair("PHTpcResiduals",tpcresiduals));
142  modules.insert(std::make_pair("PHActsSecondTrkFitter",secondtrkfit));
143  modules.insert(std::make_pair("PHTpcDeltaZCorrection",dzcor));
144 }
145