Belle II Software  release-05-02-19
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 from basf2 import *
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 set_debug_level(35)
95 set_log_level(LogLevel.INFO) # LogLevel.INFO or 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 B2INFO("Adding Local Database {} to head of chain of local databases.")
110 b2conditions.prepend_testing_payloads("localdb/database.txt")
111 B2INFO("Using Global Tag {}")
112 b2conditions.prepend_globaltag("ECL_testingNewPayload_RefCrystalPerCrate")
113 b2conditions.prepend_globaltag("master_2020-05-13")
114 b2conditions.prepend_globaltag("online_proc11")
115 b2conditions.prepend_globaltag("data_reprocessing_proc11")
116 b2conditions.prepend_globaltag("Reco_master_patch_rel5")
117 
118 
119 if (combineRuns):
120  print("Combining all runs' histograms for a single calibration")
121  print("path = ", basePathAndName)
122  alg_result = algo.execute()
123  print("Calibration completion status", alg_result)
124  if (alg_result == 0):
125  algo.commit()
126 else:
127  print("Calibrating each run individually")
128  runsWithoutEnoughData = []
129  for exprun in exprun_vector:
130  iov_to_execute = ROOT.vector("std::pair<int,int>")()
131  iov_to_execute.push_back(exprun)
132  print("path = ", basePathAndName)
133  alg_result = algo.execute(iov_to_execute, 0)
134  print("Calibration success-result was", alg_result, " (0=ok, 2=needs more data)")
135  if (alg_result == 0):
136  algo.commit()
137 
138 
139 print("Summary of possible calibration completion status values:")
140 print(" c_OK = Finished successfuly = 0 in Python")
141 print(" c_Iterate, = Needs iteration = 1 in Python")
142 print(" c_NotEnoughData, = Needs more data = 2 in Python")
143 print(" c_Failure, = Failed = 3 in Python")
144 print(" c_Undefined = Not yet known (before execution) = 4 in Python")
Belle2::Environment::Instance
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:31
Belle2::ECL::eclBhabhaTAlgorithm
Calibrate ecl crystals using bhabha events.
Definition: eclBhabhaTAlgorithm.h:39