ECCE @ EIC 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.
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(dataDict.keys(),[i[0][0] for i in np.array(list(dataDict.values()))],'+', label='line')
56 plt.loglog(dataDict.keys(),[i[1][0] for i in np.array(list(dataDict.values()))],'*', label='eigen')
57 plt.loglog(dataDict.keys(),[i[2][0] for i in np.array(list(dataDict.values()))],'o', label='atlas')
58 ax.set_xlabel('$p_T$ [GeV]')
59 ax.set_ylabel('#steps')
60 ax.set_xlim((-10,150))
61 plt.legend(numpoints=1)
62 
63 ax = plt.subplot(132)
64 plt.loglog(dataDict.keys(),[i[0][2] for i in np.array(list(dataDict.values()))],'+')
65 plt.loglog(dataDict.keys(),[i[1][2] for i in np.array(list(dataDict.values()))],'*')
66 plt.loglog(dataDict.keys(),[i[2][2] for i in np.array(list(dataDict.values()))],'o')
67 ax.set_xlabel('$p_T$ [GeV]')
68 ax.set_ylabel('time [a.u.]')
69 ax.set_xlim((-10,150))
70 
71 
72 ax = plt.subplot(133)
73 plt.loglog(dataDict.keys(),[i[0][3] for i in np.array(list(dataDict.values()))],'+')
74 plt.loglog(dataDict.keys(),[i[1][3] for i in np.array(list(dataDict.values()))],'*')
75 plt.loglog(dataDict.keys(),[i[2][3] for i in np.array(list(dataDict.values()))],'o')
76 ax.set_xlabel('$p_T$ [GeV]')
77 ax.set_ylabel('time/steps [a.u.]')
78 ax.set_xlim((-10,150))
79 
80 
81 plt.suptitle("Stepper comparison: Constant Field")
82 
83 plt.show()