Belle II Software development
caf_cdc_fudgefactor.py
1
8
9"""CDC fudge factor calibration."""
10from prompt import CalibrationSettings, INPUT_DATA_FILTERS
11from prompt.calibrations.caf_cdc import settings as cdc_tracking_calibration
12from prompt.calibrations.vxdcdc_alignment import settings as alignment
13from prompt.utils import ExpRun
14import basf2
15from ROOT import Belle2
16from caf.framework import Calibration
17from caf import strategies
18from modularAnalysis import fillParticleList, cutAndCopyList, reconstructDecay, applyCuts
19from vertex import treeFit
20
21
22settings = CalibrationSettings(name="CDC Sigma fudge factor",
23 expert_username="dvthanh",
24 description=__doc__,
25 input_data_formats=["raw"],
26 input_data_names=["mumu_tight_or_highm_calib"],
27 input_data_filters={"mumu_tight_or_highm_calib":
28 [INPUT_DATA_FILTERS["Data Tag"]["mumu_tight_or_highm_calib"],
29 INPUT_DATA_FILTERS["Data Quality Tag"]["Good"],
30 INPUT_DATA_FILTERS["Magnet"]["On"]]},
31 depends_on=[cdc_tracking_calibration, alignment],
32 expert_config={
33 "fileFormat": "RAW",
34 "min_events_per_file": 500,
35 "max_events_per_file": 30000,
36 "components": ["CDC", "ECL", "KLM"],
37 "vertex_fit": 0,
38 "payload_boundaries": [],
39 "backend_args": {"request_memory": "4 GB"}
40 })
41
42
43
46
47def get_calibrations(input_data, **kwargs):
48 # Set up config options
49 # read expert_config values
50 expert_config = kwargs.get("expert_config")
51 min_events_per_file = expert_config["min_events_per_file"]
52 max_events_per_file = expert_config["max_events_per_file"]
53# file_format = expert_config["file_format"]
54 components = expert_config["components"]
55 vertex_fit = expert_config["vertex_fit"]
56 fileFormat = expert_config["fileFormat"]
57 # In this script we want to use one sources of input data.
58 # Get the input files from the input_data variable
59 file_to_iov_mumu = input_data["mumu_tight_or_highm_calib"]
60
61 from prompt.utils import filter_by_max_files_per_run
62 reduced_file_to_iov_mumu = filter_by_max_files_per_run(file_to_iov_mumu, 100, min_events_per_file)
63 input_files_mumu = list(reduced_file_to_iov_mumu.keys())
64 basf2.B2INFO("Complete input data selection.")
65 basf2.B2INFO(f"Total number of files actually used as input = {len(input_files_mumu)}")
66
67 payload_boundaries = []
68 payload_boundaries.extend([ExpRun(*boundary) for boundary in expert_config["payload_boundaries"]])
69 basf2.B2INFO(f"Payload boundaries from expert_config: {payload_boundaries}")
70
71 from caf.utils import IoV
72 # The actual value our output IoV payload should have. Notice that we've set it open ended.
73 requested_iov = kwargs.get("requested_iov", None)
74 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
75
76 # for SingleIOV stratrgy, it's better to set the granularity to 'all' so that the collector jobs will run faster
77 collector_granularity = 'all'
78 if payload_boundaries:
79 basf2.B2INFO('Found payload_boundaries: set collector granularity to run')
80 collector_granularity = 'run'
81
82
84 col = basf2.register_module("CDCFudgeFactorCalibrationCollector",
85 granularity=collector_granularity)
86 # call algorighm
88 algo.setHistFileName("histo_fudge_factor.root")
89
91 fudge_calib = Calibration("CDC_FudgeFactor",
92 collector=col,
93 algorithms=algo,
94 input_files=input_files_mumu,
95 pre_collector_path=pre_collector(max_events_per_file,
96 components=components,
97 fileFormat=fileFormat,
98 vertex_fit=vertex_fit))
99# backend_args=expert_config["backend_args"])
100 # collector_granularity=collector_granularity)
101 # Do this for the default AlgorithmStrategy to force the output payload IoV
102 # It may be different if you are using another strategy like SequentialRunByRun
103 if payload_boundaries:
104 basf2.B2INFO("Found payload_boundaries: calibration strategies set to SequentialBoundaries.")
105 fudge_calib.strategies = strategies.SequentialBoundaries
106 for alg in fudge_calib.algorithms:
107 alg.params = {"iov_coverage": output_iov, "payload_boundaries": payload_boundaries}
108 else:
109 for alg in fudge_calib.algorithms:
110 alg.params = {"apply_iov": output_iov}
111
112 return [fudge_calib]
113
114
115
116def pre_collector(max_events=None, components=["CDC", "ECL", "KLM"], fileFormat="RAW", vertex_fit=0):
117 """
118 Define pre collection (reconstruction in our purpose).
119 Probably, we need only CDC and ECL data.
120 Parameters:
121 max_events [int] : number of events to be processed.
122 All events by Default.
123 Returns:
124 path : path for pre collection
125 """
126 from basf2 import create_path, register_module
127 from softwaretrigger.constants import HLT_INPUT_OBJECTS
128 reco_path = create_path()
129 if fileFormat == "RAW":
130 if max_events is None:
131 root_input = register_module('RootInput', branchNames=HLT_INPUT_OBJECTS)
132 else:
133 root_input = register_module('RootInput', branchNames=HLT_INPUT_OBJECTS,
134 entrySequences='0:{}'.format(max_events))
135 reco_path.add_module(root_input)
136 # unpack
137 from rawdata import add_unpackers
138 from reconstruction import add_reconstruction
139 add_unpackers(reco_path, components=components)
140 # reconstruction
141 add_reconstruction(reco_path,
142 components=components,
143 append_full_grid_cdc_eventt0=True,
144 skip_full_grid_cdc_eventt0_if_svd_time_present=False)
145 if fileFormat == "mdst":
146 from modularAnalysis import inputMdst
147 inputMdst(filename="", path=reco_path, environmentType='default', skipNEvents=0, entrySequence=['0:{}'.format(max_events)])
148
149 reco_path.add_module('Progress')
150 fillParticleList('gamma:HLT', 'E>0.1', path=reco_path)
151 goodTrack = 'abs(d0) < 2.0 and abs(z0) < 4.0 and pt > 2.0 and useCMSFrame(p) > 0.5'
152 fillParticleList('mu+:HLT', goodTrack, path=reco_path)
153 cutAndCopyList('mu+:sel', 'mu+:HLT', goodTrack, path=reco_path)
154 reconstructDecay('vpho:mumu -> mu+:sel mu-:sel', '', path=reco_path) # apply event cuts
155 applyCuts('vpho:mumu', '[nCleanedTracks('+goodTrack+') == 2]', path=reco_path)
156 if vertex_fit == 1:
157 treeFit('vpho:mumu', ipConstraint=False, updateAllDaughters=False, path=reco_path)
158
159 return reco_path