9"""ECL timing calibration that performs the crystal calibrations, one for  the whole set of runs.""" 
   11from prompt import CalibrationSettings 
   12from reconstruction import prepare_cdst_analysis 
   13from caf.utils import IoV 
   16############################## 
   18############################## 
   19# Used to identify the keys in input_data that your get_calibrations function will need in order 
   20# to assign data correctly. 
   21# Will be used to construct the calibration in the automated system, as well as set up the submission web forms. 
   22# You can view the available input data formats from CalibrationSettings.allowed_data_formats 
   24## Tells the automated system some details of this script. 
   25#     Default is to read 
in "bhabha_all_calib" since we want to
 
   27settings = CalibrationSettings(
 
   28    name=
"ECL crystal time calibrations",
 
   29    expert_username=
"ehill",
 
   31    input_data_formats=[
"cdst"],
 
   32    input_data_names=[
"bhabha_all_calib"],
 
   57def get_calibrations(input_data, **kwargs):
 
   60      input_data (dict): Should contain every name from the 
'input_data_names' variable 
as a key.
 
   61        Each value 
is a dictionary 
with {
"/path/to/file_e1_r5.root": IoV(1,5,1,5), ...}. Useful 
for 
   62        assigning to calibration.files_to_iov
 
   64      **kwargs: Configuration options to be sent 
in. Since this may change we use kwargs 
as a way to help prevent
 
   65        backwards compatibility problems. But you could use the correct arguments 
in b2caf-prompt-run 
for this
 
   66        release explicitly 
if you want to.
 
   68        Currently only kwargs[
"output_iov"] 
is used. This 
is the output IoV range that your payloads should
 
   69        correspond to. Generally your highest ExpRun payload should be open ended e.g. IoV(3,4,-1,-1)
 
   72      list(caf.framework.Calibration): All of the calibration objects we want to assign to the CAF process
 
   80    file_to_iov_physics = input_data[
"bhabha_all_calib"]
 
   86    max_files_per_run = 2600
 
   93    reduced_file_to_iov_physics = filter_by_max_files_per_run(file_to_iov_physics, max_files_per_run)
 
   94    input_files_physics = list(reduced_file_to_iov_physics.keys())
 
   95    basf2.B2INFO(f
"Total number of files actually used as input = {len(input_files_physics)}")
 
   98    from basf2 
import register_module, create_path
 
   99    from ROOT 
import Belle2
 
  100    from caf.framework 
import Collection
 
  104    root_input = register_module(
'RootInput')
 
  105    rec_path_bhabha = create_path()
 
  106    rec_path_bhabha.add_module(root_input)
 
  107    if 'Gearbox' not in rec_path_bhabha:
 
  108        rec_path_bhabha.add_module(
'Gearbox')
 
  109    if 'Geometry' not in rec_path_bhabha:
 
  110        rec_path_bhabha.add_module(
'Geometry', useDB=
True)
 
  112    prepare_cdst_analysis(rec_path_bhabha)    
 
  115    t0BiasCorrection = -0.9  
 
  118    col_bhabha = register_module(
'ECLBhabhaTCollector')
 
  119    col_bhabha.param(
'timeAbsMax', 250)
 
  120    col_bhabha.param(
'minCrystal', 1)
 
  121    col_bhabha.param(
'maxCrystal', 8736)
 
  122    col_bhabha.param(
'saveTree', 
False)
 
  123    col_bhabha.param(
'hadronEventT0_TO_bhabhaEventT0_correction', t0BiasCorrection)
 
  126                         input_files=input_files_physics,
 
  127                         pre_collector_path=rec_path_bhabha)
 
  137    eclTAlgCrystals.crateIDLo = 3
 
  138    eclTAlgCrystals.crateIDHi = 2
 
  139    eclTAlgCrystals.debugOutput = 
True 
  140    eclTAlgCrystals.meanCleanRebinFactor = 3
 
  141    eclTAlgCrystals.meanCleanCutMinFactor = 0.3
 
  142    eclTAlgCrystals.debugFilenameBase = 
"eclBhabhaTAlgorithm" 
  147    from caf.framework 
import Calibration
 
  149    cal_crystals = 
Calibration(
"ECLcrystalTimeCalibration_physics")
 
  150    cal_crystals.add_collection(name=
"bhabha", collection=eclTCol)
 
  151    cal_crystals.algorithms = [eclTAlgCrystals]
 
  154    from caf.strategies 
import SingleIOV
 
  160    cal_crystals.strategies = SingleIOV
 
  171    cal_ecl_merge = 
Calibration(name=
"ecl_t_merge", collector=
"DummyCollector", algorithms=[merging_alg],
 
  172                                input_files=input_files_physics[:1])
 
  175    cal_ecl_merge.depends_on(cal_crystals)
 
  178    ecl_merge_pre_path = basf2.create_path()
 
  179    prepare_cdst_analysis(ecl_merge_pre_path, components=[
'ECL'])
 
  180    ecl_merge_pre_path.pre_collector_path = ecl_merge_pre_path
 
  184    intermediate_iov = IoV(0, 0, -1, -1)
 
  185    requested_iov = kwargs.get(
"requested_iov", 
None)
 
  186    output_iov = IoV(requested_iov.exp_low, requested_iov.run_low, -1, -1)
 
  187    for algorithm 
in cal_crystals.algorithms:
 
  188        algorithm.params = {
"apply_iov": intermediate_iov}
 
  189    for algorithm 
in cal_ecl_merge.algorithms:
 
  190        algorithm.params = {
"apply_iov": output_iov}
 
  194    return [cal_crystals, cal_ecl_merge]
 
Calibrate ecl crystals using bhabha events.
Calibrate ecl crystals using previously created payloads.