14 from optparse
import OptionParser
15 parser = OptionParser(usage =
"usage: %prog [options] reference file",
16 description =
"Compare the histograms in two root files. See https://twiki.cern.ch/twiki/bin/view/Atlas/TrigValTools#rootcomp_py for more details and examples.")
18 parser.add_option(
"-c",
"--chi2",
19 action =
"store_true",
20 help =
"use chi2 comparison instead of bin-by-bin")
22 parser.add_option(
"-a",
"--axis",
23 action =
"store_true",
24 help =
"use axis comparison instead of bin-by-bin")
26 parser.add_option(
"-l",
"--sortLabels",
27 action =
"store_true", default=
False,
28 help =
"sort/deflate alphanumeric axis before comparing")
30 parser.add_option(
"-t",
"--threshold",
31 action =
"store", type=
"float",
32 help =
"threshold for bin or chi2 comparison (default: 1e-6 or 0.95)")
34 parser.add_option(
"-o",
"--output",
35 action =
"store", dest =
"outFile",
36 metavar =
"NAME", default =
"rootcomp",
37 help =
"write output to NAME.[ps,root] (default: rootcomp)")
39 parser.add_option(
"-s",
"--skip",
40 action =
"append", default=[], type=
"string",
41 help =
"add objects to skip (regular expression, can be used multiple times, mutual exclusive with -e)")
43 parser.add_option(
"-e",
"--select",
44 action =
"append", default=[], type=
"string",
45 help =
"select histograms to compare (regular expression, can be used multiple times, mutual exclusive with -s)")
47 parser.add_option(
"--refBaseDir",
48 action =
"store", default =
"",
49 help =
"base directory of reference file")
51 parser.add_option(
"--fileBaseDir",
52 action =
"store", default =
"",
53 help =
"base directory of file")
55 parser.add_option(
"-S",
"--noSkipList",
56 action =
"store_true", default=
False,
57 help =
"do not use default list of histograms to skip")
59 parser.add_option(
"-n",
"--noRoot",
60 action =
"store_true",
61 help =
"do not write .root file")
63 parser.add_option(
"--noPS",
64 action =
"store_true",
65 help =
"do not write ps/pdf file")
67 parser.add_option(
"-N",
"--norm",
68 action =
"store_true", default =
False,
69 help =
"draw normalized")
71 parser.add_option(
"--noDiff",
72 action =
"store_true", default =
False,
73 help =
"do not plot difference histogram")
75 parser.add_option(
"--ignoreMissingRef",
76 action =
"store_true", default =
False,
77 help =
"ignore missing references for overall test result")
79 parser.add_option(
"-z",
"--zip",
80 action =
"store_true",
81 help =
"gzip postscript output file")
83 parser.add_option(
"-p",
"--pdf",
84 action =
"store_true",
85 help =
"create pdf instead of ps output file")
87 parser.add_option(
"-v",
"--verbose",
88 action =
"store_true", default =
False,
91 parser.add_option(
"--html",action=
"store_true",default=
False,help=
"generate root html code to view results in web browser")
93 (opts, args) = parser.parse_args()
99 if not opts.noSkipList:
100 opts.skip += [
"Unpck$",
"BufFreeCnt$",
"CalEvtSize$"]
101 opts.skip += [
"/TIME_"]
102 opts.skip += [
"/athenaHLT.*/.*Time$"]
103 opts.skip += [
"HltEventLoopMgr/.*Time.*"]
104 opts.skip += [
"HltEventLoopMgr/PopScheduler.*"]
105 opts.skip += [
"MessageSvc/MessageCount"]
106 opts.skip += [
"TrigSignatureMoni/.*Rate"]
107 opts.skip += [
"TrigOpMonitor/GeneralOpInfo"]
108 opts.skip += [
"TrigOpMonitor/IOVDb.*"]
109 opts.skip += [
"TrigOpMonitor/.*ReadTime"]
110 opts.skip += [
"TrigOpMonitor/.*BytesRead"]
111 opts.skip += [
"HLTFramework/ROBDataProviderSvc"]
112 opts.skip += [
"HLTFramework/SchedulerMonSvc"]
113 opts.skip += [
"HLTSeeding/Random"]
117 if not opts.threshold:
118 if opts.chi2: opts.threshold = 0.95
119 else: opts.threshold = 1e-6
122 print(
"Command : rootcomp.py %s\n" % (
" ".
join(sys.argv[1:])))
123 print(
"Reference : %s" % args[0])
124 print(
"File : %s" % args[1])
125 print(
"Comparison : ", end=
"")
126 if opts.chi2:
print(
"CHI2 (%.2f)" % opts.threshold)
127 elif opts.axis:
print(
"AXIS")
128 else:
print(
"BIN-BY-BIN (%.1e)" % opts.threshold)
129 if not opts.skip==[]:
print(
"Ignored histograms: %s" % (
", ".
join(opts.skip)))
130 if not opts.select==[]:
print(
"Selected histograms: %s" % (
", ".
join(opts.select)))
135 from PyUtils
import RootUtils
136 ROOT = RootUtils.import_root( batch=
True )
141 from ROOT
import TRootCompare
142 from ROOT
import gROOT, gStyle
143 gROOT.SetStyle(
"Plain")
144 gStyle.SetOptStat(111111)
147 valid.setVerbose(opts.verbose)
151 valid.setAlg(TRootCompare.CHI2, opts.threshold)
153 valid.setAlg(TRootCompare.AXIS, opts.threshold)
155 valid.setAlg(TRootCompare.BIN, opts.threshold)
158 for s
in opts.select:
159 valid.passBeforeFailRegexp()
160 valid.addPassRegexp(s)
164 valid.addFailRegexp(s)
167 if not opts.noRoot: valid.setOutputFile(opts.outFile+
".root")
172 valid.setPsFile(opts.outFile+
".pdf")
174 valid.setPsFile(opts.outFile+
".ps")
176 valid.sortLabels(opts.sortLabels)
177 valid.drawNormalized(opts.norm)
178 valid.drawDiff(
not opts.noDiff)
181 rc = valid.setReferenceFile(args[0],opts.refBaseDir)
185 rc = valid.run(args[1],opts.fileBaseDir)
190 if opts.zip
and not opts.pdf:
191 print(
"GZipping postscript file -> %s.ps.gz" % opts.outFile)
192 os.system(
"gzip -f %s.ps" % (opts.outFile))
196 elif valid.totalHist()>0:
198 if opts.ignoreMissingRef: result =
min(valid.totalHist()-valid.matchingHist(),255)
200 else: result =
min(valid.totalHist()-valid.matchingHist()-valid.missingHist(),255)
201 elif valid.totalHist()==0
and valid.missingHist()==0
and valid.matchingHist()==0:
208 os.system(
"root2html.py *.root")
210 print(
"Overall test result: %i" % result)