Belle II Software light-2505-deimos
printReporting.py
1#!/usr/bin/env python
2
3
10
11"""
12 Call this "python3 fei/printReporting.py"
13 in a directory containing the monitoring output of the FEI
14 It will print out a summary and create some plots
15"""
16
17import sys
18from contextlib import redirect_stdout
19
20import fei.monitoring as monitoring
21
22
23def bold(text):
24 """Use ANSI sequence to show string in bold"""
25 return '\x1b[1m' + text + '\x1b[0m'
26
27
28def print_summary(p):
29 try:
30 print("FEI: printReporting - DEBUG: ", p.particle.identifier)
31 monitoring.MonitorROCPlot(p, monitoring.removeJPsiSlash(p.particle.identifier + '_ROC'))
32 monitoring.MonitorDiagPlot(p, monitoring.removeJPsiSlash(p.particle.identifier + '_Diag'))
33 monitoring.MonitorSigProbPlot(p, monitoring.removeJPsiSlash(p.particle.identifier + '_SigProb'))
34 for spectator in p.particle.mvaConfig.spectators.keys():
35 monitoring.MonitorSpectatorPlot(
36 p, spectator, monitoring.removeJPsiSlash(
37 p.particle.identifier + '_' + spectator + '_Money'), p.particle.mvaConfig.spectators[spectator])
38 except Exception as e:
39 print('FEI-printReporting Error: Could not create plots for particle', p.particle.identifier, e)
40 print("FEI: printReporting - DEBUG: finished plots")
41 print(bold(p.particle.identifier))
42 print('Total cpu time spent reconstructing this particle: ',
43 p.module_statistic.particle_time + sum(p.module_statistic.channel_time.values()))
44 print('Total amount of Monte Carlo particles in training sample: ', p.mc_count)
45 print('Number of decay channels: ', p.reconstructed_number_of_channels, '/', p.total_number_of_channels)
46 print(bold('PreCut'))
47 print('UserCut', p.particle.preCutConfig.userCut)
48 print('BestCandidateCut', p.particle.preCutConfig.bestCandidateVariable,
49 p.particle.preCutConfig.bestCandidateCut, p.particle.preCutConfig.bestCandidateMode)
50 print('VertexCut', p.particle.preCutConfig.vertexCut)
51 print('Stats before ranking')
52 print(sum(p.before_ranking.values()))
53 print('Stats after ranking')
54 print(sum(p.after_ranking.values()))
55 print('Stats after vertex')
56 print(sum(p.after_vertex.values()))
57 print('Stats after classifier')
58 print(sum(p.after_classifier.values()))
59 print(bold('PostCut'))
60 print('Absolute', p.particle.postCutConfig.value)
61 print('Ranking', p.particle.postCutConfig.bestCandidateCut)
62 print('Stats before postcut')
63 print(p.before_postcut)
64 print('Stats before ranking postcut')
65 print(p.before_ranking_postcut)
66 print('Stats after ranking postcut')
67 print(p.after_ranking_postcut)
68 print(bold('Tag unique signal'))
69 print('Stats before tag')
70 print(p.before_tag)
71 print('Stats after tag')
72 print(p.after_tag)
73 print(bold('Multivariate classifier'))
74 print('Method', p.particle.mvaConfig.method)
75 print('Target', p.particle.mvaConfig.target)
76 print(bold('Individual channels'))
77 for channel in p.particle.channels:
78 print(bold(channel.label))
79 print('Stats before ranking')
80 print(p.before_ranking[channel.label])
81 print('Stats after ranking')
82 print(p.after_ranking[channel.label])
83 print('Stats after vertex')
84 print(p.after_vertex[channel.label])
85 print('Stats after classifier')
86 print(p.after_classifier[channel.label])
87
88
89if __name__ == '__main__':
90 particles, configuration = monitoring.load_config()
91
92 if len(sys.argv) >= 2:
93 output = sys.argv[1]
94 redirect = open(output, 'w')
95 print('Output redirected to', output)
96 else:
97 redirect = sys.stdout
98
99 with redirect_stdout(redirect):
100 for particle in particles:
101 monitoringParticle = monitoring.MonitoringParticle(particle)
102 print_summary(monitoringParticle)
103 if len(sys.argv) >= 2:
104 redirect.close()