Belle II Software  release-08-01-10
run_eclBhabhaT_algorithm.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 
28 
29 
30 import sys
31 import ROOT
32 import basf2 as b2
33 from ROOT import Belle2
34 from glob import glob
35 
36 from basf2 import conditions as b2conditions
37 
39 
40 # Setting just with steering file
41 
42 # For whether to execute the algorithm over each run invidually or to combine them together in a single plot
43 # often it is easier just to only pass a single file to the algorithm code instead of to use this feature
44 combineRuns = True
45 
46 
47 # Set up and execute calibration
49 
50 
51 print("Python arguments:")
52 counting = 0
53 for arg in sys.argv:
54  print(counting, arg)
55  counting = counting + 1
56 
57 fileNames = ['eclBhabhaTCollector.root']
58 narg = len(sys.argv)
59 if(narg >= 2):
60  fileNames = glob(sys.argv[1])
61 algo.setInputFileNames(fileNames)
62 
63 basePath = ""
64 if(narg >= 3):
65  basePath = sys.argv[2] + "/"
66  print("basePath = ", basePath)
67 
68 
69 algo.cellIDLo = 3
70 algo.cellIDHi = 2
71 algo.debugOutput = True
72 algo.meanCleanRebinFactor = 3 # Rebin factor
73 # 0 means no cut. # 1 means keep only bins from max rebinned bin. # Note that with low stats, 0.2 is still too large.
74 algo.meanCleanCutMinFactor = 0.3
75 # algo.crateIDLo = 10
76 # algo.crateIDHi = 9
77 algo.debugFilenameBase = "eclBhabhaTAlgorithm"
78 
79 # Don't need to use this unless I want to change the reference crystals
80 # algo.refCrysPerCrate = arr.array('i', [-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
81 # -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
82 # -1,-1,-1]) # 'i' is a signed integer
83 
84 # Below is equivalent to the first payload version
85 # algo.refCrysPerCrate = arr.array('i', [2306, 2309, 2313, 2317, 2321,
86 # 2326, 2329, 2334, 2337, 2343, 2348, 2349, 2356, 2357, 2361, 2365, 2372,
87 # 2373, 2377, 2381, 2388, 2391, 2393, 2399, 2401, 2407, 2409, 2413, 2417,
88 # 2421, 2426, 2429, 2433, 2440, 2585, 2446, 671, 583, 595, 607, 619, 631,
89 # 643, 655, 8252, 8177, 8185, 8192, 8206, 8224, 8228, 8244])
90 # 'i' is a signed integer
91 
92 b2.set_debug_level(35)
93 b2.set_log_level(b2.LogLevel.INFO) # b2.LogLevel.INFO or b2.LogLevel.DEBUG
94 
95 
96 exprun_vector = algo.getRunListFromAllData()
97 
98 baseName = "eclBhabhaTAlgorithm"
99 basePathAndName = basePath + baseName
100 algo.debugFilenameBase = basePathAndName
101 
102 
103 # == Configure database
104 b2conditions.reset()
105 b2conditions.override_globaltags()
106 
107 b2.B2INFO("Adding Local Database {} to head of chain of local databases.")
108 b2conditions.prepend_testing_payloads("localdb/database.txt")
109 b2.B2INFO("Using Global Tag {}")
110 b2conditions.prepend_globaltag("dp_recon_release6_patch")
111 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
112 b2conditions.prepend_globaltag("AIRFLOW_online_snapshot_20210719-124441")
113 b2conditions.prepend_globaltag("data_reprocessing_prompt")
114 
115 
116 if (combineRuns):
117  print("Combining all runs' histograms for a single calibration")
118  print("path = ", basePathAndName)
119  alg_result = algo.execute()
120  print("Calibration completion status", alg_result)
121  if (alg_result == 0):
122  algo.commit()
123 else:
124  print("Calibrating each run individually")
125  runsWithoutEnoughData = []
126  for exprun in exprun_vector:
127  iov_to_execute = ROOT.vector("std::pair<int,int>")()
128  iov_to_execute.push_back(exprun)
129  print("path = ", basePathAndName)
130  alg_result = algo.execute(iov_to_execute, 0)
131  print("Calibration success-result was", alg_result, " (0=ok, 2=needs more data)")
132  if (alg_result == 0):
133  algo.commit()
134 
135 
136 print("Summary of possible calibration completion status values:")
137 print(" c_OK = Finished successfuly = 0 in Python")
138 print(" c_Iterate, = Needs iteration = 1 in Python")
139 print(" c_NotEnoughData, = Needs more data = 2 in Python")
140 print(" c_Failure, = Failed = 3 in Python")
141 print(" c_Undefined = Not yet known (before execution) = 4 in Python")
Calibrate ecl crystals using bhabha events.
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28