TH1D* makeHist(bool convertToLinearBinning) { double binLowEdges[41] = {130,140.761,152.413,165.03,178.691,193.483,209.5,226.842,245.62,265.952,287.968,311.805,337.616,365.564,395.825,428.592,464.07,502.486,544.081,589.12,637.887,690.691,747.866,809.774,876.807,949.389,1027.98,1113.07,1205.21,1304.98,1413.01,1529.97,1656.62,1793.76,1942.25,2103.02,2277.11,2465.61,2669.71,2890.71,3130}; if(convertToLinearBinning) { for(int i=0; i<41; i++) binLowEdges[i] = binLowEdges[0] + i*(binLowEdges[40] - binLowEdges[0])/40; } double binCenters[40]; for(int i=0; i<40; i++) binCenters[i] = (binLowEdges[i] + binLowEdges[i+1])/2.; double bkgWeights[40] = {42350,31800,24620,19600,15710,12530,9940,8110,6404,5220,4022,3221,2543,1912,1555,1132,827,680,490,362,260,201,166,101,78,49,36,26,14,11,8,5,5,3,4,2,3,1,2,1}; TH1D* hist = new TH1D("name","name",40,&binLowEdges[0]); hist->FillN(40,&binCenters[0],&bkgWeights[0]); return hist; } void plotHistPdf() { //At least one of the following must be true to fix the plotting bug! bool doNotCallRange = false; bool normalizeByHand = false; bool convertToLinearBinning = false; TH1D* hist = makeHist(convertToLinearBinning); RooRealVar x("x","x",hist->GetXaxis()->GetXmin(),hist->GetXaxis()->GetXmax()); RooDataHist rooHist("rooHist","",RooArgSet(x), hist); RooHistPdf* histPdf = new RooHistPdf("histPdf","histPdf",x,rooHist); RooCmdArg plotCmd; RooCmdArg normCmd; if(!doNotCallRange) { //Note this range simply covers the entire x-axis! x.setRange("myRange",x.getMin(),x.getMax()); plotCmd = RooFit::Range("myRange"); } if(normalizeByHand) { normCmd = RooFit::Normalization(hist->GetSumOfWeights(),RooAbsReal::NumEvent); } RooPlot* rp = x.frame(); rooHist.plotOn(rp); histPdf->plotOn(rp,plotCmd,normCmd); rp->Draw(); }