TPad overlapping problem

Hello,

I am making two pads in one canvas and there range are different [1] even though they are overlapping [2]. Do you have idea what may be I am doing wrong? For your information I am working on root 6.

with regards,
Ram

[1]

pad[i] = new TPad(Form("pad%i",i),"",0.0,0.5,1.0,1.0,0);
padB[i] = new TPad(Form("padB%i",i),"",0.0,0.0,1.0,0.45,0);

[2] nPV.pdf (15 KB)

Did you remember to “pad[i]->cd();” before drawing?

Yes they should not overlap.
Can you send a small macro reproducing the problem ?

I attached the small macro [1] also the input root files [2]. Please have a look at it.

Thanks.
Ram

[1]
test.C (3.18 KB)
[2]
WJets_FullData.root (210 KB)
data_mu_prompt_25ns_runD_v3_FullData.root (322 KB)

I get:

Processing test.C...
In file included from input_line_10:1:
/Users/couet/Downloads/test.C:8:10: fatal error: 'ClassReadTree.cc' file not
      found
#include "ClassReadTree.cc"
         ^

Also can you clean up your macro from the absolute paths ?
it would be a good idea to run the test before posting it :slight_smile:

Sorry,

I forgot to attach one file. Also I cleaned the absolute path from my macro. Both files are attached in this post. My main macro is test.C and ClassReadTree.cc is a header file.

with regards,
Ram
ClassReadTree.cc (22.4 KB)
test.C (3.09 KB)

here it is:

#include<iostream>
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include "TLorentzVector.h"
#include<vector>
#include "TTree.h"
#include "ClassReadTree.cc"

using namespace std;

void test(){

   int Bin[1] = { 50 };
   int Min[1] = { 0 };
   int Max[1] = { 50 };

   Bool_t weight = true;
   int j=0;   //for bins
   int k=2;   //reseting the color of backgrounds
   TCanvas * c1 = new TCanvas("c1","",500,600);

   THStack** hs = new THStack*[1];
   TPad** pad = new TPad*[1];
   TPad** padB = new TPad*[1];
   TH1F**hRatio = new TH1F*[1];
//========= START:: Defining some of histograms   =======================================
   for (int i=0; i<1;i++) {
      hs[i]     = new THStack(Form("hs%i",i),"");
      pad[i]    = new TPad(Form("pad%i",i),"",0.0,0.5,1.0,1.0,0);pad[i]->Draw();
      padB[i]   = new TPad(Form("padB%i",i),"",0.0,0.0,1.0,0.45,0);padB[i]->Draw();
      hRatio[i] = new TH1F(Form("hRatio%i",i),"Ratio",Bin[i],Min[i],Max[i]);
   }

   TH1F** t0_BkgHist = new TH1F*[1];
   for (int i=0; i<1;i++) {
      if (i%1==0) {j=0;   //for reset bins
                   k++;}   // for line & Fill color
      else j++;
      t0_BkgHist[i] = new TH1F(Form("t0_BkgHist%i",i),"",Bin[j],Min[j],Max[j]);
      t0_BkgHist[i]->SetLineColor(k);
      t0_BkgHist[i]->SetFillColor(k);
   }

   TH1F** DataHist = new TH1F*[1];
   for(int i=0; i<1;i++){
      DataHist[i] = new TH1F(Form("DataHist%i",i),"",Bin[i],Min[i],Max[i]);
      DataHist[i]->SetLineColor(2);
   }

//========= START:: Filling of histograms   =======================================
   TChain* t0_mc_bkg = new TChain("otree");
      t0_mc_bkg->Add("WJets_FullData.root");
      ClassReadTree mc_bkg_0(t0_mc_bkg);
      for(int iEv_0_mc_bkg=0;iEv_0_mc_bkg < t0_mc_bkg->GetEntries();iEv_0_mc_bkg++){
         t0_mc_bkg->GetEntry(iEv_0_mc_bkg);
         t0_BkgHist[0]->Fill(mc_bkg_0.nPV);
      }

   TChain* t0_data = new TChain("otree");
      t0_data->Add("data_mu_prompt_25ns_runD_v3_FullData.root");
      ClassReadTree mc_data_0(t0_data);
      for(int iEv_0_data=0;iEv_0_data < t0_data->GetEntries();iEv_0_data++){
         t0_data->GetEntry(iEv_0_data);
         DataHist[0]->Fill(mc_data_0.nPV);
      }

//========= END:: Filling of histograms   =======================================

   TLegend *leg = new TLegend(0.70,0.70,0.85,0.90,NULL,"brNDC");
   double HistMax=0.0;
   c1->cd();

   pad[0]->SetBottomMargin(0.05555562);
   pad[0]->Draw();
   pad[0]->cd();

   t0_BkgHist[0]->Scale(1./t0_BkgHist[0]->Integral());
   leg->AddEntry(t0_BkgHist[0],"WJets","l");

   DataHist[0]->Scale(1./DataHist[0]->Integral());
   leg->AddEntry(DataHist[0],"Data","l");

   hs[0]->Add(t0_BkgHist[0]);
   hs[0]->SetMaximum(0.13);
   hs[0]->SetMinimum(0.);
   hs[0]->Draw();
   DataHist[0]->Draw("same");
   leg->Draw("same");

   TH1F *h2 = (TH1F*)DataHist[0]->Clone();
   hRatio[0]->Add(t0_BkgHist[0]);

   c1->cd(); // <<<<<<<<<<<<<<<
   padB[0]->SetGridy(1);
   padB[0]->SetTopMargin(0.1);
   padB[0]->SetBottomMargin(0.00);
   padB[0]->Draw();
   padB[0]->cd();

   h2->Divide(hRatio[0]);
   h2->SetMarkerStyle(21);
   h2->SetMinimum(-0.2);
   h2->SetMaximum(3.2);
   h2->SetStats(0);
   h2->Draw("");

   c1->SaveAs("nPV.pdf");
}