def computeBkgYieldsFromABCDData(self): ''' Estimate background yields from data using the ABCD method A = b_mass < 6.27 && hnl_charge == 0 (SR) B = b_mass < 6.27 && hnl_charge != 0 C = b_mass > 6.27 && hnl_charge == 0 D = b_mass > 6.27 && hnl_charge != 0 N_A = N_B * N_C/N_D ''' f_data = ROOT.TFile.Open('root://t3dcachedb.psi.ch:1094/'+self.data_file.filename, 'READ') #quantity = Quantity(name_flat='hnl_mass', nbins=1, bin_min=0, bin_max=1000) quantity = Quantity(name_flat='hnl_mass', nbins=1, bin_min=2.83268, bin_max=3.13932) bin_selection = self.selection #hist_data_B = PlottingTools.createHisto(self, f_data, 'signal_tree', quantity, branchname='flat', selection=bin_selection+' && b_mass<6.27 && hnl_charge!=0') #hist_data_C = PlottingTools.createHisto(self, f_data, 'signal_tree', quantity, branchname='flat', selection=bin_selection+' && b_mass>6.27 && hnl_charge==0') #hist_data_D = PlottingTools.createHisto(self, f_data, 'signal_tree', quantity, branchname='flat', selection=bin_selection+' && b_mass>6.27 && hnl_charge!=0') hist_data_B = PlottingTools.createHisto(self, f_data, 'signal_tree', quantity, branchname='flat', selection=bin_selection+' && hnl_cos2d>0.993 && sv_prob<0.05') hist_data_C = PlottingTools.createHisto(self, f_data, 'signal_tree', quantity, branchname='flat', selection=bin_selection+' && hnl_cos2d<0.993 && sv_prob>0.05') hist_data_D = PlottingTools.createHisto(self, f_data, 'signal_tree', quantity, branchname='flat', selection=bin_selection+' && hnl_cos2d<0.993 && sv_prob<0.05') #hist_data.Sumw2() n_obs_data_B = hist_data_B.GetBinContent(1) n_obs_data_C = hist_data_C.GetBinContent(1) n_obs_data_D = hist_data_D.GetBinContent(1) n_err_data_B = math.sqrt(hist_data_B.GetBinContent(1)) n_err_data_C = math.sqrt(hist_data_C.GetBinContent(1)) n_err_data_D = math.sqrt(hist_data_D.GetBinContent(1)) n_obs_data_A = n_obs_data_B * (n_obs_data_C / n_obs_data_D) n_err_data_A = n_obs_data_A * (n_err_data_B / n_obs_data_B + n_err_data_C / n_obs_data_C + n_err_data_D / n_obs_data_D) return int(n_obs_data_A), int(n_err_data_A)
def getSignalEfficiency(self): ''' eff(bin) = N_flat(bin) / N_gen N_gen = N_reco / filter_efficiency ''' # get number of generated events f = ROOT.TFile.Open('root://t3dcachedb.psi.ch:1094/'+self.signal_file.filename, 'READ') n_reco = PlottingTools.getNminiAODEvts(self, f) n_gen = n_reco / self.signal_file.filter_efficiency # get number of selected reco events quantity = Quantity(name_flat='hnl_mass', nbins=1, bin_min=0, bin_max=1000) hist_flat_bin = PlottingTools.createHisto(self, f, 'signal_tree', quantity, branchname='flat', selection='ismatched==1' if self.selection=='' else 'ismatched==1 && '+self.selection) n_selected_bin = hist_flat_bin.GetBinContent(1) #print 'n_selected_bin',n_selected_bin efficiency = n_selected_bin / n_gen #print 'efficiency',efficiency return efficiency
def computeApproxWeightQCDMCtoData(self, quantity, selection): ''' weight = lumi_data / lumi_mc = N_data * sigma_mc / (N_mc * sigma_data) estimated as N_data / N_mc ''' f_data = ROOT.TFile.Open('root://t3dcachedb.psi.ch:1094/'+self.data_file.filename, 'READ') hist_data = PlottingTools.createHisto(self, f_data, 'signal_tree', quantity, branchname='flat', selection=selection) hist_data.Sumw2() n_obs_data = hist_data.GetBinContent(1) n_err_data = math.sqrt(n_obs_data) #hist_data.GetBinError(1) hist_mc_tot = PlottingTools.createWeightedHistoQCDMC(self, self.qcd_files, self.white_list, quantity=quantity, selection=selection) n_obs_mc = hist_mc_tot.GetBinContent(1) n_err_mc = math.sqrt(n_obs_mc) #hist_mc_tot.GetBinError(1) weight = n_obs_data / n_obs_mc if n_obs_data != 0 and n_obs_mc != 0: err = weight* (n_err_data / n_obs_data + n_err_mc / n_obs_mc) else: err = 0 return weight, err