Belle II Software  release-05-01-25
run_eclBhabhaT_algorithm.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 # -----------------------------------------------------------
5 # BASF2 (Belle Analysis Framework 2)
6 # Copyright(C) 2019 Belle II Collaboration
7 #
8 # Author: The Belle II Collaboration
9 # Contributors: Mikhail Remnev
10 #
11 # This software is provided "as is" without any warranty.
12 # -----------------------------------------------------------
13 
14 # Usage: basf2 run_eclBhabhaT_algorithm.py [input_file]
15 # Glob expression can be passed as an input file.
16 # Example: basf2 run_eclBhabhaT_algorithm.py "exp_0003_run_*.root"
17 
18 import os
19 import sys
20 import ROOT
21 from basf2 import *
22 from ROOT import Belle2
23 from glob import glob
24 
26 
27 # Setting just with steering file
28 
29 # For whether to execute the algorithm over each run invidually or to combine them together in a single plot
30 # often it is easier just to only pass a single file to the algorithm code instead of to use this feature
31 combineRuns = True
32 
33 
34 # Set up and execute calibration
36 
37 
38 print("Python arguments:")
39 counting = 0
40 for arg in sys.argv:
41  print(counting, arg)
42  counting = counting + 1
43 
44 fileNames = ['eclBhabhaTCollector.root']
45 narg = len(sys.argv)
46 if(narg >= 2):
47  fileNames = glob(sys.argv[1])
48 algo.setInputFileNames(fileNames)
49 
50 basePath = ""
51 if(narg >= 3):
52  basePath = sys.argv[2] + "/"
53  print("basePath = ", basePath)
54 
55 
56 algo.cellIDLo = 3
57 algo.cellIDHi = 2
58 algo.debugOutput = True
59 algo.meanCleanRebinFactor = 3 # Rebin factor
60 # 0 means no cut. # 1 means keep only bins from max rebinned bin. # Note that with low stats, 0.2 is still too large.
61 algo.meanCleanCutMinFactor = 0.3
62 # algo.crateIDLo = 10
63 # algo.crateIDHi = 9
64 algo.debugFilenameBase = "eclBhabhaTAlgorithm"
65 
66 set_debug_level(35)
67 set_log_level(LogLevel.INFO) # LogLevel.INFO or LogLevel.DEBUG
68 
69 
70 exprun_vector = algo.getRunListFromAllData()
71 
72 baseName = "eclBhabhaTAlgorithm"
73 basePathAndName = basePath + baseName
74 algo.debugFilenameBase = basePathAndName
75 
76 if (combineRuns):
77  print("Combining all runs' histograms for a single calibration")
78  print("path = ", basePathAndName)
79  alg_result = algo.execute()
80  print("Calibration completion status", alg_result)
81  if (alg_result == 0):
82  algo.commit()
83 else:
84  print("Calibrating each run individually")
85  runsWithoutEnoughData = []
86  for exprun in exprun_vector:
87  iov_to_execute = ROOT.vector("std::pair<int,int>")()
88  iov_to_execute.push_back(exprun)
89  print("path = ", basePathAndName)
90  alg_result = algo.execute(iov_to_execute, 0)
91  print("Calibration success-result was", alg_result, " (0=ok, 2=needs more data)")
92  if (alg_result == 0):
93  algo.commit()
94 
95 
96 print("Summary of possible calibration completion status values:")
97 print(" c_OK = Finished successfuly = 0 in Python")
98 print(" c_Iterate, = Needs iteration = 1 in Python")
99 print(" c_NotEnoughData, = Needs more data = 2 in Python")
100 print(" c_Failure, = Failed = 3 in Python")
101 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