Belle II Software  release-05-01-25
caf_cdcwireeff.py
1 # -*- coding: utf-8 -*-
2 
3 """CDC Wire Efficiency and BadWire creator. Creates layer-by-layer and wire-by-wire efficiencies and returns bad wire list"""
4 
5 from prompt import CalibrationSettings
6 from caf.framework import Calibration
7 
8 
9 
10 settings = CalibrationSettings(name="CDC bad wires",
11  expert_username="uchida",
12  description=__doc__,
13  input_data_formats=["raw"],
14  input_data_names=["hlt_mumu"],
15  depends_on=[])
16 
17 
18 import basf2
19 
20 
23 
24 
25 def get_calibrations(input_data, **kwargs):
26  import basf2
27  from prompt.utils import filter_by_max_files_per_run
28  # Gets the input files and IoV objects associated with the files.
29  file_to_iov_mumu = input_data["hlt_mumu"]
30 
31  max_files_per_run = 10
32  min_events_per_file = 1000
33 
34  max_events_per_calibration = 10000000
35  max_events_per_file = 10000
36 
37  reduced_file_to_iov_mumu = filter_by_max_files_per_run(file_to_iov_mumu, max_files_per_run, min_events_per_file)
38  input_files_mumu = list(reduced_file_to_iov_mumu.keys())
39  basf2.B2INFO(f"Total number of hlt_mumu files actually used as input = {len(input_files_mumu)}")
40 
41  input_file_dict = {"hlt_mumu": reduced_file_to_iov_mumu}
42 
43  # Get the overall IoV we want to cover, including the end values
44  requested_iov = kwargs.get("requested_iov", None)
45 
46  from caf.utils import IoV
47  # The actuall IoV we want for any prompt request is open-ended
48  output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
49 
50  # wire efficiency
51  cal = CDCCalibration(name='wire_eff',
52  algorithms=[wire_algo()],
53  input_file_dict=input_file_dict,
54  max_iterations=1
55  )
56 
57  # Force the output payload IoV to be correct.
58  # It may be different if you are using another strategy like SequentialRunByRun
59  for algorithm in cal.algorithms:
60  algorithm.params = {"apply_iov": output_iov}
61 
62  return [cal]
63 
64 
65 
66 
67 def pre_collector(max_events=None):
68  """
69  Define pre collection (reconstruction).
70  Needs to perform reconstruction with all wire (including bad) enabled.
71  Parameters:
72  max_events [int] : number of events to be processed.
73  All events by Default.
74  Returns:
75  path : path for pre collection
76  """
77  from basf2 import create_path, register_module
78  reco_path = create_path()
79  if max_events is None:
80  root_input = register_module('RootInput')
81  else:
82  root_input = register_module('RootInput',
83  entrySequences=['0:{}'.format(max_events)]
84  )
85  reco_path.add_module(root_input)
86 
87  gearbox = register_module('Gearbox')
88  reco_path.add_module(gearbox)
89  reco_path.add_module('Geometry', useDB=True)
90 
91  from rawdata import add_unpackers
92  # unpack raw data
93  add_unpackers(reco_path)
94 
95  from reconstruction import add_reconstruction
96  add_reconstruction(reco_path,
97  add_trigger_calculation=False,
98  trackFitHypotheses=[13], # muon hypothesis but should give the same result with pion
99  pruneTracks=False)
100 
101  for module in reco_path.modules():
102  if module.name() == "TFCDC_WireHitPreparer":
103  print("Enabling bad wires during reconstruction.")
104  module.param({"useBadWires": True})
105 
106  return reco_path
107 
108 
109 def collector(bField=True, is_cosmic=False):
110  """
111  Create a cdc calibration collector
112  Parameters:
113  bField [bool] : True if B field is on, else False
114  isCosmic [bool] : True if cosmic events,
115  else (collision) False.
116  Returns:
117  collector : collector module
118  """
119  from basf2 import register_module
120  col = register_module('CDCCalibrationCollector',
121  granularity='all',
122  calExpectedDriftTime=True,
123  eventT0Extraction=True,
124  bField=bField,
125  isCosmic=is_cosmic,
126  effStudy=True
127  )
128  return col
129 
130 
131 def wire_algo():
132  """
133  Create wire efficiency plots.
134  Returns:
135  algo : Wire efficiency algorithm
136  """
137  from ROOT import Belle2
139  return algo
140 
141 
142 from caf.framework import Calibration
143 
144 
146  '''
147  CDCCalibration is a specialized calibration class for cdc.
148  Since collector is same in all elements, no need to specify it.
149  '''
150 
151  def __init__(self,
152  name,
153  algorithms,
154  input_file_dict,
155  max_iterations=1,
156  dependencies=None,
157  max_events=10000000):
158  for algo in algorithms:
159  algo.setHistFileName(name)
160 
161  super().__init__(name=name,
162  algorithms=algorithms
163  )
164 
165  from caf.framework import Collection
166 
167  for skim_type, file_list in input_file_dict.items():
168  collection = Collection(collector=collector(),
169  input_files=file_list,
170  pre_collector_path=pre_collector(max_events=max_events),
171  )
172  self.add_collection(name=skim_type, collection=collection)
173 
174  self.max_iterations = max_iterations
175 
176  if dependencies is not None:
177  for dep in dependencies:
178  self.depends_on(dep)
prompt.utils
Definition: utils.py:1
caf_cdcwireeff.CDCCalibration
Definition: caf_cdcwireeff.py:145
collector
Definition: collector.py:1
Belle2::CDC::WireEfficiencyAlgorithm
Class for Wire Efficiency estimation.
Definition: WireEfficiencyAlgorithm.h:39
Collection
Definition: Collection.py:1
Calibration
Definition: Calibration.py:1
caf_cdcwireeff.CDCCalibration.max_iterations
max_iterations
Definition: caf_cdcwireeff.py:168