{ // Take care of hstackA //------------------------ TH1F* histoA1 = new TH1F("histoA1", "", 40, -5, 5); TH1F* histoA2 = new TH1F("histoA2", "", 40, -5, 5); // Fill histos A with gaussians centered at 0 histoA1->FillRandom("gaus", 1000); histoA2->FillRandom("gaus", 2000); Color_t colorNPB = TColor::GetColor("#0000ff"); Color_t colorPB = TColor::GetColor("#e60077"); histoA1->SetLineColor(colorNPB); histoA1->SetFillStyle(3354); histoA1->SetFillColor(colorNPB); histoA1->SetLineWidth(2); histoA2->SetLineColor(colorPB); histoA2->SetFillStyle(3354); histoA2->SetFillColor(colorPB); histoA2->SetLineWidth(2); THStack* hstackA = new THStack("hstackA", ""); hstackA->Add(histoA1); hstackA->Add(histoA2); // Take care of hstackB //------------------------- TH1F* histoB1 = new TH1F("histoB1", "histoB1", 40, -5, 5); TH1F* histoB2 = new TH1F("histoB2", "histoB2", 40, -5, 5); // Creating an offset gaussian distribution TF1 *myfunc= new TF1("myfunc", "gaus", 0, 3); myfunc->SetParameters(10.,1.5, 1); // Fill histos B with gaussians centered at 1.5 histoB1->FillRandom("myfunc", 1500); histoB2->FillRandom("myfunc", 2000); Color_t colorNP1p = TColor::GetColor("#ee7700"); Color_t colorP1p = TColor::GetColor("#0033cc"); histoB1->SetLineColor(colorP1p); histoB1->SetFillStyle(3345); histoB1->SetFillColor(colorP1p); histoB1->SetLineWidth(2); histoB2->SetLineColor(colorNP1p); histoB2->SetFillStyle(3345); histoB2->SetFillColor(colorNP1p); histoB2->SetLineWidth(2); THStack* hstackB = new THStack("hstackB", ""); hstackB->Add(histoB1); hstackB->Add(histoB2); // Set y range float Amax = hstackA->GetMaximum(); float Bmax = hstackB->GetMaximum(); float yaxismax = TMath::Max(Amax, Bmax); hstackA->SetMaximum(yaxismax); hstackB->SetMaximum(yaxismax); // ***** Set the canvas proportions //---------------------------------- TCanvas *c = new TCanvas("THStacks", "", 50,50,1000,500); c->SetFrameFillColor(0); c->SetFrameFillStyle(4000); TColor *c1000 = new TColor(1000,0.,0.,0,"c1000",0.0); // ***** Set the axis title //-------------------------- hstackA->Draw(); c->Update(); hstackA->GetXaxis()->SetTitle("#LT R #GT_{all}"); hstackB->Draw(); c->Update(); hstackB->GetXaxis()->SetTitle("#LT R #GT_{all}"); // Draw the histograms //----------------------- hstackA->Draw(); hstackB->Draw("SAME"); c->Print("temp.png"); }