def get_plot_of_data_overlayed_with_model(w): ''' RooPlot get_plot_data_overlayed_with_model(w) Returns a RooPlot of of data overlayed with the model. It takes if from the workspace if present, creates it and adds it to the workspace if needed. Preconditions: Data and model are in the workspace. Postconditions: RooPlot gauss_with_data is added to the workspace. ''' ## Retrieve the plot from the workspace. name = 'gauss_with_data' xframe = w.obj(name) ## Check if it was actually there. if xframe: ## We are done. return xframe else: ## Construct plot frame in 'x'. xframe = w.var('x').frame(roo.Name(name), roo.Title('Gaussian PDF with data')) ## Draw the data on the frame. w.data('data').plotOn(xframe) ## Draw the model on the frame. w.pdf('gauss').plotOn(xframe) w.Import(xframe) return xframe
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()
def plot_model_and_change_parameter_values(w): ''' void plot_model_and_change_parameter_values(w) Plots model `gaus' and changes the parameter values. ''' ## Construct plot frame in 'x' xframe = w.var('x').frame(roo.Title('Gaussian PDF')) ## Plot gauss in frame (i.e. in x). w.pdf('gauss').plotOn(xframe) ## Change the value of sigma to 3. w.var('sigma').setVal(3) ## Plot gauss in frame (i.e. in x) and draw frame on canvases. w.pdf('gauss').plotOn(xframe, roo.LineColor(ROOT.kRed)) ## Create a canvas and draw the plot frame on it. canvases.next('Gaussian_PDF') xframe.Draw()
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
def main(): ''' Main entry point of execution. ''' ## C r e a t e d a t a s e t w i t h X a n d Y v a l u e s ## ------------------------------------------------------------------- ## Make weighted XY dataset with asymmetric errors stored ## The StoreError() argument is essential as it makes ## the dataset store the error in addition to the values ## of the observables. If errors on one or more observables ## are asymmetric, one can store the asymmetric error ## using the StoreAsymError() argument x = ROOT.RooRealVar('x', 'x', -11, 11) y = ROOT.RooRealVar('y', 'y', -10, 200) dxy = ROOT.RooDataSet('dxy', 'dxy', ROOT.RooArgSet(x, y), roo.StoreError(ROOT.RooArgSet(x, y))) ## Fill an example dataset with X,err(X),Y,err(Y) values for i in range(11): ## Set X value and error x.setVal(-10 + 2 * i) if i < 5: x.setError(0.5 / 1.) else: x.setError(1.0 / 1.) ## Set Y value and error y.setVal(x.getVal() * x.getVal() + 4 * math.fabs(ROOT.gRandom.Gaus())) y.setError(math.sqrt(y.getVal())) dxy.add(ROOT.RooArgSet(x, y)) ## End of loop over dxy entries ## P e r f o r m c h i 2 f i t t o X + / - d x a n d Y + / - d Y v a l u e s ## --------------------------------------------------------------------------------------- ## Make fit function a = ROOT.RooRealVar('a', 'a', 0.0, -10, 10) b = ROOT.RooRealVar('b', 'b', 0, -100, 100) f = ROOT.RooPolyVar('f', 'f', x, ROOT.RooArgList(b, a, roo.RooConst(1))) ## Plot dataset in X-Y interpretation frame = x.frame( roo.Title('#chi^{2} fit of function set of ' '(X#pmdX,Y#pmdY) values')) dxy.plotOnXY(frame, roo.YVar(y)) ## Fit chi^2 using X and Y errors f.chi2FitTo(dxy, roo.YVar(y)) ## Overlay fitted function f.plotOn(frame) ## Alternative: fit chi^2 integrating f(x) over ranges defined by X errors, ## rather than taking point at center of bin f.chi2FitTo(dxy, roo.YVar(y), roo.Integrate(True)) ## Overlay alternate fit result f.plotOn(frame, roo.LineStyle(ROOT.kDashed), roo.LineColor(ROOT.kRed)) ## Draw the plot on a canvas canvases.wwidth = 600 canvases.wheight = 600 canvases.next('rf609_xychi2fit') ROOT.gPad.SetLeftMargin(0.15) ROOT.gPad.SetTopMargin(0.1) frame.GetYaxis().SetTitleOffset(1.0) frame.Draw() canvases.update()