def test_vectors( self ): h_signal = adjust_overflow_to_limit( self.h_signal, x_min, x_max ) h_signal.Scale(1/h_signal.Integral()) h_bkg1 = adjust_overflow_to_limit( self.h_bkg1, x_min, x_max ) h_bkg1.Scale(1/h_bkg1.Integral()) signal = list( h_signal.y() ) bkg1 = list( h_bkg1.y() ) v_from_fit_data = self.fit_data_1.vectors v_from_single_collection = self.single_collection.vectors() # v_from_collection = self.collection_1.vectors( 'signal region' ) # v_from_collection_1 = self.collection_1.vectors()['signal region'] self.assertEqual(signal, v_from_fit_data['signal']) self.assertEqual(bkg1, v_from_fit_data['bkg1']) self.assertEqual(signal, v_from_single_collection['signal']) self.assertEqual(bkg1, v_from_single_collection['bkg1'])
def test_vectors(self): h_signal = adjust_overflow_to_limit(self.h_signal, x_min, x_max) h_signal.Scale(1 / h_signal.Integral()) h_bkg1 = adjust_overflow_to_limit(self.h_bkg1, x_min, x_max) h_bkg1.Scale(1 / h_bkg1.Integral()) signal = list(h_signal.y()) bkg1 = list(h_bkg1.y()) v_from_fit_data = self.fit_data_1.vectors v_from_single_collection = self.single_collection.vectors() # v_from_collection = self.collection_1.vectors( 'signal region' ) # v_from_collection_1 = self.collection_1.vectors()['signal region'] self.assertEqual(signal, v_from_fit_data['signal']) self.assertEqual(bkg1, v_from_fit_data['bkg1']) self.assertEqual(signal, v_from_single_collection['signal']) self.assertEqual(bkg1, v_from_single_collection['bkg1'])
def test_adjust_overflow_to_limit( self ): x_min = 40 x_max = 80 adjusted = adjust_overflow_to_limit(self.h1, x_min, x_max) # number of events should be unchanged # the adjusted histogram should have no overflow for this example self.assertEqual(self.h1.integral( overflow = True ), adjusted.Integral()) # first bin (x_min) should contain all events # with x <= x_min x_min_bin = self.h1.FindBin(x_min) x_max_bin = self.h1.FindBin(x_max) self.assertEqual(self.h1.integral(0, x_min_bin), adjusted.GetBinContent(x_min_bin)) # last bin (x_max) should contain all events # with x >= x_max self.assertEqual( self.h1.integral( x_max_bin, self.h1.nbins() + 1 ), adjusted.GetBinContent( x_max_bin ) )
def test_adjust_overflow_to_limit(self): x_min = 40 x_max = 80 adjusted = adjust_overflow_to_limit(self.h1, x_min, x_max) # number of events should be unchanged # the adjusted histogram should have no overflow for this example self.assertEqual(self.h1.integral(overflow=True), adjusted.Integral()) # first bin (x_min) should contain all events # with x <= x_min x_min_bin = self.h1.FindBin(x_min) x_max_bin = self.h1.FindBin(x_max) self.assertEqual(self.h1.integral(0, x_min_bin), adjusted.GetBinContent(x_min_bin)) # last bin (x_max) should contain all events # with x >= x_max self.assertEqual(self.h1.integral(x_max_bin, self.h1.nbins() + 1), adjusted.GetBinContent(x_max_bin))
def test_adjust_overflow_to_limit_simple( self ): x_min = 0 x_max = 95 adjusted = adjust_overflow_to_limit(self.simple, x_min, x_max) # for entry_1, entry_2 in zip(hist_to_value_error_tuplelist(self.simple), hist_to_value_error_tuplelist(adjusted)): # print entry_1, entry_2 # print self.simple.integral( overflow = True ), adjusted.integral() # print self.simple.GetBinContent(1), self.simple.GetBinContent(self.simple.nbins()) # number of events should be unchanged # the adjusted histogram should have no overflow for this example self.assertEqual( self.simple.integral( overflow = True ), adjusted.integral() ) # first bin (x_min) should contain all events # with x <= x_min x_min_bin = self.simple.FindBin(x_min) x_max_bin = self.simple.FindBin(x_max) self.assertEqual(self.simple.integral(0, x_min_bin), adjusted.GetBinContent(x_min_bin)) # last bin (x_max) should contain all events # with x >= x_max self.assertEqual( self.simple.integral( x_max_bin, self.simple.nbins() + 1), adjusted.GetBinContent( x_max_bin ) )
def test_normalisation(self): normalisation = { name: adjust_overflow_to_limit(histogram, x_min, x_max).Integral() for name, histogram in self.histograms_1.iteritems() } normalisation_from_fit_data = self.fit_data_1.normalisation normalisation_from_single_collection = self.single_collection.mc_normalisation( ) normalisation_from_collection = self.collection_1.mc_normalisation( 'signal region') normalisation_from_collection_1 = self.collection_1.mc_normalisation( )['signal region'] for sample in normalisation.keys(): self.assertEqual(normalisation[sample], normalisation_from_fit_data[sample]) self.assertEqual(normalisation[sample], normalisation_from_single_collection[sample]) self.assertEqual(normalisation[sample], normalisation_from_collection[sample]) self.assertEqual(normalisation[sample], normalisation_from_collection_1[sample]) # data normalisation normalisation = self.h_data.integral(overflow=True) normalisation_from_fit_data = self.fit_data_1.n_data() normalisation_from_single_collection = self.single_collection.n_data() normalisation_from_collection = self.collection_1.n_data( 'signal region') normalisation_from_collection_1 = self.collection_1.n_data( )['signal region'] self.assertEqual(normalisation, normalisation_from_fit_data) self.assertEqual(normalisation, normalisation_from_single_collection) self.assertEqual(normalisation, normalisation_from_collection) self.assertEqual(normalisation, normalisation_from_collection_1) self.assertAlmostEqual(normalisation, self.collection_1.max_n_data(), delta=1)
def test_normalisation( self ): normalisation = {name:adjust_overflow_to_limit(histogram, x_min, x_max).Integral() for name, histogram in self.histograms_1.iteritems()} normalisation_from_fit_data = self.fit_data_1.normalisation normalisation_from_single_collection = self.single_collection.mc_normalisation() normalisation_from_collection = self.collection_1.mc_normalisation( 'signal region' ) normalisation_from_collection_1 = self.collection_1.mc_normalisation()['signal region'] for sample in normalisation.keys(): self.assertEqual( normalisation[sample], normalisation_from_fit_data[sample] ) self.assertEqual( normalisation[sample], normalisation_from_single_collection[sample] ) self.assertEqual( normalisation[sample], normalisation_from_collection[sample] ) self.assertEqual( normalisation[sample], normalisation_from_collection_1[sample] ) # data normalisation normalisation = self.h_data.integral( overflow = True ) normalisation_from_fit_data = self.fit_data_1.n_data() normalisation_from_single_collection = self.single_collection.n_data() normalisation_from_collection = self.collection_1.n_data( 'signal region' ) normalisation_from_collection_1 = self.collection_1.n_data()['signal region'] self.assertEqual( normalisation, normalisation_from_fit_data ) self.assertEqual( normalisation, normalisation_from_single_collection ) self.assertEqual( normalisation, normalisation_from_collection ) self.assertEqual( normalisation, normalisation_from_collection_1 ) self.assertAlmostEqual(normalisation, self.collection_1.max_n_data(), delta = 1 )
def test_adjust_overflow_to_limit_simple(self): x_min = 0 x_max = 95 adjusted = adjust_overflow_to_limit(self.simple, x_min, x_max) # for entry_1, entry_2 in zip(hist_to_value_error_tuplelist(self.simple), hist_to_value_error_tuplelist(adjusted)): # print entry_1, entry_2 # print self.simple.integral( overflow = True ), adjusted.integral() # print self.simple.GetBinContent(1), self.simple.GetBinContent(self.simple.nbins()) # number of events should be unchanged # the adjusted histogram should have no overflow for this example self.assertEqual(self.simple.integral(overflow=True), adjusted.integral()) # first bin (x_min) should contain all events # with x <= x_min x_min_bin = self.simple.FindBin(x_min) x_max_bin = self.simple.FindBin(x_max) self.assertEqual(self.simple.integral(0, x_min_bin), adjusted.GetBinContent(x_min_bin)) # last bin (x_max) should contain all events # with x >= x_max self.assertEqual( self.simple.integral(x_max_bin, self.simple.nbins() + 1), adjusted.GetBinContent(x_max_bin))