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