void FitterUtils::PlotShape2D(RooDataSet& originDataSet, RooDataSet& genDataSet, RooAbsPdf& shape, string plotsfile, string canvName, RooRealVar& B_plus_M, RooRealVar& misPT) { //**************Prepare TFile to save the plots TFile f2(plotsfile.c_str(), "UPDATE"); //**************Plot Signal Zero Gamma TH2F* th2fKey = (TH2F*)shape.createHistogram("th2Shape", B_plus_M, Binning(20), YVar(misPT, Binning(20))); cout<<genDataSet.sumEntries()<<endl; TH2F* th2fGen = (TH2F*)genDataSet.createHistogram("th2fGen", B_plus_M, Binning(20), YVar(misPT, Binning(20))); RooPlot* plotM = B_plus_M.frame(); originDataSet.plotOn(plotM); shape.plotOn(plotM); RooPlot* plotMisPT = misPT.frame(); originDataSet.plotOn(plotMisPT); shape.plotOn(plotMisPT); TCanvas canv(canvName.c_str(), canvName.c_str(), 800, 800); canv.Divide(2,2); canv.cd(1); th2fGen->Draw("lego"); canv.cd(2); th2fKey->Draw("surf"); canv.cd(3); plotM->Draw(); canv.cd(4); plotMisPT->Draw(); canv.Write(); f2.Close(); }
void TestNonCentral(){ RooWorkspace w("w"); // k <2, must use sum w.factory("NonCentralChiSquare::nc(x[0,50],k[1.99,0,5],lambda[5])"); // kk > 2 can use bessel w.factory("NonCentralChiSquare::ncc(x,kk[2.01,0,5],lambda)"); // kk > 2, force sum w.factory("NonCentralChiSquare::nccc(x,kk,lambda)"); ((RooNonCentralChiSquare*)w.pdf("nccc"))->SetForceSum(true); // a normal "central" chi-square for comparision when lambda->0 w.factory("ChiSquarePdf::cs(x,k)"); //w.var("kk")->setVal(4.); // test a large kk RooDataSet* ncdata = w.pdf("nc")->generate(*w.var("x"),100); RooDataSet* csdata = w.pdf("cs")->generate(*w.var("x"),100); RooPlot* plot = w.var("x")->frame(); ncdata->plotOn(plot,MarkerColor(kRed)); csdata->plotOn(plot,MarkerColor(kBlue)); w.pdf("nc")->plotOn(plot,LineColor(kRed)); w.pdf("ncc")->plotOn(plot,LineColor(kGreen)); w.pdf("nccc")->plotOn(plot,LineColor(kYellow),LineStyle(kDashed)); w.pdf("cs")->plotOn(plot,LineColor(kBlue),LineStyle(kDotted)); plot->Draw(); }
int main(){ RooMsgService::instance().setGlobalKillBelow(ERROR); TFile *bkgFile = TFile::Open("comb_svn/hgg.inputbkgdata_8TeV_MVA.root"); RooWorkspace *bkgWS = (RooWorkspace*)bkgFile->Get("cms_hgg_workspace"); RooRealVar *mass = (RooRealVar*)bkgWS->var("CMS_hgg_mass"); RooDataSet *data = (RooDataSet*)bkgWS->data("data_mass_cat0"); RooRealVar *p1 = new RooRealVar("p1","p1",-2.,-10.,0.); RooRealVar *p2 = new RooRealVar("p2","p2",-0.001,-0.01,0.01); RooRealVar *p3 = new RooRealVar("p3","p3",-0.0001,-0.01,0.01); //RooPowerLawSum *pow1 = new RooPowerLawSum("pow","pow",*mass,RooArgList(*p1)); //RooPowerLawSum *pow2 = new RooPowerLawSum("pow","pow",*mass,RooArgList(*p1,*p2)); //RooPowerLawSum *pow3 = new RooPowerLawSum("pow","pow",*mass,RooArgList(*p1,*p2,*p3)); RooExponentialSum *pow1 = new RooExponentialSum("pow1","pow1",*mass,RooArgList(*p1)); RooExponentialSum *pow2 = new RooExponentialSum("pow2","pow2",*mass,RooArgList(*p1,*p2)); RooExponentialSum *pow3 = new RooExponentialSum("pow3","pow3",*mass,RooArgList(*p1,*p2,*p3)); TCanvas *canv = new TCanvas(); RooPlot *frame = mass->frame(); data->plotOn(frame); cout << "bus" << endl; pow1->fitTo(*data,PrintEvalErrors(-1),PrintLevel(-1),Warnings(-1),Verbose(-1)); cout << "bus" << endl; pow1->plotOn(frame); pow2->fitTo(*data); pow2->plotOn(frame,LineColor(kRed),LineStyle(kDashed)); pow3->fitTo(*data); pow3->plotOn(frame,LineColor(kGreen),LineStyle(7)); frame->Draw(); canv->Print("test.pdf"); TFile *outFile = new TFile("test.root","RECREATE"); TTree *tree = new TTree("tree","tree"); vector<double> mu; mu.push_back(1.); mu.push_back(2.); mu.push_back(3.); mu.push_back(4.); vector<string> label; label.push_back("pol"); label.push_back("pow"); label.push_back("lau"); label.push_back("exp"); tree->Branch("mu",&mu); tree->Branch("label",&label); tree->Fill(); outFile->cd(); tree->Write(); outFile->Close(); return 0; }
RooDataHist * genHistFromModelPdf(const char * name, RooAbsPdf *model, RooRealVar *var, double ScaleLumi, int range, int rebin, int seed ) { double genEvents = model->expectedEvents(*var); TRandom3 *rndm = new TRandom3(); rndm->SetSeed(seed); double nEvt = rndm->PoissonD( genEvents) ; int intEvt = ( (nEvt- (int)nEvt) >= 0.5) ? (int)nEvt +1 : int(nEvt); RooDataSet * data = model->generate(*var , intEvt ); cout<< " expected events for " << name << " = "<< genEvents << endl; cout<< " data->numEntries() for name " << name << " == " << data->numEntries()<< endl; // cout<< " nEvt from PoissonD for" << name << " == " << nEvt<< endl; //cout<< " cast of nEvt for" << name << " == " << intEvt<< endl; RooAbsData *binned_data = data->binnedClone(); TH1 * toy_hist = binned_data->createHistogram( name, *var, Binning(range/rebin ) ); for(int i = 1; i <= toy_hist->GetNbinsX(); ++i) { toy_hist->SetBinError( i, sqrt( toy_hist->GetBinContent(i)) ); if(toy_hist->GetBinContent(i) == 0.00) { cout<< " WARNING: histo " << name << " has 0 enter in bin number " << i << endl; } if(toy_hist->GetBinContent(i) < 0.1) { toy_hist->SetBinContent(i, 0.0); toy_hist->SetBinError(i, 0.0); cout<< " WARNING: setting value 0.0 to histo " << name << " for bin number " << i << endl; } } RooDataHist * toy_rooHist = new RooDataHist(name, name , RooArgList(*var), toy_hist ); return toy_rooHist; }
void AnalyzeToy::extract_signal() { calculate_yield(); MakeSpinSPlot splotter(toyData); splotter.addSpecies("signal",ws->pdf("model_signal_mass"),signalYield); splotter.addSpecies("background",ws->pdf("model_bkg_mass"),backgroundYield); splotter.addVariable(ws->var("mass")); splotter.calculate(); RooDataSet *sweights = splotter.getSWeightDataSet(); sweights->SetName("sweights"); RooRealVar weight("weight","",-5.,5.); RooArgSet event; event.add(*mass); event.add(*cosT); event.add(weight); extractedData = new RooDataSet("extractedData","",event,WeightVar("weight")); Long64_t nEntries = toyData->numEntries(); for(int i=0;i<nEntries;i++) { double weight_double=0; weight_double += sweights->get(i)->getRealValue("signal_sw"); // weight_double += sweights->get(i)->getRealValue("background_sw"); mass->setVal(toyData->get(i)->getRealValue("mass")); cosT->setVal(toyData->get(i)->getRealValue("cosT")); extractedData->add(event,weight_double); } delete toyData; }
void trig_pt() { TCanvas *myCan=new TCanvas("myCan","myCan"); myCan->SetGrid(); TFile *f_MC= new TFile("TnP_WptCutToTrig_MCptminus.root","read"); RooDataSet *datasetMC = (RooDataSet*)f_MC->Get("tpTree/Tnp_WptCut_to_Mu15_eta2p1_pt/cnt_eff"); cout<<"ntry: "<<datasetMC->numEntries()<<endl; double XMC[Nbin],XMCerrL[Nbin],XMCerrH[Nbin],YMC[Nbin],YMCerrLo[Nbin],YMCerrHi[Nbin]; for(int i(0); i<datasetMC->numEntries();i++) { const RooArgSet &pointMC=*datasetMC->get(i); RooRealVar &ptMC=pointMC["pt"],&effMC = pointMC["efficiency"]; XMC[i]=ptMC.getVal(); XMCerrL[i]=-ptMC.getAsymErrorLo(); XMCerrH[i]=ptMC.getAsymErrorHi(); YMC[i]=effMC.getVal(); YMCerrLo[i]=-effMC.getAsymErrorLo(); YMCerrHi[i]=effMC.getAsymErrorHi(); } grMC=new TGraphAsymmErrors(11,XMC,YMC,XMCerrL,XMCerrH,YMCerrLo,YMCerrHi); grMC->SetLineColor(kRed); grMC->SetMarkerColor(kRed); grMC->Draw("AP"); //grMC->Draw("psame"); myCan->SaveAs("trig_McMinus_pt.png"); myCan->SaveAs("trig_McMinus_pt.eps"); }
void Plot(RooAbsPdf *iGen,RooAbsPdf *iFit,int iN,int iNEvents,RooRealVar &iVar,RooRealVar &iSig,RooRealVar &iMean, RooRealVar &iScale,RooRealVar &iRes,RooDataSet *iData=0) { TRandom1 *lRand = new TRandom1(0xDEADBEEF); RooDataSet * lSignal = iGen->generate(iVar,iNEvents); if(iData == 0) { iFit->fitTo(*lSignal,Strategy(1)); if(iMean.getError() < 0.05) iFit->fitTo(*lSignal,Strategy(2)); } else { iFit->fitTo(*iData,Strategy(1)); if(iMean.getError() < 0.05) iFit->fitTo(*iData,Strategy(2)); } iVar.setBins(30); RooPlot *lFrame1 = iVar.frame(RooFit::Title("XXX")) ; if(iData == 0) lSignal->plotOn(lFrame1); if(iData != 0) iData->plotOn(lFrame1); iFit->plotOn(lFrame1); TCanvas *iC =new TCanvas("A","A",800,600); iC->cd(); lFrame1->Draw(); iC->SaveAs("Crap.png"); if(iData != 0) { RooPlot *lFrame2 = iVar.frame(RooFit::Title("XXX")) ; iData->plotOn(lFrame2); iGen->plotOn(lFrame2); TCanvas *iC1 =new TCanvas("B","B",800,600); iC1->cd(); lFrame2->Draw(); iC1->SaveAs("Crap.png"); } }
void glbToId_eta() { TCanvas *myCan=new TCanvas("myCan","myCan"); myCan->SetGrid(); TFile *f_MC= new TFile("TnP_GlbToID_MCetaplus_WptTight2012_eta.root","read"); RooDataSet *datasetMC = (RooDataSet*)f_MC->Get("tpTree/WptTight2012_eta/fit_eff"); //RooDataSet *datasetMC = (RooDataSet*)f_MC->Get("tpTree/WptTight2012_eta/cnt_eff"); cout<<"ntry: "<<datasetMC->numEntries()<<endl; double XMC[Nbin],XMCerrL[Nbin],XMCerrH[Nbin],YMC[Nbin],YMCerrLo[Nbin],YMCerrHi[Nbin]; for(int i(0); i<datasetMC->numEntries();i++) { const RooArgSet &pointMC=*datasetMC->get(i); RooRealVar &etaMC=pointMC["eta"],&effMC = pointMC["efficiency"]; XMC[i]=etaMC.getVal(); XMCerrL[i]=-etaMC.getAsymErrorLo(); XMCerrH[i]=etaMC.getAsymErrorHi(); YMC[i]=effMC.getVal(); YMCerrLo[i]=-effMC.getAsymErrorLo(); YMCerrHi[i]=effMC.getAsymErrorHi(); } grMC=new TGraphAsymmErrors(Nbin,XMC,YMC,XMCerrL,XMCerrH,YMCerrLo,YMCerrHi); grMC->SetLineColor(kRed); grMC->SetMarkerColor(kRed); grMC->Draw("AP"); //grMC->Draw("psame"); myCan->SaveAs("glbToId_MCplus_eta.png"); myCan->SaveAs("glbToId_MCplus_eta.eps"); }
void test01() { // S e t u p m o d e l // --------------------- TFile *openFile = new TFile("/tmp/kyolee/dimuonTree_upsiMiniTree_pA5tev_14nb_Run210498-210909_trigBit1_allTriggers0_pt4.root"); TTree* tree = (TTree*)openFile->Get("UpsilonTree"); // Declare variables with associated name, title, initial value and allowed range RooRealVar mass("invariantMass","M_{#mu#mu} [GeV/c]",9.4,7,14) ; RooRealVar muPlusPt("muPlusPt","muPlusPt",0,40) ; RooRealVar muMinusPt("muMinusPt","muMinusPt",0,40) ; RooRealVar mean("mean","mean of gaussian",9.4,8,11) ; RooRealVar sigma("sigma","width of gaussian",1,0.1,10) ; RooDataSet* data = new RooDataSet("data", "data", RooArgSet(mass,muPlusPt,muMinusPt), Import(*tree), Cut("muPlusPt>4 && muMinusPt>4")); data->Print(); // Build gaussian p.d.f in terms of x,mean and sigma RooGaussian gauss("gauss","gaussian PDF",mass,mean,sigma) ; // Construct plot frame in 'x' RooPlot* xframe = mass.frame(Title("Gaussian p.d.f.")) ; data->plotOn(xframe); /* // P l o t m o d e l a n d c h a n g e p a r a m e t e r v a l u e s // --------------------------------------------------------------------------- // Plot gauss in frame (i.e. in x) gauss.plotOn(xframe) ; // Change the value of sigma to 3 sigma.setVal(3) ; // Plot gauss in frame (i.e. in x) and draw frame on canvas gauss.plotOn(xframe,LineColor(kRed)) ; */ // F i t m o d e l t o d a t a // ----------------------------- // Fit pdf to data gauss.fitTo(*data,Range(9,10)) ; gauss.plotOn(xframe) ; // Print values of mean and sigma (that now reflect fitted values and errors) mean.Print() ; sigma.Print() ; // Draw all frames on a canvas TCanvas* c = new TCanvas("rf101_basics","rf101_basics",800,400) ; c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.6) ; xframe->Draw() ; }
void makeDataset( TString fname, TString tname, TString outfname ) { RooWorkspace *w = new RooWorkspace("w","w"); w->factory( "Dst_M[1950.,2070.]" ); w->factory( "D0_M[1810.,1920.]" ); w->factory( "D0_LTIME_ps[0.00,5.]" ); RooArgSet *observables = new RooArgSet(); observables->add( *w->var("Dst_M") ); observables->add( *w->var("D0_M") ); observables->add( *w->var("D0_LTIME_ps") ); w->defineSet("observables", *observables); w->var("Dst_M")->setBins(240); w->var("D0_M")->setBins(220); w->var("D0_LTIME_ps")->setBins(200); double Dst_M = -999.; double D0_M = -999.; double D0_LTIME_ps = -999.; TFile *tf = TFile::Open(fname); TTree *tree = (TTree*)tf->Get(tname); tree->SetBranchAddress( "Dst_M", &Dst_M ); tree->SetBranchAddress( "D0_M" , &D0_M ); tree->SetBranchAddress( "D0_LTIME_ps", &D0_LTIME_ps ); RooDataSet *data = new RooDataSet("Data","Data",*observables); RooDataHist *dataH = new RooDataHist("DataHist","Data",*observables); for ( int ev=0; ev<tree->GetEntries(); ev++) { tree->GetEntry(ev); if ( ev%10000 == 0 ) cout << ev << " / " << tree->GetEntries() << endl; if ( Dst_M < w->var("Dst_M")->getMin() || Dst_M > w->var("Dst_M")->getMax() ) continue; if ( D0_M < w->var("D0_M")->getMin() || D0_M > w->var("D0_M")->getMax() ) continue; if ( D0_LTIME_ps < w->var("D0_LTIME_ps")->getMin() || D0_LTIME_ps > w->var("D0_LTIME_ps")->getMax() ) continue; w->var("Dst_M")->setVal(Dst_M); w->var("D0_M")->setVal(D0_M); w->var("D0_LTIME_ps")->setVal(D0_LTIME_ps); data->add( *observables ); dataH->add( *observables ); } tf->Close(); w->import(*data); w->import(*dataH); w->writeToFile(outfname); }
void rf314_paramfitrange() { // D e f i n e o b s e r v a b l e s a n d d e c a y p d f // --------------------------------------------------------------- // Declare observables RooRealVar t("t","t",0,5) ; RooRealVar tmin("tmin","tmin",0,0,5) ; // Make parameterized range in t : [tmin,5] t.setRange(tmin,RooConst(t.getMax())) ; // Make pdf RooRealVar tau("tau","tau",-1.54,-10,-0.1) ; RooExponential model("model","model",t,tau) ; // C r e a t e i n p u t d a t a // ------------------------------------ // Generate complete dataset without acceptance cuts (for reference) RooDataSet* dall = model.generate(t,10000) ; // Generate a (fake) prototype dataset for acceptance limit values RooDataSet* tmp = RooGaussian("gmin","gmin",tmin,RooConst(0),RooConst(0.5)).generate(tmin,5000) ; // Generate dataset with t values that observe (t>tmin) RooDataSet* dacc = model.generate(t,ProtoData(*tmp)) ; // F i t p d f t o d a t a i n a c c e p t a n c e r e g i o n // ----------------------------------------------------------------------- RooFitResult* r = model.fitTo(*dacc,Save()) ; // P l o t f i t t e d p d f o n f u l l a n d a c c e p t e d d a t a // --------------------------------------------------------------------------------- // Make plot frame, add datasets and overlay model RooPlot* frame = t.frame(Title("Fit to data with per-event acceptance")) ; dall->plotOn(frame,MarkerColor(kRed),LineColor(kRed)) ; model.plotOn(frame) ; dacc->plotOn(frame) ; // Print fit results to demonstrate absence of bias r->Print("v") ; new TCanvas("rf314_paramranges","rf314_paramranges",600,600) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.6) ; frame->Draw() ; return ; }
void reweight_diphotonpt_1d(TH1F*weight_diphopt,TH1F*weight_diphopto,TH2F*weight_diphoptn,TH2F*weight_diphopt2o,TH2F*weight_diphoptnr, TH2F* weight_diphopt2,RooDataSet **dset, RooDataSet *dsetdestination){ if (!(*dset)) return; if (!(dsetdestination)) return; ///numerator and denominator TH1F *hnum = new TH1F("hnum","hnum",n_diphoptbins_forreweighting,diphoptbins_forreweighting); TH1F *hden = new TH1F("hden","hden",n_diphoptbins_forreweighting,diphoptbins_forreweighting); hnum->Sumw2(); hden->Sumw2(); // RooAbsData->get*() Load a given row of data //getRealValue Get value of a RooAbsReal stored in set with given name. If none is found, value of defVal is returned. for (int i=0; i<(*dset)->numEntries(); i++){ hden->Fill(fabs((*dset)->get(i)->getRealValue("roodiphopt")),(*dset)->store()->weight(i)); } for (int i=0; i<dsetdestination->numEntries(); i++){ hnum->Fill(fabs(dsetdestination->get(i)->getRealValue("roodiphopt")),dsetdestination->store()->weight(i)); } //normalize to one hnum->Scale(1.0/hnum->Integral()); hden->Scale(1.0/hden->Integral()); hnum->Divide(hden); TH1F *h = hnum; RooDataSet *newdset = new RooDataSet(**dset,Form("%s_diphoptrew",(*dset)->GetName())); newdset->reset(); assert(newdset); for (int i=0; i<(*dset)->numEntries(); i++){ RooArgSet args = *((*dset)->get(i)); float oldw = (*dset)->store()->weight(i); float diphopt = fabs((*dset)->get(i)->getRealValue("roodiphopt")); float neww = oldw*h->GetBinContent(h->FindBin(fabs(diphopt))); newdset->add(args,neww); if(debug){ weight_diphopt->Fill(neww); weight_diphopto->Fill(oldw); weight_diphopt2o->Fill((h->FindBin(fabs(diphopt))),oldw); weight_diphoptn->Fill((h->FindBin(fabs(diphopt))),neww); if(oldw!=0)weight_diphoptnr->Fill(h->FindBin(fabs(diphopt)),oldw/neww); else {weight_diphoptnr->Fill(-10,1);}//cout << "dipho weight old 0" << endl;} if(oldw!=0)weight_diphopt2->Fill(diphopt,oldw/neww); else {weight_diphopt2->Fill(-10,1);}//cout << "dipho weight old 0" << endl;} } } newdset->SetName((*dset)->GetName()); newdset->SetTitle((*dset)->GetTitle()); delete hnum; delete hden; RooDataSet *old_dset = *dset; *dset=newdset; std::cout << "Diphoton Pt 1d rew: norm from " << old_dset->sumEntries() << " to " << newdset->sumEntries() << std::endl; delete old_dset; };
void rf602_chi2fit() { // S e t u p m o d e l // --------------------- // Declare observable x RooRealVar x("x","x",0,10) ; // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their parameters RooRealVar mean("mean","mean of gaussians",5) ; RooRealVar sigma1("sigma1","width of gaussians",0.5) ; RooRealVar sigma2("sigma2","width of gaussians",1) ; RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ; RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ; // Build Chebychev polynomial p.d.f. RooRealVar a0("a0","a0",0.5,0.,1.) ; RooRealVar a1("a1","a1",0.2,0.,1.) ; RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ; // Sum the signal components into a composite signal p.d.f. RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ; RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ; // Sum the composite signal and background RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ; RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ; // C r e a t e b i n n e d d a t a s e t // ----------------------------------------- RooDataSet* d = model.generate(x,10000) ; RooDataHist* dh = d->binnedClone() ; // Construct a chi^2 of the data and the model. // When a p.d.f. is used in a chi^2 fit, the probability density scaled // by the number of events in the dataset to obtain the fit function // If model is an extended p.d.f, the expected number events is used // instead of the observed number of events. model.chi2FitTo(*dh) ; // NB: It is also possible to fit a RooAbsReal function to a RooDataHist // using chi2FitTo(). // Note that entries with zero bins are _not_ allowed // for a proper chi^2 calculation and will give error // messages RooDataSet* dsmall = (RooDataSet*) d->reduce(EventRange(1,100)) ; RooDataHist* dhsmall = dsmall->binnedClone() ; RooChi2Var chi2_lowstat("chi2_lowstat","chi2",model,*dhsmall) ; cout << chi2_lowstat.getVal() << endl ; }
pair<double,double> datEvents(RooWorkspace *work, int m_hyp, int cat, bool spin=false){ vector<double> result; RooDataSet *data = (RooDataSet*)work->data(Form("data_mass_cat%d",cat)); double evs = data->numEntries(); double evsPerGev; if (!spin) evsPerGev = data->sumEntries(Form("CMS_hgg_mass>=%4.1f && CMS_hgg_mass<%4.1f",double(m_hyp)-0.5,double(m_hyp)+0.5)); else evsPerGev = data->sumEntries(Form("mass>=%4.1f && mass<%4.1f",double(m_hyp)-0.5,double(m_hyp)+0.5)); return pair<double,double>(evs,evsPerGev); }
void rf903_numintcache(Int_t mode=0) { // Mode = 0 : Run plain fit (slow) // Mode = 1 : Generate workspace with pre-calculated integral and store it on file (prepare for accelerated running) // Mode = 2 : Run fit from previously stored workspace including cached integrals (fast, requires run in mode=1 first) // C r e a t e , s a v e o r l o a d w o r k s p a c e w i t h p . d . f . // ----------------------------------------------------------------------------------- // Make/load workspace, exit here in mode 1 RooWorkspace* w1 = getWorkspace(mode) ; if (mode==1) { // Show workspace that was created w1->Print() ; // Show plot of cached integral values RooDataHist* hhcache = (RooDataHist*) w1->expensiveObjectCache().getObj(1) ; if (hhcache) { new TCanvas("rf903_numintcache","rf903_numintcache",600,600) ; hhcache->createHistogram("a")->Draw() ; } else { Error("rf903_numintcache","Cached histogram is not existing in workspace"); } return ; } // U s e p . d . f . f r o m w o r k s p a c e f o r g e n e r a t i o n a n d f i t t i n g // ----------------------------------------------------------------------------------- // This is always slow (need to find maximum function value empirically in 3D space) RooDataSet* d = w1->pdf("model")->generate(RooArgSet(*w1->var("x"),*w1->var("y"),*w1->var("z")),1000) ; // This is slow in mode 0, but fast in mode 1 w1->pdf("model")->fitTo(*d,Verbose(kTRUE),Timer(kTRUE)) ; // Projection on x (always slow as 2D integral over Y,Z at fitted value of a is not cached) RooPlot* framex = w1->var("x")->frame(Title("Projection of 3D model on X")) ; d->plotOn(framex) ; w1->pdf("model")->plotOn(framex) ; // Draw x projection on canvas new TCanvas("rf903_numintcache","rf903_numintcache",600,600) ; framex->Draw() ; // Make workspace available on command line after macro finishes gDirectory->Add(w1) ; return ; }
Roo2DKeysPdf *SmoothKeys(TH2F *h) { RooDataSet *dataset = th22dataset(h); RooRealVar *v1 = (RooRealVar *) dataset->get()->find("constTerm"); RooRealVar *v2 = (RooRealVar *) dataset->get()->find("alpha"); Roo2DKeysPdf *myPdf = new Roo2DKeysPdf("mypdf","", *v1, *v2, *dataset); return myPdf; }
void read() { // Open File //TFile *datafile = TFile::Open("~/Documents/uni/LHCb_CharmSummerProj/Gedcode/baryon-lifetimes-2015/data/run-II-data/datafileLambda_TAUmin200fs_max2200fs_Mmin2216_max2356.root"); //TFile *datafile = TFile::Open("~/Documents/uni/LHCb_CharmSummerProj/Gedcode/baryon-lifetimes-2015/data/run-II-data/datafileLambda_TAUmin200fs_max2200fs_Mmin2216_max2356_CutIPCHI2lt3.root"); TFile *datafile = TFile::Open("~/Documents/uni/LHCb_CharmSummerProj/learning_root/DataSetLambda_TAUmin0002_max0022.root"); //TFile *datafile = TFile::Open("~/Documents/uni/LHCb_CharmSummerProj/learning_root/DataSetfromGed_fit_data_wSWeight.root"); // Define dataset RooDataSet* ds = (RooDataSet*)datafile->Get("ds") ; // Define TAU variable, get limits. RooRealVar Lambda_cplus_TAU("Lambda_cplus_TAU","Lambda_cplus_TAU",0.0002 ,0.0022 ,"ns") ; //real range of interest is [0.00025, 0.002], this is defined later. double highestTAU; double lowestTAU; ds->getRange(Lambda_cplus_TAU, lowestTAU, highestTAU); // Define Mass variable, get limits. RooRealVar Lambda_cplus_M("Lambda_cplus_M","Lambda_cplus_M",2216 ,2356, "GeV") ; double highestM; double lowestM; ds->RooAbsData::getRange(Lambda_cplus_M, lowestM, highestM) ; // Define IPCHI2 variable RooRealVar Lambda_cplus_IPCHI2_OWNPV("Lambda_cplus_IPCHI2_OWNPV","Lambda_cplus_IPCHI2_OWNPV",-100 ,100) ; double highestIPCHI2_OWNPV; double lowestIPCHI2_OWNPV; ds->RooAbsData::getRange(Lambda_cplus_IPCHI2_OWNPV, lowestIPCHI2_OWNPV, highestIPCHI2_OWNPV) ; //Lambda_cplus_TAU.setRange("R1",0.00018, 0.0012); // Print to Screen cout<<endl<<endl<<"************info************"<<endl; cout<< "Lowest lifetime value in dataset = "<<lowestTAU<<endl; cout<< "Highest lifetime value in dataset = "<<highestTAU<<endl; cout<< "Lowest mass value in dataset (should be: 2216)= "<<lowestM<<endl; cout<< "Highest mass value in dataset (should be: 2356)= "<<highestM<<endl; cout<< "Lowest IPCHI2_OWNPV value in dataset = "<<lowestIPCHI2_OWNPV<<endl; cout<< "Highest IPCHI2_OWNPV value in dataset = "<<highestIPCHI2_OWNPV<<endl; cout<<"number of events: "<<endl ; ds->Print(); //number of events in dataset //rmodel->Print(); //results //cout<<"Chi squared ="<<chi2<<endl ; }
double effRmsFromSigmaCB(double meanCB, double meanCB_err, double sigmaCB, double sigmaCB_err) { RooRealVar mass("zmass","m(e^{+}e^{-})",75,105,"GeV/c^{2}"); float zwidth=2.4952; RooRealVar bwMean("m_{Z}","BW Mean", 91.1876, "GeV/c^{2}"); RooRealVar bwWidth("#Gamma_{Z}", "BW Width", zwidth, "GeV/c^{2}"); RooRealVar cbBias ("#Deltam_{CB}", "CB Bias", 0.00, -10, 10, "GeV/c^{2}"); // typical value RooRealVar cbSigma("#sigma_{CB}", "CB Width", 1.5, 0.8, 5.0, "GeV/c^{2}"); RooRealVar cbCut ("a_{CB}","CB Cut", 1.0, 1.0, 3.0); // typical value RooRealVar cbPower("n_{CB}","CB Order", 2.5, 0.1, 20.0); // typical value float mean_lo = meanCB - meanCB_err; float mean_hi = meanCB + meanCB_err; float sigma_lo = sigmaCB - sigmaCB_err; float sigma_hi = sigmaCB + sigmaCB_err; int nstep_mean = 10; int nstep_sigma = 10; float step_mean = 2*meanCB_err/float(nstep_mean); float step_sigma = 2*sigmaCB_err/float(nstep_sigma); double max_rms = 0.0; double min_rms = 999.; RooMsgService::instance().setGlobalKillBelow(RooFit::WARNING); int nsteps=0; for(float mean=mean_lo; mean<mean_hi; mean+=step_mean) { for(float sigma=sigma_lo; sigma<sigma_hi; sigma+=step_sigma) { cbBias.setVal(meanCB); cbSigma.setVal(sigma); RooBreitWigner bw("bw", "bw", mass, bwMean, bwWidth); RooCBShape cball("cball", "Crystal Ball", mass, cbBias, cbSigma, cbCut, cbPower); RooFFTConvPdf BWxCB("BWxCB", "bw X crystal ball", mass, bw, cball); RooDataSet *gendata = BWxCB.generate(mass,1000); TH1D *genh = (TH1D*) gendata->createHistogram("genh",mass,RooFit::Binning(100,75,105)); math::HistogramTools ht(genh); double rms = ht.effectiveSigma(); rms = sqrt(pow(rms,2)-pow(zwidth,2)); if(rms > max_rms) max_rms=rms; if(rms < min_rms) min_rms=rms; delete genh; nsteps++; } } return (max_rms-min_rms)/sqrt(12)/sqrt(nsteps); }
void rf304_uncorrprod() { // C r e a t e c o m p o n e n t p d f s i n x a n d y // ---------------------------------------------------------------- // Create two p.d.f.s gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables RooRealVar x("x","x",-5,5) ; RooRealVar y("y","y",-5,5) ; RooRealVar meanx("mean1","mean of gaussian x",2) ; RooRealVar meany("mean2","mean of gaussian y",-2) ; RooRealVar sigmax("sigmax","width of gaussian x",1) ; RooRealVar sigmay("sigmay","width of gaussian y",5) ; RooGaussian gaussx("gaussx","gaussian PDF",x,meanx,sigmax) ; RooGaussian gaussy("gaussy","gaussian PDF",y,meany,sigmay) ; // C o n s t r u c t u n c o r r e l a t e d p r o d u c t p d f // ------------------------------------------------------------------- // Multiply gaussx and gaussy into a two-dimensional p.d.f. gaussxy RooProdPdf gaussxy("gaussxy","gaussx*gaussy",RooArgList(gaussx,gaussy)) ; // S a m p l e p d f , p l o t p r o j e c t i o n o n x a n d y // --------------------------------------------------------------------------- // Generate 10000 events in x and y from gaussxy RooDataSet *data = gaussxy.generate(RooArgSet(x,y),10000) ; // Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y) RooPlot* xframe = x.frame(Title("X projection of gauss(x)*gauss(y)")) ; data->plotOn(xframe) ; gaussxy.plotOn(xframe) ; // Plot x distribution of data and projection of gaussxy on y = Int(dx) gaussxy(x,y) RooPlot* yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)")) ; data->plotOn(yframe) ; gaussxy.plotOn(yframe) ; // Make canvas and draw RooPlots TCanvas *c = new TCanvas("rf304_uncorrprod","rf304_uncorrprod",800, 400); c->Divide(2); c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ; c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.4) ; yframe->Draw() ; }
/////////////////////////////////////////////////////////////////////////////// //weightDS /////////////////////////////////////////////////////////////////////////////// RooDataSet* weightDS(RooDataSet* set, double wgt){ RooRealVar wt("wt","wt",wgt); set->addColumn(wt); RooDataSet* wSet = new RooDataSet(set->GetName(),set->GetTitle(),set,*set->get(),0,wt.GetName()) ; std::cout << "Returning weighted d.s." << std::endl; std::cout << std::endl; wSet->Print(); return wSet; }
void sc_wptCut_P_et() { TCanvas *myCan=new TCanvas("myCan","myCan"); myCan->SetGrid(); /************************ TFile *f_RD= new TFile("TnP_Z_Trigger_RDpt.root","read"); RooDataSet *dataset = (RooDataSet*)f_RD->Get("tpTree/Track_To_TightCombRelIso_Mu15_eta2p1_pt/fit_eff"); cout<<"ntry: "<<dataset->numEntries()<<endl; double X[11],XerrL[11],XerrH[11],Y[11],YerrLo[11],YerrHi[11]; for(int i(0); i<dataset->numEntries();i++) { const RooArgSet &point=*dataset->get(i); RooRealVar &pt=point["pt"],&eff = point["efficiency"]; X[i]=pt.getVal(); XerrL[i]=-pt.getAsymErrorLo(); XerrH[i]=pt.getAsymErrorHi(); Y[i]=eff.getVal(); YerrLo[i]=-eff.getAsymErrorLo(); YerrHi[i]=eff.getAsymErrorHi(); } gr=new TGraphAsymmErrors(11,X,Y,XerrL,XerrH,YerrLo,YerrHi); gr->Draw("AP"); ***************************/ TFile *f_MC= new TFile("efficiency-mc-SCToPfElectron_et_P.root","read"); RooDataSet *datasetMC = (RooDataSet*)f_MC->Get("SuperClusterToPFElectron/SCtoWptCut_efficiency/cnt_eff"); //RooDataSet *datasetMC = (RooDataSet*)f_MC->Get("tpTree/Track_with_TightCombRelIso_to_Mu15_eta2p1_pt/fit_eff"); cout<<"ntry: "<<datasetMC->numEntries()<<endl; double XMC[binSize],XMCerrL[binSize],XMCerrH[binSize],YMC[binSize],YMCerrLo[binSize],YMCerrHi[binSize]; for(int i(0); i<datasetMC->numEntries();i++) { const RooArgSet &pointMC=*datasetMC->get(i); RooRealVar &ptMC=pointMC["probe_sc_et"],&effMC = pointMC["efficiency"]; XMC[i]=ptMC.getVal(); XMCerrL[i]=-ptMC.getAsymErrorLo(); XMCerrH[i]=ptMC.getAsymErrorHi(); YMC[i]=effMC.getVal(); YMCerrLo[i]=-effMC.getAsymErrorLo(); YMCerrHi[i]=effMC.getAsymErrorHi(); } grMC=new TGraphAsymmErrors(binSize,XMC,YMC,XMCerrL,XMCerrH,YMCerrLo,YMCerrHi); grMC->SetLineColor(kRed); grMC->SetMarkerColor(kRed); //myCan->SetLogx(); grMC->Draw("AP"); //grMC->Draw("psame"); TLine *myLine=new TLine(25,0,25,1); myLine->Draw("same"); myCan->SaveAs("sc_wptCut_P_et.png"); myCan->SaveAs("sc_wptCut_P_et.eps"); }
void rf208_convolution() { // S e t u p c o m p o n e n t p d f s // --------------------------------------- // Construct observable RooRealVar t("t","t",-10,30) ; // Construct landau(t,ml,sl) ; RooRealVar ml("ml","mean landau",5.,-20,20) ; RooRealVar sl("sl","sigma landau",1,0.1,10) ; RooLandau landau("lx","lx",t,ml,sl) ; // Construct gauss(t,mg,sg) RooRealVar mg("mg","mg",0) ; RooRealVar sg("sg","sg",2,0.1,10) ; RooGaussian gauss("gauss","gauss",t,mg,sg) ; // C o n s t r u c t c o n v o l u t i o n p d f // --------------------------------------- // Set #bins to be used for FFT sampling to 10000 t.setBins(10000,"cache") ; // Construct landau (x) gauss RooFFTConvPdf lxg("lxg","landau (X) gauss",t,landau,gauss) ; // S a m p l e , f i t a n d p l o t c o n v o l u t e d p d f // ---------------------------------------------------------------------- // Sample 1000 events in x from gxlx RooDataSet* data = lxg.generate(t,10000) ; // Fit gxlx to data lxg.fitTo(*data) ; // Plot data, landau pdf, landau (X) gauss pdf RooPlot* frame = t.frame(Title("landau (x) gauss convolution")) ; data->plotOn(frame) ; lxg.plotOn(frame) ; landau.plotOn(frame,LineStyle(kDashed)) ; // Draw frame on canvas new TCanvas("rf208_convolution","rf208_convolution",600,600) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ; }
void rf301_composition() { // S e t u p c o m p o s e d m o d e l g a u s s ( x , m ( y ) , s ) // ----------------------------------------------------------------------- // Create observables RooRealVar x("x","x",-5,5) ; RooRealVar y("y","y",-5,5) ; // Create function f(y) = a0 + a1*y RooRealVar a0("a0","a0",-0.5,-5,5) ; RooRealVar a1("a1","a1",-0.5,-1,1) ; RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ; // Creat gauss(x,f(y),s) RooRealVar sigma("sigma","width of gaussian",0.5) ; RooGaussian model("model","Gaussian with shifting mean",x,fy,sigma) ; // S a m p l e d a t a , p l o t d a t a a n d p d f o n x a n d y // --------------------------------------------------------------------------------- // Generate 10000 events in x and y from model RooDataSet *data = model.generate(RooArgSet(x,y),10000) ; // Plot x distribution of data and projection of model on x = Int(dy) model(x,y) RooPlot* xframe = x.frame() ; data->plotOn(xframe) ; model.plotOn(xframe) ; // Plot x distribution of data and projection of model on y = Int(dx) model(x,y) RooPlot* yframe = y.frame() ; data->plotOn(yframe) ; model.plotOn(yframe) ; // Make two-dimensional plot in x vs y TH1* hh_model = model.createHistogram("hh_model",x,Binning(50),YVar(y,Binning(50))) ; hh_model->SetLineColor(kBlue) ; // Make canvas and draw RooPlots TCanvas *c = new TCanvas("rf301_composition","rf301_composition",1200, 400); c->Divide(3); c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ; c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.4) ; yframe->Draw() ; c->cd(3) ; gPad->SetLeftMargin(0.20) ; hh_model->GetZaxis()->SetTitleOffset(2.5) ; hh_model->Draw("surf") ; }
// // single measurement (LM0 or LM1) // void RA4Single (StatMethod method, double* sig, double* bkg) { // RooWorkspace* wspace = createWorkspace(); RA4WorkSpace ra4WSpace("wspace",true,true,true); ra4WSpace.addChannel(RA4WorkSpace::MuChannel); ra4WSpace.finalize(); double lm0_mc[4] = { 1.09, 7.68, 3.78, 21.13 }; double lm1_mc[4] = { 0.05 , 0.34 , 1.12 , 3.43 }; double* lm_mc = sig ? sig : lm0_mc; double bkg_mc[4] = { 14.73, 18.20, 8.48, 10.98 }; ra4WSpace.setBackground(RA4WorkSpace::MuChannel,bkg_mc[0],bkg_mc[1],bkg_mc[2],bkg_mc[3]); ra4WSpace.setSignal(RA4WorkSpace::MuChannel,lm_mc[0],lm_mc[1],lm_mc[2],lm_mc[3],1.,1.,1.,1.); // setBackgrounds(wspace,bkg); // setSignal(wspace,lm_mc); RooWorkspace* wspace = ra4WSpace.workspace(); // wspace->Print("v"); // RooArgSet allVars = wspace->allVars(); // // allVars.printLatex(std::cout,1); // TIterator* it = allVars.createIterator(); // RooRealVar* var; // while ( var=(RooRealVar*)it->Next() ) { // var->Print("v"); // var->printValue(std::cout); // } //////////////////////////////////////////////////////////// // Generate toy data // generate toy data assuming current value of the parameters // import into workspace. // add Verbose() to see how it's being generated // wspace->var("s")->setVal(0.); // RooDataSet* data = wspace->pdf("model")->generate(*wspace->set("obs"),1); // data->Print("v"); // // wspace->import(*data); // wspace->var("s")->setVal(lm_mc[3]); RooDataSet* data = new RooDataSet("data","data",*wspace->set("obs")); data->add(*wspace->set("obs")); data->Print("v"); MyLimit limit = computeLimit(wspace,data,method,true); std::cout << "Limit [ " << limit.lowerLimit << " , " << limit.upperLimit << " ] ; isIn = " << limit.isInInterval << std::endl; }
void rs602_HLFactoryCombinationexample() { using namespace RooStats; using namespace RooFit; // create a card TString card_name("HLFavtoryCombinationexample.rs"); ofstream ofile(card_name); ofile << "// The simplest card for combination\n\n" << "gauss1 = Gaussian(x[0,100],mean1[50,0,100],4);\n" << "flat1 = Polynomial(x,0);\n" << "sb_model1 = SUM(nsig1[120,0,300]*gauss1 , nbkg1[100,0,1000]*flat1);\n" << "gauss2 = Gaussian(x,mean2[80,0,100],5);\n" << "flat2 = Polynomial(x,0);\n" << "sb_model2 = SUM(nsig2[90,0,400]*gauss2 , nbkg2[80,0,1000]*flat2);\n"; ofile.close(); HLFactory hlf("HLFavtoryCombinationexample", card_name, false); hlf.AddChannel("model1","sb_model1","flat1"); hlf.AddChannel("model2","sb_model2","flat2"); RooAbsPdf* pdf=hlf.GetTotSigBkgPdf(); RooCategory* thecat = hlf.GetTotCategory(); RooRealVar* x= static_cast<RooRealVar*>(hlf.GetWs()->arg("x")); RooDataSet* data = pdf->generate(RooArgSet(*x,*thecat),Extended()); // --- Perform extended ML fit of composite PDF to toy data --- pdf->fitTo(*data) ; // --- Plot toy data and composite PDF overlaid --- RooPlot* xframe = x->frame() ; data->plotOn(xframe); thecat->setIndex(0); pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ; thecat->setIndex(1); pdf->plotOn(xframe,Slice(*thecat),ProjWData(*thecat,*data)) ; gROOT->SetStyle("Plain"); xframe->Draw(); }
void AnalyzeToy::generate_toy() { RooDataSet *toySignal; toySignal = ws->pdf("model_signal_mass")->generate(*genSpec_sig_mass); toySignal->merge(ws->pdf("model_signal0_cosT")->generate(*cosT,nSignal_gen,AutoBinned(false))); RooDataSet *toyBkg; toyBkg= ws->pdf("model_bkg_mass")->generate(*genSpec_bkg_mass); toyBkg->merge(ws->pdf("model_bkg_cosT")->generate(*genSpec_bkg_cosT)); toyData = new RooDataSet("toyData","",RooArgSet(*mass, *cosT)); toyData->append(*toySignal); toyData->append(*toyBkg); delete toySignal; delete toyBkg; }
int main() { std::vector<float> masses; masses.push_back( 300. ); masses.push_back( 400. ); masses.push_back( 500. ); masses.push_back( 750. ); masses.push_back( 1000. ); masses.push_back( 1250. ); masses.push_back( 1500. ); masses.push_back( 2000. ); masses.push_back( 2500. ); masses.push_back( 3000. ); masses.push_back( 5000. ); for( unsigned i=0; i<masses.size(); ++i ) { std::cout << "-> Starting mass: " << masses[i] << std::endl; TFile* file = TFile::Open( Form("toySignal_m%.0f.root", masses[i]), "recreate" ); file->cd(); float thisMass = masses[i]; RooRealVar x("mass", "mass", thisMass, 0.2*thisMass, 2.*thisMass ); // Crystal-Ball RooRealVar mean( "mean", "mean", thisMass ); RooRealVar sigma( "sigma", "sigma", 0.015*thisMass ); RooRealVar alpha( "alpha", "alpha", 1.2 ); RooRealVar n( "n", "n", 0.81 ); RooCBShape cb( "cb", "cb", x, mean, sigma, alpha, n ); // Generate a toy dataset from the interpreted p.d.f RooDataSet* data = cb.generate(x,10000) ; data->SetName("data"); data->Write(); file->Close(); } return 0; }
void rfExExpo(){ // Declare Eponential Variables RooRealVar x("x","x",0,10); RooRealVar lambda("lambda","lambda",-3,-10,0); // Create an Exponential PDF with variables RooExponential expo("expo","eponential PDF",x,lambda); // Generate a dataset of 1000 and plot it, then plot the PDF RooDataSet* data = expo.generate(x,1000); RooPlot* xframe = x.frame(Title("Exponential p.d.f.")); data->plotOn(xframe); expo.plotOn(xframe); // Draw the plot on a TCanvas TCanvas* c = new TCanvas("rfExExpo","rfExExpo",800,400); xframe->Draw(); }
void plotFromWorkspace() { TFile* file = new TFile("card_m125_1JetIncl_XX_workspace.root"); RooWorkspace* w = (RooWorkspace*)file->Get("w"); RooRealVar* m = (RooRealVar*)w->var("CMS_hmumu_mass"); RooRealVar* e = (RooRealVar*)w->var("CMS_hmumu_merr"); RooDataSet* d = (RooDataSet*)w->data("data_pseudo"); RooAbsPdf * b = w->pdf("bkg_mass_merr_1JetIncl_XX_pdf"); RooAbsPdf * s = w->pdf("sig_mass_merr_ggH_1JetIncl_XX_pdf"); RooPlot* frame = m->frame(); d->plotOn(frame); b->plotOn(frame); //s->plotOn(frame, RooFit::ProjWData(*e, *d), RooFit::LineColor(kOrange+1)); //s->plotOn(frame, RooFit::LineColor(kOrange+1)); frame->Draw(); }
void rf510_wsnamedsets() { // C r e a t e m o d e l a n d d a t a s e t // ----------------------------------------------- RooWorkspace* w = new RooWorkspace("w") ; fillWorkspace(*w) ; // Exploit convention encoded in named set "parameters" and "observables" // to use workspace contents w/o need for introspected RooAbsPdf* model = w->pdf("model") ; // Generate data from p.d.f. in given observables RooDataSet* data = model->generate(*w->set("observables"),1000) ; // Fit model to data model->fitTo(*data) ; // Plot fitted model and data on frame of first (only) observable RooPlot* frame = ((RooRealVar*)w->set("observables")->first())->frame() ; data->plotOn(frame) ; model->plotOn(frame) ; // Overlay plot with model with reference parameters as stored in snapshots w->loadSnapshot("reference_fit") ; model->plotOn(frame,LineColor(kRed)) ; w->loadSnapshot("reference_fit_bkgonly") ; model->plotOn(frame,LineColor(kRed),LineStyle(kDashed)) ; // Draw the frame on the canvas new TCanvas("rf510_wsnamedsets","rf503_wsnamedsets",600,600) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ; // Print workspace contents w->Print() ; // Workspace will remain in memory after macro finishes gDirectory->Add(w) ; }