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