Skip to content

Commit

Permalink
weight each run cycle time with its nps
Browse files Browse the repository at this point in the history
  • Loading branch information
kbat committed Dec 19, 2024
1 parent d46412a commit 07fb5d6
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions mctools/fluka/fluka-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import ROOT
ROOT.PyConfig.IgnoreCommandLineOptions = True

def Print(vals, ttype):
def Print(vals, ttype, nps):
data = np.array(vals)
n = len(data)
print("%s: %.5g ± %.5g sec" % (ttype, np.average(data), np.std(data)/sqrt(n)))
scale = n/nps
print("%s: %.5g ± %.5g sec" % (ttype, np.average(data)*scale, np.std(data)/sqrt(n)*scale))

def get(fname, ttype):
if ttype == "average":
Expand All @@ -21,6 +22,8 @@ def get(fname, ttype):
sss = "Maximum CPU time used to follow a primary particle:"
elif ttype == "total":
sss = "Total CPU time used to follow all primary particles:"
elif ttype == "nps":
sss = "Total number of primaries run"
else:
raise NameError(f"Unknown ttype argument: {ttype}")

Expand All @@ -31,7 +34,10 @@ def get(fname, ttype):
l = line.strip()
if re.search(f"\A{sss}", l):
w = l.split()
val = w[-3]
if ttype == "nps":
val = w[5]
else:
val = w[-3]
try:
val = float(val)
return val
Expand All @@ -58,18 +64,20 @@ def main():

avals = []
mvals = []

nps = 0
for fname in args.out:
aval = get(fname, "average")
if aval is not None:
mval = get(fname, "maximum")
if mval is not None:
avals.append(aval)
mvals.append(mval)

Print(avals, "Average")
Print(mvals, "Maximum")
print("TODO: take into account weight reported in Total number of primaries run")
n = get(fname, "nps")
avals.append(aval*n)
mvals.append(mval*n)
nps += n

Print(avals, "Average", nps)
Print(mvals, "Maximum", nps)
print(f"nps: {nps:e}")

if args.pdf:

Expand Down

0 comments on commit 07fb5d6

Please sign in to comment.