#include #include #include "TChain.h" #include "TH1.h" #include "TTree.h" #include "TKey.h" #include "Riostream.h" #include "TCanvas.h" #include "TFile.h" #include #include "TLegend.h" #include "TROOT.h" #include "TFrame.h" #include "TGaxis.h" #include "TStyle.h" #include #include #include #include "TList.h" #include #include "TObject.h" #include "TBranch.h" #include #include "TAxis.h" #include "TChain.h" #include "TMath.h" #include "TPie.h" #include "Riostream.h" #include #include //#include "tdrstyle.C" using namespace std; void Impose( TDirectory *ttarget, TList *ssourcelist, string &np_legend , vector titles_ ,vector xsecs); void ModifyHist (TH1D* &h, int cl,vector title); void ModifyHist (TH1D* &h, int cl,double lumi, double weight, string title, bool Norm, double xsecs); void ModifyHist (TH1D* &h, int cl,vector title, TLegend * & tleg); void ModifyHist (TH1D* &h, int cl); void OverFlow (TH1D* &h, int bin); void FixBoxPadding(TPad *pad, TBox *box, TH1D* &h1, double frac); void FixOverlay(); void FixTopRange(TPad *pad, TH1D* &h1, double fix_y, double fraction); TCanvas *modifyCanvas (TCanvas *c1); TCanvas *example_plot(int iPeriod, int iPos , TString name); int mycolor=TColor::GetColor("#ffcc66"); int mycolorvv=TColor::GetColor("#8646ba"); int mycolorqcd=TColor::GetColor("#ffccff"); int mycolortt=TColor::GetColor("#9999cc"); int mycolorttx=TColor::GetColor("#87CEFA"); int mycolorwjet=TColor::GetColor("#de5a6a"); int mycolordyj=TColor::GetColor("#ffcc66"); int mycolorztt=TColor::GetColor("#58d885"); int mycolorst=TColor::GetColor("#FF6633"); int mycolorww=TColor::GetColor("#C390D4"); TH1D* WInclw,*W1Jw,*W2Jw,*W3Jw,*W4Jw; TH1D* DYInclw,*DY1Jw,*DY2Jw,*DY3Jw,*DY4Jw; bool norm_=false; bool SO_=true; bool QCDMC=false; int MaxEventsBin = 5; bool drawData=true; bool blindData=false; TString Channel="mutau"; TH1D* hh[500]; TH1D* hsignal[500]; THStack *hs;// = new THStack(h1->GetName(),h1->GetTitle()); TLegend *legend_c1 ; TLegend *legend_c2 = new TLegend (0.3, 0.92, 0.5, 0.8); int cl, countsignal; TH1D* h1, *ratioH, *bkgRatioErrH, *DataHErrP, *DataHErrM; TCanvas *c1; void OverlapSmall() { //setTDRStyle(); vector titles; TList *FileList; TFile *Target; titles.clear(); int np=1; Float_t value=0; vector xsecs_; ifstream ifs("data.txt"); //if( QCDMC) ifstream ifs("datasetsQCD"); string line; while(std::getline(ifs, line)) // read one line from ifs { istringstream iss(line); // access line as a stream string dataname; float XSec; float xs,fact,fact2,fact3; xs=0;fact=1;fact2=1;fact3=1; iss >> dataname >> xs >> fact >> fact2 >> fact3; titles.push_back(dataname+"_B.root"); XSec= xs*fact*fact2*fact3; cout<<" Found the correct cross section "<Add (TFile::Open (file.c_str())); } Target = TFile::Open (fout.c_str (), "RECREATE"); string np_title = titles[0]; Impose (Target, FileList, np_title,titles,xsecs_); delete FileList; delete Target; } void Impose (TDirectory * target, TList * sourcelist, string & np_title_, vector titles,vector xsecs) { cout << " " << "========================================================" << endl; cout << " " << "This is a macro to superimpose plots of different root files." << endl; cout << " " << "Only TH1Dobjects are superimposed." << endl; cout << " " << "Target path: " << target->GetPath () << endl; TString path ((char *) strstr (target->GetPath (), ":")); path.Remove (0, 2); float Lumi= 35864.; cout< lumiweights; vector signal_names; signal_names.clear(); lumiweights.clear(); string sign_="Stop"; string n_; for (unsigned int k=0; kFirst (); string fsourcename = first_source->GetName(); first_source->cd (Channel); TH1D* eventCount = (TH1D*)first_source->Get(Channel+"/histWeightsH"); float nGen = eventCount->GetSumOfWeights(); float xsec = 1; float norm = xsec*Lumi/nGen; norm =1; lumiweights.push_back(float(norm)); //cout<< " for first source file, there where "<GetListOfKeys ()); //TIter nextkey (((TDirectory *) current_sourcedir->Get ("ana"))->GetListOfKeys ()); TKey *key, *oldkey = 0; int count=0; c1 = new TCanvas("c1","c1",200,10,600,600); while ((key = (TKey *) nextkey ())) { count++; //keep only the highest cycle number for each key // if (oldkey && !strcmp (oldkey->GetName (), key->GetName ())) // continue; // read object from first source file and create a canvas first_source->cd (Channel); TObject *obj = key->ReadObj (); //string nn = obj->GetName(); c1->SetTitle(obj->GetName()); string nn = obj->GetName(); bool flcont = true; if (string::npos == nn.find("_12")) flcont=false; if (!flcont) continue; if (std::string::npos != nn.find("Low") || std::string::npos != nn.find("High") || std::string::npos != nn.find("Middle") ) {MaxEventsBin = 0;} if (std::string::npos != nn.find("dR_") ) {MaxEventsBin = 5;} if (obj->IsA ()->InheritsFrom ("TTree") ) continue; if (obj->IsA ()->InheritsFrom ("TH2") ) continue; if (obj->IsA ()->InheritsFrom ("TH3") ) continue; if (obj->IsA ()->InheritsFrom ("TH1D") ) { // descendant of TH1D-> prepare the histograms to be superimposed h1 = (TH1D*) obj; if (h1->Integral() <0.0001) continue; if (SO_) legend_c1 = new TLegend (0.35, 0.92, 0.95, 0.55); if (!SO_) legend_c1 = new TLegend (0.65, 0.92, 0.9, 0.55); legend_c1->SetFillColor(1); legend_c1->SetFillStyle(0); legend_c1->SetLineColor(0); legend_c1->SetTextFont (132); legend_c1->SetTextSize (0.035); legend_c2->SetFillColor(1); legend_c2->SetFillStyle(0); legend_c2->SetLineColor(0); legend_c2->SetTextFont (132); legend_c2->SetTextSize (0.035); if (SO_) legend_c1-> SetNColumns(2); ModifyHist (h1,1,Lumi,lumiweights[0],titles[0],false,1); // loop over all source files and modify the correspondant // histogram to the one pointed to by "h1" TFile *nextsource = (TFile *) sourcelist->After (first_source); h1->SetStats(000000); h1->SetLineWidth(2); cl=1; countsignal=1; hh[cl]=h1; hs = new THStack(h1->GetName(),h1->GetTitle()); string sn="Stop"; string sdata="Single"; string sdata2="MuonEG"; string cc1="C1"; string cc2="Chi"; while (nextsource) { string fname= nextsource->GetName(); bool flagg= false; if (std::string::npos != fname.find(sn) || std::string::npos != fname.find(cc1) || std::string::npos != fname.find(sdata) || std::string::npos != fname.find(sdata2) || std::string::npos != fname.find(cc2) ) flagg=true; nextsource->cd(Channel); TH1D* eventCountt ; if ( std::string::npos == fname.find("TT_TuneCUETP8M2T4") && std::string::npos == fname.find("DataDriven")) eventCountt = (TH1D*)nextsource->Get(Channel+"/histWeightsH"); if ( std::string::npos != fname.find("TT_TuneCUETP8M2T4") ) eventCountt = (TH1D*)nextsource->Get(Channel+"/histTopPt"); float xsecc = xsecs[cl]; float nGenn = eventCountt->GetSumOfWeights(); if ( std::string::npos != fname.find("DataDriven")) nGenn=1.; float normm = float(xsecc*Lumi) / float(nGenn) ; string qcd="DataDriven"; if (std::string::npos != fname.find(qcd)) { normm =1.;} lumiweights.push_back(normm); TKey *key2 = (TKey *) gDirectory->GetListOfKeys ()->FindObject (h1->GetName ()); if (key2) { cl++; countsignal++; TH1D *h2; h2 = (TH1D*) key2->ReadObj (); h2->SetLineWidth(3); if ( string::npos == nn.find("CutFlowUnW") && string::npos == nn.find("1D_")) h2->GetXaxis()->SetRange(hh[1]->FindFirstBinAbove(0),hh[1]->FindLastBinAbove(MaxEventsBin)); ModifyHist (h2, cl,Lumi,lumiweights[cl-1],titles[cl-1],false,xsecc); h2->SetStats(0); hh[cl] = h2; if (cl==2){ allbkg = (TH1D*) h2->Clone(); allbkg->Reset(); hwj = (TH1D*) h2->Clone(); hwj->Reset(); } if (std::string::npos != fname.find(sn) || std::string::npos != fname.find(cc1) || std::string::npos != fname.find(sdata) || std::string::npos != fname.find(sdata2) ) flagg=true; string title_ = fname; //cout<<" "<Add(h2); hwj->SetLineColor(col);} if (!flagg) { hs->Add(h2); allbkg->Add(h2); } } nextsource = (TFile *) sourcelist->After (nextsource); } // while ( nextsource ) } if (obj->IsA ()->InheritsFrom ("TH1")) { ///////// TPie target->cd (); TPad *pad1 ;//= new TPad("pad1","pad1",0,0.2,1,1);//ratioH TPad *pad2 = new TPad("pad2","pad2",0, 0, 1,0.2); if (!drawData) pad1= new TPad("pad1","pad1",0,0,1,1); if (drawData) pad1= new TPad("pad1","pad1",0,0.2,1,1); pad1->SetBottomMargin(0.0); if (!drawData) pad1->SetBottomMargin(0.1); pad1->SetRightMargin(0.05); //pad1->SetGridy(); pad2->SetTopMargin(0.01); pad2->SetBottomMargin(0.38); pad2->SetRightMargin(0.05); //hs->Draw("nostack"); c1->cd(); c1->Clear(); pad1->SetLogy(); if ((std::string::npos != nn.find("Mt2lester") || std::string::npos != nn.find("MET_") || std::string::npos != nn.find("HighDzeta_") || std::string::npos != nn.find("MiddleDzeta_") || std::string::npos != nn.find("LowDzeta_")) && std::string::npos == nn.find("Phi")) { pad1->SetLogx(); pad2->SetLogx();} pad1->Draw(); if (drawData) pad2->Draw(); pad2->SetGridy(1); pad1->cd(); pad1->Clear(); TH1D *hsum = ((TH1D*)(hs->GetStack()->Last())); // the "SUM" if ( string::npos == nn.find("CutFlowUnW") && string::npos == nn.find("1D_")) hsum->GetXaxis()->SetRange(hh[1]->FindFirstBinAbove(0),hh[1]->FindLastBinAbove(MaxEventsBin)); OverFlow(hsum,hh[1]->FindLastBinAbove(MaxEventsBin)); char namee[100]; sprintf(namee,"%s",key->GetName ()); char nnn[100]; string titlee= hsum->GetName(); hsum->GetYaxis()->SetTitleOffset(1); hsum->GetYaxis()->SetTitleSize(0.045); if ( string::npos == nn.find("CutFlowUnW") && string::npos == nn.find("1D_")) hh[1]->GetXaxis()->SetRange(hh[1]->FindFirstBinAbove(0),hh[1]->FindLastBinAbove(MaxEventsBin)); OverFlow(hh[1],hh[1]->FindLastBinAbove(MaxEventsBin)); if (cl<2){ TH1F* v1 = new TH1F("", "", 1, 0, 1);v1->SetLineWidth(4); v9->SetMarkerSize(0.4); v9->SetMarkerColor(49); v1->SetMarkerSize(0.4); char lumitag[100]; sprintf(lumitag,"Data #int L = %.3g fb^{-1}",Lumi/1000); v1->SetLineColor(kBlack); if (drawData) legend_c1->AddEntry(hh[1], "Data", "LEP"); char lab_[100]; if (SO_){ legend_c1->AddEntry(hh[2],"#tilde{t}(200), #tilde{#chi}_{1}^{0}(1)","l"); } v1->SetLineColor(mycolorwjet);v1->SetFillColor(mycolorwjet);legend_c1->AddEntry(v1, "WJets", "f"); } hsum->SetMinimum(0.05); string units = "GeV"; if (std::string::npos != titlee.find("Phi") || std::string::npos != titlee.find("phi")) units="rad"; if (std::string::npos != titlee.find("dz") || std::string::npos != titlee.find("dxy")) units="cm"; sprintf(nnn,"Entries / %f %s",double(hh[1]->GetBinWidth(2)),units.c_str()); if (std::string::npos != titlee.find("dz") || std::string::npos != titlee.find("dxy") || std::string::npos != titlee.find("Phi") || std::string::npos != titlee.find("phi")) sprintf(nnn,"Entries / %.2f %s",hh[1]->GetBinWidth(2),units.c_str()); if ( ( std::string::npos != titlee.find("Eta") || std::string::npos != titlee.find("eta") || std::string::npos != titlee.find("nJ") || std::string::npos != titlee.find("nB") || std::string::npos != titlee.find("nEl") || std::string::npos != titlee.find("nM") || std::string::npos != titlee.find("nT") ) && std::string::npos == titlee.find("DZeta_")) sprintf(nnn,"Entries"); if ((std::string::npos != titlee.find("DZeta_") || std::string::npos != titlee.find("MET_") || std::string::npos != titlee.find("Mt2lester") || std::string::npos != titlee.find("Low") || std::string::npos != titlee.find("Middle") || std::string::npos != titlee.find("High") || std::string::npos != titlee.find("dEta")) && std::string::npos == titlee.find("FB_") && std::string::npos == titlee.find("Cos") && std::string::npos == titlee.find("Phi") && std::string::npos == titlee.find("phi")) sprintf(nnn,"Entries / bin"); if (std::string::npos != titlee.find("dEta")) sprintf(nnn,"Entries / %.f",hh[1]->GetBinWidth(2)); hsum->GetYaxis()->SetTitle(nnn); if (norm_) {hsum->Scale(1/hsum->Integral()); hsum->SetFillColor(0);hsum->SetLineColor(kRed);} hsum->Draw("hist"); if (!norm_) hs->Draw("same hist"); if (blindData) hh[1] = (TH1D*) allbkg->Clone(); if (drawData) hh[1]->Draw("same ep hist"); hh[1]->SetMarkerStyle(20); hh[1]->SetFillColor(0); if (norm_) hh[1]->Scale(1/hh[1]->Integral()); if (SO_){ for (int ij=2;ij<3;ij++){ if ( string::npos == nn.find("CutFlowUnW") && string::npos == nn.find("1D_")) hh[ij]->GetXaxis()->SetRange(hh[1]->FindFirstBinAbove(0),hh[1]->FindLastBinAbove(MaxEventsBin)); OverFlow(hh[ij],hh[1]->FindLastBinAbove(MaxEventsBin)); if (norm_) { hh[ij]->Scale(1/hh[ij]->Integral());hh[ij]->SetLineColor(kBlue+ij);} hh[ij]->SetLineStyle(2); hh[ij]->SetLineWidth(3); hh[ij]->SetFillColor(0); hh[ij]->Draw("same e1 hist"); } } string Title = hh[1]->GetName(); FixBoxPadding(pad1, legend_c1, hsum,0.1); legend_c1->Draw("sames"); FixOverlay(); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetBorderSize(0); c1->SetFrameBorderMode(0); c1->SetBorderSize(0); pad1->SetFrameLineColor(0);; pad2->cd(); ratioH = (TH1D*) hh[1]->Clone(); string nT = hh[1]->GetName(); if (std::string::npos != nT.find("CutFlowUnW")) ratioH->Sumw2(); ratioH->SetStats(000000); ratioH->Divide(hsum); ratioH->SetMarkerStyle(20); ratioH->SetMaximum( 2.2 ); ratioH->SetMinimum(0.5); ratioH->GetXaxis()->SetTitle(hh[1]->GetXaxis()->GetTitle()); ratioH->GetYaxis()->SetTitle(""); ratioH->SetTitleSize(0); ratioH->SetMarkerSize(0.08); ratioH->SetLineStyle(1); ratioH->SetMarkerSize(1.2); ratioH->SetMarkerColor(kBlack); ratioH->SetLineColor(kBlack); ratioH->SetLineWidth(1); ratioH->GetYaxis()->SetNdivisions(5); ratioH->GetXaxis()->SetNdivisions(545); ratioH->GetXaxis()->SetLabelSize(0.15); ratioH->GetXaxis()->SetTitleOffset(1.); ratioH->GetXaxis()->SetTitleSize(0.17); ratioH->GetYaxis()->SetLabelSize(0.1); ratioH->GetYaxis()->SetLabelSize(0.15); ratioH->GetYaxis()->SetTitleSize(0.15); ratioH->GetYaxis()->SetTitleOffset(0.25); ratioH->GetYaxis()->SetTitle("Obs / MC"); ratioH->SetTitleFont(62); if ( string::npos == nn.find("CutFlowUnW") && string::npos == nn.find("1D_")) ratioH->GetXaxis()->SetRange(hh[1]->FindFirstBinAbove(0),hh[1]->FindLastBinAbove(MaxEventsBin)); ratioH->GetXaxis()->SetNdivisions(510); ratioH->SetTitle(""); TAxis *axis = hh[1]->GetXaxis(); float halfbin = axis->GetBinWidth(hh[1]->GetBin(1))*0.5; TLine *l=new TLine(axis->GetBinLowEdge(hh[1]->FindFirstBinAbove(0.)),1,axis->GetBinLowEdge(hh[1]->FindLastBinAbove(MaxEventsBin)+1),1); // cout<<" ================= > "<< hh[1]->GetBinContent(hh[1]->FindLastBinAbove(0.0))<<" "<FindLastBinAbove(float(0.0))<SetLineColor(kRed); l->SetLineWidth(2); bkgRatioErrH = (TH1D*) ratioH->Clone(); DataHErrP = (TH1D*) hh[1]->Clone(); DataHErrM = (TH1D*) hh[1]->Clone(); bkgRatioErrH->SetLineColor(kBlack); bkgRatioErrH->SetFillStyle(3002); bkgRatioErrH->SetFillColor(1); bkgRatioErrH->SetMarkerStyle(20); bkgRatioErrH->SetMarkerSize(0); bkgRatioErrH->SetLineColor(1); bkgRatioErrH->SetLineWidth(2); for (int iB=1; iB<=hsum->GetNbinsX(); ++iB) { float datX = hh[1]->GetBinContent(iB); float datE = hh[1]->GetBinError(iB); float bkgX = hsum->GetBinContent(iB); float bkgE = hsum->GetBinError(iB); float datRatioX = datX/bkgX; float datRatioE = datE/bkgX; float bkgErr = float(bkgE / bkgX); bkgRatioErrH->SetBinContent(iB,1); bkgRatioErrH->SetBinError(iB,bkgErr); ratioH->SetBinError(iB,datE/bkgX); DataHErrP->SetBinContent(iB,datX); DataHErrP->SetBinError(iB,datE); DataHErrM->SetBinContent(iB,bkgX); DataHErrM->SetBinError(iB,bkgE); } if (drawData) ratioH->Draw("ep "); bkgRatioErrH->Draw("e2 same"); l->Draw("same"); c1->SetTitle(namee); gPad->RedrawAxis(); gPad->Modified(); gPad->Update(); c1->cd(); c1->Modified(); c1->cd(); c1->Update(); c1->Write (namee); char f[100];char ff[100]; if (SO_ && !QCDMC)sprintf(f,"Tau/%sSO.pdf",namee); if (SO_ && QCDMC)sprintf(f,"Tau/%s_QCDMC_SO.pdf",namee); if(!SO_ && !QCDMC) sprintf(f,"Tau/%s.pdf",namee); if(!SO_ && QCDMC) sprintf(f,"Tau/%s_QCDMC.pdf",namee); c1->Print (f,"pdf"); } } // while ( ( TKey *key = (TKey*)nextkey() ) ) delete c1; target->SaveSelf (kTRUE); TH1::AddDirectory (status); cout << " " << "========================================================" << endl; cout<< " Ended SuperImpose of files.... " <GetNbinsX(); int nn=1; string title1,title2; title1= h->GetName(); //h->Rebin(4); h->SetMinimum(0.0005); h->GetXaxis()->SetNdivisions(512); string titlee=h->GetName(); int col=1;//kOrange; if (std::string::npos != title_.find("Data") || std::string::npos != title_.find("Single") || std::string::npos != title_.find("MuonEG") ) { col=kBlack ; h->SetLineStyle(1); h->SetMarkerStyle(20); h->SetMarkerSize(1.2); h->SetMarkerColor(col); h->SetLineColor(col); } if ( std::string::npos != title_.find("Stop") || std::string::npos != title_.find("C1") || std::string::npos != title_.find("SMS") || std::string::npos != title_.find("Chi")){ col=cl_+1; if (cl_==2) col=kBlue; if (cl_==3) col=kRed; if (cl_==4) col=TColor::GetColor("#66ccc3");; if (cl_==5) col=TColor::GetColor("#e2cc61");; h->SetLineStyle(2); h->SetMarkerStyle(31); h->SetMarkerSize(0.4); h->SetMarkerColor(col); h->SetFillColor(0); h->SetLineWidth(3); } int nb = h->GetNbinsX(); float over_ = h->GetBinContent(nb+1); float contlast = h->GetBinContent(nb); h->Scale(weight); if ( (std::string::npos != title_.find("wJets")|| std::string::npos != title_.find("WJetsToLNu") || std::string::npos != title_.find("W1JetsToLNu") || std::string::npos != title_.find("W2JetsToLNu") || std::string::npos != title_.find("W3JetsToLNu") || std::string::npos != title_.find("W4JetsToLNu")) && std::string::npos == title_.find("TTW")) { col=mycolorwjet ; } h->SetMinimum(0.009); h->SetFillColor(col); h->SetLineColor(col); } void OverFlow(TH1D *& h, int &last_bin){ int nb = h->GetNbinsX(); float over_ = h->GetBinContent(last_bin); float contlast = 0.;//h->GetBinContent(last_bin); for (int b=last_bin; b <= nb+1; ++b) {contlast +=h->GetBinContent(b);h->SetBinContent(b,0.);h->SetBinError(b,0.);} h->SetBinContent(last_bin,0); h->SetBinError(last_bin,0); h->SetBinContent(last_bin,contlast); float err = h->GetBinError(last_bin); err = sqrt(contlast); h->SetBinError(last_bin,err); } void FixBoxPadding(TPad *pad, TBox *box, TH1D *& hobj,double frac) { // Get the bounds of the box - these are in the normalised // Pad co-ordinates. double p_x1 = box->GetX1(); double p_x2 = box->GetX2(); double p_y1 = box->GetY1(); // double p_y2 = box->GetY2(); // Convert to normalised co-ordinates in the frame double f_x1 = (p_x1 - pad->GetLeftMargin()) / (1. - pad->GetLeftMargin() - pad->GetRightMargin()); double f_x2 = (p_x2 - pad->GetLeftMargin()) / (1. - pad->GetLeftMargin() - pad->GetRightMargin()); double f_y1 = (p_y1 - pad->GetBottomMargin()) / (1. - pad->GetTopMargin() - pad->GetBottomMargin()); // Extract histogram providing the frame and axes //TH1 *hobj = GetAxisHist(pad); double xmin = hobj->GetBinLowEdge(hobj->GetXaxis()->GetFirst()); double xmax = hobj->GetBinLowEdge(hobj->GetXaxis()->GetLast()+1); double ymin = hobj->GetMinimum(); double ymax = hobj->GetMaximum(); // Convert box bounds to x-axis values double a_x1 = xmin + (xmax - xmin) * f_x1; double a_x2 = xmin + (xmax - xmin) * f_x2; // Get the histogram maximum in this range, given as y-axis value double a_max_h = hobj->GetMaximum(); // Convert this to a normalised frame value double f_max_h = (a_max_h - ymin) / (ymax - ymin); if (gPad->GetLogy()) { f_max_h = (log10(a_max_h) - log10(ymin)) / (log10(ymax) - log10(ymin)); } if (f_y1 - f_max_h < frac) { double f_target = 1. - (f_y1 - frac); FixTopRange(pad, hobj,a_max_h,f_target); } } void FixOverlay() { gPad->GetFrame()->Draw(); gPad->RedrawAxis(); } void FixTopRange(TPad *pad, TH1D *& hobj, double fix_y,double fraction) { //TH1* hobj = GetAxisHist(pad); double ymin = hobj->GetMinimum(); hobj->SetMaximum((fix_y - fraction * ymin) / (1. - fraction)); if (gPad->GetLogy()) { if (ymin == 0.) { std::cout << "Can't adjust log-scale y-axis range if the minimum is zero!\n"; return; } double max = (std::log10(fix_y) - fraction * std::log10(ymin)) / (1 - fraction); max = std::pow(8, max); hobj->SetMaximum(max); hobj->GetYaxis()->SetNdivisions(512); } }