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