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
32 """Prepare and execute a basf2 job to read generated events or generate new events then validate the CDC cluster filter"""
33
34 cluster_preparation_module = basf2.register_module("TFCDC_ClusterPreparer")
35
36
37 py_profile = True
38
39 output_file_name = "ClusterFilterValidation.root" # Specification for BrowseTFileOnTerminateRunMixin
40
41 def create_argument_parser(self, **kwds):
42 """Configure the basf2 job script using the translated command-line arguments"""
43 argument_parser = super().create_argument_parser(**kwds)
44 return argument_parser
45
46 def create_path(self):
47 """
48 Sets up a path that plays back pregenerated events or generates events
49 based on the properties in the base class.
50 """
51 main_path = super().create_path()
52
53 cluster_preparation_module = self.get_basf2_module(self.cluster_preparation_module)
54 main_path.add_module(cluster_preparation_module)
55
56 # main_path.add_module(AxialStereoPairFitterModule())
57 validation_module = ClusterFilterValidationModule(output_file_name=self.output_file_nameoutput_file_name)
58 if self.py_profile:
59 main_path.add_module(metamodules.PyProfilingModule(validation_module))
60 else:
61 main_path.add_module(validation_module)
62
63 return main_path
64
65
66class ClusterFilterValidationModule(harvesting.HarvestingModule):
67
68 """Module to collect information about the facet creation cuts and compose validation plots on terminate."""
69
70 def __init__(self, output_file_name):
71 """Constructor"""
72 super().__init__(foreach="CDCWireHitClusterVector",
73 output_file_name=output_file_name)
74
76
77 self.cluster_varset = Belle2.TrackFindingCDC.CDCWireHitClusterVarSet()
78
79 def initialize(self):
80 """Receive signal at the start of event processing"""
82 super().initialize()
83
84 def terminate(self):
85 """Receive signal at the end of event processing"""
87 super().terminate()
88
89 def prepare(self):
90 """Fill the MC hit table"""
91 self.mc_hit_lookup.fill()
92
93 def pick(self, facet):
94 """Always pick, never reject"""
95 return True
96
97 def peel(self, cluster):
98 """Extract and store CDC hit and cluster information"""
99
100 mc_hit_lookup = self.mc_hit_lookup
101
102 self.cluster_varset.extract(cluster)
103 cluster_crops = self.cluster_varset.getNamedValues()
104 cluster_crops = dict(cluster_crops)
105
106 # Truth variables
107 n_background = 0
108 for wireHit in list(cluster.items()):
109 cdcHit = wireHit.getHit()
110 if mc_hit_lookup.isBackground(cdcHit):
111 n_background += 1
112
113 truth_dict = dict(
114 n_background_truth=n_background,
115 background_fraction_truth=1.0 * n_background / cluster.size()
116 )
117
118 cluster_crops.update(truth_dict)
119 return cluster_crops
120
121
123 save_tree = refiners.save_tree(
124
125 folder_name="tree"
126
127 )
128
129 save_histograms = refiners.save_histograms(
130
131 outlier_z_score=5.0,
132 allow_discrete=True,
133 folder_name="histograms"
134
135 )
136
137
138def main():
140 run.configure_and_execute_from_commandline()
141
142
143if __name__ == "__main__":
144 logging.basicConfig(stream=sys.stdout, level=logging.INFO, format='%(levelname)s:%(message)s')
145 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