13Functionality to extract quantities from various ROOT objects (TH1).
17def default_extractor():
19 Returns a list of default extractors for the most common
23 def computeMean(profile_obj):
25 compute the mean values of the y dimension, also with
28 nbinsx = profile_obj.GetNbinsX()
30 sumZeroSuppressed = 0.0
31 countZeroSuppressed = 0
32 for i
in range(nbinsx):
33 v = profile_obj.GetBinContent(i + 1)
38 sumZeroSuppressed = sumZeroSuppressed + v
39 countZeroSuppressed = countZeroSuppressed + 1
41 meanYzeroSuppressed = sum / countZeroSuppressed
43 return (meanY, meanYzeroSuppressed)
45 def extractNtupleValues(ntuple_obj):
48 if ntuple_obj.GetEntries() > 0:
50 for branch
in ntuple_obj.GetListOfBranches():
51 branch_name = branch.GetName()
55 ntuple_obj.GetName() +
"_" + branch_name,
56 float(getattr(ntuple_obj, branch_name)),
62 lambda x: [(
"mean_x", x.GetMean(1))],
63 lambda x: [(
"entries", x.GetEntries())],
64 lambda x: [(
"mean_y", computeMean(x)[0])],
65 lambda x: [(
"mean_y_zero_suppressed", computeMean(x)[1])],
69 lambda x: [(
"mean_y", computeMean(x)[0])],
70 lambda x: [(
"mean_y_zero_suppressed", computeMean(x)[1])],
73 tntuple = [extractNtupleValues]
86 Class to automatically extract quantities from ROOT Objects
91 Initialize the class with a set of quantity extractors
104 Adds an extractor to this class
106 @param class_type: the string you get when
107 running <root_object>.IsA().GetName()
108 This
is used to map the correct extractor to
115 self.
extractor[class_type].append(extractor)
119 def extract(self, obj):
121 Extract quantities from a root object
123 @return: a dictionary of extracted quantities
125 this_class_type = obj.IsA().GetName()
128 ext_list = self.
extractor[this_class_type]
136 result += result_list