Belle II Software development
clusterFilterValidation.py
1#!/usr/bin/env python3
2
3
10
11import logging
12from tracking.run.mixins import BrowseTFileOnTerminateRunMixin
13from tracking.run.event_generation import StandardEventGenerationRun
14import tracking.metamodules as metamodules
15import tracking.harvest.refiners as refiners
16import tracking.harvest.harvesting as harvesting
17from ROOT import Belle2 # make Belle2 namespace available
18import sys
19
20import basf2
21
22from ROOT import gSystem
23gSystem.Load('libtracking')
24gSystem.Load('libtracking_trackFindingCDC')
25
26
27def get_logger():
28 return logging.getLogger(__name__)
29
30
31CONTACT = "oliver.frost@desy.de"
32
33
35 """Prepare and execute a basf2 job to read generated events or generate new events then validate the CDC cluster filter"""
36
37 cluster_preparation_module = basf2.register_module("TFCDC_ClusterPreparer")
38
39
40 py_profile = True
41
42 output_file_name = "ClusterFilterValidation.root" # Specification for BrowseTFileOnTerminateRunMixin
43
44 def create_argument_parser(self, **kwds):
45 """Configure the basf2 job script using the translated command-line arguments"""
46 argument_parser = super().create_argument_parser(**kwds)
47 return argument_parser
48
49 def create_path(self):
50 """
51 Sets up a path that plays back pregenerated events or generates events
52 based on the properties in the base class.
53 """
54 main_path = super().create_path()
55
56 cluster_preparation_module = self.get_basf2_module(self.cluster_preparation_module)
57 main_path.add_module(cluster_preparation_module)
58
59 # main_path.add_module(AxialStereoPairFitterModule())
60 validation_module = ClusterFilterValidationModule(output_file_name=self.output_file_nameoutput_file_name)
61 if self.py_profile:
62 main_path.add_module(metamodules.PyProfilingModule(validation_module))
63 else:
64 main_path.add_module(validation_module)
65
66 return main_path
67
68
69class ClusterFilterValidationModule(harvesting.HarvestingModule):
70
71 """Module to collect information about the facet creation cuts and compose validation plots on terminate."""
72
73 def __init__(self, output_file_name):
74 """Constructor"""
75 super().__init__(foreach="CDCWireHitClusterVector",
76 output_file_name=output_file_name)
77
79
80 self.cluster_varset = Belle2.TrackFindingCDC.CDCWireHitClusterVarSet()
81
82 def initialize(self):
83 """Receive signal at the start of event processing"""
85 super().initialize()
86
87 def terminate(self):
88 """Receive signal at the end of event processing"""
90 super().terminate()
91
92 def prepare(self):
93 """Fill the MC hit table"""
94 self.mc_hit_lookup.fill()
95
96 def pick(self, facet):
97 """Always pick, never reject"""
98 return True
99
100 def peel(self, cluster):
101 """Extract and store CDC hit and cluster information"""
102
103 mc_hit_lookup = self.mc_hit_lookup
104
105 self.cluster_varset.extract(cluster)
106 cluster_crops = self.cluster_varset.getNamedValues()
107 cluster_crops = dict(cluster_crops)
108
109 # Truth variables
110 n_background = 0
111 for wireHit in list(cluster.items()):
112 cdcHit = wireHit.getHit()
113 if mc_hit_lookup.isBackground(cdcHit):
114 n_background += 1
115
116 truth_dict = dict(
117 n_background_truth=n_background,
118 background_fraction_truth=1.0 * n_background / cluster.size()
119 )
120
121 cluster_crops.update(truth_dict)
122 return cluster_crops
123
124
126 save_tree = refiners.save_tree(
127
128 folder_name="tree"
129
130 )
131
132 save_histograms = refiners.save_histograms(
133
134 outlier_z_score=5.0,
135 allow_discrete=True,
136 folder_name="histograms"
137
138 )
139
140
141def main():
143 run.configure_and_execute_from_commandline()
144
145
146if __name__ == "__main__":
147 logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(levelname)s:%(message)s')
148 main()
static const CDCMCHitLookUp & getInstance()
Getter for the singletone instance.
mc_hit_lookup
reference to the CDCMCHitlookUp singleton
cluster_varset
reference to the CDCWireHitClusterVarSet
basf2 cluster_preparation_module
basf2 module for CDC cluster preparation
None output_file_name
There is no default for the name of the output TFile.
Definition: mixins.py:60
Definition: main.py:1