-
Notifications
You must be signed in to change notification settings - Fork 2
/
graph.tracking.physics.py
executable file
·64 lines (53 loc) · 1.84 KB
/
graph.tracking.physics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
import numpy as np,matplotlib as mpl,plot,sys,re
from collections import Counter
clrs=plot.colors
#plot the physicsprocesses per step in a Gate log
hist=[]
sourcefile = open(sys.argv[-1],'r')
for line in sourcefile:
newline = line.strip()
if '_phys' in newline:
hist.append(newline.split()[9])
#cntr = dict(Counter(hist).most_common(8))
cntr = Counter(hist)
labels = '-'.join(cntr.keys())
d = {
'nCapture':'Neutron Capture (h)',
'hIoni':'Hadron Ionisation (h)',
'Transportation':'Transportation (MC)',
'StepLimiter':'StepLimiter (MC)',
'ionIoni':'Ion Ionisation (h)',
'phot':'Photoelectric Effect ($\gamma$)',
'initStep':'Initial Step (MC)',
'neutronInelastic':'Neutron Inelastic (h)',
'hadElastic':'Hadron Elastic (h)',
'compt':'Compton Scatter ($\gamma$)',
'Rayl':'Rayleigh Scatter ($\gamma$)',
'protonInelastic':'Proton Inelastic (h)',
'eBrem':'Bremsstrahlung (e)',
'eIoni':'Ionisation (e)',
'annihil':'Annihilation (e)',
'msc':'Coulomb Scatter (e, h)',
'conv':'Pair creation/Gamma Conversion ($\gamma$)'
}
pattern = re.compile(r'\b(' + '|'.join(d.keys()) + r')\b')
labels = pattern.sub(lambda x: d[x.group()], labels)
labels = labels.split('-')
ind = np.arange(len(cntr))
margin = 0.2
width = (1.-2.*margin)
xdata = ind - width/2.
f, ax1 = plot.subplots(nrows=1, ncols=1, sharex=False, sharey=False)
ax1.bar(xdata, cntr.values(), width, color=clrs[0],lw=0)
ax1.xaxis.set_major_locator(mpl.ticker.FixedLocator(range(len(cntr))))
ax1.set_xticklabels(labels, fontsize=8, rotation=20, ha='center')
#ax1.set_xticklabels(['']+cntr.keys(), fontsize=8, rotation=15, ha='center')
ax1.set_ylabel('Counts')
ax1.set_title('Physics processes in Geant4')
ax1.set_yscale('log')
ax1.set_ylim(bottom=0.9)
plot.texax(ax1)
f.savefig('physicstracking.pdf', bbox_inches='tight')
#f.savefig('physicstracking.png', bbox_inches='tight',dpi=300)
plot.close('all')