9 from ROOT
import TH1F, TH2F, TProfile, TFile
13 def checkIfRunUsable(file):
15 h = file.FindObject(
'DQMInfo/rtype')
17 logging.warning(fileName +
' ... histogram runtype not found')
19 if not h.GetTitle() ==
"physics":
20 logging.info(fileName +
' ... not a physics run, skipping')
24 h = file.FindObject(
'TOP/good_hits_per_event1')
26 logging.warning(fileName +
' ... histogram good_hits_per_event1 not found')
28 nev = int(h.GetEntries())
30 logging.warning(fileName +
'run =' + str(run) +
'events =' + str(nev) +
' ... skipped, not enough events')
34 h = file.FindObject(
'TOP/good_hits')
36 logging.warning(fileName +
' ... histogram good_hits not found')
38 if h.GetEntries() == 0:
39 logging.warning(fileName +
' ... histogram good_hits has no entries ... skipped')
45 def makeChannelMasks(file, outFileName):
47 masks = [TH1F(
'slot_' + str(slot),
'Channel mask for slot ' + str(slot),
48 512, 0.0, 512.0)
for slot
in range(1, 17)]
52 for slot
in range(1, 17):
53 h = file.FindObject(
'TOP/good_channel_hits_' + str(slot))
55 logging.error(
'no good_channel_hits found for slot'+str(slot))
60 for chan
in range(h.GetNbinsX()):
61 y = h.GetBinContent(chan+1)
70 for chan
in range(h.GetNbinsX()):
71 y = h.GetBinContent(chan+1)
73 masks[slot-1].SetBinContent(chan+1, 1)
76 masks[slot-1].SetBinContent(chan+1, 2)
80 for slot
in range(1, 17):
81 h = file.FindObject(
'TOP/window_vs_asic_' + str(slot))
83 logging.error(
'Error: no window_vs_asic found for slot' + str(slot))
86 h1 = h.ProjectionX(
'_tmp', 222, 245)
87 for asic
in range(h.GetNbinsX()):
88 if h0.GetBinContent(asic+1) > 0:
89 r = 1 - h1.GetBinContent(asic+1) / h0.GetBinContent(asic+1)
92 masks[slot-1].SetBinContent(asic*8+chan+1, 2)
97 outfile = TFile(outFileName,
'recreate')
105 experimentstring =
"{:04d}".format(experiment)
107 if not os.path.exists(outdir):
109 fileNames = sorted(glob.glob(
'/group/belle2/phase3/dqm/dqmsrv1/e'+experimentstring+
'/dqmhisto/hltdqm*.root'))
111 logging.basicConfig(level=logging.INFO, filename=
"channelmasking.log")
112 logging.info(
"Starting channelmasking from HLT histograms")
113 logging.info(
"Experiment: "+str(experiment))
115 numFiles = len(fileNames)
117 logging.error(
'No files found, exiting')
120 for fileName
in fileNames:
121 run = ((fileName.split(
'/')[-1]).split(
'r')[1]).split(
'.')[0]
122 outFileName = outdir +
'/channelMask_e' + experimentstring +
'_r' + run +
'.root'
125 if os.path.exists(outFileName)
or os.path.exists(outFileName.replace(
'masks/',
'masks/imported/')):
126 logging.debug(
'Output file exists for run ='+str(run)+
', skipping')
130 file = TFile(fileName)
132 logging.error(fileName +
' ... cannot open')
135 nev = checkIfRunUsable(file)
140 masked = makeChannelMasks(file, outFileName)
141 logging.info(fileName +
'run =' + str(run) +
'events =' + str(nev) +
'masked channels =' + str(masked))
143 logging.critical(
"Result looks completely wrong, over 3000 masked channels. Inspect run "+str(run))