-
Notifications
You must be signed in to change notification settings - Fork 3
/
plot_regressions_from2files.py
1002 lines (900 loc) · 46.7 KB
/
plot_regressions_from2files.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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import h5py
import argparse
import os, sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from matplotlib.collections import PatchCollection
import matplotlib.colors as colors
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input",type=str,default=None,
dest="input_file", help="path and name of the input file")
parser.add_argument("--input2",type=str,default=None,
dest="input_file2", help="path and name of the input file")
parser.add_argument("-o", "--outdir",type=str,default='/mnt/home/micall12/LowEnergyNeuralNetwork/output_plots/',
dest="output_dir", help="path of ouput file")
parser.add_argument("-n", "--savename",default=None,
dest="savename", help="additional directory to save in")
parser.add_argument("--compare_cnn", default=False,action='store_true',
dest='compare_cnn',help="compare to CNN")
parser.add_argument("--i3",default=False,action='store_true',
dest="i3",help="flag if inputting i3 files (not hdf5)")
parser.add_argument("-f", "--flavor",type=str,default="All",
dest="flavor", help="flavor particle to cut on (NuMu, NuE, NuTau, Muon, All)")
parser.add_argument("-s", "--sample",type=str,default="All",
dest="sample", help="neutrino interaction to look at (CC, NC, All)")
parser.add_argument("--mu_cut",type=float,default=0.01,
dest="mu_cut", help="muon cut, default at 0.01")
args = parser.parse_args()
input_file = args.input_file
input_file2 = args.input_file2
compare_cnn = args.compare_cnn
save_folder_name = args.output_dir + "/"
if args.savename is not None:
save_folder_name += args.savename + "/"
if os.path.isdir(save_folder_name) != True:
os.mkdir(save_folder_name)
print("Saving to %s"%save_folder_name)
i3 = args.i3
flavor=args.flavor
sample = args.sample
#CUT values
cut1 = {}
cut1['r'] = 200 #165
cut1['zmin'] = -495
cut1['zmax'] = -225
cut1['coszen'] = 0.3
cut1['emin'] = 5
cut1['emax'] = 100
cut1['mu'] = args.mu_cut
cut1['nDOM'] = 7
numu_files1 = 1518 #391
nue_files1 = 602 #91
muon_files1 = 17992 #19391 #1
nutau_files1 = 334 #187
cut2 = {}
cut2['r'] = 300
cut2['zmin'] = -500
cut2['zmax'] = -200
cut2['coszen'] = 0.3
cut2['emin'] = 5
cut2['emax'] = 300
cut2['mu'] = args.mu_cut
cut2['nDOM'] = 7
numu_files2 = 1518 #391
nue_files2 = 602 #91
muon_files2 = 19991 #1
nutau_files2 = 334 #187
#IMPORT FILE 1
if i3:
#Find (and edit) number of files
numu_file_list = list(filter(lambda x: "pass2.14" in x, full_path))
nue_file_list = list(filter(lambda x: "pass2.12" in x, full_path))
muon_file_list = list(filter(lambda x: "pass2.13" in x, full_path))
nutau_file_list = list(filter(lambda x: "pass2.16" in x, full_path))
if numu_files is None:
numu_files = len(numu_file_list)
print("Including all %i NuMu files"%numu_files)
else:
numu_files = int(numu_files)
print("Cutting NuMu files to include first %i files, from %s to %s"%(numu_files,numu_file_list[0],numu_file_list[numu_files-1]))
if nue_files is None:
nue_files = len(nue_file_list)
print("Including all %i NuE files"%nue_files)
else:
nue_files = int(nue_files)
print("Cutting NuE files to include LAST %i files, from %s to %s"%(nue_files,nue_file_list[-nue_files],nue_file_list[-1]))
if nutau_files is None:
nutau_files = len(nutau_file_list)
print("Including all %i NuTau files"%nutau_files)
else:
nutau_files = int(nutau_files)
print("Cutting NuTau files to include first %i files, from %s to %s"%(nutau_files,nutau_file_list[0],nutau_file_list[nutau_files-1]))
if muon_files is None:
muon_files = len(muon_file_list)
print("Including all %i Muon files"%muon_files)
else:
muon_files = int(muon_files)
print("Cutting Muon files to include LAST %i files, from %s to %s"%(muon_files,muon_file_list[-muon_files],muon_file_list[-1]))
print("Using %i numu files, %i nue files, %i nutau files, %i muon files"%(numu_files, nue_files, nutau_files, muon_files))
numu_file_list = numu_file_list[:numu_files]
nue_file_list = nue_file_list[-nue_files:]
nutau_file_list = nutau_file_list[:nutau_files]
muon_file_list = muon_file_list[-muon_files:]
full_path = np.concatenate((numu_file_list,nue_file_list,nutau_file_list,muon_file_list))
from read_cnn_i3_files import read_i3_files
variable_list = ["energy", "prob_track", "zenith", "vertex_x", "vertex_y", "vertex_z", "prob_muon", "nDOM", "end_x", "end_y", "end_z"]
predict1, truth1, old_reco, info1, raw_weights1, input_features_DC, input_features_IC = read_i3_files(full_path,variable_list)
else:
f = h5py.File(input_file, "r")
truth1 = f["Y_test_use"][:]
predict1 = f["Y_predicted"][:]
#reco1 = f["reco_test"][:]
raw_weights1 = f["weights_test"][:]
try:
info1 = f["additional_info"][:]
except:
info1 = None
f.close()
del f
#Truth
true1 = {}
true1['energy'] = np.array(truth1[:,0])
true1['em_equiv_energy'] = np.array(truth1[:,14])
true1['total_daughter_energy'] = np.array(truth1[:,13])
true1['x'] = np.array(truth1[:,4])
true1['y'] = np.array(truth1[:,5])
true1['z'] = np.array(truth1[:,6])
x1_origin = np.ones((len(true1['x'])))*46.290000915527344
y1_origin = np.ones((len(true1['y'])))*-34.880001068115234
true1['r'] = np.sqrt( (true1['x'] - x1_origin)**2 + (true1['y'] - y1_origin)**2 )
true1['isCC'] = np.array(truth1[:,11],dtype=bool)
true1['isTrack'] = np.array(truth1[:,8]) == 1
true1['isCascade'] = np.array(truth1[:,8]) == 0
true1['PID'] = truth1[:,9]
true1['zenith'] = np.array(truth1[:,12])
true1['coszenith'] = np.cos(np.array(truth1[:,12]))
#ending calculation
true1['azimuth'] = truth1[:,2]
true1['track_length'] = truth1[:,7]
n_x = np.sin(true1['zenith'])*np.cos(true1['azimuth'])
n_y = np.sin(true1['zenith'])*np.sin(true1['azimuth'])
n_z = np.cos(true1['zenith'])
true1['x_end'] = true1['x'] + true1['track_length']*n_x
true1['y_end'] = true1['y'] + true1['track_length']*n_y
true1['z_end'] = true1['z'] + true1['track_length']*n_z
true1['r_end'] = np.sqrt( (true1['x_end'] - x1_origin)**2 + (true1['y_end'] - y1_origin)**2 )
try:
true1['daughter_energy'] = np.array(truth1[:,15])
except:
true1['daughter_energy'] = None
#Reconstructed values (CNN)
reco1 = {}
reco1['energy'] = np.array(predict1[:,0])
reco1['prob_track'] = np.array(predict1[:,1])
reco1['zenith'] = np.array(predict1[:,2])
reco1['coszenith'] = np.cos(reco1['zenith'])
reco1['x'] = np.array(predict1[:,3])
reco1['y'] = np.array(predict1[:,4])
reco1['z'] = np.array(predict1[:,5])
reco1['r'] = np.sqrt( (reco1['x'] - x1_origin)**2 + (reco1['y'] - y1_origin)**2 )
reco1['prob_mu'] = np.array(predict1[:,9]) #np.array(predict1[:,6])
reco1['nDOMs'] = np.array(predict1[:,7])
try:
reco1['x_end'] = np.array(predict1[:,8])
reco1['y_end'] = np.array(predict1[:,9])
reco1['z_end'] = np.array(predict1[:,10])
reco1['r_end'] = np.sqrt( (reco1['x_end'] - x1_origin)**2 + (reco1['y_end'] - y1_origin)**2 )
except:
reco1['x_end'] = None
reco1['y_end'] = None
reco1['z_end'] = None
reco1['r_end'] = None
#RECO masks
mask1 = {}
mask1['Energy'] = np.logical_and(reco1['energy'] > cut1['emin'], reco1['energy'] < cut1['emax'])
mask1['Zenith'] = reco1['coszenith'] <= cut1['coszen']
mask1['R'] = reco1['r'] < cut1['r']
mask1['Z'] = np.logical_and(reco1['z'] > cut1['zmin'], reco1['z'] < cut1['zmax'])
mask1['Vertex'] = np.logical_and(mask1['R'], mask1['Z'])
mask1['ProbMu'] = reco1['prob_mu'] <= cut1['mu']
mask1['Reco'] = np.logical_and(mask1['ProbMu'], np.logical_and(mask1['Zenith'], np.logical_and(mask1['Energy'], mask1['Vertex'])))
mask1['DOM'] = reco1['nDOMs'] >= cut1['nDOM']
mask1['RecoNoEn'] = np.logical_and(mask1['ProbMu'], np.logical_and(mask1['Zenith'], mask1['Vertex']))
mask1['RecoNoZenith'] = np.logical_and(mask1['ProbMu'], np.logical_and(mask1['Energy'], mask1['Vertex']))
mask1['RecoNoZ'] = np.logical_and(mask1['ProbMu'], np.logical_and(mask1['Zenith'], np.logical_and(mask1['Energy'], mask1['R'])))
mask1['RecoNoR'] = np.logical_and(mask1['ProbMu'], np.logical_and(mask1['Zenith'], np.logical_and(mask1['Energy'], mask1['Z'])))
mask1['RecoNoMu'] = np.logical_and(mask1['Zenith'], np.logical_and(mask1['Energy'], mask1['Vertex']))
mask1['RecoNoMuNoR'] = np.logical_and(mask1['Zenith'], np.logical_and(mask1['Energy'], mask1['Z']))
mask1['All'] = true1['energy'] > 0
true1['All'] = true1['energy'] > 0
#PID identification
muon_mask_test1 = (true1['PID']) == 13
true1['isMuon'] = np.array(muon_mask_test1,dtype=bool)
numu_mask_test1 = (true1['PID']) == 14
true1['isNuMu'] = np.array(numu_mask_test1,dtype=bool)
nue_mask_test1 = (true1['PID']) == 12
true1['isNuE'] = np.array(nue_mask_test1,dtype=bool)
nutau_mask_test1 = (true1['PID']) == 16
true1['isNuTau'] = np.array(nutau_mask_test1,dtype=bool)
nu_mask1 = np.logical_or(np.logical_or(numu_mask_test1, nue_mask_test1), nutau_mask_test1)
true1['isNu'] = np.array(nu_mask1,dtype=bool)
#Weight adjustments
weights1 = raw_weights1[:,8]
if weights1 is not None:
if sum(true1['isNuMu']) > 1:
weights1[true1['isNuMu']] = weights1[true1['isNuMu']]/numu_files1
if sum(true1['isNuE']) > 1:
weights1[true1['isNuE']] = weights1[true1['isNuE']]/nue_files1
if sum(true1['isMuon']) > 1:
weights1[true1['isMuon']] = weights1[true1['isMuon']]/muon_files1
if sum(nutau_mask_test1) > 1:
weights1[true1['isNuTau']] = weights1[true1['isNuTau']]/nutau_files1
true1['run_id'] = np.array(raw_weights1[:,0],dtype=int)
true1['subrun_id'] = np.array(raw_weights1[:,1],dtype=int)
true1['event_id'] = np.array(raw_weights1[:,2],dtype=int)
together1 = [str(i) + str(j) + str(k) for i, j, k in zip(true1['run_id'], true1['subrun_id'], true1['event_id'])]
true1['full_ID'] = np.array(together1,dtype=int )
weights_squared1 = weights1*weights1
#Deposited Energy
if true1['daughter_energy'] is not None:
true1['deposited_energy'] = np.zeros(len(true1['energy']))
CC_not_tau = np.logical_and(np.logical_or(true1['isNuMu'], true1['isNuE']), true1['isCC'])
CC_tau = np.logical_and(true1['isCC'], true1['isNuTau'])
true1['isNC'] = np.logical_not(true1['isCC'])
#NC
true1['deposited_energy'][true1['isNC']] = true1['energy'][true1['isNC']] - true1['daughter_energy'][true1['isNC']]
#Tau CC
true1['deposited_energy'][CC_tau] = true1['energy'][CC_tau] - (true1['daughter_energy'][CC_tau]*0.5)
#NuMu CC and NuE CC
true1['deposited_energy'][CC_not_tau] = true1['total_daughter_energy'][CC_not_tau]
else:
true1['deposited_energy'] = None
print(true1['deposited_energy'][true1['isNC']][:10])
print(true1['energy'][true1['isNC']][:10])
#Additional info
more_info1 = {}
if info1 is not None:
more_info1['prob_nu'] = info1[:,1]
more_info1['coin_muon'] = info1[:,0]
more_info1['true_ndoms'] = info1[:,2]
more_info1['fit_success'] = info1[:,3]
more_info1['noise_class'] = info1[:,4]
more_info1['nhit_doms'] = info1[:,5]
more_info1['n_top15'] = info1[:,6]
more_info1['n_outer'] = info1[:,7]
more_info1['prob_nu2'] = info1[:,8]
more_info1['total_hits'] = info1[:,9]
#INFO masks
if info1 is not None:
mask1['Hits8'] = more_info1['total_hits'] >= 8
mask1['oscNext_Nu'] = more_info1['prob_nu'] > 0.8 #CHANGED FROM 0.4
mask1['Noise'] = more_info1['noise_class'] > 0.95
mask1['nhit'] = more_info1['nhit_doms'] > 2.5
mask1['ntop']= more_info1['n_top15'] < 0.5
mask1['nouter'] = more_info1['n_outer'] < 7.5
mask1['CoinHits'] = np.logical_and(np.logical_and(mask1['nhit'], mask1['ntop']), mask1['nouter'])
mask1['MC'] = np.logical_and(np.logical_and(mask1['CoinHits'],mask1['Noise']),mask1['DOM'])
#Combined Masks
mask1['Analysis'] = np.logical_and(mask1['MC'], mask1['Reco'])
mask1['AnalysisNoDOM'] = np.logical_and(np.logical_and(mask1['CoinHits'],mask1['Noise']),mask1['Reco'])
print("Events file 1: %i, NuMu Rate: %.2e"%(len(true1['energy']),sum(weights1[true1['isNuMu']])))
if input_file2 is not None:
#IMPORT FILE 2
f2 = h5py.File(input_file2, "r")
truth2 = f2["Y_test_use"][:]
predict2 = f2["Y_predicted"][:]
raw_weights2 = f2["weights_test"][:]
try:
old_reco2 = f2["reco_test"][:]
except:
old_reco2 = None
try:
info2 = f2["additional_info"][:]
except:
info2 = None
f2.close()
del f2
#Truth
true2 = {}
true2['energy'] = np.array(truth2[:,0])
true2['em_equiv_energy'] = np.array(truth2[:,14])
true2['total_daughter_energy'] = np.array(truth2[:,13])
true2['x'] = np.array(truth2[:,4])
true2['y'] = np.array(truth2[:,5])
true2['z'] = np.array(truth2[:,6])
x2_origin = np.ones((len(true2['x'])))*46.290000915527344
y2_origin = np.ones((len(true2['y'])))*-34.880001068115234
true2['r'] = np.sqrt( (true2['x'] - x2_origin)**2 + (true2['y'] - y2_origin)**2 )
true2['isCC'] = np.array(truth2[:,11],dtype=bool)
true2['isTrack'] = np.array(truth2[:,8]) == 1
true2['isCascade'] = np.array(truth2[:,8]) == 0
true2['PID'] = truth2[:,9]
true2['zenith'] = np.array(truth2[:,12])
true2['coszenith'] = np.cos(np.array(truth2[:,12]))
try:
true2['daughter_energy'] = np.array(truth2[:,15])
except:
true2['daughter_energy'] = None
reco2 = {}
mask2 = {}
if compare_cnn:
#Reconstructed values (CNN)
reco2['energy'] = np.array(predict2[:,0])
reco2['prob_track'] = np.array(predict2[:,1])
reco2['zenith'] = np.array(predict2[:,2])
reco2['coszenith'] = np.cos(reco2['zenith'])
reco2['x'] = np.array(predict2[:,3])
reco2['y'] = np.array(predict2[:,4])
reco2['z'] = np.array(predict2[:,5])
reco2['r'] = np.sqrt( (reco2['x'] - x2_origin)**2 + (reco2['y'] - y2_origin)**2 )
reco2['prob_mu'] = np.array(predict2[:,6])
reco2['nDOMs'] = np.array(predict2[:,7])
#RECO masks
mask2['ProbMu'] = reco2['prob_mu'] <= cut2['mu']
mask2['DOM'] = reco2['nDOMs'] >= cut2['nDOM']
else:
reco2['energy'] = np.array(old_reco2[:,0])
reco2['zenith'] = np.array(old_reco2[:,1])
reco2['coszenith'] = np.cos(reco2['zenith'])
reco2['time'] = np.array(old_reco2[:,3])
reco2['prob_track'] = np.array(old_reco2[:,13])
reco2['prob_track_full'] = np.array(old_reco2[:,12])
reco2['x'] = np.array(old_reco2[:,4])
reco2['y'] = np.array(old_reco2[:,5])
reco2['z'] = np.array(old_reco2[:,6])
reco2['r'] = np.sqrt( (reco2['x'] - x2_origin)**2 + (reco2['y'] - y2_origin)**2 )
reco2['iterations'] = np.array(old_reco2[:,14])
reco2['nan'] = np.isnan(reco2['energy'])
#mask1['Reco'] = np.logical_and(mask1['ProbMu'], np.logical_and(mask1['Zenith'], np.logical_and(mask1['Energy'], mask1['Vertex'])))
#mask1['RecoNoEn'] = np.logical_and(mask1['ProbMu'], np.logical_and(mask1['Zenith'], mask1['Vertex']))
#PID identification
muon_mask_test2 = (true2['PID']) == 13
true2['isMuon'] = np.array(muon_mask_test2,dtype=bool)
numu_mask_test2 = (true2['PID']) == 14
true2['isNuMu'] = np.array(numu_mask_test2,dtype=bool)
nue_mask_test2 = (true2['PID']) == 12
true2['isNuE'] = np.array(nue_mask_test2,dtype=bool)
nutau_mask_test2 = (true2['PID']) == 16
true2['isNuTau'] = np.array(nutau_mask_test2,dtype=bool)
nu_mask2 = np.logical_or(np.logical_or(numu_mask_test2, nue_mask_test2), nutau_mask_test2)
true2['isNu'] = np.array(nu_mask2,dtype=bool)
#Weight adjustments
weights2 = raw_weights2[:,8]
if weights2 is not None:
if sum(true2['isNuMu']) > 1:
weights2[true2['isNuMu']] = weights2[true2['isNuMu']]/numu_files2
if sum(true2['isNuE']) > 1:
weights2[true2['isNuE']] = weights2[true2['isNuE']]/nue_files2
if sum(true2['isMuon']) > 1:
weights2[true2['isMuon']] = weights2[true2['isMuon']]/muon_files2
if sum(nutau_mask_test1) > 1:
weights2[true2['isNuTau']] = weights2[true2['isNuTau']]/nutau_files2
true2['run_id'] = np.array(raw_weights2[:,0],dtype=int)
true2['subrun_id'] = np.array(raw_weights2[:,1],dtype=int)
true2['event_id'] = np.array(raw_weights2[:,2],dtype=int)
together2 = [str(i) + str(j) + str(k) for i, j, k in zip(true2['run_id'], true2['subrun_id'], true2['event_id'])]
true2['full_ID'] = np.array(together2,dtype=int )
weights_squared2 = weights2*weights2
#Deposited Energy
if true2['daughter_energy'] is not None:
true2['deposited_energy'] = np.zeros(len(true2['energy']))
CC_not_tau = np.logical_and(np.logical_or(true2['isNuMu'], true2['isNuE']), true2['isCC'])
CC_tau = np.logical_and(true2['isCC'], true2['isNuTau'])
true2['isNC'] = np.logical_not(true2['isCC'])
#NC
true2['deposited_energy'][true2['isNC']] = true2['energy'][true2['isNC']] - true2['daughter_energy'][true2['isNC']]
#Tau CC
true2['deposited_energy'][CC_tau] = true2['energy'][CC_tau] - (true2['daughter_energy'][CC_tau]*0.5)
#NuMu CC and NuE CC
true2['deposited_energy'][CC_not_tau] = true2['total_daughter_energy'][CC_not_tau]
else:
true2['deposited_energy'] = None
#Additional info
more_info2 = {}
if info2 is not None:
more_info2['prob_nu'] = info2[:,1]
more_info2['coin_muon'] = info2[:,0]
more_info2['true_ndoms'] = info2[:,2]
more_info2['fit_success'] = info2[:,3]
more_info2['noise_class'] = info2[:,4]
more_info2['nhit_doms'] = info2[:,5]
more_info2['n_top15'] = info2[:,6]
more_info2['n_outer'] = info2[:,7]
more_info2['prob_nu2'] = info2[:,8]
more_info2['total_hits'] = info2[:,9]
#INFO masks
if info2 is not None:
mask2['Hits8'] = more_info2['total_hits'] >= 8
print("Hits8 failure cuts:", sum(mask2['Hits8'])/len(mask2['Hits8']))
mask2['oscNext_Nu'] = more_info2['prob_nu'] > 0.8 #CHANGED FROM 0.4
mask2['Noise'] = more_info2['noise_class'] > 0.95
mask2['nhit'] = more_info2['nhit_doms'] > 2.5
mask2['ntop'] = more_info2['n_top15'] < 0.5
mask2['nouter'] = more_info2['n_outer'] < 7.5
mask2['CoinHits'] = np.logical_and(np.logical_and(mask2['nhit'], mask2['ntop']), mask2['nouter'])
if not compare_cnn:
mask2['ProbMu'] = mask2['oscNext_Nu']
mask2['Time'] = reco2['time'] < 14500
mask2['NotNAN'] = np.logical_not(reco2['nan'])
mask2['RetroIterations'] = reco2['iterations'] < 10000
mask2['RetroPass'] = np.logical_and(np.logical_and(mask2['Hits8'],mask2['RetroIterations']), mask2['NotNAN'])
print("Retro failure cuts:", sum(mask2['RetroPass']/len(mask2['RetroPass'])))
mask2['Class'] = np.logical_and(mask2['oscNext_Nu'],mask2['Noise'])
mask2['MC'] = np.logical_and(np.logical_and(np.logical_and(mask2['CoinHits'],mask2['Class']), mask2['RetroPass']),mask2['Time'])
else:
mask2['Class'] = mask2['Noise']
mask2['MC'] = np.logical_and(np.logical_and(mask2['CoinHits'],mask2['Class']),mask2['DOM'])
#RECO2 MASKS
mask2['Energy'] = np.logical_and(reco2['energy'] > cut2['emin'], reco2['energy'] < cut2['emax'])
mask2['Zenith'] = reco2['coszenith'] <= cut2['coszen']
mask2['R'] = reco2['r'] < cut2['r']
mask2['Z'] = np.logical_and(reco2['z'] > cut2['zmin'], reco2['z'] < cut2['zmax'])
mask2['Vertex'] = np.logical_and(mask2['R'], mask2['Z'])
mask2['Reco'] = np.logical_and(mask2['ProbMu'], np.logical_and(mask2['Zenith'], np.logical_and(mask2['Energy'], mask2['Vertex'])))
mask2['RecoNoEn'] = np.logical_and(mask2['ProbMu'], np.logical_and(mask2['Zenith'], mask2['Vertex']))
mask2['RecoNoZenith'] = np.logical_and(mask2['ProbMu'], np.logical_and(mask2['Energy'], mask2['Vertex']))
mask2['RecoNoZ'] = np.logical_and(mask2['ProbMu'], np.logical_and(mask2['Zenith'], np.logical_and(mask2['Energy'], mask2['R'])))
mask2['RecoNoR'] = np.logical_and(mask2['ProbMu'], np.logical_and(mask2['Zenith'], np.logical_and(mask2['Energy'], mask2['Z'])))
mask2['All'] = true2['energy'] > 0
true2['All'] = true2['energy'] > 0
if info2 is not None:
mask2['Analysis'] = np.logical_and(mask2['MC'], mask2['Reco'])
print("Events file 2: %i, NuMu Rate: %.2e"%(len(true2['energy']),sum(weights2[true2['isNuMu']])))
#Plot
from PlottingFunctions import plot_distributions
from PlottingFunctions import plot_2D_prediction
from PlottingFunctions import plot_single_resolution
from PlottingFunctions import plot_bin_slices
from PlottingFunctions import plot_rms_slices
from PlottingFunctionsClassification import my_confusion_matrix
save=True
if save ==True:
print("Saving to %s"%save_folder_name)
save_base_name = save_folder_name
var_names = ["Energy", "Cosine Zenith", "Z Position", "Radius", "X End", "Y End", "Z End", "R End", "X Position", "Y Postition"]
units = ["(GeV)", "", "(m)", "(m)", "(m)", "(m)", "(m)", "(m)", "(m)", ]
minvals = [5, -1, cut1['zmin'], 0, -200, -200, -450, 0, -200, -200]
maxvals = [100, cut1['coszen'], cut1['zmax'], cut1['r'], 200, 200, -200, 300, 200, 200]
res_ranges = [100, 1, 75, 100, 100, 100, 100, 100, 100, 100]
frac_res_ranges = [2, 2, 0.5, 1, 2, 2, 2, 2, 2, 2]
binss = [95, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100]
binned_fracs = [True, False, False, False, False, False, False, False, False, False, False]
syst_bins = [95, 100, 100, 100, 100, 100, 100, 100, 100, 100]
cut_mins = [cut1['emin'], None, cut1['zmin'], None, -1000, -1000, cut1['zmax'], cut1['r'], -1000, -1000]
cut_maxs = [cut1['emax'], cut1['coszen'], cut1['zmax'], cut1['r'], None, None, cut1['zmin'], None, None, None]
#Names of mask keys to Use/hold back when plotting
keynames = ['Energy', 'Zenith', 'Z', 'R', 'All', 'All', 'All', 'All', 'All', 'All', 'All']
masknames = ['RecoNoEn', 'RecoNoZenith', 'RecoNoZ', 'RecoNoR', 'Reco', 'Reco', 'Reco', 'Reco', 'Reco', 'Reco']
check_depo = true1['energy'] - true1['deposited_energy']
check_depo2 = true2['energy'] - true2['deposited_energy']
near_zero = check_depo < 1e-3
near_zero2 = check_depo2 < 1e-3
print("Check deposited different than true 1: %i"%sum(near_zero))
print("Check deposited different than true 2: %i"%sum(near_zero2))
name1 = "CNN"
name2 = "Likelihood"
logmax = 10**1.5
bins_log = 10**np.linspace(0,1.5,100)
variable_names = ['energy', 'coszenith', 'z', 'r', 'x_end', 'y_end', 'z_end', 'r_end', 'x', 'y']
flavors = ["NuMu", "NuE", "NuTau", "Nu", "Muon", "Nu", "All", "Nu", "Nu"]
selects = ["CC", "CC", "CC", "NC", "All", "All", "All", "Track", "Cascade"]
############## CHANGE THESE LINES ##############
variable_index_list = [1,2,3] #chose variable from list above
check_index_list = [-2, -1] #corresponds to flavor/select index
cut_or = False #use for ending cuts, want below min OR above max
energy_type = "True" #"EM Equiv" or Deposited or True
plot_find_rate = False
print_rates = False
make_distributions = True
make_2d_hist = True
make_2d_hist_vs_reco = False
make_resolution = True
make_bin_slice = True
make_bin_slice_vs_reco = False
make_confusion = False
make_PID = False
make_muon = False
##################################################
all_remaining1 = mask1['Analysis']
if input_file2 is not None:
if compare_cnn:
all_remaining2 = mask2['Analysis']
else:
all_remaining2 = np.logical_and(mask2['Analysis'], mask2['RetroPass'])
#sample_mask1 = true1['isNu']
#check1 = np.logical_and(sample_mask1, mask1['AnalysisNoDOM'])
#final1 = np.logical_and(sample_mask1, mask1['Analysis'])
#print("NU CUT NDOM", sum(weights1[final1])/sum(weights1[check1]))
"""
check_cuts = np.arange(0.0001,0.001,0.0001)
for i in check_cuts:
check1 = np.logical_and(true1['isMuon'], np.logical_and(mask1['MC'],mask1['RecoNoMu']))
check_prob1 = reco1['prob_mu'] <= i
check_total = np.logical_and(check1,check_prob1)
numu_check = np.logical_and(np.logical_and(np.logical_and(true1['isNuMu'], np.logical_and(mask1['MC'],mask1['RecoNoMu'])),check_prob1),true1['isCC'])
print("Cut: %.4f, Muon Rate: %.3e, NuMu Rate: %.3e"%(i, sum(weights1[check_total]), sum(weights1[numu_check])))
"""
def return_rates(true_PID,prediction,weights,threshold):
predictionNu = prediction < threshold
predictionMu = prediction >= threshold
save_weights = weights[predictionNu]
true_PID = true_PID[predictionNu]
muon_mask = true_PID == 13
true_isMuon = np.array(muon_mask,dtype=bool)
nue_mask = true_PID == 12
true_isNuE = np.array(nue_mask,dtype=bool)
numu_mask = true_PID == 14
true_isNuMu = np.array(numu_mask,dtype=bool)
nutau_mask = true_PID == 16
true_isNuTau = np.array(nutau_mask,dtype=bool)
muon_rate = sum(save_weights[true_isMuon])
nue_rate = sum(save_weights[true_isNuE])
numu_rate = sum(save_weights[true_isNuMu])
nutau_rate = sum(save_weights[true_isNuTau])
return muon_rate, nue_rate, numu_rate, nutau_rate
if plot_find_rate:
mask_noR_noMu = np.logical_and(mask1['MC'],mask1['RecoNoMuNoR'])
cut_values = np.arange(0.0005,0.05,0.0005)
target_muon_rate = 0.000004
r36_cuts = np.arange(90,200,5)
mu_threshold = []
nu_rates_save = []
numu_rates_save = []
mu_rates_save = []
for r36_check in r36_cuts:
r36_mask = reco1['r'] < r36_check
muon_rates = []
numu_rates = []
nu_rates = []
difference_to_target = []
for muon_cut in cut_values:
check_mask_here = np.logical_and(mask_noR_noMu,r36_mask)
muon_rate, nue_rate, numu_rate, nutau_rate = return_rates(true1['PID'][check_mask_here], reco1['prob_mu'][check_mask_here], weights1[check_mask_here], muon_cut)
muon_rates.append(muon_rate)
nu_rates.append(nue_rate + numu_rate + nutau_rate)
numu_rates.append(numu_rate)
difference_to_target.append(np.abs(muon_rate - target_muon_rate))
closest_target_index = difference_to_target.index(min(difference_to_target))
mu_threshold.append(cut_values[closest_target_index])
nu_rates_save.append(nu_rates[closest_target_index])
numu_rates_save.append(numu_rates[closest_target_index])
mu_rates_save.append(muon_rates[closest_target_index])
print(r36_cuts)
print(mu_threshold)
print(mu_rates_save)
plt.figure(figsize=(10,7))
plt.title("Neutrino Rate vs. R36 Cut (const Mu rate = .004mHz)",fontsize=25)
plt.plot(r36_cuts,nu_rates_save,color='g',label=r'$\nu$ Energy [3, 100]')
plt.plot(r36_cuts,numu_rates_save,color='g',linestyle="dashed",label=r'$\nu_\mu$ Energy [3, 100]')
plt.axhline(0.000704,color='k',label=r'oscNext $\nu$ rate')
plt.axhline(0.000435,color='k',linestyle="dashed",label=r'oscNext $\nu$ CC rate')
plt.xlabel("R36 cut values (< X m)",fontsize=20)
plt.ylabel("Remaining Neutrino Rate (Hz)",fontsize=20)
plt.legend(fontsize=20)
plt.savefig("%sNuVsR36Rates.png"%(save_folder_name),bbox_inches='tight')
plt.close()
if print_rates:
print("Flavor", "Type", "Num events (after)", "Rate (after)", "Fraction Of Sample")
for check_set in range(0,7):
flavor = flavors[check_set]
sample = selects[check_set]
if flavor == "All":
flavor_key = flavor
else:
flavor_key = "is%s"%flavor
if sample =="CC" or sample == "NC":
select = "is%s"%sample
else:
select = sample
sample_mask1 = np.logical_and(true1[flavor_key],true1[select])
final1 = np.logical_and(sample_mask1, mask1['Analysis'])
print("%s\t %s\t %i\t %.3e\t %.3f"%(flavor, sample, sum(final1), sum(weights1[final1]), sum(weights1[final1])/sum(weights1[mask1['Analysis']])))
if input_file2 is not None:
sample_mask2 = np.logical_and(true2[flavor_key],true2[select])
final2 = np.logical_and(sample_mask2, mask2['Analysis'])
print("%s\t %s\t %i\t %.3e\t %.3f"%(flavor, sample, sum(final2), sum(weights2[final2]), sum(weights2[final2])/sum(weights2[mask2['Analysis']])))
#Find shared events
shared_events = len(set(true1['full_ID'][final1]) & set(true2['full_ID'][final2]))
unique_set1 = len(true1['full_ID'][final1]) - shared_events
unique_set2 = len(true2['full_ID'][final2]) - shared_events
print("%s\t %s\t %i\t %i\t %i\t %.3f\t %.3f"%(flavor, sample, shared_events, unique_set1, unique_set2, unique_set1/(shared_events+unique_set1), unique_set2/(shared_events+unique_set2)))
if make_muon:
#NEED BINARY PROBMU
percent_save = my_confusion_matrix(true1['isNu'], mask1['ProbMu'], weights1,
mask=mask1['Analysis'],title="%s Muon Cut"%name1,
save=save,save_folder_name=save_folder_name)
if input_file2 is not None:
percent_save = my_confusion_matrix(true2['isNu'], mask2['ProbMu'],
weights2,
mask=mask2['Analysis'],title="%s Muon Cut"%name2,
save=save,save_folder_name=save_folder_name)
if make_PID:
#NEED BINARY PROB TRACK
mask1_here = np.logical_and(mask1['Analysis'], true1['isNu'])
percent_save = my_confusion_matrix(true1['isTrack'], true1['prob_track'], weights1,label0="Cascade",label1="Track",
mask=mask1_here,title="%s PID Cut"%name1,
save=save,save_folder_name=save_folder_name)
if input_file2 is not None:
mask2_here = np.logical_and(mask2['Analysis'], true2['isNu'])
percent_save = my_confusion_matrix(true2['isTrack'], true2['prob_track'],
weights2,label0="Cascade",label1="Track",
mask=mask2_here,title="%s Muon Cut"%name2,
save=save,save_folder_name=save_folder_name)
for variable_index in variable_index_list:
for check_set in check_index_list:
flavor = flavors[check_set]
sample = selects[check_set]
if flavor == "All":
flavor_key = flavor
else:
flavor_key = "is%s"%flavor
if sample =="CC" or sample == "NC" or sample == "Track" or sample == "Cascade":
select = "is%s"%sample
else:
select = sample
var_type="True" #labeling purposes
if energy_type is "EM Equiv":
use_em = 'em_equiv_'
if variable_index == 0:
var_type="EM Equiv"
if energy_type is "Deposited":
use_em = 'deposited_'
if variable_index == 0:
var_type="Deposited"
else:
use_em = ''
print("Plotting %s %s against %s energy"%(flavor, sample,var_type))
save_folder_name = save_base_name + "/%s%s_%s%s/"%(use_em,variable_names[variable_index],flavor,sample)
if os.path.isdir(save_folder_name) != True:
os.mkdir(save_folder_name)
print("saving to %s"%save_folder_name)
variable_name = variable_names[variable_index]
minval = minvals[variable_index]
maxval = maxvals[variable_index]
bins = binss[variable_index]
binned_frac = binned_fracs[variable_index]
syst_bin = syst_bins[variable_index]
plot_name = var_names[variable_index]
plot_units = units[variable_index]
res_range = res_ranges[variable_index]
frac_res_range = frac_res_ranges[variable_index]
cut_min = cut_mins[variable_index]
cut_max = cut_maxs[variable_index]
keyname = keynames[variable_index]
maskname = masknames[variable_index]
sample_mask1 = np.logical_and(true1[flavor_key],true1[select])
full_mask1 = np.logical_and(sample_mask1, mask1['Analysis'])
minus_var_mask1 = np.logical_and(np.logical_and(sample_mask1, mask1['MC']), mask1[maskname])
if input_file2 is not None:
sample_mask2 = np.logical_and(true2[flavor_key],true2[select])
full_mask2 = np.logical_and(sample_mask2, mask2['Analysis'])
minus_var_mask2 = np.logical_and(np.logical_and(sample_mask2, mask2['MC']), mask2[maskname])
print("using %s"%(use_em + variable_name))
true1_value = true1[use_em + variable_name][minus_var_mask1]
reco1_value = reco1[variable_name][minus_var_mask1]
weights1_value = weights1[minus_var_mask1]
true1_value_fullAnalysis = true1[use_em + variable_name][full_mask1]
reco1_value_fullAnalysis = reco1[variable_name][full_mask1]
weights1_value_fullAnalysis = weights1[full_mask1]
true1_energy_fullAnalysis = true1[use_em + 'energy'][full_mask1]
if cut_min is not None:
if cut_max is not None:
if cut_or:
true1_binary = np.logical_or(true1[variable_name][minus_var_mask1] > cut_min, true1[variable_name][minus_var_mask1] < cut_max)
reco1_binary = np.logical_or(reco1[variable_name][minus_var_mask1] > cut_min, reco1[variable_name][minus_var_mask1] < cut_max)
print(variable_name, "Checking > ", cut_min, " OR < ", cut_max)
else:
true1_binary = np.logical_and(true1[variable_name][minus_var_mask1] > cut_min, true1[variable_name][minus_var_mask1] < cut_max)
reco1_binary = np.logical_and(reco1[variable_name][minus_var_mask1] > cut_min, reco1[variable_name][minus_var_mask1] < cut_max)
print(variable_name, "Checking > ", cut_min, " AND < ", cut_max)
else:
true1_binary = true1[variable_name][minus_var_mask1] > cut_min
reco1_binary = reco1[variable_name][minus_var_mask1] > cut_min
print(variable_name, "Checking > ", cut_min)
else:
true1_binary = true1[variable_name][minus_var_mask1] < cut_max
reco1_binary = reco1[variable_name][minus_var_mask1] < cut_max
print(variable_name, "Checking < ", cut_max)
print(true1_binary[:10],reco1_binary[:10])
print(sum(weights1_value_fullAnalysis)/sum(weights1[true1['isCC']]))
print(true1_value[:10], reco1_value[:10])
if input_file2 is not None:
true2_value = true2[use_em + variable_name][minus_var_mask2]
reco2_value = reco2[variable_name][minus_var_mask2]
true2_value_fullAnalysis = true2[use_em + variable_name][full_mask2]
reco2_value_fullAnalysis = reco2[variable_name][full_mask2]
weights2_value = weights2[minus_var_mask2]
weights2_value_fullAnalysis = weights2[full_mask2]
true2_energy_fullAnalysis = true2[use_em + 'energy'][full_mask2]
if cut_min is not None:
if cut_max is not None:
true2_binary = np.logical_and(true2[variable_name][minus_var_mask2] > cut_min, true2[variable_name][minus_var_mask2] < cut_max)
reco2_binary = np.logical_and(reco2[variable_name][minus_var_mask2] > cut_min, reco2[variable_name][minus_var_mask2] < cut_max)
print(variable_name, "Checking > ", cut_min, " AND < ", cut_max)
else:
true2_binary = true2[variable_name][minus_var_mask2] > cut_min
reco2_binary = reco2[variable_name][minus_var_mask2] > cut_min
print(variable_name, "Checking > ", cut_min)
else:
true2_binary = true2[variable_name][minus_var_mask2] < cut_max
reco2_binary = reco2[variable_name][minus_var_mask2] < cut_max
print(variable_name, "Checking < ", cut_max)
print(sum(weights2_value_fullAnalysis)/sum(weights2[true2['isCC']]))
print(true2_value[:10], reco2_value[:10])
else:
true2_value = None
reco2_value = None
true2_value_fullAnalysis = None
reco2_value_fullAnalysis = None
weights2_value = None
weights2_value_fullAnalysis = None
true2_energy = None
"""
plt.figure(figsize=(10,7))
plt.hist(true1_value, color="green",label="true",
bins=bins_log,range=[minval,logmax],
weights=weights1_value,alpha=0.5)
plt.hist(reco1_value, color="blue",label="CNN",
bins=bins_log,range=[minval,logmax],
weights=weights1_value,alpha=0.5)
plt.xscale('log')
plt.title("Energy Distribution Weighted for %s events"%len(true1_value),fontsize=25)
plt.xlabel("Energy (GeV)",fontsize=20)
plt.xticks(fontsize=15)
plt.yticks(fontsize=15)
plt.axvline(5,linewidth=3,linestyle="--",color='k',label="Cut at 5 GeV")
plt.legend(loc='upper left',fontsize=15)
plt.savefig("%s/%sLogEnergyDist_ZoomInLE.png"%(save_folder_name,name1.replace(" ","")))
plt.figure(figsize=(10,7))
plt.hist(true2_value, color="green",label="true",
bins=bins_log,range=[minval,logmax],
weights=weights2_value,alpha=0.5)
plt.hist(reco2_value, color="blue",label="CNN",
bins=bins_log,range=[minval,logmax],
weights=weights2_value,alpha=0.5)
plt.xscale('log')
plt.title("Energy Distribution Weighted for %s events"%len(true2_value),fontsize=25)
plt.xlabel("Energy (GeV)",fontsize=20)
plt.xticks(fontsize=15)
plt.yticks(fontsize=15)
plt.axvline(5,linewidth=3,linestyle="--",color='k',label="Cut at 5 GeV")
plt.legend(loc='upper left',fontsize=15)
plt.savefig("%s/%sLogEnergyDist_ZoomInLE.png"%(save_folder_name,name2.replace(" ","")))
"""
if make_distributions:
plot_distributions(true1_value_fullAnalysis,
reco1_value_fullAnalysis,
weights=weights1_value_fullAnalysis,
save=save, savefolder=save_folder_name,
cnn_name = name1, variable=plot_name,
units= plot_units,
minval=minval,maxval=maxval,
bins=bins,true_name=energy_type)
if input_file2 is not None:
plot_distributions(true2_value_fullAnalysis,
old_reco=reco2_value_fullAnalysis,
weights=weights2_value_fullAnalysis,
save=save, savefolder=save_folder_name,
reco_name = name2, variable=plot_name,
units= plot_units,
minval=minval,maxval=maxval,
bins=bins,true_name=energy_type)
if make_2d_hist:
switch = False
plot_2D_prediction(true1_value, reco1_value,
weights=weights1_value,\
save=save, savefolder=save_folder_name,
bins=bins, switch_axis=switch,
variable=plot_name, units=plot_units, reco_name=name1,
flavor=flavor,sample=sample,variable_type=energy_type)
plot_2D_prediction(true1_value, reco1_value,
weights=weights1_value,\
save=save, savefolder=save_folder_name,
bins=bins,switch_axis=switch,\
minval=minval, maxval=maxval, axis_square=True,\
variable=plot_name, units=plot_units, reco_name=name1,
flavor=flavor,sample=sample,variable_type=energy_type)
if input_file2 is not None:
plot_2D_prediction(true2_value, reco2_value,
weights=weights2_value,
save=save, savefolder=save_folder_name,
bins=bins,switch_axis=switch,\
variable=plot_name, units=plot_units, reco_name=name2,
flavor=flavor,sample=sample,variable_type=energy_type)
plot_2D_prediction(true2_value, reco2_value,
weights=weights2_value,
save=save, savefolder=save_folder_name,
bins=bins,switch_axis=switch,\
minval=minval, maxval=maxval, axis_square=True,\
variable=plot_name, units=plot_units, reco_name=name2,
flavor=flavor,sample=sample,variable_type=energy_type)
if make_2d_hist_vs_reco:
switch = True
plot_2D_prediction(true1_value, reco1_value,
weights=weights1_value,\
save=save, savefolder=save_folder_name,
bins=bins, switch_axis=switch,
variable=plot_name, units=plot_units, reco_name=name1)
plot_2D_prediction(true1_value, reco1_value,
weights=weights1_value,\
save=save, savefolder=save_folder_name,
bins=bins,switch_axis=switch,\
minval=minval, maxval=maxval,
cut_truth=True, axis_square=True,\
variable=plot_name, units=plot_units, reco_name=name1)
if input_file2 is not None:
plot_2D_prediction(true2_value, reco2_value,
weights=weights2_value,
save=save, savefolder=save_folder_name,
bins=bins,switch_axis=switch,\
variable=plot_name, units=plot_units, reco_name=name2)
plot_2D_prediction(true2_value, reco2_value,
weights=weights2_value,
save=save, savefolder=save_folder_name,
bins=bins,switch_axis=switch,\
minval=minval, maxval=maxval,
cut_truth=True, axis_square=True,\
variable=plot_name, units=plot_units, reco_name=name2)
if make_resolution:
#Resolution
if input_file2 is None:
use_old_reco = False
else:
use_old_reco = True
plot_single_resolution(true1_value_fullAnalysis, reco1_value_fullAnalysis,
weights=weights1_value_fullAnalysis,
old_reco_weights=weights2_value_fullAnalysis,
use_old_reco = use_old_reco,
old_reco = reco2_value_fullAnalysis,
old_reco_truth=true2_value_fullAnalysis,\
minaxis=-res_range, maxaxis=res_range, bins=bins,\
save=save, savefolder=save_folder_name,\
variable=plot_name, units=plot_units, reco_name=name1,
flavor=flavor,sample=sample)
plot_single_resolution(true1_value_fullAnalysis, reco1_value_fullAnalysis,
weights=weights1_value_fullAnalysis,
old_reco_weights=weights2_value_fullAnalysis,\
use_old_reco = use_old_reco,
old_reco = reco2_value_fullAnalysis,
old_reco_truth=true2_value_fullAnalysis,\
minaxis=-frac_res_range, maxaxis=frac_res_range,
bins=bins, use_fraction=True,\
save=save, savefolder=save_folder_name,\
variable=plot_name, units=plot_units, reco_name=name1,
flavor=flavor,sample=sample)
if make_bin_slice:
#Bin Slices
plot_bin_slices(true1_value, reco1_value,
old_reco = reco2_value,
old_reco_truth=true2_value,
weights=weights1_value,
old_reco_weights=weights2_value,
use_fraction = binned_frac, bins=syst_bin,
min_val=minval, max_val=maxval,
#ylim=[-0.6,1.3],
save=save, savefolder=save_folder_name,
variable=plot_name, units=plot_units,
cnn_name=name1, reco_name=name2,variable_type=var_type,
flavor=flavor,sample=sample,legend="upper right") #add_contour=True
plot_bin_slices(true1_value_fullAnalysis, reco1_value_fullAnalysis,
energy_truth=true1_energy_fullAnalysis,
old_reco = reco2_value_fullAnalysis,
old_reco_truth=true2_value_fullAnalysis,
reco_energy_truth = true2_energy_fullAnalysis,
weights=weights1_value_fullAnalysis,
old_reco_weights=weights2_value_fullAnalysis,\
use_fraction = binned_frac, bins=syst_bin,
min_val=minvals[0], max_val=maxvals[0],\
save=save, savefolder=save_folder_name,
variable=plot_name, units=plot_units,
cnn_name=name1, reco_name=name2,
variable_type=energy_type,
xvariable="%s Energy"%energy_type,xunits="(GeV)",
flavor=flavor,sample=sample,legend="outside")
if make_bin_slice_vs_reco:
plot_bin_slices(true1_value, reco1_value,
old_reco = reco2_value,old_reco_truth=true2_value,
weights=weights1_value, old_reco_weights=weights2_value,\
use_fraction = binned_frac, bins=syst_bin,
min_val=minval, max_val=maxval,\
save=save, savefolder=save_folder_name,
variable=plot_name, units=plot_units,
cnn_name=name1, reco_name=name2,variable_type=var_type,
vs_predict=True,flavor=flavor,sample=sample)
if make_confusion:
from PlottingFunctionsClassification import my_confusion_matrix
percent_save = my_confusion_matrix(true1_binary, reco1_binary, weights1_value,
mask=None,title="%s %s Cut"%(name1,plot_name),
label0="Outside Cut",label1="Inside Cut",
save=save,save_folder_name=save_folder_name)
print("Reco1 Positive, True Positive: %.2f"%percent_save[2])
print("Reco1 Negative, True Negative: %.2f"%percent_save[1])
if input_file2 is not None:
percent_save2 = my_confusion_matrix(true2_binary, reco2_binary,
weights2_value,ylabel="Retro Prediction",
label0="Outside Cut",label1="Inside Cut",
mask=None,title="%s %s Cut"%(name2,plot_name),
save=save,save_folder_name=save_folder_name)