Belle II Software  release-06-02-00
run_eclBhabhaTimeCalibrationValidation_algorithm.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
18 
19 # Usage: basf2 run_eclBhabhaTimeCalibrationValidation_algorithm.py [input_file]
20 # Glob expression can be passed as an input file.
21 # Example: basf2 run_eclBhabhaTimeCalibrationValidation_algorithm.py "exp_0003_run_*.root"
22 
23 import os
24 import sys
25 import ROOT
26 import basf2 as b2
27 from ROOT import Belle2
28 from glob import glob
29 import array as arr
30 
31 from basf2 import conditions as b2conditions
32 
34 
35 # Setting just with steering file
36 
37 # For whether to execute the algorithm over each run invidually or to combine them together in a single plot
38 # often it is easier just to only pass a single file to the algorithm code instead of to use this feature
39 combineRuns = True
40 
41 
42 # Set up and execute calibration
43 algo = Belle2.ECL.eclTValidationAlgorithm("eclBhabhaTimeCalibrationValidationCollector")
44 
45 
46 print("Python arguments:")
47 counting = 0
48 for arg in sys.argv:
49  print(counting, arg)
50  counting = counting + 1
51 
52 fileNames = ['eclBhabhaTimeCalibrationValidationCollector.root']
53 narg = len(sys.argv)
54 if(narg >= 2):
55  fileNames = glob(sys.argv[1])
56 algo.setInputFileNames(fileNames)
57 
58 basePath = ""
59 if(narg >= 3):
60  basePath = sys.argv[2] + "/"
61  print("basePath = ", basePath)
62 
63 
64 # algo.cellIDLo = 3
65 # algo.cellIDHi = 2
66 algo.meanCleanRebinFactor = 3 # Rebin factor
67 # 0 means no cut. # 1 means keep only bins from max rebinned bin.
68 algo.meanCleanCutMinFactor = 0.4
69 
70 b2.set_debug_level(35)
71 b2.set_log_level(b2.LogLevel.INFO) # b2.LogLevel.INFO or b2.LogLevel.DEBUG
72 
73 
74 exprun_vector = algo.getRunListFromAllData()
75 
76 baseName = "eclBhabhaTValidationAlgorithm"
77 basePathAndName = basePath + baseName
78 algo.debugFilenameBase = basePathAndName
79 
80 
81 # == Configure database
82 b2conditions.reset()
83 b2conditions.override_globaltags()
84 
85 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
86 b2conditions.prepend_testing_payloads("localdb/database.txt")
87 b2.B2INFO("Using Global Tag {}")
88 b2conditions.prepend_globaltag("dp_recon_release6_patch")
89 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
90 b2conditions.prepend_globaltag("AIRFLOW_online_snapshot_20210719-124441")
91 b2conditions.prepend_globaltag("data_reprocessing_prompt")
92 
93 
94 if (combineRuns):
95  print("Combining all runs' histograms for a single calibration")
96  print("path = ", basePathAndName)
97  alg_result = algo.execute()
98  print("Calibration completion status", alg_result)
99  if (alg_result == 0):
100  algo.commit()
101 else:
102  print("Calibrating each run individually")
103  runsWithoutEnoughData = []
104  for exprun in exprun_vector:
105  iov_to_execute = ROOT.vector("std::pair<int,int>")()
106  iov_to_execute.push_back(exprun)
107  print("path = ", basePathAndName)
108  alg_result = algo.execute(iov_to_execute, 0)
109  print("Calibration success-result was", alg_result, " (0=ok, 2=needs more data)")
110  if (alg_result == 0):
111  algo.commit()
112 
113 
114 print("Summary of possible calibration completion status values:")
115 print(" c_OK = Finished successfuly = 0 in Python")
116 print(" c_Iterate, = Needs iteration = 1 in Python")
117 print(" c_NotEnoughData, = Needs more data = 2 in Python")
118 print(" c_Failure, = Failed = 3 in Python")
119 print(" c_Undefined = Not yet known (before execution) = 4 in Python")
Validate the ecl timing calibrations using a hadronic event selection.
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:29