10Validation of KLM time cabledelay calibration.
15from prompt
import ValidationSettings
17from ROOT.Belle2
import KLMCalibrationChecker
23from ROOT
import TH1F, TCanvas, TFile, gStyle
26settings = ValidationSettings(name=
'KLM time cabledelay',
28 download_files=[
'stdout'],
31 "LowerTimeBoundaryRPC": -800.0,
32 "UpperTimeBoundaryRPC": -600.0,
33 "LowerTimeBoundaryScintilltorsBKLM": -4800.0,
34 "UpperTimeBoundaryScintilltorsBKLM": -4400.0,
35 "LowerTimeBoundaryScintilltorsEKLM": -4900.0,
36 "UpperTimeBoundaryScintilltorsEKLM": -4500.0,
40def run_validation(job_path, input_data_path, requested_iov, expert_config):
44 - job_path will be replaced with path/to/calibration_results
45 - input_data_path will be replaced
with path/to/data_path used
for calibration, e.g. /group/belle2/dataprod/Data/PromptSkim/
49 expert_config = json.loads(expert_config)
51 chunk_size = expert_config[
'chunk_size']
52 LowerTimeBoundaryRPC = expert_config[
'LowerTimeBoundaryRPC']
53 UpperTimeBoundaryRPC = expert_config[
'UpperTimeBoundaryRPC']
54 LowerTimeBoundaryScintilltorsBKLM = expert_config[
'LowerTimeBoundaryScintilltorsBKLM']
55 UpperTimeBoundaryScintilltorsBKLM = expert_config[
'UpperTimeBoundaryScintilltorsBKLM']
56 LowerTimeBoundaryScintilltorsEKLM = expert_config[
'LowerTimeBoundaryScintilltorsEKLM']
57 UpperTimeBoundaryScintilltorsEKLM = expert_config[
'UpperTimeBoundaryScintilltorsEKLM']
60 ROOT.PyConfig.IgnoreCommandLineOptions =
True
62 ROOT.gROOT.SetBatch(
True)
64 ROOT.gROOT.SetStyle(
"BELLE2")
66 ROOT.gStyle.SetOptStat(0)
69 database_file = os.path.join(f
'{job_path}',
'KLMTime',
'outputdb',
'database.txt')
74 with open(database_file)
as f:
76 fields = line.split(
' ')
77 if (fields[0] ==
'dbstore/KLMTimeCableDelay'):
78 iov = fields[2].split(
',')
81 if (exp != previous_exp):
82 exp_run_dict[exp] = [run]
85 exp_run_dict[exp].append(run)
89 for exp, run_list
in exp_run_dict.items():
92 if run_list[0] == 0
and run_list[1] > 5:
93 run_list[0] = run_list[1] - 5
96 for exp, run_list
in exp_run_dict.items():
98 checker = KLMCalibrationChecker()
99 checker.setExperimentRun(exp, run)
100 checker.setTestingPayload(database_file)
101 basf2.B2INFO(f
'Creating time cable delay results tree for experiment {exp}, run {run}.')
102 checker.setTimeCableDelayResultsFile(f
'time_cabledelay_exp{exp}_run{run}.root')
103 checker.checkTimeCableDelay()
106 for exp, run_list
in exp_run_dict.items():
108 chunks = math.ceil(len(run_list) / chunk_size)
109 for chunk
in range(chunks):
110 file_name = f
'time_cabledelay_exp{exp}_chunk{chunk}.root'
112 f
'time_cabledelay_exp{exp}_run{run}.root' for run
in run_list[chunk * chunk_size:(chunk + 1) * chunk_size]]
113 subprocess.run([
'hadd',
'-f', file_name] + run_files, check=
True)
114 input_file = ROOT.TFile(f
'{file_name}')
116 gStyle.SetOptStat(1111111)
117 gStyle.SetOptFit(1111)
118 barrel_RPC = TH1F(
"barrel_RPC",
"time cable delay for Barrel RPC", 100, LowerTimeBoundaryRPC, UpperTimeBoundaryRPC)
119 barrel_scintillator = TH1F(
"barrel_scintillator",
"time cable delay for Barrel scintillator",
120 100, LowerTimeBoundaryScintilltorsBKLM, UpperTimeBoundaryScintilltorsBKLM)
121 endcap_scintillator = TH1F(
"endcap_scintillator",
"time cable delay for endcap scintillator",
122 100, LowerTimeBoundaryScintilltorsEKLM, UpperTimeBoundaryScintilltorsEKLM)
124 tree = input_file.Get(
"cabledelay")
125 assert isinstance(tree, ROOT.TTree) == 1
128 tree.Draw(
"timeDelay>>barrel_RPC",
"subdetector==1 & layer>=3")
129 barrel_RPC.Fit(
"gaus")
130 barrel_RPC.GetXaxis().SetTitle(
"T_{cable} (ns)")
131 barrel_RPC.GetYaxis().SetTitle(
"Entries")
132 myC.Print(
"barrel_RPC.png")
134 tree.Draw(
"timeDelay>>barrel_scintillator",
"subdetector==1 & layer<3")
135 barrel_scintillator.Fit(
"gaus")
136 barrel_scintillator.GetXaxis().SetTitle(
"T_{cable} (ns)")
137 barrel_scintillator.GetYaxis().SetTitle(
"Entries")
138 myC.Print(
"barrel_scintillator.png")
140 tree.Draw(
"timeDelay>>endcap_scintillator",
"subdetector==2")
141 endcap_scintillator.Fit(
"gaus")
142 endcap_scintillator.GetXaxis().SetTitle(
"T_{cable} (ns)")
143 endcap_scintillator.GetYaxis().SetTitle(
"Entries")
144 myC.Print(
"endcap_scintillator.png")
147 fout = TFile(
"KLMTimeCableDelay.root",
"recreate")
149 barrel_scintillator.Write()
150 endcap_scintillator.Write()
155 for run_file
in run_files:
159 basf2.B2ERROR(f
'The file {run_file} can not be removed: {e.strerror}')
162if __name__ ==
"__main__":