{ gROOT->Reset(); gStyle->SetPalette(1,0); // violet - red TFile * infile = new TFile("hsimple.root"); TH2 * hist = infile->Get("hpxpy"); if(!hist) return; Double_t bothratio = 0.5; TCanvas * cHist = new TCanvas("forboth", "forboth", 800, 800); if(bothratio > 1 || bothratio <= 0)bothratio = 0.8; cHist->SetTopMargin(1 - bothratio); cHist->SetRightMargin(1 - bothratio); hist->Draw("col"); TH1D * projHistX = hist->ProjectionX(); TH1D * projHistY = hist->ProjectionY(); TAxis * xa = hist->GetXaxis(); TAxis * ya = hist->GetYaxis(); Double_t xmin = xa->GetXmin(); Double_t xmax = xa->GetXmax(); Double_t dx = (xmax - xmin) / (Double_t)projHistX->GetNbinsX(); Double_t ymin = ya->GetXmin(); Double_t ymax = ya->GetXmax(); Double_t y0 = ymax + 0.005 * (ymax - ymin); Double_t y1 = ymin + 0.9 *(ymax - ymin)/ bothratio; // cout << "ymax " << ymax << " ymin " << ymin<< " y1 " << y1<< endl; Double_t maxcont = -10000000; Int_t nbins = projHistX->GetNbinsX(); for(Int_t i=1; i <= nbins; i++){ if(projHistX->GetBinContent(i) > maxcont) maxcont=projHistX->GetBinContent(i); } if(maxcont == 0) return; Double_t yfac = (y1 - y0) / maxcont; Int_t np = 0; Double_t x = xmin; Double_t y = y0; TPolyLine * lpx = new TPolyLine(nbins * 2 + 3); for(Int_t i=1; i <= nbins; i++){ lpx->SetPoint(np, x, y); np++; y = y0 + yfac * projHistX->GetBinContent(i); lpx->SetPoint(np, x, y); np++; x += dx; } lpx->SetPoint(np, x, y); np++; lpx->SetPoint(np, x, y0); np++; lpx->SetPoint(np, xmin, y0); cout << "np " << np << endl; lpx->Draw("F"); lpx->SetFillStyle(1001); lpx->SetFillColor(38); lpx->Draw(); TGaxis * naxis = new TGaxis(xmin+dx*nbins, y0, xmin+dx*nbins, y1, 0, maxcont, 404, "-"); naxis->SetLabelOffset(0.01); naxis->SetLabelSize(0.02); naxis->Draw(); xmin = xa->GetXmin(); xmax = xa->GetXmax(); ymin = ya->GetXmin(); ymax = ya->GetXmax(); Double_t dy = (ymax - ymin) / (Double_t)projHistY->GetNbinsX(); Double_t x0 = xmax + 0.005 * (xmax - xmin); Double_t x1 = xmin + 0.9 * (xmax - xmin) / bothratio; maxcont = -10000000; for(Int_t i=1; i <= projHistY->GetNbinsX(); i++){ if(projHistY->GetBinContent(i) > maxcont) maxcont=projHistY->GetBinContent(i); } if(maxcont == 0) return; Double_t xfac = (x1 - x0) / maxcont; np = 0; x = x0; y = ymin; TPolyLine * lpy = new TPolyLine(projHistY->GetNbinsX()* 2 + 3); nbins = projHistY->GetNbinsX(); for(Int_t i=1; i <= nbins; i++){ lpy->SetPoint(np, x, y); np++; x = x0 + xfac * projHistY->GetBinContent(i); lpy->SetPoint(np, x, y); np++; y += dy; } lpy->SetPoint(np, x, y); np++; lpy->SetPoint(np, x0, y); np++; lpy->SetPoint(np, x0, ymin); cout << "np " << np << endl; lpy->Draw("F"); lpy->SetFillStyle(1001); lpy->SetFillColor(45); lpy->Draw(); naxis = new TGaxis(x0, ymin+nbins*dy, x1, ymin+nbins*dy, 0, maxcont, 404, "-"); naxis->SetLabelOffset(0.01); naxis->SetLabelSize(0.02); naxis->Draw(); cHist->Update(); }