12 Validation of ARICH channel masking calibration.
17 from prompt
import ValidationSettings
19 from ROOT.Belle2
import ARICHCalibrationChecker
26 settings = ValidationSettings(name=
'ARICH channel masks',
28 download_files=[
'stdout'],
29 expert_config={
"chunk_size": 100})
32 def run_validation(job_path, input_data_path, requested_iov, expert_config):
37 expert_config = json.loads(expert_config)
38 chunk_size = expert_config[
"chunk_size"]
41 ROOT.PyConfig.IgnoreCommandLineOptions =
True
44 ROOT.gROOT.SetBatch(
True)
46 ROOT.gStyle.SetOptStat(0)
49 database_file = f
'{job_path}/ARICHChannelMasks/outputdb/database.txt'
54 with open(database_file)
as f:
56 fields = line.split(
' ')
57 if (fields[0] ==
'dbstore/ARICHChannelMask'):
58 iov = fields[2].split(
',')
61 if (exp != previous_exp):
62 exp_run_dict[exp] = [run]
65 exp_run_dict[exp].append(run)
69 for exp, run_list
in exp_run_dict.items():
72 if run_list[0] == 0
and run_list[1] > 5:
73 run_list[0] = run_list[1] - 5
76 for exp, run_list
in exp_run_dict.items():
78 checker = ARICHCalibrationChecker()
79 checker.setExperimentRun(exp, run)
80 checker.setTestingPayload(database_file)
81 basf2.B2INFO(f
'Creating arich channel mask results tree for experiment {exp}, run {run}.')
82 checker.setChannelMaskResultsFile(f
'channel_mask_exp{exp}_run{run}.root')
83 checker.checkChannelMask()
86 for exp, run_list
in exp_run_dict.items():
88 chunks = math.ceil(len(run_list) / chunk_size)
89 for chunk
in range(chunks):
90 file_name = f
'channel_mask_exp{exp}_chunk{chunk}.root'
92 f
'channel_mask_exp{exp}_run{run}.root' for run
in run_list[chunk * chunk_size:(chunk + 1) * chunk_size]]
93 subprocess.run([
'hadd',
'-f', file_name] + run_file_names, check=
True)
94 input_file = ROOT.TFile(f
'{file_name}')
95 output_file = ROOT.TFile(f
'histograms_{file_name}',
'recreate')
97 tree = input_file.Get(
'arich_masked')
98 assert isinstance(tree, ROOT.TTree) == 1
99 canvas = ROOT.TCanvas(f
'canvas_exp{exp}_chunk{chunk}',
'canvas', 800, 500)
102 mg = ROOT.TMultiGraph(
"mg",
"ARICH masked channels")
103 leg = ROOT.TLegend(0.9, 0.5, 0.98, 0.9)
106 for i
in range(0, 6):
107 n = tree.Draw(f
'frac_masked_sector[{i}]:run',
"",
"goff")
108 graphs.append(ROOT.TGraph(n, tree.GetV2(), tree.GetV1()))
109 graphs[i].SetMarkerStyle(7)
110 graphs[i].SetMarkerColor(i + 1)
111 graphs[i].SetLineWidth(0)
112 graphs[i].SetTitle(f
'sector {i+1}')
113 leg.AddEntry(graphs[i])
117 n = tree.Draw(f
'frac_masked:run',
"",
"goff")
118 graphs.append(ROOT.TGraph(n, tree.GetV2(), tree.GetV1()))
119 graphs[6].SetMarkerStyle(20)
120 graphs[6].SetMarkerColor(6 + 1)
121 graphs[6].SetLineWidth(0)
122 graphs[6].SetTitle(
'total')
123 leg.AddEntry(graphs[6])
127 mg.GetXaxis().SetTitle(f
'Exp. {exp} -- Run number')
128 mg.GetYaxis().SetTitle(
'fraction of masked channels')
133 canvas.SaveAs(file_name.replace(
"root",
"pdf"))
138 subprocess.run([
'rm',
'-rf'] + run_file_names, check=
True)
141 if __name__ ==
"__main__":