-
Notifications
You must be signed in to change notification settings - Fork 2
/
analysis.art2.amv.py
237 lines (173 loc) · 9.21 KB
/
analysis.art2.amv.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env python
############################################################################################################
################################# DEZE FILE IS VOOR AMV. ENKEL 1MEV dus
############################################################################################################
import numpy as np,plot,auger,subprocess,tableio,dump,math
from matplotlib.ticker import AutoMinorLocator
#OPT: quickly get sorted rundirs
# zb autogen | sort -k1.17 -r
#OPT: fix seed
#np.random.seed(65983247)
#np.random.seed(9832324)
addnoise=False #false for all AMV
precolli=False #gaan we niet meer doen
pgexit = False #idem
#np.seterr(all='raise') #use to catch Numpy RuntimeWarnings
PHYSDET_PROFILE_IBA=None
PHYSDET_PROFILE_IPNL=None
print 'Computing pgprod ratios...'
pgprod_1mev_ipnl = 0.07547789 #obatined with image.sum on source image with first mev taken out
pgprod_1mev_iba = 0.029948339 #idem, but iba_source image where up to -5cm from fop voxels were zeroed
print 'done.'
resultstable=[["typ","nprim","fopmu","fopsigma","fow","contrast","detyieldmu","detyieldsigma","detcount","detcount/prod"]]
if precolli:
resultstable[0].extend(["collieffmu","collieffsigma"])
def megaplot(ctsets,studyname,emisfops=None,labels=["$10^9$","$10^8$","$10^7$","$10^6$"],axlabel='Primaries [nr]'):
f, (ax1,ax2) = plot.subplots(nrows=2, ncols=1, sharex=False, sharey=False)
x=ctsets[0]['ct']['x']
y=ctsets[0]['ct']['av']
if 'iba' in ctsets[0]['name']: # ctset['name'] == typ
mm=4/0.8
if 'ipnl' in ctsets[0]['name']:
mm=8
falloff_pos,g_fwhm,contrast = auger.get_fop_fow_contrast(x,y,plot='wut',ax=ax1,ax2=ax2,smooth=0.2,filename=ctsets[0]['ct']['path'],contrast_divisor=ctsets[0]['nprim']*len(ctsets[0]['ct']['files'])*mm,fitlines=False)
# some cosmetics
maxyrounded = int(math.ceil(max(y) / 100.0)) * 100
ticks = np.arange(0, maxyrounded, 100)
if len(ticks)>10:
ticks = np.arange(0, maxyrounded+100, 200)
if len(ticks)>10:
ticks = np.arange(0, maxyrounded+200, 400)
if len(ticks)>10:
ticks = np.arange(0, maxyrounded+400, 800)
ax1.set_yticks(ticks)
minor_locator = AutoMinorLocator(2)
minor_locator1 = AutoMinorLocator(2)
ax1.xaxis.set_minor_locator(minor_locator)
ax2.xaxis.set_minor_locator(minor_locator)
ax2.yaxis.set_minor_locator(minor_locator1)
if PHYSDET_PROFILE_IBA!=None and 'iba' in ctsets[0]['name']:
ax1.scatter( x,PHYSDET_PROFILE_IBA, color='lightgrey',marker="x",clip_on=False)
if PHYSDET_PROFILE_IPNL!=None and 'ipnl' in ctsets[0]['name']:
ax1.scatter( x,PHYSDET_PROFILE_IPNL, color='lightgrey',marker="x",clip_on=False)
print "NPRIM", ctsets[0]['nprim'],"NJOBS",len(ctsets[0]['ct']['files']),"MM",mm
#gebruiken deze falloff_pos niet. we doen contrast en fow over de average van 50 batches wegens smoothe curve. daardoor geen sigma
f.savefig(studyname+'-'+typ+str(ctsets[0]['nprim'])+'-FOW.pdf', bbox_inches='tight')
plot.close('all')
#############################################################################################
# results table
for ctset in ctsets:
res=[typ,ctset['nprim'],ctset['ct']['fopmu'],ctset['ct']['fopsigma'],g_fwhm,contrast,ctset['detyieldmu'],ctset['detyieldsigma'],ctset['detcount'],ctset['detcount']]
if ctset['nprim'] == 10**9:
if 'iba' in typ:
#res.append(pgprod_1mev_iba*ctset['nprim'])
res[-1]=res[-1]/(pgprod_1mev_iba*ctset['nprim'])
if 'ipnl' in typ:
#res.append(pgprod_1mev_ipnl*ctset['nprim'])
res[-1]=res[-1]/(pgprod_1mev_ipnl*ctset['nprim'])
else:
res[-1]=''
if precolli:
res.extend([ctset['precollidetyieldmu'],ctset['precollidetyieldsigma']])
resultstable.append(res)
#############################################################################################
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
print 'FOP distributions'
fig = plt.figure()
ax1 = plt.axes(projection='3d')
ax1.view_init(30, -50)
for i,ctset in enumerate(ctsets):
auger.plotfodist_CTONLY(ax1,ctset,i,emisfops,labels,axlabel)
# plt.legend()#shadow = True,frameon = True,fancybox = True,ncol = 1,fontsize = 'x-small',loc = 'lower right')
# plt.tight_layout(rect = [-0.1, 0.0, 1.0, 1.1])#L,B,R,T
plt.savefig(studyname+'-'+typ+'-FOP-dist.pdf')#, bbox_inches='tight')
plt.close('all')
# nu gaan we drie studies doen!
# 1: physabsorber en physcolli. typ=*-auger-notof-1.root, dirs: zonder kill
# 2: perabsorber en physical colli. typ=*-perdet, dirs: zonder kill
# 3: physical absorber en perfect colli. typ=*-auger-notof-1.root, dirs: kill
# 4: perabsorber en perfect colli. typ=*-perdet, dirs: kill
print("######################### 111111111111111111111111111111111111111111111111111")
resultstable.append(["physabs-physcolli"]*len(resultstable[-1]))
typs=['ipnl-auger-notof-1.root','iba-auger-notof-1.root']
dirs = [x for x in subprocess.check_output(['find . -iname "*autogen*NPRIM-1000000000*" | sort -k1.17'],shell=True).split('\n')[:-1] if '.kill.' not in x]
print(dirs)
numprots = [1e9,1e9]
for typ in typs:
ctsetsets = []
for line,numprot in zip(dirs,[item for item in numprots for i in range(len(typs)/len(numprots))]):
for haha in ['iba','ipnl']:
if (haha+'lyso' in line) and haha+'-' in typ:
print (haha,line,typ,numprot)
ctsetsets.append( auger.getctset(numprot,line[2:14],None,typ,addnoise=addnoise,precolli=precolli) )
PHYSDET_PROFILE_IPNL = ctsetsets[-1]['ct']['av']
if haha+'zinv' in line and haha+'-' in typ:
print (haha,line,typ,numprot)
ctsetsets.append( auger.getctset(numprot,line[2:14],None,typ,addnoise=addnoise,precolli=precolli) )
PHYSDET_PROFILE_IBA = ctsetsets[-1]['ct']['av']
megaplot(ctsetsets,'physabs-physcolli')
print 'Mean detection yield in',typ,'study over',sum([ctset['totnprim'] for ctset in ctsetsets]),'primaries in',sum([ctset['nreal'] for ctset in ctsetsets]),'realisations:',sum([ctset['detyieldmu'] for ctset in ctsetsets])
print("######################### 2222222222222222222222222222222222222222222222222222222222")
resultstable.append(["perabs-physcolli"]*len(resultstable[-1]))
dirs = subprocess.check_output(['find . -iname "*autogen*ibazinv.mac" | sort -k1.17'],shell=True).split('\n')[:-1]
dirs += subprocess.check_output(['find . -iname "*autogen*ipnllyso.mac" | sort -k1.17'],shell=True).split('\n')[:-1]
#bovenstaande zijn 2 calls, dus NIET bash sort
dirs.sort(key=lambda x: x[17:],reverse=True)
print(dirs)
numprots = [1e9,1e9]
typ=None
for dirr,numprot in zip(dirs,numprots):
if numprot != 1e9:
continue
ctsetsets = []
if 'iba' in dirr:
typ='iba-perdet.root'
ctsetsets.append( auger.getctset(numprot,dirr[2:14],None,typ,addnoise=addnoise) )
if 'ipnl' in dirr:
typ='ipnl-perdet.root'
ctsetsets.append( auger.getctset(numprot,dirr[2:14],None,typ,addnoise=addnoise) )
megaplot(ctsetsets,'perdet-physcolli')
print 'Mean detection yield in',typ,'study over',sum([ctset['totnprim'] for ctset in ctsetsets]),'primaries in',sum([ctset['nreal'] for ctset in ctsetsets]),'realisations:',sum([ctset['detyieldmu'] for ctset in ctsetsets])
print("############################ 333333333333333333333333333333333333333333333")
resultstable.append(["physabs-percolli"]*len(resultstable[-1]))
typs=['ipnl-auger-notof-1.root','iba-auger-notof-1.root']
dirs = subprocess.check_output(['find . -iname "*autogen*NPRIM-1000000000*kill*" | sort -k1.17'],shell=True).split('\n')[:-1]
print(dirs)
numprots = [1e9,1e9]
for typ in typs:
ctsetsets = []
for line,numprot in zip(dirs,[item for item in numprots for i in range(len(typs)/len(numprots))]):
for haha in ['iba','ipnl']:
if (haha+'lyso' in line or haha+'bgo' in line) and haha+'-' in typ:
print (haha,line,typ,numprot)
ctsetsets.append( auger.getctset(numprot,line[2:14],None,typ,addnoise=addnoise,precolli=precolli) )
#PHYSDET_PROFILE_IPNL = ctsetsets[-1]['ct']['av']
if haha+'zinv' in line and haha+'-' in typ:
print (haha,line,typ,numprot)
ctsetsets.append( auger.getctset(numprot,line[2:14],None,typ,addnoise=addnoise,precolli=precolli) )
#PHYSDET_PROFILE_IBA = ctsetsets[-1]['ct']['av']
megaplot(ctsetsets,'physabs-percolli')
print 'Mean detection yield in',typ,'study over',sum([ctset['totnprim'] for ctset in ctsetsets]),'primaries in',sum([ctset['nreal'] for ctset in ctsetsets]),'realisations:',sum([ctset['detyieldmu'] for ctset in ctsetsets])
print("############################ 44444444444444444444444444444444")
resultstable.append(["perabs-percolli"]*len(resultstable[-1]))
dirs = subprocess.check_output(['find . -iname "*autogen*kill*" | sort -k1.17'],shell=True).split('\n')[:-1]
dirs = dirs[0:2] #only 10e9
print(dirs)
numprots = [1e9,1e9,1e8,1e8,1e7,1e7]
typ=None
for dirr,numprot in zip(dirs,numprots):
if numprot != 1e9:
continue
ctsetsets = []
if 'iba' in dirr:
typ='iba-perdet.root'
ctsetsets.append( auger.getctset(numprot,dirr[2:14],None,typ,addnoise=addnoise) )
if 'ipnl' in dirr:
typ='ipnl-perdet.root'
ctsetsets.append( auger.getctset(numprot,dirr[2:14],None,typ,addnoise=addnoise) )
megaplot(ctsetsets,'perdet-percolli')
print 'Mean detection yield in',typ,'study over',sum([ctset['totnprim'] for ctset in ctsetsets]),'primaries in',sum([ctset['nreal'] for ctset in ctsetsets]),'realisations:',sum([ctset['detyieldmu'] for ctset in ctsetsets])
print "######################################################### FINIS"
tableio.print2d(resultstable)
tableio.write(resultstable,'results.tsv')