Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
propagation_timing.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file propagation_timing.py
1 import ROOT
2 import csv
3 import matplotlib.pyplot as plt
4 import numpy as np
5 
6 # Data preparation
7 dataDict = {}
8 
9 # Open the output file
10 with open("output.log", mode="r") as csv_file:
11  csv_reader = csv.reader(csv_file, delimiter=",")
12  # read lines and go for it
13  for csv_row in csv_reader:
14  if len(csv_row) > 1:
15  # get the job id
16  jobID = csv_row[0]
17  # we need the exec time
18  exectime = 0.0
19  with open("timing_" + jobID + ".tsv") as tsv_file:
20  tsv_reader = csv.reader(tsv_file, delimiter="\t")
21  for tsv_row in tsv_reader:
22  if str(tsv_row[0]) == "Algorithm:PropagationAlgorithm":
23  exectime = float(tsv_row[2])
24  # stepper and pt
25  stepper = int(csv_row[1])
26  ptvalue = float(csv_row[2])
27  # now open the ROOT file and extract the numbers
28  rfile = ROOT.TFile("propagation_steps_" + str(jobID) + ".root")
29  stree = rfile.Get("propagation_steps")
30  stree.Draw("@g_x->size()>>h_steps")
31  h_steps = ROOT.gDirectory.Get("h_steps")
32  steps = h_steps.GetMean()
33  stepsSpread = h_steps.GetMeanError()
34 
35  # Make sure you have all the keys ready
36  try:
37  cdict = dataDict[ptvalue]
38  except:
39  dataDict[ptvalue] = {}
40  cdict = dataDict[ptvalue]
41 
42  # Now fill the sub dictionary
43  try:
44  vdict = cdict[stepper]
45  except:
46  cdict[stepper] = []
47  vdict = cdict[stepper]
48 
49  vdict += [steps, stepsSpread, exectime, exectime / steps]
50 
51 # plot the dataDict
52 plt.figure(figsize=(16, 5))
53 
54 ax = plt.subplot(131)
55 plt.loglog(
56  dataDict.keys(),
57  [i[0][0] for i in np.array(list(dataDict.values()))],
58  "+",
59  label="line",
60 )
61 plt.loglog(
62  dataDict.keys(),
63  [i[1][0] for i in np.array(list(dataDict.values()))],
64  "*",
65  label="eigen",
66 )
67 plt.loglog(
68  dataDict.keys(),
69  [i[2][0] for i in np.array(list(dataDict.values()))],
70  "o",
71  label="atlas",
72 )
73 ax.set_xlabel("$p_T$ [GeV]")
74 ax.set_ylabel("#steps")
75 ax.set_xlim((-10, 150))
76 plt.legend(numpoints=1)
77 
78 ax = plt.subplot(132)
79 plt.loglog(dataDict.keys(), [i[0][2] for i in np.array(list(dataDict.values()))], "+")
80 plt.loglog(dataDict.keys(), [i[1][2] for i in np.array(list(dataDict.values()))], "*")
81 plt.loglog(dataDict.keys(), [i[2][2] for i in np.array(list(dataDict.values()))], "o")
82 ax.set_xlabel("$p_T$ [GeV]")
83 ax.set_ylabel("time [a.u.]")
84 ax.set_xlim((-10, 150))
85 
86 
87 ax = plt.subplot(133)
88 plt.loglog(dataDict.keys(), [i[0][3] for i in np.array(list(dataDict.values()))], "+")
89 plt.loglog(dataDict.keys(), [i[1][3] for i in np.array(list(dataDict.values()))], "*")
90 plt.loglog(dataDict.keys(), [i[2][3] for i in np.array(list(dataDict.values()))], "o")
91 ax.set_xlabel("$p_T$ [GeV]")
92 ax.set_ylabel("time/steps [a.u.]")
93 ax.set_xlim((-10, 150))
94 
95 
96 plt.suptitle("Stepper comparison: Constant Field")
97 
98 plt.show()