Belle II Software prerelease-10-00-00a
caf_cdc_badwire.py
1
8"""CDC badwire calibration."""
9import basf2
10from prompt import CalibrationSettings, INPUT_DATA_FILTERS
11from prompt.calibrations.caf_cdc import settings as cdc_tracking_calibration
12from ROOT import Belle2
13
14settings = CalibrationSettings(name="CDC badwire",
15 expert_username="manhtt",
16 description=__doc__,
17 input_data_formats=["raw"],
18 input_data_names=["mumu_tight_or_highm_calib"],
19 input_data_filters={"mumu_tight_or_highm_calib":
20 [INPUT_DATA_FILTERS["Data Tag"]["mumu_tight_or_highm_calib"],
21 INPUT_DATA_FILTERS["Data Quality Tag"]["Good"],
22 INPUT_DATA_FILTERS["Magnet"]["On"]]},
23 depends_on=[cdc_tracking_calibration],
24 expert_config={
25 "min_events_per_file": 500,
26 "max_events_per_file": 10000,
27 "components": ["CDC", "ECL", "KLM"],
28 "payload_boundaries": [],
29 "backend_args": {"request_memory": "4 GB"}
30 })
31
32
33# Main function to get calibrations
34def get_calibrations(input_data, **kwargs):
35 expert_config = kwargs.get("expert_config")
36 min_events_per_file = expert_config["min_events_per_file"]
37 max_events_per_file = expert_config["max_events_per_file"]
38 components = expert_config["components"]
39
40 # In this script we want to use one sources of input data.
41 # Get the input files from the input_data variable
42 file_to_iov_mumu = input_data["mumu_tight_or_highm_calib"]
43 from prompt.utils import filter_by_max_files_per_run
44 reduced_file_to_iov_mumu = filter_by_max_files_per_run(file_to_iov_mumu, 100, min_events_per_file)
45 input_files_mumu = list(reduced_file_to_iov_mumu.keys())
46 basf2.B2INFO("Complete input data selection.")
47 basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_mumu)}")
48
49 from prompt.utils import ExpRun
50 from caf.utils import IoV
51 from caf import strategies
52 payload_boundaries = []
53 payload_boundaries.extend([ExpRun(*boundary) for boundary in expert_config["payload_boundaries"]])
54 basf2.B2INFO(f"Payload boundaries from expert_config: {payload_boundaries}")
55
56 # The actual value our output IoV payload should have. Notice that we've set it open ended.
57 requested_iov = kwargs.get("requested_iov", None)
58 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
59
60 # for SingleIOV stratrgy, it's better to set the granularity to 'all' so that the collector jobs will run faster
61 if payload_boundaries:
62 basf2.B2INFO('Found payload_boundaries: set collector granularity to run')
63 # call collector module
64 col = basf2.register_module("CDCBadWireCollector")
65
66 # call algorighm
68 algo.setInputFileNames("histo_badwire.root")
69 # Calibration setup
70 from caf.framework import Calibration
71 badwire_calib = Calibration("CDC_Badwire",
72 collector=col,
73 algorithms=algo,
74 input_files=input_files_mumu,
75 pre_collector_path=pre_collector(max_events_per_file,
76 components=components))
77 # Do this for the default AlgorithmStrategy to force the output payload IoV
78 # It may be different if you are using another strategy like SequentialRunByRun
79 if payload_boundaries:
80 basf2.B2INFO("Found payload_boundaries: calibration strategies set to SequentialBoundaries.")
81 badwire_calib.strategies = strategies.SequentialBoundaries
82 for alg in badwire_calib.algorithms:
83 alg.params = {"iov_coverage": output_iov, "payload_boundaries": payload_boundaries}
84 else:
85 for alg in badwire_calib.algorithms:
86 alg.params = {"apply_iov": output_iov}
87
88 return [badwire_calib]
89
90
91def pre_collector(max_events=None, components=["CDC", "ECL", "KLM"]):
92 from rawdata import add_unpackers
93 # Create an execution path
94 path = basf2.create_path()
95 branches = ['EventMetaData', 'RawCDCs', 'RawFTSWs']
96 unpackers = ['CDC']
97 path.add_module("RootInput", branchNames=branches)
98 path.add_module("Gearbox")
99 path.add_module("Geometry", useDB=True)
100 path.add_module("SetupGenfitExtrapolation",
101 energyLossBrems=False, noiseBrems=False)
102 add_unpackers(path, components=unpackers)
103
104 # Print some progress messages
105 path.add_module("Progress")
106
107 from reconstruction import default_event_abort, add_prefilter_pretracking_reconstruction
108 from tracking import add_prefilter_tracking_reconstruction
109
110 # Do not even attempt at reconstructing events w/ abnormally large occupancy.
111 doom = path.add_module("EventsOfDoomBuster")
112 default_event_abort(doom, ">=1", Belle2.EventMetaData.c_ReconstructionAbort)
113 path.add_module('StatisticsSummary').set_name('Sum_EventsofDoomBuster')
114
115 Components = ["CDC"]
116 # Add modules that have to be run BEFORE track reconstruction
117 add_prefilter_pretracking_reconstruction(path, components=Components)
118
119 # Add tracking reconstruction modules
120 add_prefilter_tracking_reconstruction(path=path,
121 components=Components,
122 trackFitHypotheses=[211],
123 prune_temporary_tracks=False,
124 fit_tracks=True,
125 append_full_grid_cdc_eventt0=True,
126 skip_full_grid_cdc_eventt0_if_svd_time_present=False)
127 path.add_module('StatisticsSummary').set_name('Sum_Tracking')
128
129 # Making sure CDC Raw Hits are stored
130 for module in path.modules():
131 if module.name() == 'CDCUnpacker':
132 print('Enabling Raw CDC hits')
133 module.param({'enableStoreCDCRawHit': True})
134 if module.name() == 'TFCDC_WireHitPreparer':
135 print('Enabling bad wires')
136 module.param({'useBadWires': True})
137
138 # Print a textual representation of what was just put together
139 basf2.print_path(path)
140 return path
Class for Wire Efficiency estimation.