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