Understanding THStack Output

I’m having trouble understanding the output of the default and lego draw option. They seem to ignore the setlogy option, the scale on the y-axis is definitely log scale but the plots have the shape as if they were on a normal axis scale. I have these plots with four of the THStack options: StackPt.pdf (33.6 KB)

The code is as follows:

TH1F *highWeightPt = nullptr;
TH1F *withoutHighWeightPt=nullptr;
highWeightPt=(TH1F*)f2->Get("h");
  highWeightPt->SetFillColor(kRed);
   highWeightPt->SetMarkerStyle(21);
   highWeightPt->SetMarkerColor(kRed);
withoutHighWeightPt = (TH1F*)_file0->Get("h");
  withoutHighWeightPt->SetFillColor(kBlue);
   withoutHighWeightPt->SetMarkerStyle(21);
   withoutHighWeightPt->SetMarkerColor(kBlue);
  THStack *hs = new THStack("pt stack","");


hs->Add(highWeightPt);
hs->Add(withoutHighWeightPt);
  TCanvas *cs = new TCanvas("cs","cs",10,10,700,900);
cs->cd();
 cs->SetLogy();
   TText T; T.SetTextFont(42); T.SetTextAlign(21);
   cs->Divide(2,2);
   cs->cd(1); gPad-> SetLogy(); hs->Draw(); T.DrawTextNDC(.5,.95,"Default drawing option");
   cs->cd(2); gPad-> SetLogy(); hs->Draw("nostack"); T.DrawTextNDC(.5,.95,"Option \"nostack\"");
 cs->cd(3); gPad-> SetLogy(); hs->Draw("nostackb"); T.DrawTextNDC(.5,.95,"Option \"nostackb\"");
   cs->cd(4);gPad-> SetLogy();  hs->Draw("lego1"); T.DrawTextNDC(.5,.95,"Option \"lego1\"");
cs->Draw();
cs->Write();
cs->Print("StackPt.pdf", "pdf");

 TCanvas *cst = new TCanvas("cst","stacked hists",10,10,700,700);
//   cst->SetLogy();
   cst->Divide(2,2);
   // in top left pad, draw the stack with defaults
   cst->cd(1);
gPad-> SetLogy();
   hs->Draw();
   // in top right pad, draw the stack in non-stack mode
   // and errors option
   cst->cd(2);
gPad-> SetLogy();
   gPad->SetGrid();
   hs->Draw("nostack,e1p");
   //in bottom left, draw in stack mode with "lego1" option
   cst->cd(3);
gPad-> SetLogy();
  gPad->SetFrameFillColor(17);
   gPad->SetTheta(3.77);
   gPad->SetPhi(2.9);
   hs->Draw("lego1");

The top right and bottom left plots are what I would expect from these pt plots on the log scale, showing all the way up to 7000 on the x-axis.

I may just be misunderstanding what it is I’ve actually told root to plot, but I’m very confused by the differences here, does anyone know why two of the log scale plots are so compressed in x?

Thanks for any help :slight_smile:

__
Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Can you upload the root file/s from which you read the histograms, so we can reproduce your results?
The x axis is not “compressed”, it’s just that the y axis range is smaller, cutting at 2x10^-4 or so; it seems that you did not show all (or the actual) code you used to create the pdf file you included, or the axis range is being changed for some reason; plus, the histograms should look like bars (not markers; compare with the example in the THStack docs), and the plots of pads 2 and 3 appear to be the same, but according to your code they shouldn’t.

The LEGO option does not really mean sense for stack made of 1D histograms. The LEGO option if for 2D histograms.

Apologies, the code is long but I think this has all relevant parts:

#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <iostream>
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TGraphErrors.h"
#include <iostream>
#include "TRint.h"
#include "TFile.h"
#include "TLatex.h"
#include "TROOT.h"
#include "TLegend.h"
#include "THStack.h"

void MakePlots(){

        TFile *_file0 = TFile::Open("ROCLeadingAndSubleading.root");

TFile *f2 = TFile::Open("PythiaWithHighWeightsROCLeadingAndSubleading.root");
TH1F *highWeightPt = nullptr;
TH1F *withoutHighWeightPt=nullptr;
highWeightPt=(TH1F*)f2->Get("h");
  highWeightPt->SetFillColor(kRed);
   highWeightPt->SetMarkerStyle(21);
   highWeightPt->SetMarkerColor(kRed);
withoutHighWeightPt = (TH1F*)_file0->Get("h");
  withoutHighWeightPt->SetFillColor(kBlue);
   withoutHighWeightPt->SetMarkerStyle(21);
   withoutHighWeightPt->SetMarkerColor(kBlue);
  THStack *hs = new THStack("pt stack","");


hs->Add(highWeightPt);
hs->Add(withoutHighWeightPt);
  TCanvas *cs = new TCanvas("cs","cs",10,10,700,900);
cs->cd();
 cs->SetLogy();
   TText T; T.SetTextFont(42); T.SetTextAlign(21);
   cs->Divide(2,2);
   cs->cd(1); gPad-> SetLogy(); hs->Draw(); T.DrawTextNDC(.5,.95,"Default drawing option");
   cs->cd(2); gPad-> SetLogy(); hs->Draw("nostack"); T.DrawTextNDC(.5,.95,"Option \"nostack\"");
 cs->cd(3); gPad-> SetLogy(); hs->Draw("nostackb"); T.DrawTextNDC(.5,.95,"Option \"nostackb\"");
   cs->cd(4);gPad-> SetLogy();  hs->Draw("lego1"); T.DrawTextNDC(.5,.95,"Option \"lego1\"");
cs->Draw();
cs->Write();
cs->Print("StackPt.pdf", "pdf");

 TCanvas *cst = new TCanvas("cst","stacked hists",10,10,700,700);
//   cst->SetLogy();
   cst->Divide(2,2);
   // in top left pad, draw the stack with defaults
   cst->cd(1);
gPad-> SetLogy();
   hs->Draw();
   // in top right pad, draw the stack in non-stack mode
   // and errors option
   cst->cd(2);
gPad-> SetLogy();
   gPad->SetGrid();
   hs->Draw("nostack,e1p");
   //in bottom left, draw in stack mode with "lego1" option
   cst->cd(3);
gPad-> SetLogy();
  gPad->SetFrameFillColor(17);
   gPad->SetTheta(3.77);
   gPad->SetPhi(2.9);
   hs->Draw("lego1");

   cst->cd(4);
gPad-> SetLogy();
cst->Draw();
cst->Print("MorePtStacks.pdf","pdf");

}

I’ve attached the files. I also noticed the difference with points vs bars, and wonder if it’s a draw option I set several root files back or something - I’ve put these plots through many macros.

ROCLeadingAndSubleading.root (98.1 KB)
PythiaWithHighWeightsROCLeadingAndSubleading.root (73.2 KB)

Hi couet, ah ok. I was looking at the documentation here and in these first set of four plots here, the one on the bottom right is a TH1F with the lego plot option I thought?

https://root.cern.ch/doc/master/classTHStack.html

Seems that the problem with the minimum is that if the minimum in the THStack is 0 (and this is the case here; you can check with cout << hs->GetMinimum() << endl;), ROOT determines a minimum as themin = themax*1.e-3' when using logy in stacked drawing (around line 810 in ROOT: hist/hist/src/THStack.cxx Source File).
You can force your own minimum, though, before drawing the non-stacked histo:

hs->SetMinimum(1e-23);

which of course requires knowing that minimum value.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.