5 Simultaneous Global and Local VXD and CDC (layers-only) alignment with Millepede II
7 The input collections can be (only single tracks currently):
8 - cosmics (hlt skim) - mandatorry
9 - physics - all raw data -> once off-ip is available, this can be omitted
10 - hadron - for "low" momentum tracks from IP
11 - mumu - mumu_2trk or mumu_tight - for high momentum tracks from IP
12 - offip - not yet available - tracks from outside IP (beam background, beam-gas)
14 Time-dependence can be (manually) configured for VXD half-shells and CDC layers.
15 For example to allow VXD alignment to change in run 10, 20 an 30 in experiment 12, you set:
17 >>> timedep_vxd : [[0, 10, 12], [0, 20, 12], [0, 30, 12]]
19 Note that the first run in your requested iov will be added automatically.
23 from prompt
import CalibrationSettings
24 from prompt.calibrations.caf_cdc
import settings
as cdc_calibration
26 collection_names = [
"physics",
"cosmic",
"hadron",
"mumu",
"offip"]
30 'min_entries': 1000000,
32 'method':
'diagonalization 3 0.1',
38 "physics.min_events": 400000,
39 "physics.max_processed_events_per_file": 2000,
41 "cosmic.min_events": 1000000,
42 "cosmic.max_processed_events_per_file": 5000,
44 "hadron.min_events": 100000,
45 "hadron.max_processed_events_per_file": 1000,
47 "mumu.min_events": 400000,
48 "mumu.max_processed_events_per_file": 3000,
50 "offip.min_events": 400000,
51 "offip.max_processed_events_per_file": 2000,
58 settings = CalibrationSettings(name=
"VXD and CDC Alignment",
59 expert_username=
"bilkat",
61 input_data_formats=[
"raw"],
62 input_data_names=collection_names,
63 expert_config=default_config,
64 depends_on=[cdc_calibration])
67 def select_files(all_input_files, min_events, max_processed_events_per_file):
69 from random
import choice
74 while total_events < min_events:
77 if not all_input_files:
80 new_file_choice = choice(all_input_files)
82 all_input_files.remove(new_file_choice)
84 total_events_in_file = events_in_basf2_file(new_file_choice)
85 if not total_events_in_file:
89 events_contributed = min(total_events_in_file, max_processed_events_per_file)
91 chosen_files.append(new_file_choice)
92 total_events += events_contributed
94 basf2.B2INFO(f
"Total chosen files = {len(chosen_files)}")
95 basf2.B2INFO(f
"Total events in chosen files = {total_events}")
96 if total_events < min_events:
98 f
"There weren't enough files events selected when max_processed_events_per_file={max_processed_events_per_file}")
102 def create_std_path():
104 import rawdata
as raw
105 import reconstruction
as reco
107 path = basf2.create_path()
108 path.add_module(
'Progress')
109 path.add_module(
'RootInput')
110 path.add_module(
'Gearbox')
111 path.add_module(
'Geometry')
112 raw.add_unpackers(path)
113 path.add_module(
'SetupGenfitExtrapolation')
114 reco.add_reconstruction(
117 skipGeometryAdding=
True,
119 path.add_module(
'DAFRecoFitter')
123 def create_cosmics_path():
125 import rawdata
as raw
126 import reconstruction
as reco
127 import modularAnalysis
as ana
129 path = basf2.create_path()
130 path.add_module(
'Progress')
132 path.add_module(
'RootInput')
133 path.add_module(
'Gearbox')
134 path.add_module(
'Geometry')
137 triggerLines=[
"software_trigger_cut&filter&cosmic"]).if_value(
140 basf2.AfterConditionPath.END)
142 raw.add_unpackers(path)
143 path.add_module(
'SetupGenfitExtrapolation')
144 reco.add_cosmics_reconstruction(
147 skipGeometryAdding=
True,
148 addClusterExpertModules=
False,
149 data_taking_period=
'early_phase3',
153 path.add_module(
'SetRecoTrackMomentum', automatic=
True)
154 path.add_module(
'DAFRecoFitter', pdgCodesToUseForFitting=[13])
156 ana.fillParticleList(
157 'mu+:goodForVXDCDCAlignment',
158 '[z0 <= 57. or abs(d0) >= 26.5] and abs(dz) > 0.4 and nTracks == 1',
160 path.add_module(
'SkimFilter', particleLists=[
'mu+:goodForVXDCDCAlignment']).if_false(basf2.create_path())
169 def get_calibrations(input_data, **kwargs):
173 from caf.utils
import IoV
175 import millepede_calibration
as mpc
180 from random
import seed
183 cfg = kwargs[
'expert_config']
186 for colname
in collection_names:
187 file_to_iov = input_data[colname]
188 input_files = list(file_to_iov.keys())
190 if not len(input_files):
194 basf2.B2INFO(f
"Selecting files for: {colname}")
195 input_files = select_files(input_files[:], cfg[f
'{colname}.min_events'], cfg[f
'{colname}.max_processed_events_per_file'])
196 files[colname] = input_files
199 requested_iov = kwargs.get(
"requested_iov",
None)
201 output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
204 method = cfg[
'method']
205 scaleerrors = cfg[
'scaleerrors']
206 entries = cfg[
'entries']
210 timedep_vxd = cfg[
'timedep_vxd']
211 timedep_cdc = cfg[
'timedep_cdc']
214 slices = [(erx[0], erx[1], erx[2])
for erx
in timedep_vxd] + [(0, requested_iov.run_low, requested_iov.exp_low)]
218 slices = [(erx[0], erx[1], erx[2])
for erx
in timedep_cdc] + [(0, requested_iov.run_low, requested_iov.exp_low)]
222 name=
'VXDCDCalignment',
223 dbobjects=[
'VXDAlignment',
'CDCAlignment'],
225 mpc.make_collection(
"cosmic", path=create_cosmics_path(), tracks=[
"RecoTracks"]),
226 mpc.make_collection(
"physics", path=create_std_path(), tracks=[
"RecoTracks"]),
227 mpc.make_collection(
"hadron", path=create_std_path(), tracks=[
"RecoTracks"]),
228 mpc.make_collection(
"mumu", path=create_std_path(), tracks=[
"RecoTracks"]),
229 mpc.make_collection(
"offip", path=create_std_path(), tracks=[
"RecoTracks"])
241 f
"scaleerrors {scaleerrors} {scaleerrors}",
242 f
"entries {entries}"],
243 params=dict(minPValue=cfg[
'minPValue'], externalIterations=0),
244 min_entries=cfg[
'min_entries'])
246 for colname
in collection_names:
247 max_processed_events_per_file = cfg[f
'{colname}.max_processed_events_per_file']
248 basf2.set_module_parameters(
249 cal.collections[colname].pre_collector_path,
251 entrySequences=[f
'0:{max_processed_events_per_file}'])
255 fix_mille_paths_for_algo(cal.algorithms[0])
258 cal.max_iterations = cfg[
'max_iterations']
262 for algorithm
in cal.algorithms:
263 algorithm.params = {
"apply_iov": output_iov}