-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheASTROGAM_ANALYSISv1_file_remote.py
414 lines (277 loc) · 14.2 KB
/
eASTROGAM_ANALYSISv1_file_remote.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
from astropy.io import fits
import numpy as np
import matplotlib.pyplot as plt
import math
import os
import pickle
from astropy.table import Table
import copy
import time
import sys
from DHSim import *
sys.argv[0] = 'eASTROGAM_ANALYSISv1_file_remote.py'
##############################
# parametri iniziali #
##############################
astrogam_version = sys.argv[1] # Enter eASTROGAM release (e.g. V1.0):
bogemms_tag = int(sys.argv[2]) # Enter BoGEMMS release (e.g. 211):
sim_type = int(sys.argv[3]) # Enter simulation type [0 = Mono, 1 = Range, 2 = Chen, 3: Vela, 4: Crab, 5: G400]:
py_list = int(sys.argv[4]) # Enter the Physics List [0 = QGSP_BERT_EMV, 100 = ARGO, 300 = FERMI, 400 = ASTROMEV]:
N_in = int(sys.argv[5]) # Enter the number of emitted particles:
part_type = sys.argv[6] # Enter the particle type [ph = photons, mu = muons, g = geantino, p = proton, el = electron]:
ene_range = int(sys.argv[7]) # Enter energy distribution [0 = MONO, 1 = POW, 2 = EXP, 3 = LIN]:
ene_min = sys.argv[8] # Enter miminum energy [MeV]:
ene_max = sys.argv[9] # Enter maximum energy [MeV]:
ang_type = sys.argv[10] # Enter the angular distribution [e.g. UNI, ISO]:
theta_type = int(sys.argv[11]) # Enter theta:
phi_type = int(sys.argv[12]) # Enter phi:
pol_type = int(sys.argv[13]) # Is the source polarized? [0 = false, 1 = true]:
pol_angle = int(sys.argv[14]) # Enter Polarization angle:
source_g = int(sys.argv[15]) # Enter source geometry [0 = Point, 1 = Plane]:
isStrip = int(sys.argv[16]) # Strip/Pixels activated? [0 = false, 1 = true]
repli = int(sys.argv[17]) # Strips/Pixels replicated? [0 = false, 1 = true]
cal_flag = int(sys.argv[18]) # Is Cal present? [0 = false, 1 = true]:
ac_flag = int(sys.argv[19]) # Is AC present? [0 = false, 1 = true]:
passive_flag = int(sys.argv[20]) # Is Passive present? [0 = false, 1 = true]:
energy_thresh = int(sys.argv[21]) # Enter energy threshold [keV]:
ifile = int(sys.argv[22]) # Enter the initial number of FITS files
n_fits = int(sys.argv[23]) # Enter the final number of FITS files :
print astrogam_version
dhseASTROGAM = DHSim()
### parametri iniziali
dhseASTROGAM.parameter(sim_type, py_list, part_type, ene_range, pol_type, source_g, isStrip, repli, cal_flag, ac_flag, astrogam_version, bogemms_tag, ene_min, ene_max , passive_flag, energy_thresh)
#parte lettura file fits
dhseASTROGAM.get_filepath(astrogam_version, theta_type, N_in, part_type)
dhseASTROGAM.get_outdir(astrogam_version, theta_type, N_in, part_type, energy_thresh)
while ifile <= n_fits:
start = time.time()
print('Reading the THELSIM file.....'+ str(ifile))
dhseASTROGAM.reading_fits(ifile, cal_flag, ac_flag, part_type, isStrip)
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#% Processing the tracker %
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if astrogam_version == 'V1.0' or astrogam_version == 'V1.1' or astrogam_version == 'V1.2' or astrogam_version == 'V2.0' or astrogam_version == 'V10.0':
# From Tracker volume ID to strip and tray ID and conversion from tray ID (starting from bottom) to plane ID (starting from the top)
dhseASTROGAM.conversion(isStrip, repli)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' Tracker ' )
print(' Saving the Tracker raw hits (fits and .dat) ')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
if astrogam_version == 'V1.0' or astrogam_version == 'V1.1' or astrogam_version == 'V1.2' or astrogam_version == 'V2.0' or astrogam_version == 'V10.0':
dhseASTROGAM.writing_G4raw(N_in, part_type, theta_type, phi_type, ifile, astrogam_version)
if isStrip == 0:
# ASCII Columns:
# - c1 = event ID
# - c2 = theta input
# - c3 = phi input
# - c4 = energy input
# - c5 = plane ID
# - c6 = Pos Z
# - c7 = X/Y flag (X = 0, Y = 1)
# - c8 = Cluster position (reference system center at the Silicon layer center)
# - c9 = energy deposition (keV)
# - c10 = number of strips composing the cluster
# - c11 = child id
# - c12 = proc id
dhseASTROGAM.writing_AA_fake(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' Tracker ')
print(' Creation of LUT data table with summed energy for each volume ')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
# Loading the LUT
if isStrip == 1:
dhseASTROGAM.loading_geom(astrogam_version)
### Flag events #####
dhseASTROGAM.flag_events()
###################
# Accoppiamento Capacitivo
###################
dhseASTROGAM.acap(astrogam_version)
##################
# Introducing the noise in every strip
#################
#dhseASTROGAM.noise()
#
# Summing the energy along the strip and applying the energy threshold
#
dhseASTROGAM.summing_energy(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
#################
# Energy Threshold
################
dhseASTROGAM.energy_threshold()
####index uniq event_id_tot
dhseASTROGAM.index_uniq()
if astrogam_version == 'V1.0' or astrogam_version == 'V1.1' or astrogam_version == 'V1.2' or astrogam_version == 'V2.0' or astrogam_version == 'V10.0':
if isStrip == 1:
#Total number of strips
print('Number of tracker triggered events: '+ str(dhseASTROGAM.N_trig))
dhseASTROGAM.strip_analysis()
print('N_ev: '+ str(dhseASTROGAM.N_ev))
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' Tracker ')
print(' Build the LEVEL 0 output ')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
dhseASTROGAM.build_L0()
# Level 0 = energy summed
# Level 0 = the events are sorted in tray, and Y before X within the same tray
# energy threshold applied
dhseASTROGAM.writing_L0(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' ASCII data format for AA input - strip')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
# ASCII Columns:
# - c1 = event ID
# - c2 = theta input
# - c3 = phi input
# - c4 = energy input
# - c5 = plane ID
# - c6 = Pos Z
# - c7 = X/Y flag (X = 0, Y = 1)
# - c8 = Strip ID
# - c9 = strip position (reference system center at the Silicon layer center)
# - c10 = energy deposition (keV)
# - c11 = pair flag (1 = pair, 0 = not pair)
dhseASTROGAM.writing_AA_strip(N_in, part_type, ang_type, theta_type, phi_type, ifile)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' Tracker ')
print(' L0.5 - cluster baricenter ')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print('N_trig: '+ str(dhseASTROGAM.N_trig))
dhseASTROGAM.L05_cluster_x()
dhseASTROGAM.L05_cluster_y()
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' Tracker ')
print(' L0.5 - X-Y layers merging ')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
dhseASTROGAM.merging()
# Level 0.5 = energy summed, MIP threshold applied, strip position used
dhseASTROGAM.writing_L05(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' ASCII data format for AA input - cluster')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
# ASCII Columns:
# - c1 = event ID
# - c2 = theta input
# - c3 = phi input
# - c4 = energy input
# - c5 = plane ID
# - c6 = Pos Z
# - c7 = X/Y flag (X = 0, Y = 1)
# - c8 = Cluster position (reference system center at the Silicon layer center)
# - c9 = energy deposition (keV)
# - c10 = number of strips composing the cluster
# - c11 = pair flag (1 = pair, 0 = not pair, 2 = compton)
dhseASTROGAM.writing_AA_cluster(N_in, part_type, ang_type, theta_type, phi_type, ifile)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' ASCII data format for AA input - pairs')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
# ASCII Columns:
# - c1 = event ID
# - c2 = theta input
# - c3 = phi input
# - c4 = energy input
# - c5 = plane ID
# - c6 = Pos Z
# - c7 = X/Y flag (X = 0, Y = 1)
# - c8 = Cluster position (reference system center at the Silicon layer center)
# - c9 = energy deposition (keV)
# - c10 = number of strips composing the cluster
# - c11 = pair flag (1 = pair)
dhseASTROGAM.writing_AA_cluster_pairs(N_in, part_type, ang_type, theta_type, phi_type, ifile)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' ASCII data format for AA input - compton')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
# ASCII Columns:
# - c1 = event ID
# - c2 = theta input
# - c3 = phi input
# - c4 = energy input
# - c5 = plane ID
# - c6 = Pos Z
# - c7 = X/Y flag (X = 0, Y = 1)
# - c8 = Cluster position (reference system center at the Silicon layer center)
# - c9 = energy deposition (keV)
# - c10 = number of strips composing the cluster
# - c11 = pair flag (2 = compton)
dhseASTROGAM.writing_AA_cluster_compton(N_in, part_type, ang_type, theta_type, phi_type, ifile)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' ASCII data format for AA input - rayleigh')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
# ASCII Columns:
# - c1 = event ID
# - c2 = theta input
# - c3 = phi input
# - c4 = energy input
# - c5 = plane ID
# - c6 = Pos Z
# - c7 = X/Y flag (X = 0, Y = 1)
# - c8 = Cluster position (reference system center at the Silicon layer center)
# - c9 = energy deposition (keV)
# - c10 = number of strips composing the cluster
# - c11 = pair flag (3 = rayleigh)
dhseASTROGAM.writing_AA_cluster_rayleigh(N_in, part_type, ang_type, theta_type, phi_type, ifile)
####### S1 data format ##############
# ID Type Edep VolumeID X Y Z
# - ID = Event ID
# - Type = event flag
# - Edep = energy deposited in the strip/calorimeter bar
# - volume ID = unique ID for the volume
# - X, Y, Z = position of the center of the volume
dhseASTROGAM.writing_S1_trk(N_in, part_type, ang_type, theta_type, phi_type, ifile)
####################
#Angular resolution
###################
#dhseASTROGAM.resolution(N_in, part_type, ang_type, theta_type, phi_type, ifile)
if cal_flag == 1:
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Processing the calorimeter
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' Calorimeter Bar Energy attenuation' )
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' Calorimeter ')
print(' Applying the minimum cut ')
print(' Summing the energy ')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
dhseASTROGAM.writing_cal_raw(N_in, part_type, theta_type, phi_type, ifile, astrogam_version)
dhseASTROGAM.G4_cal()
dhseASTROGAM.writing_G4cal(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
dhseASTROGAM.compton_cal()
if len(dhseASTROGAM.where_compton_cal) != 0:
dhseASTROGAM.writing_G4_cal_compton(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
dhseASTROGAM.pair_cal()
if len(dhseASTROGAM.where_pair_cal) != 0:
dhseASTROGAM.writing_G4_cal_pair(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
dhseASTROGAM.ray_cal()
if len(dhseASTROGAM.where_ray_cal) != 0:
dhseASTROGAM.writing_G4_cal_ray(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
dhseASTROGAM.cal_sum()
dhseASTROGAM.writing_cal_sum(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
dhseASTROGAM.writing_S1_cal(N_in, part_type, ang_type, theta_type, phi_type, ifile)
if ac_flag == 1:
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' AC')
print(' write raw data ')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
dhseASTROGAM.writing_ac_raw(N_in, part_type, theta_type, phi_type, ifile, astrogam_version)
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
print(' AC')
print(' Summing the energy ')
print('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')
dhseASTROGAM.AC_analysis()
dhseASTROGAM.writing_G4ac(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
dhseASTROGAM.writing_S1_ac(N_in, part_type, ang_type, theta_type, phi_type, ifile)
dhseASTROGAM.compton_ac()
if len(dhseASTROGAM.where_compton_ac) != 0:
dhseASTROGAM.writing_G4_ac_compton(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
dhseASTROGAM.pair_ac()
if len(dhseASTROGAM.where_pair_ac) != 0:
dhseASTROGAM.writing_G4_ac_pair(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
dhseASTROGAM.ray_ac()
if len(dhseASTROGAM.where_ray_ac) != 0:
dhseASTROGAM.writing_G4_ac_ray(astrogam_version, N_in, part_type, theta_type, phi_type, ifile)
############ next fits file ####################
end = time.time() - start
print('Time: ' + str(end))
ifile = ifile + 1