Belle II Software  release-08-01-10
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 sys
24 import ROOT
25 import basf2 as b2
26 from ROOT import Belle2
27 from glob import glob
28 
29 from basf2 import conditions as b2conditions
30 
32 
33 # Setting just with steering file
34 
35 # For whether to execute the algorithm over each run invidually or to combine them together in a single plot
36 # often it is easier just to only pass a single file to the algorithm code instead of to use this feature
37 combineRuns = True
38 
39 
40 # Set up and execute calibration
41 algo = Belle2.ECL.eclTValidationAlgorithm("eclBhabhaTimeCalibrationValidationCollector")
42 
43 
44 print("Python arguments:")
45 counting = 0
46 for arg in sys.argv:
47  print(counting, arg)
48  counting = counting + 1
49 
50 fileNames = ['eclBhabhaTimeCalibrationValidationCollector.root']
51 narg = len(sys.argv)
52 if(narg >= 2):
53  fileNames = glob(sys.argv[1])
54 algo.setInputFileNames(fileNames)
55 
56 basePath = ""
57 if(narg >= 3):
58  basePath = sys.argv[2] + "/"
59  print("basePath = ", basePath)
60 
61 
62 # algo.cellIDLo = 3
63 # algo.cellIDHi = 2
64 algo.meanCleanRebinFactor = 3 # Rebin factor
65 # 0 means no cut. # 1 means keep only bins from max rebinned bin.
66 algo.meanCleanCutMinFactor = 0.4
67 
68 b2.set_debug_level(35)
69 b2.set_log_level(b2.LogLevel.INFO) # b2.LogLevel.INFO or b2.LogLevel.DEBUG
70 
71 
72 exprun_vector = algo.getRunListFromAllData()
73 
74 baseName = "eclBhabhaTValidationAlgorithm"
75 basePathAndName = basePath + baseName
76 algo.debugFilenameBase = basePathAndName
77 
78 
79 # == Configure database
80 b2conditions.reset()
81 b2conditions.override_globaltags()
82 
83 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
84 b2conditions.prepend_testing_payloads("localdb/database.txt")
85 b2.B2INFO("Using Global Tag {}")
86 b2conditions.prepend_globaltag("dp_recon_release6_patch")
87 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
88 b2conditions.prepend_globaltag("AIRFLOW_online_snapshot_20210719-124441")
89 b2conditions.prepend_globaltag("data_reprocessing_prompt")
90 
91 
92 if (combineRuns):
93  print("Combining all runs' histograms for a single calibration")
94  print("path = ", basePathAndName)
95  alg_result = algo.execute()
96  print("Calibration completion status", alg_result)
97  if (alg_result == 0):
98  algo.commit()
99 else:
100  print("Calibrating each run individually")
101  runsWithoutEnoughData = []
102  for exprun in exprun_vector:
103  iov_to_execute = ROOT.vector("std::pair<int,int>")()
104  iov_to_execute.push_back(exprun)
105  print("path = ", basePathAndName)
106  alg_result = algo.execute(iov_to_execute, 0)
107  print("Calibration success-result was", alg_result, " (0=ok, 2=needs more data)")
108  if (alg_result == 0):
109  algo.commit()
110 
111 
112 print("Summary of possible calibration completion status values:")
113 print(" c_OK = Finished successfuly = 0 in Python")
114 print(" c_Iterate, = Needs iteration = 1 in Python")
115 print(" c_NotEnoughData, = Needs more data = 2 in Python")
116 print(" c_Failure, = Failed = 3 in Python")
117 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:28