16 from ROOT
import TFile, TH1F
20 def checkIfRunUsable(file):
22 h = file.FindObject(
'DQMInfo/rtype')
24 logging.warning(fileName +
' ... histogram runtype not found')
26 if not h.GetTitle() ==
"physics":
27 logging.info(fileName +
' ... not a physics run, skipping')
31 h = file.FindObject(
'TOP/good_hits_per_event1')
33 logging.warning(fileName +
' ... histogram good_hits_per_event1 not found')
35 nev = int(h.GetEntries())
37 logging.warning(fileName +
'run =' + str(run) +
'events =' + str(nev) +
' ... skipped, not enough events')
41 h = file.FindObject(
'TOP/good_hits')
43 logging.warning(fileName +
' ... histogram good_hits not found')
45 if h.GetEntries() == 0:
46 logging.warning(fileName +
' ... histogram good_hits has no entries ... skipped')
52 def makeChannelMasks(file, outFileName):
54 masks = [TH1F(
'slot_' + str(slot),
'Channel mask for slot ' + str(slot),
55 512, 0.0, 512.0)
for slot
in range(1, 17)]
59 for slot
in range(1, 17):
60 h = file.FindObject(
'TOP/good_channel_hits_' + str(slot))
62 logging.error(
'no good_channel_hits found for slot'+str(slot))
67 for chan
in range(h.GetNbinsX()):
68 y = h.GetBinContent(chan+1)
77 for chan
in range(h.GetNbinsX()):
78 y = h.GetBinContent(chan+1)
80 masks[slot-1].SetBinContent(chan+1, 1)
83 masks[slot-1].SetBinContent(chan+1, 2)
87 for slot
in range(1, 17):
88 h = file.FindObject(
'TOP/window_vs_asic_' + str(slot))
90 logging.error(
'Error: no window_vs_asic found for slot' + str(slot))
93 h1 = h.ProjectionX(
'_tmp', 222, 245)
94 for asic
in range(h.GetNbinsX()):
95 if h0.GetBinContent(asic+1) > 0:
96 r = 1 - h1.GetBinContent(asic+1) / h0.GetBinContent(asic+1)
99 masks[slot-1].SetBinContent(asic*8+chan+1, 2)
104 outfile = TFile(outFileName,
'recreate')
112 experimentstring =
"{:04d}".format(experiment)
114 if not os.path.exists(outdir):
116 fileNames = sorted(glob.glob(
'/group/belle2/phase3/dqm/dqmsrv1/e'+experimentstring+
'/dqmhisto/hltdqm*.root'))
118 logging.basicConfig(level=logging.INFO, filename=
"channelmasking.log")
119 logging.info(
"Starting channelmasking from HLT histograms")
120 logging.info(
"Experiment: "+str(experiment))
122 numFiles = len(fileNames)
124 logging.error(
'No files found, exiting')
127 for fileName
in fileNames:
128 run = ((fileName.split(
'/')[-1]).split(
'r')[1]).split(
'.')[0]
129 outFileName = outdir +
'/channelMask_e' + experimentstring +
'_r' + run +
'.root'
132 if os.path.exists(outFileName)
or os.path.exists(outFileName.replace(
'masks/',
'masks/imported/')):
133 logging.debug(
'Output file exists for run ='+str(run)+
', skipping')
137 file = TFile(fileName)
139 logging.error(fileName +
' ... cannot open')
142 nev = checkIfRunUsable(file)
147 masked = makeChannelMasks(file, outFileName)
148 logging.info(fileName +
'run =' + str(run) +
'events =' + str(nev) +
'masked channels =' + str(masked))
150 logging.critical(
"Result looks completely wrong, over 3000 masked channels. Inspect run "+str(run))