# Problem with 2D plot values

Dear @Wile_E_Coyote, I was just noticing one thing about the 2d plot that you helped me to do in this topic Difference between arrays .

As you can see, by plotting the energies in two scintillators (Called scintillator 8 and scintillator 9) I’ve energies around 1700ADC count

when I plot the energies in 2d plots, energies looks likes divided by 1000, indeed I’ve these plots in which energies are 2 ADC counts… I can’t understand the reason…

This is the used code:

``````TCanvas *c25 = new TCanvas("c25",canvtitle,1280,1024);
c25->Divide (2,1);
c25->cd(1);
TH2F *henecdsubstringcutrelTHF = new TH2F("henecdsubstringcutrelTHF", "", 50, 0., 50.,50., 0.,50.);
TCut cut1 = TString::Format("TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f) && TMath::Abs(Calo_Time[%d] - Calo_Time[%d] - (%f)) < (%d)*(%f)", a, b, p1, csig, p2, a, c, p13sub, csig, p23sub,a, d, p14sub, csig, p24sub).Data();
TString what = TString::Format("Calo_EnDep[%d] : Calo_EnDep[%d]>> henecdsubstringcutrelTHF", d, c);
t->Draw(what, cut1);
gPad->Update(); // make sure it's really (re)drawn
henecdsubstringcutrelTHF->SetTitle(cdhenecdsubstringcutrelTHFname);
henecdsubstringcutrelTHF->GetXaxis()->SetTitle(cdeneXnameabenecvsd);
henecdsubstringcutrelTHF->GetYaxis()->SetTitle(cdeneYnameabenecvsd);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleSize(c2_YTitleSize);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleFont(c2_YTitleFont);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
henecdsubstringcutrelTHF->GetYaxis()->SetLabelFont(c2_YLabelFont);
henecdsubstringcutrelTHF->GetYaxis()->SetLabelSize(c2_YLabelSize);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleSize(c2_XTitleSize);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleFont(c2_XTitleFont);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
henecdsubstringcutrelTHF->GetXaxis()->SetLabelFont(c2_XLabelFont);
henecdsubstringcutrelTHF->GetXaxis()->SetLabelSize(c2_XLabelSize);
henecdsubstringcutrelTHF->Draw("COLZ");
henecdsubstringcutrelTHF->SetName(heneabname);
gPad->Update(); // make sure it's really (re)drawn
TLegend* leghenecdsubstringcutrelTHF = new TLegend(0.65, 0.7, .75, .75);
leghenecdsubstringcutrelTHF->SetNColumns(1);
leghenecdsubstringcutrelTHF->Draw();
TPaveStats *statsghenecdsubstringcutrelTHF = (TPaveStats*)henecdsubstringcutrelTHF->GetListOfFunctions()->FindObject("stats");
statsghenecdsubstringcutrelTHF->SetTextColor(kBlue);
statsghenecdsubstringcutrelTHF->SetX1NDC(0.80); statsghenecdsubstringcutrelTHF->SetX2NDC(0.98);
statsghenecdsubstringcutrelTHF->SetY1NDC(0.77); statsghenecdsubstringcutrelTHF->SetY2NDC(0.92);
c25->cd(2);
TH2F *henecdsubstringcutrelTHFsumdiff = new TH2F("henecdsubstringcutrelTHFsumdiff", "", 50, 0., 50., 50, 0., 50.);
TString whatsumdiff = TString::Format("(Calo_EnDep[%d] - Calo_EnDep[%d]) : (Calo_EnDep[%d] + Calo_EnDep[%d])>> henecdsubstringcutrelTHFsumdiff", c, d,c,d);
t->Draw(whatsumdiff, cut1);
gPad->Update(); // make sure it's really (re)drawn
henecdsubstringcutrelTHFsumdiff->SetTitle(cdhenecdsubstringcutrelTHFnamesumdiff);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitle(cdeneXnameabenecvsdsumdiff);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitle(cdeneYnameabenecvsdsumdiff);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleSize(c2_YTitleSize);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleFont(c2_YTitleFont);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetLabelFont(c2_YLabelFont);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetLabelSize(c2_YLabelSize);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleSize(c2_XTitleSize);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleFont(c2_XTitleFont);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetLabelFont(c2_XLabelFont);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetLabelSize(c2_XLabelSize);
henecdsubstringcutrelTHFsumdiff->Draw("COLZ");
henecdsubstringcutrelTHFsumdiff->SetName(heneabname);
gPad->Update(); // make sure it's really (re)drawn
TLegend* leghenecdsubstringcutrelTHFsumdiff = new TLegend(0.65, 0.7, .75, .75);
leghenecdsubstringcutrelTHFsumdiff->SetNColumns(1);
leghenecdsubstringcutrelTHFsumdiff->Draw();
TPaveStats *statsghenecdsubstringcutrelTHFsumdiff = (TPaveStats*)henecdsubstringcutrelTHFsumdiff->GetListOfFunctions()->FindObject("stats");
statsghenecdsubstringcutrelTHFsumdiff->SetTextColor(kBlue);
statsghenecdsubstringcutrelTHFsumdiff->SetX1NDC(0.80); statsghenecdsubstringcutrelTHFsumdiff->SetX2NDC(0.98);
statsghenecdsubstringcutrelTHFsumdiff->SetY1NDC(0.77); statsghenecdsubstringcutrelTHFsumdiff->SetY2NDC(0.92);
c25->Print(myplothenecdsubstringcutrelTHF);
delete c25;
``````

ROOT Version: 5.3438
Platform: Windows
Compiler: Not Provided

Try with “automatic binning”:

``````TH2F *henecdsubstringcutrelTHF = new TH2F("henecdsubstringcutrelTHF", "", 50, 0., 0., 50, 0., 0.);
``````

Hi @Wile_E_Coyote, thank you. If I replace

``````TH2F *henecdsubstringcutrelTHF = new TH2F("henecdsubstringcutrelTHF", "", 50, 0., 0., 50., 0., 0.);
``````

with

``````TH2F *henecdsubstringcutrelTHF = new TH2F("henecdsubstringcutrelTHF", "");
``````

I get this error

Is this really what I advised you to do?

I’m sorry, I didn’t see that you replaced

``````50, 0., 50.,50., 0.,50.
``````

with

``````50, 0., 0., 50, 0., 0.
``````

Anyway, now I setted

``````1800, 0., 0., 180, 0., 0.

``````

and I get this plot

I think that the color palette cover the x10^3 (because I’ve it just on y axis but I don’t see it on x axis). is it possible move or re-size the color palette?

Right after `c25->cd(1);` add `gPad->SetRightMargin(0.15);`.

Hi @Wile_E_Coyote, thank you. Unfortunately, the color palette doesn’t look like moving…I also tried setting a big number (20). Maybe the best should be to resize it doing it shorter. Is it possible?

Hi @Wile_E_Coyote, thank you…I wrote:

``````henecdsubstringcutrelTHF->Draw("COLZ");
henecdsubstringcutrelTHF->SetName(heneabname);
gPad->Update(); // make sure it's really (re)drawn
TH1 *hh = henecdsubstringcutrelTHF->DrawCopy("colz"); // creates all axes
TPaletteAxis * palette = (TPaletteAxis *) hh->GetListOfFunctions()->FindObject("palette");
palette->SetX2NDC(0.93);
gPad->Update(); // make sure it's really (re)drawn
c25->Modified();
c25->Update();
TLegend* leghenecdsubstringcutrelTHF = new TLegend(0.65, 0.7, .75, .75);
``````

but it didn’t change.

I guess you need:

``````gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
``````

right after “DrawCopy” (i.e. before “GetListOfFunctions”).

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

Hi @Wile_E_Coyote, sorry because I didn’t reply earlier to your last reply in this topic https://root-forum.cern.ch/t/problem-with-2d-plot-values/33142/10 (now it’s close).

``````gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn
``````

right after right after “DrawCopy”, I wrote in this way

``````TH2F *henecdsubstringcutrelTHF = new TH2F("henecdsubstringcutrelTHF", "", 10000, 0., 0.,10000., 0.,0.);
TString what = TString::Format("Calo_EnDep[%d] : Calo_EnDep[%d]>> henecdsubstringcutrelTHF", d, c);
t->Draw(what, cut && cut3sub && cut4sub && !cut5sub && !cut5sub2);
gPad->Update(); // make sure it's really (re)drawn
henecdsubstringcutrelTHF->SetTitle(cdhenecdsubstringcutrelTHFname);
henecdsubstringcutrelTHF->GetXaxis()->SetTitle(cdeneXnameabenecvsd);
henecdsubstringcutrelTHF->GetYaxis()->SetTitle(cdeneYnameabenecvsd);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleSize(c2_YTitleSize);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleFont(c2_YTitleFont);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
henecdsubstringcutrelTHF->GetYaxis()->SetLabelFont(c2_YLabelFont);
henecdsubstringcutrelTHF->GetYaxis()->SetLabelSize(c2_YLabelSize);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleSize(c2_XTitleSize);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleFont(c2_XTitleFont);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
henecdsubstringcutrelTHF->GetXaxis()->SetLabelFont(c2_XLabelFont);
henecdsubstringcutrelTHF->GetXaxis()->SetLabelSize(c2_XLabelSize);
henecdsubstringcutrelTHF->Draw("COLZ");
henecdsubstringcutrelTHF->SetName(heneabname);
gPad->Update(); // make sure it's really (re)drawn
TH1 *hh = henecdsubstringcutrelTHF->DrawCopy("colz"); // creates all axes
gPad->Update(); // make sure it's really (re)drawn
TPaletteAxis * palette = (TPaletteAxis *) hh->GetListOfFunctions()->FindObject("palette");
palette->SetX2NDC(0.93);
gPad->Update(); // make sure it's really (re)drawn
c25->Modified();
c25->Update();
TLegend* leghenecdsubstringcutrelTHF = new TLegend(0.65, 0.7, .75, .75);
leghenecdsubstringcutrelTHF->SetNColumns(1);
leghenecdsubstringcutrelTHF->Draw();
TPaveStats *statsghenecdsubstringcutrelTHF = (TPaveStats*)henecdsubstring
``````

but palette didn’t move…

ROOT Version: 5.34/38
Platform: Windows
Compiler: Not Provided

@couet any recommendation here?

Can you provide some macro I can run ?
The piece of code you posted is not complete.

Hi @couet , in attachment the macro and root file. Don’t worry about the numerical results, because currently I’m doing one other work, so I didn’t set the Initialization parameters for the fit. Just consider the problem about the palette.calo.cpp (941.4 KB)

@faca87 I can run your test. It generates a lot of pdf files. which one should I look at ?

Hi @couet , the plot is si-500636660_ene3-vs-ene2.pdf and you will find it in the folder `si-500636660\sub_8-9\sub_3\sub_2`

The attached example clearly moves the palette.

calo.C (938.3 KB)

Hi @couet, you code works, but I’m trying to use it also for the second pad then I get error.

``````c25->cd(1);
TH2F *henecdsubstringcutrelTHF = new TH2F("henecdsubstringcutrelTHF", "", 10000, 0., 0.,10000., 0.,0.);
TString what = TString::Format("Calo_EnDep[%d] : Calo_EnDep[%d]>> henecdsubstringcutrelTHF", d, c);
t->Draw(what, cut && cut3sub && cut4sub && !cut5sub && !cut5sub2);
gPad->Update(); // make sure it's really (re)drawn
henecdsubstringcutrelTHF->SetTitle(cdhenecdsubstringcutrelTHFname);
henecdsubstringcutrelTHF->GetXaxis()->SetTitle(cdeneXnameabenecvsd);
henecdsubstringcutrelTHF->GetYaxis()->SetTitle(cdeneYnameabenecvsd);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleSize(c2_YTitleSize);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleFont(c2_YTitleFont);
henecdsubstringcutrelTHF->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
henecdsubstringcutrelTHF->GetYaxis()->SetLabelFont(c2_YLabelFont);
henecdsubstringcutrelTHF->GetYaxis()->SetLabelSize(c2_YLabelSize);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleSize(c2_XTitleSize);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleFont(c2_XTitleFont);
henecdsubstringcutrelTHF->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
henecdsubstringcutrelTHF->GetXaxis()->SetLabelFont(c2_XLabelFont);
henecdsubstringcutrelTHF->GetXaxis()->SetLabelSize(c2_XLabelSize);
henecdsubstringcutrelTHF->Draw("COLZ");
henecdsubstringcutrelTHF->SetName(heneabname);
gPad->Update(); // make sure it's really (re)drawn
TH1 *hh = henecdsubstringcutrelTHF->DrawCopy("colz"); // creates all axes
gPad->Update(); // make sure it's really (re)drawn
TPaletteAxis * palette = (TPaletteAxis *) hh->GetListOfFunctions()->FindObject("palette");
palette->SetX1NDC(0.86);
palette->SetX2NDC(0.90);
palette->SetY1NDC(0.20);
palette->SetY2NDC(0.80);
c25->Modified();
c25->Update();
TLegend* leghenecdsubstringcutrelTHF = new TLegend(0.65, 0.7, .75, .75);
leghenecdsubstringcutrelTHF->SetNColumns(1);
leghenecdsubstringcutrelTHF->Draw();
TPaveStats *statsghenecdsubstringcutrelTHF = (TPaveStats*)hh->GetListOfFunctions()->FindObject("stats");
statsghenecdsubstringcutrelTHF->SetTextColor(kBlue);
statsghenecdsubstringcutrelTHF->SetX1NDC(0.80); statsghenecdsubstringcutrelTHF->SetX2NDC(0.98);
statsghenecdsubstringcutrelTHF->SetY1NDC(0.77); statsghenecdsubstringcutrelTHF->SetY2NDC(0.92);
``````

In the second one I wrote:

``````	c25->cd(2);
TH2F *henecdsubstringcutrelTHFsumdiff = new TH2F("henecdsubstringcutrelTHFsumdiff", "", 10000, 0., 0., 10000, 0., 0.);
TString whatsumdiff = TString::Format("(Calo_EnDep[%d] - Calo_EnDep[%d]) : (Calo_EnDep[%d] + Calo_EnDep[%d])>> henecdsubstringcutrelTHFsumdiff", c, d,c,d);
t->Draw(whatsumdiff, cut && cut3sub && cut4sub && !cut5sub && !cut5sub2);
gPad->Update(); // make sure it's really (re)drawn
henecdsubstringcutrelTHFsumdiff->SetTitle(cdhenecdsubstringcutrelTHFnamesumdiff);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitle(cdeneXnameabenecvsdsumdiff);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitle(cdeneYnameabenecvsdsumdiff);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleSize(c2_YTitleSize);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleFont(c2_YTitleFont);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetTitleOffset(c2_YTitleOffset);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetLabelFont(c2_YLabelFont);
henecdsubstringcutrelTHFsumdiff->GetYaxis()->SetLabelSize(c2_YLabelSize);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleSize(c2_XTitleSize);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleFont(c2_XTitleFont);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetTitleOffset(c2_XTitleOffset);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetLabelFont(c2_XLabelFont);
henecdsubstringcutrelTHFsumdiff->GetXaxis()->SetLabelSize(c2_XLabelSize);
henecdsubstringcutrelTHFsumdiff->Draw("COLZ");
henecdsubstringcutrelTHFsumdiff->SetName(heneabname);
gPad->Update(); // make sure it's really (re)drawn
TH1 *hh2 = henecdsubstringcutrelTHFsumdiff->DrawCopy("colz"); // creates all axes
gPad->Update(); // make sure it's really (re)drawn
TPaletteAxis * palette2 = (TPaletteAxis *) hh2->GetListOfFunctions()->FindObject("palette");
palette2->SetX1NDC(0.86);
palette2->SetX2NDC(0.90);
palette2->SetY1NDC(0.20);
palette2->SetY2NDC(0.80);
c25->Modified();
c25->Update();
TLegend* leghenecdsubstringcutrelTHFsumdiff = new TLegend(0.65, 0.7, .75, .75);
leghenecdsubstringcutrelTHFsumdiff->SetNColumns(1);
leghenecdsubstringcutrelTHFsumdiff->Draw();
TPaveStats *statsghenecdsubstringcutrelTHFsumdiff = (TPaveStats*)henecdsubstringcutrelTHFsumdiff->GetListOfFunctions()->FindObject("stats");
statsghenecdsubstringcutrelTHFsumdiff->SetTextColor(kBlue);
statsghenecdsubstringcutrelTHFsumdiff->SetX1NDC(0.80); statsghenecdsubstringcutrelTHFsumdiff->SetX2NDC(0.98);
statsghenecdsubstringcutrelTHFsumdiff->SetY1NDC(0.77); statsghenecdsubstringcutrelTHFsumdiff->SetY2NDC(0.92);
c25->Print(myplothenecdsubstringcutrelTHF);
``````

but I get this error:

I copied all the code of first pad, just replacing the name:

``````henecdsubstringcutrelTHF -> henecdsubstringcutrelTHFsumdiff
hh->hh2
palette->palette2

etc.
``````

calo.C (938.3 KB)