Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
generic.models.PlotInfo.ComparisonSummary Class Reference
Inheritance diagram for generic.models.PlotInfo.ComparisonSummary:
object

Public Member Functions

def __init__ (self, plots)
 

Static Public Member Functions

def Chi2 (plot1, plot2)
 
def AndersonDarling (plot1, plot2)
 

Public Attributes

 plot_keys
 
 comparison_stats
 
short int type
 
short int number
 
char name [SIZE_OF_OBJ_NAME]
 
cat_entry star
 

Static Public Attributes

tuple COMPARISONS_TO_DO
 
list SORT_STATISTIC_PRIORITY = ["Chi2", "AndersonDarling"]
 

Detailed Description

Makes and stores information about the comparison between a pair of plots that are ostensibly the same distribution. 

Definition at line 162 of file PlotInfo.py.

Constructor & Destructor Documentation

def generic.models.PlotInfo.ComparisonSummary.__init__ (   self,
  plots 
)

Definition at line 173 of file PlotInfo.py.

173  def __init__(self, plots):
174  assert len(plots) == 2, "Can only build comparisons of pairs of plots. You gave me %d plots instead..." % len(plots)
175 
176  self.plot_keys = PlotSet()
177  for k in plots:
178  self.plot_keys.add(k)
179 
181  for comparison_test in ComparisonSummary.COMPARISONS_TO_DO:
182  self.comparison_stats[comparison_test] = getattr(ComparisonSummary, comparison_test)(*plots.values())
183 

Member Function Documentation

def generic.models.PlotInfo.ComparisonSummary.AndersonDarling (   plot1,
  plot2 
)
static

Definition at line 206 of file PlotInfo.py.

References check_time_usage.float, and PandAna.Demos.demo1.range.

206  def AndersonDarling(plot1, plot2):
207  stat_container = PlotComparisonStatistic(name="AndersonDarling")
208 
209  # todo: could make this work for (e.g.) TGraphs too
210  if not all(isinstance(p, ROOT.TH1) for p in (plot1, plot2)):
211  return stat_container
212 
213  # note that the Anderson-Darling, like most goodness-of-fit tests,
214  # doesn't make a lot of sense for > 1 dim distributions.
215  # (they're technically unbinned tests in the first place...)
216  if any(p.GetDimension() > 1 for p in (plot1, plot2)):
217  return stat_container
218 
219  # gotta pass the data in ROOT::Fit::BinData objects...
220  data_structures = []
221  for plot in (plot1, plot2):
222  val_sum = 0
223  ds = ROOT.Fit.BinData(plot.GetNbinsX())
224  for bin_num in range(1, plot.GetNbinsX()+1):
225  val = 0
226  if plot.GetBinContent(bin_num) != 0:
227  val = plot.GetBinContent(bin_num)
228  ds.Add(plot.GetXaxis().GetBinCenter(bin_num), val, plot.GetBinError(bin_num))
229 
230  val_sum += val
231 
232  # if no bins were nonzero, we can't do the Anderson-Darling comparison.
233  # also, if it will overflow when stuffed into a UInt_t, also abort.
234  # (the statistic calculator throws away empty bins, and the sum of the values,
235  # which is interpreted as a number of events,
236  # gets coerced to an integer which is used to index an array.)
237  if ds.Size() < 1 or val_sum < 1 or val_sum > 4294967295:
238  return stat_container
239 
240  data_structures.append(ds)
241 
242 
243  pval = ROOT.Double()
244  statistic = ROOT.Double()
245  args = data_structures
246  args.append(pval)
247  args.append(statistic)
248  ROOT.Math.GoFTest.AndersonDarling2SamplesTest(*args)
249  stat_container.statistic = float(statistic)
250  stat_container.p_value = float(pval)
251 
252  return stat_container
def generic.models.PlotInfo.ComparisonSummary.Chi2 (   plot1,
  plot2 
)
static

Definition at line 185 of file PlotInfo.py.

185  def Chi2(plot1, plot2):
186  stat_container = PlotComparisonStatistic(name="#chi^{2}")
187 
188  # todo: could make this work for (e.g.) TGraphs too
189  if not all(isinstance(p, ROOT.TH1) for p in (plot1, plot2)):
190  return stat_container
191 
192  # silly to have to call the method 3 times, but that's the only way to get all the info
193  pval = plot1.Chi2Test(plot2, "WW") # just assume they're weighted. doesn't hurt if all the weights are 1
194  chi2 = plot1.Chi2Test(plot2, "WW CHI2")
195  chi2norm = plot1.Chi2Test(plot2, "WW CHI2/NDF")
196  ndf = 0 if chi2norm == 0 else chi2 / chi2norm
197 
198  stat_container.statistic = chi2
199  stat_container.p_value = pval
200  stat_container.other_properties = {"ndf": ndf}
201 
202  return stat_container
203 
204 

Member Data Documentation

generic.models.PlotInfo.ComparisonSummary.comparison_stats

Definition at line 180 of file PlotInfo.py.

tuple generic.models.PlotInfo.ComparisonSummary.COMPARISONS_TO_DO
static
Initial value:
1 = (
2  "AndersonDarling",
3  "Chi2",
4 # "KS", # ROOT's TH1::KolgomorovTest() doesn't calculate p-values sensibly for histograms...
5  )

Definition at line 165 of file PlotInfo.py.

short int object::number
inherited

Definition at line 115 of file novas.h.

generic.models.PlotInfo.ComparisonSummary.plot_keys

Definition at line 176 of file PlotInfo.py.

list generic.models.PlotInfo.ComparisonSummary.SORT_STATISTIC_PRIORITY = ["Chi2", "AndersonDarling"]
static

Definition at line 171 of file PlotInfo.py.

cat_entry object::star
inherited

Definition at line 117 of file novas.h.

short int object::type
inherited

Definition at line 114 of file novas.h.


The documentation for this class was generated from the following file: