CMS 3D CMS Logo

Public Member Functions | Public Attributes

utils::Chi2 Class Reference

Inheritance diagram for utils::Chi2:
utils::StatisticalTest

List of all members.

Public Member Functions

def __init__
def absval
def check_filled_bins
def check_histograms
def do_test

Public Attributes

 name

Detailed Description

Definition at line 238 of file utils.py.


Constructor & Destructor Documentation

def utils::Chi2::__init__ (   self,
  threshold 
)

Reimplemented from utils::StatisticalTest.

Definition at line 239 of file utils.py.

00240                                :
00241     StatisticalTest.__init__(self,threshold)
00242     self.name="Chi2"     


Member Function Documentation

def utils::Chi2::absval (   self)

Definition at line 254 of file utils.py.

00255                   :
00256     nbins=getNbins(self.h1)
00257     binc=0
00258     for i in xrange(1,nbins):
00259       for h in self.h1,self.h2:
00260         binc=h.GetBinContent(i)
00261         if binc<0:
00262           h.SetBinContent(i,-1*binc)
00263         if h.GetBinError(i)==0 and binc!=0:
00264           #print "Histo ",h.GetName()," Bin:",i,"-Content:",h.GetBinContent(i)," had zero error"
00265           h.SetBinContent(i,0)

def utils::Chi2::check_filled_bins (   self,
  min_filled 
)

Definition at line 243 of file utils.py.

00244                                         :
00245     nbins=self.h1.GetNbinsX()
00246     n_filled_l=[]
00247     for h in self.h1,self.h2:
00248       nfilled=0.
00249       for ibin in xrange(1,nbins+1):
00250         if h.GetBinContent(ibin)>0:
00251           nfilled+=1
00252       n_filled_l.append(nfilled)
00253     return len(filter (lambda x:x>=min_filled,n_filled_l) )>0

def utils::Chi2::check_histograms (   self,
  histogram 
)

Definition at line 266 of file utils.py.

00267                                        :
00268       if histogram.InheritsFrom("TProfile") or  (histogram.GetEntries()!=histogram.GetSumOfWeights()):
00269           return 'W'
00270       else:
00271           return 'U'

def utils::Chi2::do_test (   self)

Reimplemented from utils::StatisticalTest.

Definition at line 272 of file utils.py.

00273                    :
00274     self.absval()
00275     if self.check_filled_bins(3):
00276       #if self.h1.InheritsFrom("TProfile") or  (self.h1.GetEntries()!=self.h1.GetSumOfWeights()):
00277       #  chi2=self.h1.Chi2Test(self.h2,'WW')
00278       #  #if chi2==0: print "DEBUG",self.h1.GetName(),"Chi2 is:", chi2
00279       #  return chi2
00280       #else:
00281       #  return self.h1.Chi2Test(self.h2,'UU')
00282       hist1 = self.check_histograms(self.h1)
00283       hist2 = self.check_histograms(self.h2)
00284       if hist1 =='W' and hist2 =='W': ##in case 
00285           chi2 = self.h1.Chi2Test(self.h2,'WW')     ## the both histograms are weighted
00286           return chi2
00287       elif hist1 == 'U' and hist2 == 'U':
00288           chi2 = self.h1.Chi2Test(self.h2,'UU')    ##the both histograms are unweighted
00289           return chi2
00290       elif hist1 == 'U' and hist2 == 'W':
00291           chi2 = self.h1.Chi2Test(self.h2,'UW')   ## 1st histogram is unweighted, 2nd weighted
00292           return chi2
00293       elif hist1 == 'W' and hist2 == 'U':
00294           chi2 = self.h2.Chi2Test(self.h1,'UW')   ## 1 is wieghted, 2nd unweigthed. so flip order to make a UW comparison
00295           return chi2
00296     else:
00297       return 1
00298       #return test_codes["FEW_BINS"]
00299 
00300 #-------------------------------------------------------------------------------


Member Data Documentation

Reimplemented from utils::StatisticalTest.

Definition at line 239 of file utils.py.