File indexing completed on 2024-04-06 12:07:27
0001 import ROOT
0002 import os, sys
0003 import argparse
0004 import array
0005
0006
0007 bitDigiOcc = 0
0008
0009 listBitConfFilter = [
0010 { "name": "AMC13", "error": 1, "warning": -1 },
0011 { "name": "AMC", "error": 2, "warning": 3 },
0012 { "name": "OH", "error": 4, "warning": 5 },
0013 { "name": "VFAT", "error": 6, "warning": 7 },
0014 ]
0015
0016
0017 parser = argparse.ArgumentParser()
0018
0019 parser.add_argument("src", default="", help="")
0020 parser.add_argument("dst", default="", help="")
0021
0022 opts = parser.parse_args()
0023
0024 fDQM = ROOT.TFile.Open(opts.src)
0025 dirMain = None
0026
0027 for k1 in fDQM.GetListOfKeys():
0028 d1 = fDQM.Get(k1.GetName())
0029 if not isinstance(d1, ROOT.TDirectoryFile):
0030 continue
0031
0032 for k2 in d1.GetListOfKeys():
0033 d2 = d1.Get(k2.GetName())
0034 if not isinstance(d1, ROOT.TDirectoryFile):
0035 continue
0036
0037 dirMain = d2
0038 break
0039
0040 if dirMain:
0041 break
0042
0043 dirEventInfo = dirMain.Get("GEM/Run summary/EventInfo")
0044 listHistLumi = [ k.GetName() for k in dirEventInfo.GetListOfKeys() ]
0045 listHistLumi = [ s for s in listHistLumi if s.startswith("chamberStatus_inLumi") ]
0046
0047 fOut = ROOT.TFile.Open(opts.dst, "RECREATE")
0048
0049 for name in listHistLumi:
0050 histCurr = dirEventInfo.Get(name)
0051
0052 listFillLumi = [ histCurr.GetBinContent(i + 1, 0) for i in range(histCurr.GetNbinsX()) ]
0053 numLumi = max([ i for i, x in enumerate(listFillLumi) if abs(x) > 0 ]) + 1
0054
0055 listBinLumi = [ histCurr.GetXaxis().GetBinLowEdge(i + 1) for i in range(numLumi + 1) ]
0056 listBinY = [ histCurr.GetYaxis().GetBinLowEdge(i + 1) for i in range(histCurr.GetNbinsY() + 1) ]
0057
0058 for dicConf in listBitConfFilter:
0059 fOut.cd()
0060
0061 numBinY = len(listBinY) - 1
0062
0063 histNew = ROOT.TH2S(
0064 dicConf[ "name" ] + "_" + name,
0065 histCurr.GetTitle() + " ({})".format(dicConf[ "name" ]),
0066 numLumi,
0067 array.array("d", listBinLumi),
0068 numBinY,
0069 array.array("d", listBinY),
0070 )
0071
0072 histNew.GetXaxis().SetTitle(histCurr.GetXaxis().GetTitle())
0073 histNew.GetYaxis().SetTitle(histCurr.GetYaxis().GetTitle())
0074
0075 for i in range(len(listBinY) - 1):
0076 histNew.GetYaxis().SetBinLabel(i + 1, histCurr.GetYaxis().GetBinLabel(i + 1))
0077
0078 for j in range(numBinY):
0079 for i in range(numLumi):
0080 val = int(histCurr.GetBinContent(i + 1, j + 1))
0081 occ = val & ( 1 << bitDigiOcc ) != 0
0082 err = val & ( 1 << dicConf[ "error" ] ) != 0 if dicConf[ "error" ] >= 0 else False
0083 warn = val & ( 1 << dicConf[ "warning" ] ) != 0 if dicConf[ "warning" ] >= 0 else False
0084 print(dicConf[ "name" ], val, occ, err, warn)
0085
0086 out = 0
0087 if err:
0088 out = 2
0089 elif warn:
0090 out = 3
0091 elif occ:
0092 out = 1
0093
0094 histNew.SetBinContent(i + 1, j + 1, out)
0095
0096 histNew.Write()
0097
0098 fOut.Write()
0099 fOut.Close()
0100 fDQM.Close()
0101
0102