8 Functionality to extract quantities from various ROOT objects (TH1).
10 Author: The Belle II Collaboration
11 Contributors: Thomas Hauth
16 def default_extractor():
18 Returns a list of default extractors for the most common
22 def computeMean(profile_obj):
24 compute the mean values of the y dimension, also with
27 nbinsx = profile_obj.GetNbinsX()
29 sumZeroSuppressed = 0.0
30 countZeroSuppressed = 0
31 for i
in range(nbinsx):
32 v = profile_obj.GetBinContent(i + 1)
35 sumZeroSuppressed = sumZeroSuppressed + v
36 countZeroSuppressed = countZeroSuppressed + 1
38 meanYzeroSuppressed = sum / countZeroSuppressed
40 return (meanY, meanYzeroSuppressed)
42 def extractNtupleValues(ntuple_obj):
45 if ntuple_obj.GetEntries() > 0:
46 ent0 = ntuple_obj.GetEntry(0)
47 for branch
in ntuple_obj.GetListOfBranches():
48 branch_name = branch.GetName()
50 results.append((ntuple_obj.GetName() +
"_" + branch_name, float(getattr(ntuple_obj, branch_name))))
53 th1_like = [
lambda x: [(
"mean_x", x.GetMean(1))],
54 lambda x: [(
"entries", x.GetEntries())],
55 lambda x: [(
"mean_y", computeMean(x)[0])],
56 lambda x: [(
"mean_y_zero_suppressed", computeMean(x)[1])]]
58 tprofile = [
lambda x: [(
"mean_y", computeMean(x)[0])],
59 lambda x: [(
"mean_y_zero_suppressed", computeMean(x)[1])]]
61 tntuple = [extractNtupleValues]
63 return {
"TH1D": th1_like,
72 Class to automatically quntaties from ROOT Objects
77 Initialize the class with a set of quantity extractors
90 Adds an extractor to this class
92 @param class_type: the string you get when
93 running <root_object>.IsA().GetName()
94 This is used to map the correct extractor to
101 self.
extractor[class_type].append(extractor)
107 Extract quantities from a root object
109 @return: a dictionary of extracted quantities
111 this_class_type = obj.IsA().GetName()
114 ext_list = self.
extractor[this_class_type]
122 result += result_list