10Validation of ARICH channel masking calibration.
15from prompt
import ValidationSettings
17from ROOT.Belle2
import ARICHCalibrationChecker
24settings = ValidationSettings(name=
'ARICH channel masks',
26 download_files=[
'stdout'],
27 expert_config={
"chunk_size": 100})
30def run_validation(job_path, input_data_path, requested_iov, expert_config):
35 expert_config = json.loads(expert_config)
36 chunk_size = expert_config["chunk_size"]
39 ROOT.PyConfig.IgnoreCommandLineOptions =
True
42 ROOT.gROOT.SetBatch(
True)
44 ROOT.gStyle.SetOptStat(0)
47 database_file = f
'{job_path}/ARICHChannelMasks/outputdb/database.txt'
52 with open(database_file)
as f:
54 fields = line.split(
' ')
55 if (fields[0] ==
'dbstore/ARICHChannelMask'):
56 iov = fields[2].split(
',')
59 if (exp != previous_exp):
60 exp_run_dict[exp] = [run]
63 exp_run_dict[exp].append(run)
67 for exp, run_list
in exp_run_dict.items():
70 if run_list[0] == 0
and run_list[1] > 5:
71 run_list[0] = run_list[1] - 5
74 for exp, run_list
in exp_run_dict.items():
76 checker = ARICHCalibrationChecker()
77 checker.setExperimentRun(exp, run)
78 checker.setTestingPayload(database_file)
79 basf2.B2INFO(f
'Creating arich channel mask results tree for experiment {exp}, run {run}.')
80 checker.setChannelMaskResultsFile(f
'channel_mask_exp{exp}_run{run}.root')
81 checker.checkChannelMask()
84 for exp, run_list
in exp_run_dict.items():
86 chunks = math.ceil(len(run_list) / chunk_size)
87 for chunk
in range(chunks):
88 file_name = f
'channel_mask_exp{exp}_chunk{chunk}.root'
90 f
'channel_mask_exp{exp}_run{run}.root' for run
in run_list[chunk * chunk_size:(chunk + 1) * chunk_size]]
91 subprocess.run([
'hadd',
'-f', file_name] + run_file_names, check=
True)
92 input_file = ROOT.TFile(f
'{file_name}')
93 output_file = ROOT.TFile(f
'histograms_{file_name}',
'recreate')
95 tree = input_file.Get(
'arich_masked')
96 assert isinstance(tree, ROOT.TTree) == 1
97 canvas = ROOT.TCanvas(f
'canvas_exp{exp}_chunk{chunk}',
'canvas', 800, 500)
100 mg = ROOT.TMultiGraph(
"mg",
"ARICH masked channels")
101 leg = ROOT.TLegend(0.9, 0.5, 0.98, 0.9)
104 for i
in range(0, 6):
105 n = tree.Draw(f
'frac_masked_sector[{i}]:run',
"",
"goff")
106 graphs.append(ROOT.TGraph(n, tree.GetV2(), tree.GetV1()))
107 graphs[i].SetMarkerStyle(7)
108 graphs[i].SetMarkerColor(i + 1)
109 graphs[i].SetLineWidth(0)
110 graphs[i].SetTitle(f
'sector {i+1}')
111 leg.AddEntry(graphs[i])
115 n = tree.Draw(
'frac_masked:run',
"",
"goff")
116 graphs.append(ROOT.TGraph(n, tree.GetV2(), tree.GetV1()))
117 graphs[6].SetMarkerStyle(20)
118 graphs[6].SetMarkerColor(6 + 1)
119 graphs[6].SetLineWidth(0)
120 graphs[6].SetTitle(
'total')
121 leg.AddEntry(graphs[6])
125 mg.GetXaxis().SetTitle(f
'Exp. {exp} -- Run number')
126 mg.GetYaxis().SetTitle(
'fraction of masked channels')
131 canvas.SaveAs(file_name.replace(
"root",
"pdf"))
136 subprocess.run([
'rm',
'-rf'] + run_file_names, check=
True)
139if __name__ ==
"__main__":