void Plot(RooRealVar *mass, RooDataSet *data, RooAbsPdf *pdf, pair<double,double> sigRange, vector<double> fwhmRange, string title, string savename){ double semin=sigRange.first; double semax=sigRange.second; double fwmin=fwhmRange[0]; double fwmax=fwhmRange[1]; double halfmax=fwhmRange[2]; double binwidth=fwhmRange[3]; RooPlot *plot = mass->frame(Bins(binning_),Range("higgsRange")); if (data) data->plotOn(plot,Invisible()); pdf->plotOn(plot,NormRange("higgsRange"),Range(semin,semax),FillColor(19),DrawOption("F"),LineWidth(2),FillStyle(1001),VLines(),LineColor(15)); TObject *seffLeg = plot->getObject(int(plot->numItems()-1)); pdf->plotOn(plot,NormRange("higgsRange"),Range(semin,semax),LineColor(15),LineWidth(2),FillStyle(1001),VLines()); pdf->plotOn(plot,NormRange("higgsRange"),Range("higgsRange"),LineColor(kBlue),LineWidth(2),FillStyle(0)); TObject *pdfLeg = plot->getObject(int(plot->numItems()-1)); if (data) data->plotOn(plot,MarkerStyle(kOpenSquare)); TObject *dataLeg = plot->getObject(int(plot->numItems()-1)); TLegend *leg = new TLegend(0.15,0.89,0.5,0.55); leg->SetFillStyle(0); leg->SetLineColor(0); leg->SetTextSize(0.03); if (data) leg->AddEntry(dataLeg,"Simulation","lep"); leg->AddEntry(pdfLeg,"Parametric model","l"); leg->AddEntry(seffLeg,Form("#sigma_{eff} = %1.2f GeV",0.5*(semax-semin)),"fl"); plot->GetXaxis()->SetNdivisions(509); halfmax*=(plot->getFitRangeBinW()/binwidth); TArrow *fwhmArrow = new TArrow(fwmin,halfmax,fwmax,halfmax,0.02,"<>"); fwhmArrow->SetLineWidth(2.); TPaveText *fwhmText = new TPaveText(0.15,0.45,0.45,0.58,"brNDC"); fwhmText->SetFillColor(0); fwhmText->SetLineColor(kWhite); fwhmText->SetTextSize(0.03); fwhmText->AddText(Form("FWHM = %1.2f GeV",(fwmax-fwmin))); TLatex lat1(0.65,0.85,"#splitline{CMS Preliminary}{Simulation}"); lat1.SetNDC(1); lat1.SetTextSize(0.03); TLatex lat2(0.65,0.75,title.c_str()); lat2.SetNDC(1); lat2.SetTextSize(0.025); TCanvas *canv = new TCanvas("c","c",600,600); plot->SetTitle(""); plot->GetXaxis()->SetTitle("m_{#gamma#gamma} (GeV)"); plot->Draw(); leg->Draw("same"); fwhmArrow->Draw("same <>"); fwhmText->Draw("same"); lat1.Draw("same"); lat2.Draw("same"); canv->Print(Form("%s.pdf",savename.c_str())); canv->Print(Form("%s.png",savename.c_str())); string path = savename.substr(0,savename.find('/')); canv->Print(Form("%s/animation.gif+100",path.c_str())); delete canv; }
///////////////////////////////////////////// // Have a nice plotting functiong // ///////////////////////////////////////////// void MethodDatasetsProbScan::plotFitRes(TString fName) { for (int i=0; i<pdf->getFitObs().size(); i++) { TString fitVar = pdf->getFitObs()[i]; TCanvas *fitCanv = newNoWarnTCanvas( getUniqueRootName(), Form("S+B and B only fits to the dataset for %s",fitVar.Data()) ); TLegend *leg = new TLegend(0.6,0.7,0.92,0.92); leg->SetFillColor(0); leg->SetLineColor(0); RooPlot *plot = w->var(fitVar)->frame(); // data invisible for norm w->data(pdf->getDataName())->plotOn( plot, Invisible() ); // bkg pdf if( pdf->getBkgPdf() ){ if ( !bkgOnlyFitResult ) { cout << "MethodDatasetsProbScan::plotFitRes() : ERROR : bkgOnlyFitResult is NULL" << endl; exit(1); } setParameters(w, bkgOnlyFitResult); if ( !w->pdf(pdf->getBkgPdfName()) ) { cout << "MethodDatasetsProbScan::plotFitRes() : ERROR : No background pdf " << pdf->getBkgPdfName() << " found in workspace" << endl; exit(1); } w->pdf(pdf->getBkgPdfName())->plotOn( plot, LineColor(kRed) ); leg->AddEntry( plot->getObject(plot->numItems()-1), "Background Only Fit", "L"); } else cout << "MethodDatasetsProbScan::plotFitRes() : WARNING : No background pdf is given. Will only plot S+B hypothesis." << std::endl; // free fit if ( !dataFreeFitResult ) { cout << "MethodDatasetsProbScan::plotFitRes() : ERROR : dataFreeFitResult is NULL" << endl; exit(1); } setParameters(w, dataFreeFitResult); if ( !w->pdf(pdf->getPdfName()) ) { cout << "MethodDatasetsProbScan::plotFitRes() : ERROR : No pdf " << pdf->getPdfName() << " found in workspace" << endl; exit(1); } w->pdf(pdf->getPdfName())->plotOn(plot); leg->AddEntry( plot->getObject(plot->numItems()-1), "Free Fit", "L"); // data unblinded if needed map<TString,TString> unblindRegs = pdf->getUnblindRegions(); if ( unblindRegs.find( fitVar ) != unblindRegs.end() ) { w->data(pdf->getDataName())->plotOn( plot, CutRange(pdf->getUnblindRegions()[fitVar]) ); leg->AddEntry( plot->getObject(plot->numItems()-1), "Data", "LEP"); } plot->Draw(); leg->Draw("same"); savePlot(fitCanv, fName); } }
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; }
void test(int numbersigmas = 0, Bool_t debugtest = true) { using namespace RooFit; using namespace std; TCanvas *canvas = new TCanvas("canvas","canvas",900,100,500,500); gSystem->Load("libRooFit"); gSystem->AddIncludePath("-I$ROOFITSYS/include"); float ptbinsarray[] = {20.,40.,60.,80.,100.,120.,200.,600.}; std::vector<float> ptbins(ptbinsarray,ptbinsarray+sizeof(ptbinsarray)/sizeof(ptbinsarray[0])); std::vector<std::vector<float> > allbins; allbins.push_back(ptbins); std::vector<TString> VarString; VarString.push_back("VsPt"); std::vector<TString> HistoNameString; HistoNameString.push_back("ptbin"); std::vector<TString> GraphXTitleString; GraphXTitleString.push_back("p_{t} (GeV)"); std::vector<TString> SideBandDefinitions; SideBandDefinitions.push_back("SideBand5_10"); // ------------FOR TESTING---------------- unsigned int sidebandloopmax = 1;//5_10, 5_20, ... unsigned int templatevarsloopmax = 1;//sinin with conv safe veto, sinin, ch isol unsigned int binsloopmax = 1;//pt, eta, phi, pu //----------Open .root Templates //All the Jet Templates TFile *histojetfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/TemplateHistosJetCheckBinsEndcapsLoose.root"); //TFile *histojetdenfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/Denominator_FREndCaps.root"); // TFile *histojetdatafile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/Num_Templates.root"); //Real Photon Templates TFile *historealmcfile = TFile::Open("/afs/cern.ch/user/c/ciperez/CMSSW_7_4_5/src/RealPhotonTemplatesEndCaps.root"); //--- Write NEW .root Historams for Fake Rate TFile *FRhistosfile = new TFile("FakeRatePlotsCheckBins.root","recreate"); //loop on error systematics for(unsigned int m = 0; m<templatevarsloopmax; m++) { for(unsigned int l = 0; l<binsloopmax; l++) { TMultiGraph *mg = new TMultiGraph(); TLegend *legendAllGraphs = new TLegend(0.37,0.59,0.57,0.79); legendAllGraphs->SetTextSize(0.02); legendAllGraphs->SetFillColor(kWhite); legendAllGraphs->SetLineColor(kWhite); std::vector<float> fakeratevalues; std::vector<float> fakerateptvalues; std::vector<float> fakerateerrorvalues; for(unsigned int k = 0; k<allbins[0].size()-1; k++) { // for(unsigned int k = 0;k<1;k++){ float binlow = allbins[0][k]; float binmax = allbins[0][k+1]; TString binstring = TString::Format("%4.2f_%4.2f",binlow,binmax); binstring.ReplaceAll(".00",""); binstring.ReplaceAll("-","m"); binstring.ReplaceAll(".","p"); binstring.ReplaceAll("10000","Inf"); cout<<binstring.Data()<<endl; //Histograms for templates //Get histograms from each of the histojetfiles declared earlier //Numerator Fakes - FakePhotonNumEndCaps.root - FakePhoton_num2040... TH1F *h1 = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedFakeJetptbin"+binstring).Data());// .Data() changes to char* h1->Print(); //Numerator Real Photons - RealPhotonTemplatesEndCaps.root - EndCapsMCReal_20_40 TH1F *h2 = (TH1F*)historealmcfile->Get(("EndCapsMCReal_"+binstring).Data()); h2->Print(); //Numerator Templates - Num_Templates.root - num2040... TH1F *hData = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedDataJetptbin"+binstring).Data()); hData->Print(); //Denominator Templates - Denominator_FREndCaps.root -FakePhoton_den2040... TH1F *hnum = (TH1F*)histojetfile->Get(("histoSininWithPixelSeedTightAndFakeJetptbin"+binstring).Data()); hnum->Print(); //avoiding 0 entries in the histograms //fake and real mc histos are the most critical for(int bincount = 1; bincount <= h1->GetNbinsX(); bincount++) { if(h1->GetBinContent(bincount) == 0.) h1->SetBinContent(bincount,1.e-6); } for(int bincount = 1; bincount <= h2->GetNbinsX(); bincount++) { if(h2->GetBinContent(bincount) == 0.) h2->SetBinContent(bincount,1.e-6); } int ndataentries = hData->GetEntries(); float sininmin = 0.; //? sigmaIetaIeta float sininmax = 0.1; //? sigmaIetaIeta // ----------------- Probability Density Function TString roofitvartitle = "#sigma_{i #eta i #eta}"; RooRealVar sinin("sinin",roofitvartitle.Data(),sininmin,sininmax); sinin.setRange("sigrange",0.018,0.06); //? this is the range because? Need to recall. //sinin.setRange("sigrange",0.005, 0.011); //Fake Template pdf RooDataHist faketemplate("faketemplate","fake template",sinin,h1); RooHistPdf fakepdf("fakepdf","test hist fake pdf",sinin,faketemplate); //Real Template pdf RooDataHist realtemplate("realtemplate","real template",sinin,h2); RooHistPdf realpdf("realpdf","test hist real pdf",sinin,realtemplate); //Data to be fitted to RooDataHist data("data","data to be fitted to",sinin,hData); //Declaration of Variables for Fake Rate RooRealVar fsig("fsig","signal fraction",0.1,0,1);// RooRealVar signum("signum","signum",0,ndataentries);// #of real contamination RooRealVar fakenum("fakenum","fakenum",0,ndataentries); //# of fake //Extend RooExtendPdf extpdfsig("Signal","extpdfsig",realpdf,signum,"sigrange"); RooExtendPdf extpdffake("Background","extpdffake",fakepdf,fakenum,"sigrange"); RooAddPdf model("model","sig + background",RooArgList(extpdfsig,extpdffake)); //----------- FITTING TO DATA ------------------- model.fitTo(data,RooFit::Minos()); //Define Plot Frame RooPlot *xframe = sinin.frame(); xframe->SetTitle(""); data.plotOn(xframe); model.plotOn(xframe); model.plotOn(xframe,Components(extpdfsig),LineColor(2),LineStyle(2)); model.plotOn(xframe,Components(extpdffake),LineColor(8),LineStyle(2)); canvas->cd(); canvas->SetGridx(true); canvas->SetGridy(true); xframe->GetXaxis()->SetRangeUser(0.,0.1); float xframemax = xframe->GetMaximum(); xframe->GetYaxis()->SetRangeUser(1.e-1,1.1*xframemax); xframe->Draw(); // ----- DEFINE LEGENDS and their position TLegend *legend = new TLegend(0.62,0.65,0.82,0.85); //Why these values? legend->SetTextSize(0.02); legend->SetFillColor(kWhite); legend->SetLineColor(kWhite); //Legend Header which tells the bin TString legendheader = "Pt (GeV):["+ binstring; legendheader.ReplaceAll("_",","); legendheader.ReplaceAll("m","-"); legendheader.ReplaceAll("p","."); legendheader.Append("]"); cout<<"legend "<<legendheader.Data()<<endl; legend->SetHeader(legendheader.Data()); TObject *objdata; //What is TObect? TObject *objmodel; TObject *objsignal; TObject *objfake; for(int i=0; i<xframe->numItems(); i++) { cout<<xframe->nameOf(i)<<endl; TString objname = xframe->nameOf(i); if(objname.Contains("data")) objdata = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && !objname.Contains("Comp")) objmodel = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && objname.Contains("Signal")) objsignal = (TObject*)xframe->findObject(objname.Data()); if(objname.Contains("model") && objname.Contains("Background")) objfake = (TObject*)xframe->findObject(objname.Data()); } //------ LEGEND -------- legend->AddEntry(objdata,"Data","lp"); legend->AddEntry(objsignal,"Signal","l"); legend->AddEntry(objfake,"Background","l"); legend->AddEntry(objmodel,"Signal + Background","l"); legend->Draw("same");//make them overlap for comparison canvas->Print(("Endcapfits"+binstring+".png").Data()); canvas->Print(("TemplateFitResultEndcap"+binstring+".C").Data()); float fakevalue = fakenum.getValV(); float fakeerrorhi = fakenum.getErrorHi(); float fakeerrorlo = fakenum.getErrorLo(); float fakeerrormax = max(fabs(fakeerrorhi),fabs(fakeerrorlo)); TString fakeresults = TString::Format("Fake results %f +%f %f",fakevalue,fakeerrorhi,fakeerrorlo); canvas->SetLogy(0); float sigvalue = signum.getValV(); float sigerrorhi = signum.getErrorHi(); float sigerrorlo = signum.getErrorLo(); float sigerrormax = max(fabs(sigerrorhi),fabs(sigerrorlo)); TString sigresults = TString::Format("Signal results %f +%f %f",sigvalue,sigerrorhi,sigerrorlo); cout<<"sigvalue "<<sigvalue<<" sigerrormax "<<sigerrormax<<" sigerrormax/sigvalue "<<sigerrormax/sigvalue<<endl; cout<<"fakevalue "<<fakevalue<<" fakeerrormax "<<fakeerrormax<<" fakeerrormax/fakevalue "<<fakeerrormax/fakevalue<<endl; cout<<fakeresults.Data()<<endl; cout<<sigresults.Data()<<endl; float Ratio = (fakevalue/(fakevalue+sigvalue)); float RatioError = Ratio*sqrt( ((fakeerrormax/fakevalue)*(fakeerrormax/fakevalue) + (sigerrormax/sigvalue)*(sigerrormax/sigvalue)) ); cout<<"Ratio "<<Ratio<<" +- "<<RatioError<<endl; //---------------------- FAKE RATE CALCULATOR ------------------------- //find the bin corresponding to 0.011 //int binnr = 22; int binnr = 34; //compute the integral of tight and fake in that range float numerator = hData->Integral(0,binnr); //Is the Integral function part of RooFit? float denominator = hnum->Integral(); float contamination = sigvalue; cout<<numerator<<" "<<denominator<<" "<<contamination<<endl; float fakerate = (numerator-contamination)/denominator; float fakerateerror = fakerate * sqrt( (1./numerator) + (1./denominator) + ((sigerrormax/sigvalue)*(sigerrormax/sigvalue)) ); cout<<"Here: "<<fakerate<<" "<<fakerateerror<<endl; //fakerateptvalues.push_back(hnumvspt->GetMean()); fakeratevalues.push_back(fakerate); fakerateerrorvalues.push_back(fakerateerror); cout<<""<<endl; cout<<"***********************************************************"<<endl; cout<<"So in sigmaietaieta < 0.011 there are "<<contamination<<" to subtract from "<<numerator<<endl; cout<<"and thus there are "<<(numerator-contamination)<<" total tight entries "<<endl; cout<<"and there are "<<denominator<<" entries in the tight and fake sample "<<endl; cout<<"and so the fake rate for the pt range "<<binlow<<"-"<<binmax<<" is "<<fakerate<<"+-"<<fakerateerror<<endl; cout<<"***********************************************************"<<endl; cout<<""<<endl; }//loop on all bins /* cout<<fakeratevalues.size()<<endl; for(int k=0;k<fakeratevalues.size();k++){ cout<<"Range: ["<<allbins[l][k]<<"-"<<allbins[l][k+1]<<"] --> fake rate: ("<<fakeratevalues[k]*100<<" +- "<<fakerateerrorvalues[k]*100<<")%"<<endl; }//end of loop over all fake rate values // *************************************************************-// // TGraphErrors *FRgraph = new TGraphErrors(fakeratevalues.size()); for(int k=0;k<fakeratevalues.size();k++){ cout<<(allbins[l][k+1]+allbins[l][k])/2.<<endl; FRgraph->SetPoint(k,(allbins[l][k+1]+allbins[l][k])/2.,fakeratevalues[k]); FRgraph->SetPointError(k,(allbins[l][k+1]-allbins[l][k])/2.,fakerateerrorvalues[k]); }//end of filling TGraph //// FRGraph->SetName(FakeRate.Data()); FRgraph->SetTitle(""); canvas->cd(); canvas->SetLogy(0); FRgraph->Draw("a*"); // **********************************************************-// // ***************************************** //float maxFRvalue = max_element(fakeratevalues.begin(),fakeratevalues.end()); FRgraph->GetYaxis()->SetRangeUser(0.,0.2); FRgraph->GetYaxis()->SetTitle("#epsilon_{FR}"); FRgraph->GetXaxis()->SetTitle((GraphXTitleString[l]).Data()); TString FakeRateFunctionName = " TF1 *FRfunc = new TF1(FakeRateFunctionName.Data(),"[0]+[1]/pow(x,[2])", allbins[l][0],allbins[l][fakeratevalues.size()]); FRfunc->SetParameters(1.,1.,1.); if(l==0){ FRgraph->Fit(FakeRateFunctionName.Data(),"R"); FRgraph->Fit(FakeRateFunctionName.Data()); FRfunc->Draw("same"); } // ******************************************** cout<<"***** Fit function parameters *****"<<endl; cout<<FRfunc->GetParameter(0)<<" " <<FRfunc->GetParameter(1)<<" " <<FRfunc->GetParameter(2)<<" " <<endl; cout<<"***** Fit function errors *****"<<endl; cout<<FRfunc->GetParError(0)<<" " <<FRfunc->GetParError(1)<<" " <<FRfunc->GetParError(2)<<" " <<endl; if(!debugtest){ canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.png").Data(),"png"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.gif").Data(),"gif"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.eps").Data(),"eps"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoos.pdf").Data(),"pdf"); canvas->Print(("FakeRateJetRun2012ABCD13JulLoose.C").Data(),"cxx"); } canvas->Print(("FakeRateEndCaps.png").Data(),"png"); canvas->Print(("FakeRateEndCaps.C").Data(),"cxx"); // ************************************************ if(!debugtest){ if(count == 0){ FRhistosfile->cd(); FRgraph->Write(); FRfunc->Write(); } } if(numbersigmas != 0){ FRgraph->SetLineColor(count+numbersigmas+1); FRgraph->SetMarkerColor(count+numbersigmas+1); TString numsigmastring = TString::Format("%d #sigma",count); legendAllGraphs->AddEntry(FRgraph,numsigmastring.Data(),"lep"); } mg->Add(FRgraph);*/ // }//end of loop over systematic errors if(numbersigmas != 0) { mg->Draw(); legendAllGraphs->Draw("same"); } }//end of loop over all variables (pt, eta, phi, pu) }//end of loop over template variables histojetfile->cd(); histojetfile->Close(); historealmcfile->cd(); historealmcfile->Close(); FRhistosfile->cd(); FRhistosfile->Close(); // }//end of loop over sideband definitions }//end of method
int main() { float min_logL1 = 5986.94; float min_logL0 = 5987.16; string filepath="FINAL_RESULT_AB.root_RESULT__RESULT"; filepath="/shome/buchmann/KillerKoala/CBAF/Development/exchange/RooFit__WorkSpace__Exchange_201417_175622__RNSG_46692.4.root__RESULT__RESULT"; // final MCwS filepath="/shome/buchmann/KillerKoala/CBAF/Development/exchange/RooFit__WorkSpace__Exchange_201417_175622__RNSG_46692.4.root__RESULT__RESULT"; filepath="/shome/buchmann/KillerKoala/CBAF/Development/exchange/RooFit__WorkSpace__Exchange_201417_141126__RNSG_97048.1.root__RESULT__RESULT"; // ************************************************************************************* setlumi(PlottingSetup::luminosity); setessentialcut(PlottingSetup::essential); // this sets the essential cut; this one is used in the draw command so it is AUTOMATICALLY applied everywhere. IMPORTANT: Do NOT store weights here! stringstream resultsummary; // write_analysis_type(PlottingSetup::RestrictToMassPeak,PlottingSetup::DoBTag); do_png(true); do_pdf(true); do_eps(false); do_C(true); do_root(false); PlottingSetup::directoryname = "pValuePlot"; gROOT->SetStyle("Plain"); bool do_fat_line = false; // if you want to have HistLineWidth=1 and FuncWidth=1 as it was before instead of 2 setTDRStyle(do_fat_line); gStyle->SetTextFont(42); bool showList = true; set_directory(PlottingSetup::directoryname); // Indicate the directory name where you'd like to save the output files in Setup.C set_treename("events"); // you can set the treename here to be used; options are "events" (for reco) for "PFevents" (for particle flow) TFile *f = new TFile(filepath.c_str()); if(f->IsZombie()) { cout << "Seems to be a zombie. goodbye." << endl; return -1; } RooWorkspace *wa = (RooWorkspace*)f->Get("transferSpace"); RooPlot *plot = (RooPlot*) wa->obj("frame_mlledge_109fde50"); // cout << plot << endl; wa->Print("v"); TCanvas *can = new TCanvas("can","can"); cout << "Address of plot : " << plot << endl; // plot->Draw(); float pVal_mllmin=35; float pVal_mllmax=90; int is_data=PlottingSetup::data; vector < std::pair < float, float> > loglikelihoods; string function=""; for(int i=0; i< plot->numItems();i++){ string name = plot->getObject(i)->GetName(); if (plot->getObject(i)->IsA()->InheritsFrom( "RooCurve" ))function=name; } RooCurve* curve = (RooCurve*) plot->findObject(function.c_str(),RooCurve::Class()) ; if (!curve) { dout << "RooPlot::residHist(" << plot->GetName() << ") cannot find curve" << endl ; return 0 ; } int iMinimum=0; float min=1e7; for(int i=0;i<curve->GetN();i++) { double x,y; curve->GetPoint(i,x,y); if(y<min & y>=0) { min=y; iMinimum=i; } } double x,y; curve->GetPoint(iMinimum,x,y); cout << "Minimum is at " << x << " : " << y << endl; loglikelihoods.push_back(make_pair(x,y+min_logL1)); //move right starting from the minimum for(int i=iMinimum+1;i<curve->GetN();i++) { float yold=y; curve->GetPoint(i,x,y); //if(abs((y-yold)/yold)>0.5) continue; loglikelihoods.push_back(make_pair(x,y+min_logL1)); } /* for(int i=0;i<curve->GetN();i++) { double x,y; curve->GetPoint(i,x,y); loglikelihoods.push_back(make_pair(x,y+min_logL1)); }*/ cout << "The whole thing contains " << loglikelihoods.size() << " points " << endl; ProduceSignificancePlots(min_logL0, loglikelihoods, pVal_mllmin, pVal_mllmax, is_data, "", ""); can->SaveAs("Crap.png"); delete can; delete plot; delete wa; f->Close(); return 0; }