236 """ Master method for canvas making. """ 240 self.
im = ImageMaker()
246 overlays = PlotLibrary()
249 by_name_then_dataset = PlotLibrary()
252 for key, histogram
in self.histogram_table.iteritems():
253 if histogram.GetTitle() ==
"":
254 histogram.SetTitle(key.plot_id.name)
257 no_category_key = PlotCollectionKey(
259 "name": key.plot_id.name,
265 by_name_then_dataset.setdefault(no_category_key, {}).setdefault(key.data_set, PlotSet()).
add(key)
270 if len(key.plot_id.categories) > 0:
273 categories = key.plot_id.categories[:-1]
274 categories.append(PlotID.OVERLAY_STRING)
276 "name": key.plot_id.name,
277 "categories": categories,
278 "groups": key.plot_id.groups
280 plotid_args[
"categories"] = categories
281 overlay_key = PlotCollectionKey( PlotID(plotid_args), key.data_set, key.path )
282 overlays.setdefault(overlay_key, {})[key.plot_id.categories[-1]] = histogram
285 categories[-1] = PlotID.SUM_STRING
286 plotid_args[
"categories"] = categories
287 sum_key = PlotCollectionKey( PlotID(plotid_args), key.data_set, key.path )
288 if sum_key
not in sums:
289 sum_histogram = histogram.Clone( sum_key.plot_id.id_str )
290 sum_histogram.exposure = histogram.exposure
291 sum_histogram.SetTitle(histogram.GetTitle()
or "Untitled plot")
292 sums[sum_key] = sum_histogram
293 overlays[overlay_key][PlotID.SUM_STRING] = sum_histogram
295 sums[sum_key].Add(histogram)
297 self.
WriteAndRegisterCanvas({histogram.GetTitle(): histogram}, self.PrepareOutputPath(key.data_set, key.path, key.plot_id.id_str), key)
300 for key, histogram
in sums.iteritems():
302 {histogram.GetTitle(): histogram},
303 self.PrepareOutputPath(key.data_set, key.path, key.plot_id.id_str),
310 for key, histogram_collection
in overlays.iteritems():
312 histogram_collection,
313 self.PrepareOutputPath(key.data_set, key.path, key.plot_id.id_str),
315 plot_order=self.config.plot_order,
328 comparison_dirname = PathTools.ComparisonSubdirName(self.config.histogram_topdirs)
329 for no_category_key, plots_by_dataset
in by_name_then_dataset.iteritems():
330 if len(plots_by_dataset) < 2:
336 for dataset_name, plot_keys
in plots_by_dataset.iteritems():
337 category_lists[dataset_name] = []
338 cl = category_lists[dataset_name]
339 for plot_key
in plot_keys:
340 for cat_idx, cat_name
in enumerate(plot_key.plot_id.categories):
341 if len(cl) < cat_idx + 1:
343 max_num_gps =
max(max_num_gps, cat_idx+1)
344 cl[cat_idx].
add(cat_name)
346 identical_keys =
True 347 for gp_idx
in range(max_num_gps):
349 if len(set([len(category_lists[ds])
for ds
in category_lists])) != 1:
350 identical_keys =
False 353 if len(set.union(*[category_lists[ds][gp_idx]
for ds
in category_lists])) != len(category_lists[category_lists.keys()[0]][gp_idx]):
354 identical_keys =
False 358 category_lists = [ set.union(*[cat_list[cat_idx]
for ds, cat_list
in category_lists.iteritems()
if cat_idx < len(cat_list)])
for cat_idx
in range(max_num_gps)]
366 if len(category_lists) > 0
and not identical_keys:
367 del category_lists[-1]
372 for category_combination
in itertools.product(*category_lists):
374 for dataset_name
in plots_by_dataset:
380 reduced_groups = {k: v
for k,v
in plot_key.plot_id.groups.iteritems()
if v < len(categories)}
381 reduced_key = PlotCollectionKey(
383 "name": plot_key.plot_id.name,
384 "categories": categories,
385 "groups": reduced_groups
387 data_set = dataset_name,
388 path=no_category_key.path
398 if len(categories) <= len(category_combination)
and len(categories) > 0
and categories[-1] == PlotID.SUM_STRING:
399 if len(categories) > 0:
404 to_plot[dataset_name] = reduced_key
408 if i >= len(category_combination):
412 categories.append(category_combination[i])
415 categories.append(PlotID.SUM_STRING)
417 categories.insert(-1, category_combination[i])
422 print "Could not find plot for category sequence", category_combination,
"in plot / dataset =", no_category_key.plot_id,
"/", dataset_name
427 if any(isinstance(self.
histogram_table[key], ROOT.TH2)
for key
in to_plot.itervalues())
and not self.config.force_2d_comp:
428 SINGLE_WARN(
"comparisons will not be made for 2D plots. Pass 'force_2d_comp' as true in your config to change.")
434 for key
in to_plot.values():
435 stricter = all(key.plot_id
in other_key.plot_id
for other_key
in to_plot.values()
if other_key != key)
439 assert strictest_key,
"Couldn't find one key that contains all the others in this collection. Keys in collection: %s" % to_plot.values()
448 categories = strictest_key.plot_id.categories
449 if len(strictest_key.plot_id.categories) > 0
and categories[-1] == PlotID.SUM_STRING:
450 categories = strictest_key.plot_id.categories[:-1]
451 comparison_key = PlotCollectionKey(
453 "name": strictest_key.plot_id.name,
454 "categories": categories,
455 "groups": {k: v
for k,v
in strictest_key.plot_id.groups.iteritems()
if v < len(strictest_key.plot_id.categories)-1}
458 path=no_category_key.path
462 plots = {ds: self.
histogram_table[key]
for ds, key
in to_plot.iteritems()}
464 if self.config.ratio_denom
is not None and self.config.ratio_denom
in plots:
465 ratio_denom = self.config.ratio_denom
468 outfile_stub=self.PrepareOutputPath(PathTools.DATASET_COMPARISON_DIRNAME, comparison_dirname, no_category_key.path, comparison_key.plot_id.id_str),
471 plot_order=self.config.plot_order,
472 ratio_denom=ratio_denom
475 if len(to_plot) == 2:
476 c = ComparisonSummary({key: self.
histogram_table[key]
for key
in to_plot.itervalues()})
477 self.comparison_registry.comparisons[comparison_key] = c
479 self.plot_registry.Serialize(self.config.validation_dir)
480 self.comparison_registry.Serialize(self.config.validation_dir)
def WriteAndRegisterCanvas(self, histograms, outfile_stub, key, include_ratio=False, plot_order=[], ratio_denom=None)
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
add("abs", expr_type(int_type()), expr_type(int_type()))