TH1D *h1 = new TH1D("h1", "Original Histogram", 100, 0, 10); // create a new histogram with 100 bins between 0 and 10 // fill the histogram with some data h1->Fill(2.3); h1->Fill(4.5); h1->Fill(6.7); // clone the histogram TH1D *h2 = (TH1D*)h1->Clone("h2"); h2->SetTitle("Cloned Histogram"); // draw the histograms side by side h1->Draw(); h2->SetLineColor(kRed); h2->Draw("same");
TH1D *h1 = new TH1D("h1", "Original Histogram", 100, 0, 10); // create a new histogram with 100 bins between 0 and 10 // fill the histogram with some data h1->Fill(2.3); h1->Fill(4.5); h1->Fill(6.7); // clone the histogram TH1D *h2 = (TH1D*)h1->Clone(); h2->SetTitle("Cloned Histogram"); h2->SetLineColor(kRed); // scale the cloned histogram by a factor of 2 h2->Scale(2); // draw the histograms side by side h1->Draw(); h2->Draw("same");In this example, we create an original histogram "h1" with 100 bins between 0 and 10, and fill it with some data. Then, we clone the histogram into a new histogram "h2" with a different title, set the line color to red, and scale it by a factor of 2. Lastly, we draw the histograms side by side. Overall, TH1D Clone is a useful method from the ROOT package library for creating copies of histograms with identical properties as existing histograms.