Set LogScale on Z axis in 2D histo

Dear All,
I would like to plot a 2D histo using colz option (let’s say the background) and on top of it I plot the signal using box option. It works pretty well but if I set z axis in logscale by doing for instance this:

 c1->SetLogz();

the signal disappears. Can someone tell me please how to resolve it?
Thanks in adavance.
Cheers

Warnings concerning a “logarithmic palette” (maybe it’s just TGraph2D specific) … I think this problem has not been fixed: Number of divisions on palette

I will look at it. thanks

Hi,
Thanks for replying, hope there will be a solution :slight_smile: .
Cheers
Diallo

I tried the following and it seems ok:

void colcontsame() {
   TH2F *h1 = new TH2F("h1","h1",100,-10,10,100,-10,10);
   TH2F *h2 = new TH2F("h2","h2",40,-3,3,40,-3,3);
   for (Int_t i=0;i<1000;i++) {
      double x,y;
      gRandom->Rannor(x,y);
      h1->Fill(5*x,5*y,4);
      if(x<0 && y<0) h2->Fill(x,y,3);
   }
   h1->SetFillColor(1);
   h2->SetLineColor(kRed);
   h2->SetContour(5);
   h1->Draw("col");
   h2->Draw("cont3 same");
   gPad->SetLogz();
}

replacing cont3 by box seems fine too.

Hi,
Thanks so much it works with cont 3 option :slight_smile:
Cheers
Diallo

As I said box option is fine too in that case.

HI,
If I put box instead of cont3 the bar will appear with logScal but the signal is not plotted.
Cheers
Diallo

Ok … to help further I would need a example.
With my macro both box and cont3 are fine.

Ok here is the code for instance:

 TFile* f2   = new TFile("/afs/cern.ch/user/d/diboye/diboye_work/ZdZdTruthArea/run/Plots/Mzd50GeV_Gamma4MeV_KinVar_ACC.root");
 TFile* f8   = new TFile("/afs/cern.ch/user/d/diboye/diboye_work/ZdZdRecoArea/run/Diamoond_Square_Circle_Bkg/bkg_ggFH_KinVar_ACC.root");
 TH2D * Hist_M12vsM34_ACC   = (TH2D*)f2->Get("myHist_M12vsM34_all");
   Double_t scale48 = 1/Hist_M12vsM34_ACC->Integral();
   Hist_M12vsM34_ACC->Scale(scale48);
   Hist_M12vsM34_ACC->SetFillColor(1);
   Hist_M12vsM34_ACC->SetMarkerColor(1);
 TH2D * Hist_M12vsM34_ACC_bkg_ggFH   = (TH2D*)f8->Get("myHist_M12vsM34_all");
   Double_t scale54 = 1/Hist_M12vsM34_ACC_bkg_ggFH->Integral();
   Hist_M12vsM34_ACC_bkg_ggFH->Scale(scale54);
   Hist_M12vsM34_ACC_bkg_ggFH->SetFillColor(4);
  gStyle->SetPalette(55);
   Hist_M12vsM34_ACC_bkg_ggFH->GetXaxis()->SetTitle("M_{34}[GeV]");
   Hist_M12vsM34_ACC_bkg_ggFH->GetYaxis()->SetTitle("M_{12}[GeV]");
    Hist_M12vsM34_ACC->SetContour(5);
     Hist_M12vsM34_ACC->SetLineColor(1);
       Hist_M12vsM34_ACC_bkg_ggFH->Draw("colz");
       Hist_M12vsM34_ACC->Draw("box same");
       c1->SetLogz();

bkg_ggFH_KinVar_ACC.root (15.0 KB)
Mzd50GeV_Gamma4MeV_KinVar_ACC.root (117.4 KB)
I uploaded a part of my macro which is supposed to do the job with the files.
Cheers
Diallo

I do not know why but:

{
   TFile* f2   = new TFile("Mzd50GeV_Gamma4MeV_KinVar_ACC.root");
   TH2D * Hist_M12vsM34_ACC   = (TH2D*)f2->Get("myHist_M12vsM34_all");
   Double_t scale48 = 1/Hist_M12vsM34_ACC->Integral();
   Hist_M12vsM34_ACC->Scale(scale48); // if you comment this line then the box option works with logz
   Hist_M12vsM34_ACC->Draw("box ");
   c1->SetLogz();
}

Hi,
You are right, it’s a bit strange but it works like that, the same also for “scat” option.
Cheers
Diallo

I am investigating why it does not show in case of box

Ok Thanks in advance :slight_smile:

This problem now fixed in the ROOT master.

Hi
Thanks very much, really appreciate :slight_smile:

By the way did you try with the code I sent you? didn’t manage yet to use box option with the line uncomment

That was the bug I fixed in the master …

1 Like

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