{ // 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); colorNPB = TColor::GetColor("#0000ff"); colorPB = TColor::GetColor("#e60077"); histoA1->SetLineColor(colorNPB); histoA1->SetFillStyle(4050); histoA1->SetFillColor(colorNPB); histoA1->SetLineWidth(2); histoA2->SetLineColor(colorPB); histoA2->SetFillStyle(4050); 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", "", 40, -5, 5); TH1F* histoB2 = new TH1F("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); colorNP1p = TColor::GetColor("#ee7700"); colorP1p = TColor::GetColor("#0033cc"); histoB1->SetLineColor(colorP1p); histoB1->SetFillStyle(4050); histoB1->SetFillColor(colorP1p); histoB1->SetLineWidth(2); histoB2->SetLineColor(colorNP1p); histoB2->SetFillStyle(4050); 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); // Draw the histograms //----------------------- TCanvas *c = new TCanvas; c->SetFrameFillColor(0); c->SetFrameFillStyle(4000); TColor *c1000 = new TColor(1000,0.,0.,0,"c1000",0.0); hstackA->Draw(); hstackB->Draw("SAME"); }