def test(max_entries=-1): ''' Tests the PhotonIdCorrector class. ''' global raw_data, target_data, corr, vplot varname = 'setab' option = 'skim10k' raw_name = 's12-zllm50-v7n' target_name = 'r12a-pho-j22-v1' raw_data = get_dataset(raw_name, varname, max_entries, option) target_data = get_dataset(target_name, varname, max_entries, option) xvar = raw_data.get().first() raw_data.SetTitle('Raw ' + raw_name.split('-')[0].capitalize()) target_data.SetTitle('Raw ' + target_name.split('-')[0].capitalize()) corr = PhotonIdCorrector(raw_data, target_data, rho=0.7) corr.SetName('_'.join([ raw_name.split('-')[0], 'to', target_name.split('-')[0], varname, 'qqcorrector' ])) corr.SetTitle(' '.join([ raw_name.split('-')[0].capitalize(), 'to', target_name.split('-')[0].capitalize(), xvar.GetTitle(), 'Q-Q Corrector' ])) plot = xvar.frame(roo.Title(raw_data.GetTitle())) raw_data.plotOn(plot) corr.xpdf.plotOn(plot) canvases.next(varname + '_' + raw_name.split('-')[0]).SetGrid() draw_and_append(plot) plot = xvar.frame(roo.Title(target_data.GetTitle())) target_data.plotOn(plot) corr.ypdf.plotOn(plot) canvases.next(varname + '_' + target_name.split('-')[0]).SetGrid() draw_and_append(plot) canvases.next(corr.GetName()).SetGrid() draw_and_append(corr.get_correction_plot()) canvases.next(corr.GetName() + '_validation').SetGrid() draw_and_append(corr.get_validation_plot()) canvases.update()
class QQExtractor: ''' Extracts the Q-Q corrections for photon ID variables. ''' #__________________________________________________________________________ def __init__(self, varname, raw_name, target_name, option='noskim', max_entries=-1, prescale=1, prescale_phase=0, rho=0.7): #print 'DEBUG', self.__class__.__name__, '__init__' common_args = [varname, option, max_entries, prescale, prescale_phase] self.raw = DataSource(raw_name, *common_args) self.target = DataSource(target_name, *common_args) self.corrector = PhotonIdCorrector(self.raw.data, self.target.data, rho) self.postprocess_corrector() ## End of QQExtractor.__init__(..) #__________________________________________________________________________ def postprocess_corrector(self): ''' Customizes corrector name and title and updetes raw and target sources with corrector pdfs. ''' name = '_'.join([self.raw.xvar.GetName(), 'qq']) title = ' '.join([ self.raw.xvar.GetTitle(), self.raw.name.split('-')[0].capitalize(), 'to', self.target.name.split('-')[0].capitalize(), 'Q-Q Corrector' ]) self.corrector.SetName(name) self.corrector.SetTitle(title) self.raw.pdf = self.corrector.xpdf self.target.pdf = self.corrector.ypdf ## End of QQExtractor.postprocess_corrector() #__________________________________________________________________________ def make_plots(self): ''' Makes plots of the raw and target source, the corrector function, and the corrected data. ''' for src in [self.raw, self.target]: plot = self.get_plot_of_source(src) canvases.next(src.varname + '_' + src.data.GetName()).SetGrid() self.draw_and_append(plot) ## Also with log scale on y-axis c = canvases.next(src.varname + '_' + src.data.GetName() + '_logy') c.SetGrid() c.SetLogy() plot.Draw() canvases.next(self.corrector.GetName()).SetGrid() self.draw_and_append(self.corrector.get_correction_plot()) canvases.next(self.corrector.GetName() + '_adiff').SetGrid() self.draw_and_append(self.corrector.get_absolute_difference_plot()) canvases.next(self.corrector.GetName() + '_rdiff').SetGrid() self.draw_and_append(self.corrector.get_relative_difference_plot()) plot = self.corrector.get_validation_plot() cname = self.corrector.GetName() + '_validation' canvases.next(cname).SetGrid() self.draw_and_append(plot) ## Also y-axis log-scale canvases.next(cname + '_logy').SetGrid() canvases.canvases[-1].SetLogy() plot.Draw() ## End of QQExtractor.make_plots(..) #__________________________________________________________________________ def get_plot_of_source(self, source): plot = source.xvar.frame(roo.Title(source.data.GetTitle())) source.data.plotOn(plot) source.pdf.plotOn(plot) return plot ## End of QQExtractor.get_plot_of_source() #__________________________________________________________________________ def draw_and_append(self, plot): if not hasattr(self, 'plots'): self.plots = [] plot.Draw() self.plots.append(plot) ## End of QQExtractor.draw_and_append(plot) #__________________________________________________________________________ def write_corrector_to_file(self, file_name): self.corrector.write_to_file(file_name, False) ## Also as an interpolation graph graph = self.corrector.get_interpolation_graph() out_file = ROOT.TFile.Open(file_name, "update") graph.Write() out_file.Write() out_file.Close()