I was having trouble getting the code displayed in chapter 5.3 (2D histograms) of the tutorial (by Piparo, Quast, and Zeise) and couldn’t get it to work as displayed. The result of the code in the tutorial was all of the graphs stacked on top of each other, rather than on four separate pads.
I made the following modifications for it to work:
-I declared bidi_h as a pointer
-I used Draw() instead of DrawClone in each instance of DrawClone(). My code was as follows:
void Chapter5p3(){
gStyle->SetPalette(kSunset);
gStyle->SetOptStat(0);
gStyle->SetOptTitle(0);
TH2F* bidi_h = 0;
bidi_h = new TH2F ("bidi_h","2D Histogram;Gaussian Vals;Exp Vals)",
10,-5,5, // x axis
30,0,10);//y axis
TRandom3 rgen;
for (int i=0;i<500000;i++)
bidi_h->Fill(rgen.Gaus(0,2),10-rgen.Exp(4),.1);
auto c = new TCanvas("Canvas","Canvas",800,800);
c->Divide(2,2);
c->cd(1);bidi_h->Draw("Cont1");
c->cd(2);bidi_h->Draw("Colz");
c->cd(3);bidi_h->Draw("lego1");
c->cd(4);bidi_h->Draw("surf3");
//Profiles and Projections
auto c2=new TCanvas("Canvas2","Canvas2",800,800);
c2->Divide(2,2,0,0);
c2->cd(1);bidi_h->ProjectionX()->Draw();
c2->cd(2);bidi_h->ProjectionY()->Draw();
c2->cd(3);bidi_h->ProfileX()->Draw();
c2->cd(4);bidi_h->ProfileY()->Draw();
}
ROOT Version: 6.12/06
Platform: OSX
Compiler: Not Provided