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