15from ROOT
import TFile, TH1F
19def checkIfRunUsable(file):
21 h = file.FindObject(
'DQMInfo/rtype')
23 logging.warning(fileName +
' ... histogram runtype not found')
25 if not h.GetTitle() ==
"physics":
26 logging.info(fileName +
' ... not a physics run, skipping')
30 h = file.FindObject(
'TOP/good_hits_per_event1')
32 logging.warning(fileName +
' ... histogram good_hits_per_event1 not found')
34 nev = int(h.GetEntries())
36 logging.warning(fileName +
'run =' + str(run) +
'events =' + str(nev) +
' ... skipped, not enough events')
40 h = file.FindObject(
'TOP/good_hits')
42 logging.warning(fileName +
' ... histogram good_hits not found')
44 if h.GetEntries() == 0:
45 logging.warning(fileName +
' ... histogram good_hits has no entries ... skipped')
51def makeChannelMasks(file, outFileName):
53 masks = [TH1F(
'slot_' + str(slot),
'Channel mask for slot ' + str(slot),
54 512, 0.0, 512.0)
for slot
in range(1, 17)]
58 for slot
in range(1, 17):
59 h = file.FindObject(
'TOP/good_channel_hits_' + str(slot))
61 logging.error(
'no good_channel_hits found for slot'+str(slot))
66 for chan
in range(h.GetNbinsX()):
67 y = h.GetBinContent(chan+1)
76 for chan
in range(h.GetNbinsX()):
77 y = h.GetBinContent(chan+1)
79 masks[slot-1].SetBinContent(chan+1, 1)
82 masks[slot-1].SetBinContent(chan+1, 2)
86 for slot
in range(1, 17):
87 h = file.FindObject(
'TOP/window_vs_asic_' + str(slot))
89 logging.error(
'Error: no window_vs_asic found for slot' + str(slot))
92 h1 = h.ProjectionX(
'_tmp', 222, 245)
93 for asic
in range(h.GetNbinsX()):
94 if h0.GetBinContent(asic+1) > 0:
95 r = 1 - h1.GetBinContent(asic+1) / h0.GetBinContent(asic+1)
98 masks[slot-1].SetBinContent(asic*8+chan+1, 2)
103 outfile = TFile(outFileName,
'recreate')
111experimentstring = f
"{experiment:04d}"
113if not os.path.exists(outdir):
115fileNames = sorted(glob.glob(
'/group/belle2/phase3/dqm/dqmsrv1/e'+experimentstring+
'/dqmhisto/hltdqm*.root'))
117logging.basicConfig(level=logging.INFO, filename=
"channelmasking.log")
118logging.info(
"Starting channelmasking from HLT histograms")
119logging.info(
"Experiment: "+str(experiment))
121numFiles = len(fileNames)
123 logging.error(
'No files found, exiting')
126for fileName
in fileNames:
127 run = ((fileName.split(
'/')[-1]).split(
'r')[1]).split(
'.')[0]
128 outFileName = outdir +
'/channelMask_e' + experimentstring +
'_r' + run +
'.root'
131 if os.path.exists(outFileName)
or os.path.exists(outFileName.replace(
'masks/',
'masks/imported/')):
132 logging.debug(
'Output file exists for run ='+str(run)+
', skipping')
136 file = TFile(fileName)
138 logging.error(fileName +
' ... cannot open')
141 nev = checkIfRunUsable(file)
146 masked = makeChannelMasks(file, outFileName)
147 logging.info(fileName +
'run =' + str(run) +
'events =' + str(nev) +
'masked channels =' + str(masked))
149 logging.critical(
"Result looks completely wrong, over 3000 masked channels. Inspect run "+str(run))