TGraphErrors plot(RooDataSet *dataset, TString alpha, TString constTerm){ TTree *tree = dataset2tree(dataset); TH2F *hist = prof2d(tree, alpha, constTerm, "nll"); RooHistPdf *histPdf = nllToL(hist); TTree *genTree = dataset2tree(histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE)); TGraphErrors graph = g(genTree); delete tree; delete hist; delete histPdf; delete genTree; return graph; }
TGraphErrors plot(TFile *f, TString alpha, TString constTerm){ RooStats::MarkovChain *chain = (RooStats::MarkovChain *)f->Get("_markov_chain"); TTree *tree = dataset2tree(chain->GetAsDataSet()); TH2F *hist = prof2d(tree, alpha, constTerm, "nll_MarkovChain_local_"); RooHistPdf *histPdf = nllToL(hist); TTree *genTree = dataset2tree(histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE)); TGraphErrors graph = g(genTree); delete tree; delete hist; delete histPdf; delete genTree; return graph; }
void MakePlots(TString filename, TString energy="8TeV", TString lumi=""){ TString outDir=filename; outDir.ReplaceAll("fitres","img"); outDir="tmp/"; //std::map<TString, TH2F *> deltaNLL_map; /*------------------------------ Plotto */ TCanvas *c = new TCanvas("c","c"); TFile f_in(filename, "read"); if(f_in.IsZombie()){ std::cerr << "File opening error: " << filename << std::endl; return; } TList *KeyList = f_in.GetListOfKeys(); std::cout << KeyList->GetEntries() << std::endl; for(int i =0; i < KeyList->GetEntries(); i++){ c->Clear(); TKey *key = (TKey *)KeyList->At(i); if(TString(key->GetClassName())!="RooDataSet") continue; RooDataSet *dataset = (RooDataSet *) key->ReadObj(); TString constTermName = dataset->GetName(); TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha"); TTree *tree = dataset2tree(dataset); TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName); TH2F *hist = prof2d(tree, alphaName, constTermName, "nll", "(12,-0.0005,0.0115,29,-0.0025,0.1425)",true); // // deltaNLL_map.insert(std::pair <TString, TH2F *>(keyName,hist)); hist->SaveAs(outDir+"/deltaNLL-"+constTermName+".root"); hist->Draw("colz"); bestFit_.Draw("P same"); bestFit_.SetMarkerSize(2); Int_t iBinX, iBinY; Double_t x,y; hist->GetBinWithContent2(0,iBinX,iBinY); x= hist->GetXaxis()->GetBinCenter(iBinX); y= hist->GetYaxis()->GetBinCenter(iBinY); TGraph nllBestFit(1,&x,&y); nllBestFit.SetMarkerStyle(3); nllBestFit.SetMarkerColor(kRed); TList* contour68 = contourFromTH2(hist, 0.68); hist->Draw("colz"); hist->GetZaxis()->SetRangeUser(0,50); bestFit_.Draw("P same"); nllBestFit.Draw("P same"); //contour68->Draw("same"); c->SaveAs(outDir+"/deltaNLL-"+constTermName+".png"); hist->SaveAs("tmp/hist-"+constTermName+".root"); nllBestFit.SaveAs("tmp/nllBestFit.root"); contour68->SaveAs("tmp/contour68.root"); delete hist; hist = prof2d(tree, alphaName, constTermName, "nll", "(12,-0.0005,0.0115,29,-0.0025,0.1425)"); RooHistPdf *histPdf = nllToL(hist); delete hist; RooDataSet *gen_dataset=histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE); TTree *genTree = dataset2tree(gen_dataset); genTree->SaveAs("tmp/genTree-"+constTermName+".root"); delete gen_dataset; delete histPdf; TGraphErrors toyGraph = g(genTree, constTermName); TGraphErrors bestFitGraph = g(tree,alphaName, constTermName); TGraphErrors bestFitScanGraph = g(y, x); delete genTree; delete tree; toyGraph.SetFillColor(kGreen); toyGraph.SetLineColor(kBlue); toyGraph.SetLineStyle(2); bestFitGraph.SetLineColor(kBlack); bestFitScanGraph.SetLineColor(kRed); bestFitScanGraph.SetLineWidth(2); TMultiGraph g_multi("multigraph",""); g_multi.Add(&toyGraph,"L3"); g_multi.Add(&toyGraph,"L"); g_multi.Add(&bestFitGraph, "L"); g_multi.Add(&bestFitScanGraph, "L"); g_multi.Draw("A"); c->Clear(); g_multi.Draw("A"); c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".png"); // TPaveText *pv = new TPaveText(0.7,0.7,1, 0.8); // TLegend *legend = new TLegend(0.7,0.8,0.95,0.92); // legend->SetFillStyle(3001); // legend->SetFillColor(1); // legend->SetTextFont(22); // 132 // legend->SetTextSize(0.04); // l'ho preso mettendo i punti con l'editor e poi ho ricavato il valore con il metodo GetTextSize() // // legend->SetFillColor(0); // colore di riempimento bianco // legend->SetMargin(0.4); // percentuale della larghezza del simbolo // SetLegendStyle(legend); //Plot(c, data,mc,mcSmeared,legend, region, filename, energy, lumi); } f_in.Close(); return; }
TTree *ToyTree(TString dirname="test/dato/fitres/Hgg_Et-toys/0.01-0.00", TString fname="outProfile-scaleStep2smearing_7-Et_25-trigger-noPF-EB.root", TString opt="", int nSmooth=10){ TString outDir=dirname; outDir.ReplaceAll("fitres","img"); outDir="tmp/"; //std::map<TString, TH2F *> deltaNLL_map; //bool smooth=false; //if(opt.Contains("smooth")) smooth=true; /*------------------------------ Plotto */ TCanvas c("ctoy","c"); TTree *toys = new TTree("toys",""); toys->SetDirectory(0); Double_t constTerm_tree, constTermTrue_tree; Double_t alpha_tree, alphaTrue_tree; char catName[100]; Int_t catIndex; toys->Branch("constTerm", &constTerm_tree, "constTerm/D"); toys->Branch("alpha", &alpha_tree, "alpha/D"); toys->Branch("constTermTrue", &constTermTrue_tree, "constTermTrue/D"); toys->Branch("alphaTrue", &alphaTrue_tree, "alphaTrue/D"); toys->Branch("catName", catName, "catName/C"); toys->Branch("catIndex", &catIndex, "catIndex/I"); std::map<TString, Int_t> catIndexMap; ///1/ for(int itoy =2; itoy <= 50; itoy++){ TString filename=dirname+"/"; filename+=itoy; filename+="/"+fname; TString fout=dirname+"/"; fout+=itoy; fout+="/"; TFile f_in(filename, "read"); if(f_in.IsZombie()){ std::cerr << "File opening error: " << filename << std::endl; continue; //return NULL; } //std::cout << filename << std::endl; TList *KeyList = f_in.GetListOfKeys(); //std::cout << KeyList->GetEntries() << std::endl; for(int i =0; i < KeyList->GetEntries(); i++){ c.Clear(); TKey *key = (TKey *)KeyList->At(i); if(TString(key->GetClassName())!="RooDataSet") continue; RooDataSet *dataset = (RooDataSet *) key->ReadObj(); TString constTermName = dataset->GetName(); TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha"); if(constTermName.Contains("scale")) continue; if(constTermName.Contains("alpha")) continue; if(constTermName.Contains("1.4442-gold")) continue; TTree *tree = dataset2tree(dataset); TGraph *rhoGraph = GetRho(tree, alphaName, constTermName); rhoGraph->SaveAs(fout+"rhoGraph-"+constTermName+".root"); TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName); //TString binning="(241,-0.0005,0.2405,61,-0.00025,0.03025)"; //"(40,0.00025,0.02025,61,-0.0022975,0.1401475)"; TString binning="(241,-0.0005,0.2405,301,-0.00005,0.03005)"; TH2F *hist = prof2d(tree, constTermName, alphaName, "nll", binning, true, nSmooth, opt); //hist->SaveAs("myhist.root"); Int_t iBinX, iBinY; hist->GetBinWithContent2(0.0002,iBinX,iBinY,1,-1,1,-1,0.0000001); // if(iBinX!=0 && iBinY!=0 && iBinX < 41 && iBinY < 62){ { TString catName_=constTermName; catName_.ReplaceAll("constTerm_",""); catName_.ReplaceAll("-","_"); if(catIndexMap.count(catName_)==0) catIndexMap.insert(std::pair<TString,Int_t>(catName_,catIndexMap.size())); catIndex=catIndexMap[catName_]; constTerm_tree = hist->GetYaxis()->GetBinCenter(iBinY); alpha_tree = hist->GetXaxis()->GetBinCenter(iBinX); sprintf(catName,"%s", catName_.Data()); bestFit_.GetPoint(0, constTermTrue_tree,alphaTrue_tree); // std::cout << constTerm_tree << " " << constTermTrue_tree // << "\t" << alpha_tree << " " << alphaTrue_tree // << std::endl; if(opt.Contains("scandiff")){ constTermTrue_tree = getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_")); } else if(opt.Contains("scan")){ constTerm_tree = getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_")); } //std::cout << iBinX << "\t" << iBinY << "\t" << constTerm_tree - getMinimumFromTree(tree, "nll",TString(constTermName).ReplaceAll("-","_")) << std::endl; toys->Fill(); // }else{ // hist->SaveAs("myhist.root"); // exit(0); } delete tree; delete hist; } f_in.Close(); } //toys->SaveAs("tmp/toysTree.root"); return toys; }
void MakePlots(TString filename, float zmax=30, int nSmooth=10, TString opt="", TString energy="8TeV", TString lumi=""){ TString outDir=filename; outDir.Remove(outDir.Last('/')); outDir+="/img/"+opt; //outDir="tmp/k5b/"; //std::map<TString, TH2F *> deltaNLL_map; /*------------------------------ Plotto */ TCanvas *c = new TCanvas("c","c"); TFile f_in(filename, "read"); if(f_in.IsZombie()){ std::cerr << "File opening error: " << filename << std::endl; return; } TList *KeyList = f_in.GetListOfKeys(); std::cout << KeyList->GetEntries() << std::endl; for(int i =0; i < KeyList->GetEntries(); i++){ c->Clear(); TKey *key = (TKey *)KeyList->At(i); if(TString(key->GetClassName())!="RooDataSet") continue; RooDataSet *dataset = (RooDataSet *) key->ReadObj(); if(dataset==NULL){ std::cerr << "[WARNING] No dataset for " << key->GetName() << "\t" << key->GetTitle() << std::endl; continue; } TString constTermName = dataset->GetName(); TString alphaName=constTermName; alphaName.ReplaceAll("constTerm","alpha"); if(constTermName.Contains("absEta_1_1.4442-gold")) continue; if(constTermName.Contains("rho") || constTermName.Contains("phi")) continue; if(constTermName.Contains("scale")) continue; TTree *tree = dataset2tree(dataset); TGraphErrors bestFit_ = bestFit(tree, alphaName, constTermName); // TString binning="(241,-0.0005,0.2405,60,0.00025,0.03025)"; TString binning="(241,-0.0005,0.2405,301,-0.00005,0.03005)"; TH2F *hist = prof2d(tree, constTermName, alphaName, "nll", binning, true,nSmooth, opt); // std::cout << "Bin width = " << hist->GetXaxis()->GetBinWidth(10) << "\t" << hist->GetYaxis()->GetBinWidth(10) << std::endl; // std::cout << "Bin 1 center = " << hist->GetXaxis()->GetBinCenter(1) << "\t" << hist->GetYaxis()->GetBinCenter(1) << std::endl; // std::cout << "Bin 10 center = " << hist->GetXaxis()->GetBinCenter(10) << "\t" << hist->GetYaxis()->GetBinCenter(10) << std::endl; // return; hist->Draw("colz"); hist->GetZaxis()->SetRangeUser(0,zmax); hist->GetXaxis()->SetRangeUser(0,0.15); hist->GetYaxis()->SetRangeUser(0,0.018); hist->GetXaxis()->SetTitle("#Delta S"); hist->GetYaxis()->SetTitle("#Delta C"); Int_t iBinX, iBinY; Double_t x,y; hist->GetBinWithContent2(0.0002,iBinX,iBinY,1,-1,1,-1,0.0000001); x= hist->GetXaxis()->GetBinCenter(iBinX); y= hist->GetYaxis()->GetBinCenter(iBinY); std::cout << "Best Fit: " << x << "\t" << y << std::endl; TGraph nllBestFit(1,&x,&y); TString fileName=outDir+"/"+constTermName; fileName+="-"; fileName+=nSmooth; nllBestFit.SetMarkerStyle(3); nllBestFit.SetMarkerColor(kRed); nllBestFit.Draw("P same"); std::cout << fileName << std::endl; ofstream fout(fileName+".dat", ios_base::app); fout << constTermName << "\t" << x << "\t" << y << std::endl; c->SaveAs(fileName+".png"); c->SaveAs(fileName+".eps"); if(fileName.Contains("constTerm")) c->SaveAs(fileName+".C"); fileName+="-zoom"; hist->GetZaxis()->SetRangeUser(0,1); //hist->GetXaxis()->SetRangeUser(0.00,0.12); //hist->GetYaxis()->SetRangeUser(0,0.005); c->SaveAs(fileName+".png"); c->SaveAs(fileName+".eps"); // hist->SaveAs(outDir+"/deltaNLL-"+constTermName+".root"); // hist->Draw("colz"); // bestFit_.Draw("P same"); // bestFit_.SetMarkerSize(2); // nllBestFit.SetMarkerStyle(3); // nllBestFit.SetMarkerColor(kRed); // TList* contour68 = contourFromTH2(hist, 0.68); // hist->Draw("colz"); // hist->GetZaxis()->SetRangeUser(0,zmax); // //bestFit_.Draw("P same"); // nllBestFit.Draw("P same"); // //contour68->Draw("same"); delete hist; RooAbsPdf *histPdf = NULL; if(!opt.Contains("keys")){ hist = prof2d(tree, alphaName, constTermName, "nll", binning, false, nSmooth, opt); histPdf = nllToL(hist); }else{ hist = prof2d(tree, alphaName, constTermName, "nll", binning, false,nSmooth); histPdf = Smooth(hist,1,"keys"); } delete hist; // RooDataSet *gen_dataset=histPdf->generate(*histPdf->getVariables(),1000000,kTRUE,kFALSE); // TTree *genTree = dataset2tree(gen_dataset); // genTree->SaveAs(fileName+"-genTree.root"); // delete gen_dataset; // delete histPdf; // TGraphErrors toyGraph = g(genTree, constTermName); // TGraphErrors bestFitGraph = g(tree,alphaName, constTermName); // TGraphErrors bestFitScanGraph = g(y, x); // delete genTree; // delete tree; // toyGraph.SetFillColor(kGreen); // toyGraph.SetLineColor(kBlue); // toyGraph.SetLineStyle(2); // bestFitGraph.SetLineColor(kBlack); // bestFitScanGraph.SetLineColor(kRed); // bestFitScanGraph.SetLineWidth(2); // TMultiGraph g_multi("multigraph",""); // g_multi.Add(&toyGraph,"L3"); // g_multi.Add(&toyGraph,"L"); // g_multi.Add(&bestFitGraph, "L"); // g_multi.Add(&bestFitScanGraph, "L"); // g_multi.Draw("A"); // c->Clear(); // g_multi.Draw("A"); // c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".png"); // c->SaveAs(outDir+"/smearing_vs_energy-"+constTermName+".eps"); // // TPaveText *pv = new TPaveText(0.7,0.7,1, 0.8); // // TLegend *legend = new TLegend(0.7,0.8,0.95,0.92); // // legend->SetFillStyle(3001); // // legend->SetFillColor(1); // // legend->SetTextFont(22); // 132 // // legend->SetTextSize(0.04); // l'ho preso mettendo i punti con l'editor e poi ho ricavato il valore con il metodo GetTextSize() // // // legend->SetFillColor(0); // colore di riempimento bianco // // legend->SetMargin(0.4); // percentuale della larghezza del simbolo // // SetLegendStyle(legend); // //Plot(c, data,mc,mcSmeared,legend, region, filename, energy, lumi); } f_in.Close(); return; }