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