4
def mc_file_names(job_name, datasets):
5
file_list = ["/home/cr67/work/reco/mc/"+job_name+"/"+datasets+"/*_sim.root"]
8
def reco_file_names(run_number_list, maus):
10
for run in run_number_list:
11
run = str(run).rjust(5, '0')
12
a_file = "/work/ast/cr67/reco/"+maus+"/"+run+"/"+run+"_recon.root"
13
file_list.append(a_file)
17
def get_systematics_dir(emittance, suffix, absorber, analysis):
18
a_dir = "output/2017-02-7-Systematics-v4/plots_Simulated_2017-2.7_"+str(emittance)+\
19
"-140_"+absorber+"_Systematics_"+suffix+"/"+analysis+"/"+analysis+".json"
22
def get_systematics(emittance, analysis="amplitude"):
23
us_name = {"amplitude":"all_upstream", "density":"us", "fractional_emittance":"us"}[analysis]
24
ds_name = {"amplitude":"all_downstream", "density":"ds", "fractional_emittance":"ds"}[analysis]
27
"detector_reference":get_systematics_dir(emittance, "tku_base", "lH2_empty", analysis),
28
"performance_reference":get_systematics_dir(emittance, "tku_base", "lH2_empty", analysis),
30
"detector_systematics":{
31
get_systematics_dir(emittance, "tku_pos_plus", "lH2_empty", analysis):1.,
32
get_systematics_dir(emittance, "tku_rot_plus", "lH2_empty", analysis):1.,
33
get_systematics_dir(emittance, "tku_scale_SSUE1_plus", "lH2_empty", analysis):1.,
34
get_systematics_dir(emittance, "tku_scale_SSUC_neg", "lH2_empty", analysis):1.,
35
get_systematics_dir(emittance, "tku_scale_SSUE2_plus", "lH2_empty", analysis):1.,
36
get_systematics_dir(emittance, "tku_density_plus", "lH2_empty", analysis):1.,
38
"performance_systematics":{}
41
"detector_systematics":{
42
get_systematics_dir(emittance, "tkd_pos_plus", "lH2_empty", analysis):1.,
43
get_systematics_dir(emittance, "tkd_rot_plus", "lH2_empty", analysis):1.,
44
get_systematics_dir(emittance, "tkd_scale_SSDE1_plus", "lH2_empty", analysis):1.,
45
get_systematics_dir(emittance, "tkd_scale_SSDC_plus", "lH2_empty", analysis):0.1,
46
get_systematics_dir(emittance, "tkd_scale_SSDE2_plus", "lH2_empty", analysis):1.,
47
get_systematics_dir(emittance, "tkd_density_plus", "lH2_empty", analysis):1.,
49
"performance_systematics":{
50
get_systematics_dir(emittance, "tku_base_tkd_fiducial_radius", "lH2_empty", analysis):1.,
51
get_systematics_dir(emittance, "tku_base_tkd_chi2_threshold", "lH2_empty", analysis):1.,
58
def get_analysis(run_list, name, tof01_min_max, maus_version, data_dir, emittance, p_bins, tkd_cut, tramlines_dp):
59
plot_dir = data_dir+"/plots_"+name+"/"
60
plot_dir = plot_dir.replace(" ", "_")
61
min_p = min([min(a_bin) for a_bin in p_bins])
62
max_p = max([max(a_bin) for a_bin in p_bins])
64
analysis_variables = {
65
"plot_dir":plot_dir, # makedirs and then put plots in this directory. Removes any old plots there!!!
68
"tof12_cut_low":32., # TOF12 cut lower bound
69
"tof12_cut_high":39., # TOF12 cut upper bound
70
"delta_tof01_lower":-1., # Delta TOF01 cut lower bound
71
"delta_tof01_upper":+1.5, # Delta TOF01 cut upper bound
72
"delta_tof12_lower":-5., # Delta TOF01 cut lower bound
73
"delta_tof12_upper":5., # Delta TOF01 cut upper bound
74
"tof01_tramline_lower":-15.+tramlines_dp, # p_tof01 - p_tku
75
"tof01_tramline_upper":+15.+tramlines_dp, # p_tof01 - p_tku
76
"tof01_cut_low":tof01_min_max[0], # TOF01 cut lower bound
77
"tof01_cut_high":tof01_min_max[1], # TOF01 cut upper bound
78
"p_bins":p_bins, # set of momentum bins; for now really it is just a lower and upper bound
79
"p_bins_alt":[[100, 180]], # alternative momentum cut
80
"p_tot_ds_low":tkd_cut[0], # downstream momentum cut lower bound
81
"p_tot_ds_high":tkd_cut[1], # downstream momentum cut upper bound
82
"reco_files":reco_file_names(run_list, maus_version), # list of strings to be handed to glob
83
"name":name, # appears on plots
85
"pid":-13, # assume pid of tracks following TOF cut
86
"pvalue_threshold":0.02, # minimum allowed pvalue for pvalue cut
87
"tku_chi2_threshold":8.0, # maximum allowed chi2/dof for chi2 cut
88
"tkd_chi2_threshold":8.0, # maximum allowed chi2/dof for chi2 cut
89
"tku_fiducial_radius":150.,
90
"tkd_fiducial_radius":150.,
91
"amplitude_corrections":get_systematics_dir(emittance, "tku_base", "lH2_empty", "amplitude"),
92
"amplitude_systematics":get_systematics(emittance, "amplitude"),
93
"field_uncertainty":0.02,
94
"csv_output_detectors":["tof1", "diffuser_us", "diffuser_mid", "diffuser_ds"], # write data at listed detector locations
95
"csv_output_filename":"test", #"8590_mc_extrapolated_tracks.csv", # write a summary output of data in flat text format to listed filename; set to None to do nothing
96
"extrapolation_source":"tku_tp",
97
"amplitude_chi2":False,
99
"weight_tof01_source":None,
100
"weight_tof01_target":plot_dir+"tof01_weights",
101
"weight_tof01_mode":"build_distribution",
102
"cov_fixed_us":None, #cov_us,
103
"cov_fixed_ds":None, #cov_ds,
104
"amplitude_algorithm":"binned",
106
"fractional_emittance_mc":False,
107
"fractional_emittance_corrections":get_systematics_dir(emittance,
110
"fractional_emittance"),
111
"fractional_emittance_systematics":get_systematics(emittance, "fractional_emittance"),
112
"fractional_emittance_corrections_draw":True,
113
"fractional_emittance_systematics_draw":True,
115
"density_mc":False, # True if Monte Carlo data
116
"density_corrections_cutoff":.5, # Cutoff above which correction is averaged
117
"density_corrections":get_systematics_dir(emittance, "tku_base", "lH2_empty", "density"),
118
"density_systematics":get_systematics(emittance, "density"),
119
"density_corrections_draw":True, # True if density correctoins are to be drawn
120
"density_systematics_draw":True, # True if density systematics are to be drawn
121
"density_sections":False, # True if density sections are to be printed
124
"do_magnet_alignment":False,
125
"do_fractional_emittance":False,
126
"do_efficiency":False,
127
"do_extrapolation":False,
132
"do_cuts_plots":True,
133
"do_tof01_weighting":False,
135
"do_data_recorder":True,
137
return analysis_variables
140
class Config(object):
141
# location to which data and plots will be dumped following analysis
142
info_file = "geometry_08681/Maus_Information.gdml"
143
will_require_tof1 = True # require at least one TOF1 Space point to even load the data
144
will_require_tof2 = False # require at least one TOF2 Space point to even load the data
145
tk_station = 1 # load data from a particular tracker station
147
# prerequisite for space point cut
148
will_require_triplets = False #True # require triplet space points
149
upstream_cuts = { # Set to true to make data_plotter and amplitude_analysis use these cuts; False to ignore the cut
151
"scifi_space_clusters":False,
152
"scifi_space_points":False,
153
"scifi_tracks_us":True,
154
"scifi_nan_us":False,
155
"scifi_track_points_us":False,
156
"scifi_fiducial_us":True,
161
"scifi_tracks_ds":False,
162
"scifi_nan_ds":False,
163
"scifi_track_points_ds":False,
164
"scifi_fiducial_ds":False,
168
"tof01_tramlines":True,
171
"p_tot_us_alt":False,
176
"upstream_aperture_cut":True,
177
"downstream_aperture_cut":False,
178
"delta_tof01":False, #True, #extrapolatedtof01 compared to recon tof01
179
"delta_tof12":False, #extrapolatedtof12 compared to recon tof12
180
"global_through_tof0":False,
181
"global_through_tof1":False,
182
"global_through_us_apertures":True,
183
"global_through_tku_tp":False,
184
"global_through_tkd_tp":False,
185
"global_through_tof2":False,
186
"tof01_selection":False,
188
"mc_stations_us":False,
189
"mc_scifi_fiducial_us":False,
191
"mc_stations_ds":False,
192
"mc_scifi_fiducial_ds":False,
194
data_recorder_cuts = copy.deepcopy(upstream_cuts)
195
data_recorder_cuts["p_tot_us"] = False
196
data_recorder_cuts["p_tot_us_alt"] = False
197
downstream_cuts = copy.deepcopy(upstream_cuts)
198
downstream_cuts["p_tot_ds"] = False
199
downstream_cuts["tof2_sp"] = False
200
downstream_cuts["pvalue_ds"] = False
201
downstream_cuts["chi2_ds"] = True
202
downstream_cuts["scifi_fiducial_ds"] = True
203
downstream_cuts["tof12"] = False # if TOF12 is out of range chuck it (but ignore "no TOF2" events)
204
downstream_cuts["scifi_tracks_ds"] = True
205
extrapolation_cuts = copy.deepcopy(downstream_cuts)
206
extrapolation_cuts["downstream_aperture_cut"] = True
207
extrapolation_cuts["tof2_sp"] = True
208
extrapolation_cuts["global_through_tkd_tp"] = True
209
extrapolation_cuts["global_through_tof2"] = True
210
mc_true_us_cuts = copy.deepcopy(upstream_cuts)
211
mc_true_ds_cuts = copy.deepcopy(upstream_cuts)
212
cut_report = [[], [], []]
213
cut_report[0] = ["hline", "all events", "hline",]
214
cut_report[0] += ["tof_1_sp", "tof_0_sp", "scifi_tracks_us", "chi2_us", "scifi_fiducial_us", "hline",]
215
cut_report[0] += ["tof01", "p_tot_us", "tof01_tramlines", "hline",]
216
cut_report[0] += ["global_through_us_apertures"]
217
cut_report[0] += ["upstream_aperture_cut", "hline",]
218
cut_report[0] += ["upstream_cut", "hline",]
219
cut_report[1] += ["hline", "upstream_cut", "hline",]
220
cut_report[1] += ["scifi_tracks_ds", "chi2_ds", "scifi_fiducial_ds", "hline",]
221
cut_report[1] += ["downstream_cut", "hline",]
222
cut_report[2] = ["hline", "downstream_cut", "hline",]
223
cut_report[2] += ["downstream_aperture_cut", "tof_2_sp", "global_through_tkd_tp", "global_through_tof2", "hline",]
224
cut_report[2] += ["extrapolation_cut", "hline"]
227
data_dir = "output/2017-02-7-production-test-3/"
228
src_dir = "Production-v3"
230
analyses.append(get_analysis([10064], "2017-2.7 4-140 lH2 empty", [1.5, 6.0], src_dir, data_dir, 4, [[135, 145]], [90, 170], 32))
231
analyses.append(get_analysis([9962], "2017-2.7 4-140 lH2 full", [1.5, 6.0], src_dir, data_dir, 4, [[135, 145]], [90, 170], 32))
232
analyses.append(get_analysis([10484], "2017-2.7 4-140 LiH", [1.5, 6.0], src_dir, data_dir, 4, [[135, 145]], [90, 170], 32))
233
analyses.append(get_analysis([10445], "2017-2.7 4-140 None", [1.5, 6.0], src_dir, data_dir, 4, [[135, 145]], [90, 170], 32))
235
analyses.append(get_analysis([10051], "2017-2.7 6-140 lH2 empty", [1.5, 5.5], src_dir, data_dir, 6, [[135, 145]], [90, 170], 35))
236
analyses.append(get_analysis([9966], "2017-2.7 6-140 lH2 full", [1.5, 5.5], src_dir, data_dir, 6, [[135, 145]], [90, 170], 35))
237
analyses.append(get_analysis([10485], "2017-2.7 6-140 LiH", [1.5, 5.5], src_dir, data_dir, 6, [[135, 145]], [90, 170], 35))
238
analyses.append(get_analysis([10446], "2017-2.7 6-140 None", [1.5, 5.5], src_dir, data_dir, 6, [[135, 145]], [90, 170], 35))
240
analyses.append(get_analysis([10052], "2017-2.7 10-140 lH2 empty", [1.5, 4.5], src_dir, data_dir, 10, [[135, 145]], [90, 170], 70))
241
analyses.append(get_analysis([9970], "2017-2.7 10-140 lH2 full", [1.5, 4.5], src_dir, data_dir, 10, [[135, 145]], [90, 170], 70))
242
analyses.append(get_analysis([10486], "2017-2.7 10-140 LiH", [1.5, 4.5], src_dir, data_dir, 10, [[135, 145]], [90, 170], 70))
243
analyses.append(get_analysis([10447], "2017-2.7 10-140 None", [1.5, 4.5], src_dir, data_dir, 10, [[135, 145]], [90, 170], 70))
245
required_trackers = [0, 1] # for space points
246
required_number_of_track_points = 12 # doesnt do anything
247
global_min_step_size = 1. # for extrapolation, set the extrapolation step size
248
global_max_step_size = 100. # for extrapolation, set the extrapolation step size
249
will_load_tk_space_points = True # determines whether data loader will attempt to load tracker space points
250
will_load_tk_track_points = True # determines whether data loader will attempt to load tracker track points
251
number_of_spills = None # if set to an integer, limits the number of spills loaded for each sub-analysis
252
preanalysis_number_of_spills = 500 # number of spills to analyse during "pre-analysis"
253
analysis_number_of_spills = 100 # number of spills to analyse during each "analysis" step
254
momentum_from_tracker = True # i.e. not from TOFs
259
#z_tof2 - ztof1 = 21139.4-12929.6 = 8209.800000000001
260
#dt_tof2 = 8209.8/299.8 = 27.384256170780517
261
#compare with position of the electron peak dt_tof2 = 27.793
263
residuals_plots_nbins = 100 # used for track extrapolation plots
264
extrapolation_does_apertures = True # set to True in order to include apertures in track extrapolation
265
maus_verbose_level = 5
267
amplitude_bin_width = 5
268
amplitude_min_events = 100
269
amplitude_min_bin = 0
271
fractional_emittance_bins = [0., 5., 10., 15., 20., 30., 50.]
272
fractional_emittance_fraction = 0.09 # Fraction at which to evaluate the quantiles
273
fractional_emittance_uncertainty = 0 # 0: theoretical, 1: bootstrapped
276
density_knn_rotate = True # rotate to eigenvector system
277
density_uncertainty = False # assume Gaussian for errors; True - use subsampling for errors
278
density_npoints = 100
279
density_graph_scaling = 1e9
283
"max_iterations":100,
287
# z position of central absorber (used for offsetting
289
# z position of detectors (used for track extrapolation) (z, name)
290
# 13692: diffuser us edge
291
# 13782: diffuser ds edge
292
# 16639: lH2 window mount us (us edge)
293
# 16710: lH2 window mount us (ds edge)
294
# 16953.5: LiH centre
295
# 17166: lH2 window mount ds (us edge)
296
# 17242: lH2 window mount ds (ds edge)
297
# 17585: SSU aperture
298
# 18733: SSU He window
302
(5287.2-25., None, "tof0_us"),
303
(5287.2, None, "tof0"),
304
(5287.2+25., None, "tof0_ds"),
305
(12929.6-25., None, "tof1_us"),
306
(12929.6, None, "tof1"),
307
(12929.6+25., None, "tof1_ds"),
308
(15068.0-1100.+tku_offset, None, "tku_5"),
309
(15068.0-750.+tku_offset, None, "tku_4"),
310
(15068.0-450.+tku_offset, None, "tku_3"),
311
(15068.0-200.+tku_offset, None, "tku_2"),
312
(15068.0+tku_offset, None, "tku_tp"),
313
(18836.8+tkd_offset, None, "tkd_tp"),
314
(18836.8+200.+tkd_offset, None, "tkd_2"),
315
(18836.8+450.+tkd_offset, None, "tkd_3"),
316
(18836.8+750.+tkd_offset, None, "tkd_4"),
317
(18836.8+1100.+tkd_offset, None, "tkd_5"),
318
(21114.4, None, "tof2_us"),
319
(21139.4, None, "tof2"),
320
(21164.4, None, "tof2_ds"),
321
(21208., None, "cal"),
322
(21214.4, None, "cal"),
323
(21220.4, None, "cal"),
326
virtual_detectors = [
327
(12904., None, "virtual_tof1_us"),
328
(12929.6, None, "virtual_tof1"),
329
(12954., None, "virtual_tof1_ds"),
330
(13205., None, "virtual_us_pry_us"),
331
(13305., None, "virtual_us_pry_ds"),
332
(13403., None, "virtual_tku_butterfly_us"),
333
(13486., None, "virtual_tku_butterfly_ds"),
334
(13578., None, "virtual_diffuser_shield"),
335
(13698., None, "virtual_diffuser_us"),
336
(13782., None, "virtual_diffuser_ds"),
337
(16639., None, "virtual_lh2_us_window_flange_1"),
338
(16710., None, "virtual_lh2_us_window_flange_2"),
339
(16953.5, None, "virtual_absorber_centre"),
340
(17166., None, "virtual_lh2_ds_window_flange_1"),
341
(17242., None, "virtual_lh2_ds_window_flange_2"),
342
(17585., None, "virtual_ssd_aperture"),
343
(18733., None, "virtual_ssd_he"),
344
(20447., None, "virtual_ds_pry"),
346
plot_virtual_stations = [station for dummy, dummy, station in virtual_detectors]
347
virtual_detectors += [(500.*i, None, "virtual_"+str(i)) for i in range(51)]
348
virtual_detectors += [(z, None, "virtual_"+det) for z, dummy, det in detectors]
349
virtual_detectors = sorted(virtual_detectors)
350
for z, dummy, plane in virtual_detectors:
352
upstream_aperture_cut = {
353
"global_through_virtual_diffuser_us":90.,
354
"global_through_virtual_diffuser_ds":90.,
356
downstream_aperture_cut = {
357
"global_through_virtual_lh2_us_window_flange_1":100.,
358
"global_through_virtual_lh2_us_window_flange_2":100.,
359
"global_through_virtual_absorber_centre":100.,
360
"global_through_virtual_lh2_ds_window_flange_1":100.,
361
"global_through_virtual_lh2_ds_window_flange_2":100.,
362
"global_through_virtual_ssd_aperture":100.,
363
"global_through_virtual_ssd_he":100.,
364
"global_ds_virtual_ds_pry":100.,
369
"tku":"virtual_tku_tp",
370
"tkd":"virtual_tkd_tp",
376
# z position of apertures (z, maximum radius, name)
377
# Notes from Jason: 209.6 to fixed flange
378
# 282.5 to movable flange
379
# what about tracker butterfly us and ds?
381
[(-3325.74+z_afc, 100., "diffuser_us"),
382
(-3276.74+z_afc, 100., "diffuser_mid"),
383
(-3227.74+z_afc, 100., "diffuser_ds"),]+\
384
[(float(z)+z_afc, 150., "tku_"+str(z)) for z in range(-2918, -1817, 100)]+\
385
[(float(z)+z_afc, 150., "tkd_"+str(z)) for z in range(1818, 2919, 100)]+\
386
[(float(z)+z_afc, 200., "pipe_"+str(z)) for z in range(-1800, 1801, 100)]+\
387
[(+209.6+z_afc, 160., "afc_209.6")],