pair<double,double> bkgEvPerGeV(RooWorkspace *work, int m_hyp, int cat, int spin=false){ RooRealVar *mass = (RooRealVar*)work->var("CMS_hgg_mass"); if (spin) mass = (RooRealVar*)work->var("mass"); mass->setRange(100,180); RooAbsPdf *pdf = (RooAbsPdf*)work->pdf(Form("pdf_data_pol_model_8TeV_cat%d",cat)); RooAbsData *data = (RooDataSet*)work->data(Form("data_mass_cat%d",cat)); RooPlot *tempFrame = mass->frame(); data->plotOn(tempFrame,Binning(80)); pdf->plotOn(tempFrame); RooCurve *curve = (RooCurve*)tempFrame->getObject(tempFrame->numItems()-1); double nombkg = curve->Eval(double(m_hyp)); RooRealVar *nlim = new RooRealVar(Form("nlim%d",cat),"",0.,0.,1.e5); //double lowedge = tempFrame->GetXaxis()->GetBinLowEdge(FindBin(double(m_hyp))); //double upedge = tempFrame->GetXaxis()->GetBinUpEdge(FindBin(double(m_hyp))); //double center = tempFrame->GetXaxis()->GetBinUpCenter(FindBin(double(m_hyp))); nlim->setVal(nombkg); mass->setRange("errRange",m_hyp-0.5,m_hyp+0.5); RooAbsPdf *epdf = 0; epdf = new RooExtendPdf("epdf","",*pdf,*nlim,"errRange"); RooAbsReal *nll = epdf->createNLL(*data,Extended(),NumCPU(4)); RooMinimizer minim(*nll); minim.setStrategy(0); minim.setPrintLevel(-1); minim.migrad(); minim.minos(*nlim); double error = (nlim->getErrorLo(),nlim->getErrorHi())/2.; data->Print(); return pair<double,double>(nombkg,error); }
double getMyNLL(RooRealVar *var, RooAbsPdf *pdf, RooDataHist *data){ RooPlot *plot = var->frame(); data->plotOn(plot); pdf->plotOn(plot); RooCurve *pdfCurve = (RooCurve*)plot->getObject(plot->numItems()-1); double sum=0.; for (int i=0; i<data->numEntries(); i++){ double binCenter = data->get(i)->getRealValue("CMS_hgg_mass"); double weight = data->weight(); sum+=TMath::Log(TMath::Poisson(100.*weight,100.*pdfCurve->Eval(binCenter))); } return -1.*sum; }