13
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.")
17
18 parser.add_option("-c", "--chi2",
19 action = "store_true",
20 help = "use chi2 comparison instead of bin-by-bin")
21
22 parser.add_option("-a", "--axis",
23 action = "store_true",
24 help = "use axis comparison instead of bin-by-bin")
25
26 parser.add_option("-l", "--sortLabels",
27 action = "store_true", default=False,
28 help = "sort/deflate alphanumeric axis before comparing")
29
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)")
33
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)")
38
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)")
42
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)")
46
47 parser.add_option("--refBaseDir",
48 action = "store", default = "",
49 help = "base directory of reference file")
50
51 parser.add_option("--fileBaseDir",
52 action = "store", default = "",
53 help = "base directory of file")
54
55 parser.add_option("-S", "--noSkipList",
56 action = "store_true", default=False,
57 help = "do not use default list of histograms to skip")
58
59 parser.add_option("-n", "--noRoot",
60 action = "store_true",
61 help = "do not write .root file")
62
63 parser.add_option("--noPS",
64 action = "store_true",
65 help = "do not write ps/pdf file")
66
67 parser.add_option("-N", "--norm",
68 action = "store_true", default = False,
69 help = "draw normalized")
70
71 parser.add_option("--noDiff",
72 action = "store_true", default = False,
73 help = "do not plot difference histogram")
74
75 parser.add_option("--ignoreMissingRef",
76 action = "store_true", default = False,
77 help = "ignore missing references for overall test result")
78
79 parser.add_option("-z", "--zip",
80 action = "store_true",
81 help = "gzip postscript output file")
82
83 parser.add_option("-p", "--pdf",
84 action = "store_true",
85 help = "create pdf instead of ps output file")
86
87 parser.add_option("-v", "--verbose",
88 action = "store_true", default = False,
89 help = "be verbose")
90
91 parser.add_option("--html",action="store_true",default=False,help="generate root html code to view results in web browser")
92
93 (opts, args) = parser.parse_args()
94
95 if len(args)!=2:
96 parser.print_help()
97 return 255
98
99 if not opts.noSkipList:
100 opts.skip += ["Unpck$", "BufFreeCnt$", "CalEvtSize$"]
101 opts.skip += ["/TIME_"]
102 opts.skip += ["HltEventLoopMgr/.*Time.*"]
103 opts.skip += ["HltEventLoopMgr/PopScheduler.*"]
104 opts.skip += ["MessageSvc/MessageCount"]
105 opts.skip += ["TrigSignatureMoni/.*Rate"]
106 opts.skip += ["TrigOpMonitor/GeneralOpInfo"]
107 opts.skip += ["TrigOpMonitor/IOVDb.*"]
108 opts.skip += ["TrigOpMonitor/.*ReadTime"]
109 opts.skip += ["TrigOpMonitor/.*BytesRead"]
110 opts.skip += ["HLTFramework/ROBDataProviderSvc"]
111 opts.skip += ["HLTFramework/SchedulerMonSvc"]
112 opts.skip += ["HLTSeeding/Random"]
113
114
115
116 if not opts.threshold:
117 if opts.chi2: opts.threshold = 0.95
118 else: opts.threshold = 1e-6
119
121 print(
"Command : rootcomp.py %s\n" % (
" ".join(sys.argv[1:])))
122 print(
"Reference : %s" % args[0])
123 print(
"File : %s" % args[1])
124 print(
"Comparison : ", end=
"")
125 if opts.chi2:
print(
"CHI2 (%.2f)" % opts.threshold)
126 elif opts.axis:
print(
"AXIS")
127 else:
print(
"BIN-BY-BIN (%.1e)" % opts.threshold)
128 if not opts.skip==[]:
print(
"Ignored histograms: %s" % (
", ".join(opts.skip)))
129 if not opts.select==[]:
print(
"Selected histograms: %s" % (
", ".join(opts.select)))
130
132
133
134 from PyUtils import RootUtils
135 ROOT = RootUtils.import_root( batch=True )
136
137 sys.stdout.flush()
138 sys.stderr.flush()
139
140 from ROOT import TRootCompare
141 from ROOT import gROOT, gStyle
142 gROOT.SetStyle("Plain")
143 gStyle.SetOptStat(111111)
144
146 valid.setVerbose(opts.verbose)
147
148
149 if opts.chi2:
150 valid.setAlg(TRootCompare.CHI2, opts.threshold)
151 elif opts.axis:
152 valid.setAlg(TRootCompare.AXIS, opts.threshold)
153 else:
154 valid.setAlg(TRootCompare.BIN, opts.threshold)
155
156
157 for s in opts.select:
158 valid.passBeforeFailRegexp()
159 valid.addPassRegexp(s)
160
161
162 for s in opts.skip:
163 valid.addFailRegexp(s)
164
165
166 if not opts.noRoot: valid.setOutputFile(opts.outFile+".root")
167
168 if opts.noPS:
169 valid.setPsFile("")
170 elif opts.pdf:
171 valid.setPsFile(opts.outFile+".pdf")
172 else:
173 valid.setPsFile(opts.outFile+".ps")
174
175 valid.sortLabels(opts.sortLabels)
176 valid.drawNormalized(opts.norm)
177 valid.drawDiff(not opts.noDiff)
178
179
180 rc = valid.setReferenceFile(args[0],opts.refBaseDir)
181 if rc is False:
182 return 255
183
184 rc = valid.run(args[1],opts.fileBaseDir)
185
186 sys.stdout.flush()
187 sys.stderr.flush()
188
189 if opts.zip and not opts.pdf:
190 print(
"GZipping postscript file -> %s.ps.gz" % opts.outFile)
191 os.system("gzip -f %s.ps" % (opts.outFile))
192
193 if rc != 0:
194 result = 255
195 elif valid.totalHist()>0:
196
197 if opts.ignoreMissingRef: result =
min(valid.totalHist()-valid.matchingHist(),255)
198
199 else: result =
min(valid.totalHist()-valid.matchingHist()-valid.missingHist(),255)
200 elif valid.totalHist()==0 and valid.missingHist()==0 and valid.matchingHist()==0:
201
202 result = 0
203 else:
204 result = 255
205
206 if opts.html:
207 os.system("root2html.py *.root")
208
209 print(
"Overall test result: %i" % result)
210 return result
211
void print(char *figname, TCanvas *c1)
Class to compare the histograms in two root files.