# \`\`\`TH1D::DrawClone()\`\`\` seems to not take the \`\`\`Option\_t\`\`\` into account

**URL:** <https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121>\
**Category:** Newbie\
**Created:** [January 16, 2023, 10:38am UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121 "2023-01-16T10:38:12Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo\_Tarbouriech](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/leo_tarbouriech/32/32139_2.png) [@Leo\_Tarbouriech](https://root-forum.cern.ch/u/Leo_Tarbouriech)\
**Post date:** [January 16, 2023, 10:38am UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/1 "2023-01-16T10:38:12Z")

</div>

Dear experts,

I am trying to draw a seri of histograms. As I want to make to plots, one with the “brut” histograms, one with the histograms that have been renormalized. To achieve this, I have decided to use the `TH1D::DrawClone()` method to draw the “brut” histograms and then I renormalize them and redraw in another `TPad`. I want to draw the histograms with the options : `"HIST E"`in both case. It works perfectly with the `TH1D::Draw()` method the options have no influence on the behavior of `TH1D::DrawClone()`.

How can I force `TH1D::DrawClone()` to take these options into account properly ?

The other way to turn around the problem is to create copies of these histograms and draw them independently with `TH1D::Draw()` but it is heavy in terms of memory and number of variables (I think).

Thank in advance for your thoughts,  
Leo

Here is my code:

```auto
//Drawing
    c1->cd();
    ptlead_00->DrawClone("HIST E");
    ptlead_15->DrawClone("HIST E same");
    ptlead_40->DrawClone("HIST E same");
    ptlead_60->DrawClone("HIST E same");
    ptlead_80->DrawClone("HIST E same");
    ptlead_MC->DrawClone("HIST E same");
    leg->Draw();
    c1->SaveSource();

    //Drawing normalised plots
    c2->cd();
    ptlead_00->Scale(1./ptlead_00->Integral());
    ptlead_15->Scale(1./ptlead_15->Integral());
    ptlead_40->Scale(1./ptlead_40->Integral());
    ptlead_60->Scale(1./ptlead_60->Integral());
    ptlead_80->Scale(1./ptlead_80->Integral());
    ptlead_MC->Scale(1./ptlead_MC->Integral());
    ptlead_00->GetYaxis()->SetRangeUser(0.,0.24);
    ptlead_00->Draw("HIST E");
    ptlead_15->Draw("HIST E same");
    ptlead_40->Draw("HIST E same");
    ptlead_60->Draw("HIST E same");
    ptlead_80->Draw("HIST E same");
    ptlead_MC->Draw("HIST E same");
    leg->Draw();
    c2->SaveSource();

```

For the first bloc I obtain as output : (left, the result of the first bloc, right the result of the second bloc). You see, the line of the histograms are not drawn as it should according to `"HIST"`.

 ![Capture d’écran 2023-01-16 à 11.36.28](https://root-forum.cern.ch/uploads/default/original/3X/f/f/ff1239454390a81fdd687d1090a5cdcf8f931514.png)

* * *

\_ROOT Version: 6.22/09  
\_Platform: lxplus, C++  
\_Compiler: slc7\_amd64\_gcc900

* * *

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [January 16, 2023, 10:56am UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/2 "2023-01-16T10:56:16Z")

</div>

I’m sure @couet will take care of this

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 16, 2023, 12:40pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/3 "2023-01-16T12:40:24Z")

</div>

I tried with a histogram I have, and I got the same plot with Draw and DrawClone. Can you post a macro, we can run, reproducing the problem?

---

<div class="post-metadata">

**Author:** ![Leo\_Tarbouriech](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/leo_tarbouriech/32/32139_2.png) [@Leo\_Tarbouriech](https://root-forum.cern.ch/u/Leo_Tarbouriech)\
**Post date:** [January 16, 2023, 1:15pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/4 "2023-01-16T13:15:58Z")

</div>

This is the full function:

```auto
void plot_ptleading()
{
    //Reading the getMNobservables folders
    TFile *Data = new TFile("/eos/home-l/ltarbour/DAS/v32/MN_system_1/1D_JEScorrected/getMNobservables/2017H_all.root","READ");
    TFile *Data15 = new TFile("/eos/home-l/ltarbour/DAS/v32/MN_system_1/1D_JEScorrected/getMNobservables/2017H_HLT_HIAK4PFJets15.root","READ");
    TFile *Data40 = new TFile("/eos/home-l/ltarbour/DAS/v32/MN_system_1/1D_JEScorrected/getMNobservables/2017H_HLT_HIAK4PFJets40.root","READ");
    TFile *Data60 = new TFile("/eos/home-l/ltarbour/DAS/v32/MN_system_1/1D_JEScorrected/getMNobservables/2017H_HLT_HIAK4PFJets60.root","READ");
    TFile *Data80 = new TFile("/eos/home-l/ltarbour/DAS/v32/MN_system_1/1D_JEScorrected/getMNobservables/2017H_HLT_HIAK4PFJets80.root","READ");
    TFile *MC = new TFile("getMNobservables/2017H_Flat2018_TuneCP5_13TeV.root","READ");

    TH1F *ptlead_00 = (TH1F*)Data->Get("ptlead");
    TH1F *ptlead_15 = (TH1F*)Data15->Get("ptlead");
    TH1F *ptlead_40 = (TH1F*)Data40->Get("ptlead");
    TH1F *ptlead_60 = (TH1F*)Data60->Get("ptlead");
    TH1F *ptlead_80 = (TH1F*)Data80->Get("ptlead");
    TH1F *ptlead_MC = (TH1F*)MC->Get("ptlead");

    //Preparing the graphical rendering
    TCanvas *c1 = new TCanvas("datavsMC","dataVsMC",400,400);
    gStyle->SetTitleFont(22,"xy");
    c1->SetTopMargin(2.);
    c1->SetLeftMargin(2.);
    c1->SetRightMargin(2.);
    c1->SetBottomMargin(2.);
    c1->SetFrameBorderSize(5);

    TCanvas *c2 = new TCanvas("datavsMC_relativ","dataVsMC_relativ",400,400);
    gStyle->SetTitleFont(22,"xy");
    c1->SetTopMargin(2.);
    c1->SetLeftMargin(2.);
    c1->SetRightMargin(2.);
    c1->SetBottomMargin(2.);
    c1->SetFrameBorderSize(5);

   TLegend *leg = new TLegend(.5,.8,.99,.4);
    leg->SetFillColorAlpha(0,0.0);
    leg->SetBorderSize(0);
    leg->SetTextFont(22);
    leg->SetTextSize(.04);
    leg->SetMargin(0.1);

    ptlead_00->SetLineColor(kBlue);
    ptlead_00->SetMarkerColor(kBlue);
    ptlead_00->SetLineStyle(kSolid);
    ptlead_00->GetXaxis()->SetTitleFont(22);
    ptlead_00->GetXaxis()->SetTitleSize(.06);
    //ptlead_00->GetXaxis()->LabelOffset(0);
    //ptlead_00->GetXaxis()->SetLabelSize(.06);
    ptlead_00->GetXaxis()->SetTitle("p_{T,lead.}");
    ptlead_00->GetYaxis()->SetTitleFont(22);
    ptlead_00->GetYaxis()->SetTitleSize(.06);
    ptlead_00->GetYaxis()->SetLabelSize(.04);
    ptlead_00->GetYaxis()->SetTitle("events");
    ptlead_00->SetTitle("every");
    ptlead_00->SetStats(0);
    leg->AddEntry(ptlead_00,ptlead_00->GetTitle());

    ptlead_15->SetLineColor(kRed+1);
    ptlead_15->SetMarkerColor(kRed+1);
    ptlead_15->SetLineStyle(kSolid);
    ptlead_15->GetXaxis()->SetTitleFont(22);
    ptlead_15->GetXaxis()->SetTitleSize(.06);
    //ptlead_15->GetXaxis()->LabelOffset(0);
    //ptlead_15->GetXaxis()->SetLabelSize(.06);
    ptlead_15->GetXaxis()->SetTitle("p_{T,lead.}");
    ptlead_15->GetYaxis()->SetTitleFont(22);
    ptlead_15->GetYaxis()->SetTitleSize(.06);
    ptlead_15->GetYaxis()->SetLabelSize(.04);
    ptlead_15->GetYaxis()->SetTitle("events");
    ptlead_15->SetTitle("HLT_HIAK4PFJets15");
    ptlead_15->SetStats(0);
    leg->AddEntry(ptlead_15,ptlead_15->GetTitle());

    ptlead_40->SetLineColor(kRed+2);
    ptlead_40->SetMarkerColor(kRed+2);
    ptlead_40->SetLineStyle(kSolid);
    ptlead_40->GetXaxis()->SetTitleFont(22);
    ptlead_40->GetXaxis()->SetTitleSize(.06);
    //ptlead_40->GetXaxis()->LabelOffset(0);
    //ptlead_40->GetXaxis()->SetLabelSize(.06);
    ptlead_40->GetXaxis()->SetTitle("p_{T,lead.}");
    ptlead_40->GetYaxis()->SetTitleFont(22);
    ptlead_40->GetYaxis()->SetTitleSize(.06);
    ptlead_40->GetYaxis()->SetLabelSize(.04);
    ptlead_40->GetYaxis()->SetTitle("events");
    ptlead_40->SetTitle("HLT_HIAK4PFJets40");
    ptlead_40->SetStats(0);
    leg->AddEntry(ptlead_40,ptlead_40->GetTitle());

ptlead_60->SetLineColor(kRed+3);
    ptlead_60->SetMarkerColor(kRed+3);
    ptlead_60->SetLineStyle(kSolid);
    ptlead_60->GetXaxis()->SetTitleFont(22);
    ptlead_60->GetXaxis()->SetTitleSize(.06);
    //ptlead_60->GetXaxis()->LabelOffset(0);
    //ptlead_60->GetXaxis()->SetLabelSize(.06);
    ptlead_60->GetXaxis()->SetTitle("p_{T,lead.}");
    ptlead_60->GetYaxis()->SetTitleFont(22);
    ptlead_60->GetYaxis()->SetTitleSize(.06);
    ptlead_60->GetYaxis()->SetLabelSize(.04);
    ptlead_60->GetYaxis()->SetTitle("events");
    ptlead_60->SetTitle("HLT_HIAK4PFJets60");
    ptlead_60->SetStats(0);
    leg->AddEntry(ptlead_60,ptlead_60->GetTitle());

    ptlead_80->SetLineColor(kRed+4);
    ptlead_80->SetMarkerColor(kRed+4);
    ptlead_80->SetLineStyle(kSolid);
    ptlead_80->GetXaxis()->SetTitleFont(22);
    ptlead_80->GetXaxis()->SetTitleSize(.06);
    //ptlead_80->GetXaxis()->LabelOffset(0);
    //ptlead_80->GetXaxis()->SetLabelSize(.06);
    ptlead_80->GetXaxis()->SetTitle("p_{T,lead.}");
    ptlead_80->GetYaxis()->SetTitleFont(22);
    ptlead_80->GetYaxis()->SetTitleSize(.06);
    ptlead_80->GetYaxis()->SetLabelSize(.04);
    ptlead_80->GetYaxis()->SetTitle("events");
    ptlead_80->SetTitle("HLT_HIAK4PFJets80");
    ptlead_80->SetStats(0);
    leg->AddEntry(ptlead_80,ptlead_80->GetTitle());

    ptlead_MC->SetLineColor(kGreen+3);
    ptlead_MC->SetMarkerColor(kGreen+3);
    ptlead_MC->SetLineStyle(kSolid);
    ptlead_MC->GetXaxis()->SetTitleFont(22);
    ptlead_MC->GetXaxis()->SetTitleSize(.06);
    //ptlead_MC->GetXaxis()->LabelOffset(0);
    //ptlead_MC->GetXaxis()->SetLabelSize(.06);
    ptlead_MC->GetXaxis()->SetTitle("p_{T,lead.}");
    ptlead_MC->GetYaxis()->SetTitleFont(22);
    ptlead_MC->GetYaxis()->SetTitleSize(.06);
    ptlead_MC->GetYaxis()->SetLabelSize(.04);
    ptlead_MC->GetYaxis()->SetTitle("events");
    ptlead_MC->SetTitle("MC(No Trigger)");
    ptlead_MC->SetStats(0);
    leg->AddEntry(ptlead_MC,ptlead_MC->GetTitle());

    //Drawing
    c1->cd();
    ptlead_00->DrawClone("HIST E");
    ptlead_15->DrawClone("HIST E same");
    ptlead_40->DrawClone("HIST E same");
    ptlead_60->DrawClone("HIST E same");
    ptlead_80->DrawClone("HIST E same");
    ptlead_MC->DrawClone("HIST E same");
    leg->Draw();
    c1->SaveSource();

    //Drawing normalised plots
    c2->cd();
    ptlead_00->Scale(1./ptlead_00->Integral());
    ptlead_15->Scale(1./ptlead_15->Integral());
    ptlead_40->Scale(1./ptlead_40->Integral());
    ptlead_60->Scale(1./ptlead_60->Integral());
    ptlead_80->Scale(1./ptlead_80->Integral());
    ptlead_MC->Scale(1./ptlead_MC->Integral());
    ptlead_00->GetYaxis()->SetRangeUser(0.,0.24);
    ptlead_00->Draw("HIST E");
    ptlead_15->Draw("HIST E same");
    ptlead_40->Draw("HIST E same");
    ptlead_60->Draw("HIST E same");
    ptlead_80->Draw("HIST E same");
    ptlead_MC->Draw("HIST E same");
    leg->Draw();
    c2->SaveSource();
}

```

---

<div class="post-metadata">

**Author:** ![Leo\_Tarbouriech](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/leo_tarbouriech/32/32139_2.png) [@Leo\_Tarbouriech](https://root-forum.cern.ch/u/Leo_Tarbouriech)\
**Post date:** [January 16, 2023, 1:16pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/5 "2023-01-16T13:16:42Z")

</div>

It takes the histograms from a file that contains histograms.

---

<div class="post-metadata">

**Author:** ![Leo\_Tarbouriech](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/leo_tarbouriech/32/32139_2.png) [@Leo\_Tarbouriech](https://root-forum.cern.ch/u/Leo_Tarbouriech)\
**Post date:** [January 16, 2023, 1:23pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/6 "2023-01-16T13:23:07Z")

</div>

All the input files are exactly similar to this one. They have all been generated with the same function. The only difference is the original content of the events.

---

<div class="post-metadata">

**Author:** ![Leo\_Tarbouriech](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/leo_tarbouriech/32/32139_2.png) [@Leo\_Tarbouriech](https://root-forum.cern.ch/u/Leo_Tarbouriech)\
**Post date:** [January 16, 2023, 1:24pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/7 "2023-01-16T13:24:51Z")

</div>

Unfortunately I cannot add the input file as an example. It says that new user cannot post links… I hope the aforementioned information will be sufficient.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 16, 2023, 1:33pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/8 "2023-01-16T13:33:03Z")

</div>

> [@Leo\_Tarbouriech](#):
>
> I hope the aforementioned information will be sufficient.

No, I would need at least one of the faulty histograms to test it.

---

<div class="post-metadata">

**Author:** ![Leo\_Tarbouriech](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/leo_tarbouriech/32/32139_2.png) [@Leo\_Tarbouriech](https://root-forum.cern.ch/u/Leo_Tarbouriech)\
**Post date:** [January 16, 2023, 2:39pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/9 "2023-01-16T14:39:59Z")

</div>

Ok so how can I upload a file on the chat ?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [January 16, 2023, 2:57pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/10 "2023-01-16T14:57:35Z")

</div>

There is limitations in posting for new users. May be @bellenot can help.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [January 16, 2023, 5:33pm UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/11 "2023-01-16T17:33:26Z")

</div>

Some things you can try in the meantime, just in case (all in DrawClone):  
1 - use no options, except “same” when needed  
2 - use only “histo” and “same”  
3 - use only “e” and “same”  
and see in which case/s, if any, you don’t get what you should.  
You could also try a more recent ROOT version, although this does not seem to be an issue in older versions; try this example, which follows most of what you do, and that I tested even on 5.34/38 and works as expected:

```auto
{
   TCanvas *c = new TCanvas("c","c",1000,600);
   c->Divide(2,1);
   TH1F *h = new TH1F("h","histo",10,-4,4);
   TH1F *h2 = new TH1F("h2","histo",10,-4,4);
   float x, y;
   for (Int_t i = 0; i < 1000; i++) {
      gRandom->Rannor(x,y);
       h->Fill(x);
      h2->Fill(y);
   }
   h->SetLineColor(kGreen+1);
   h->SetMarkerColor(kGreen+1);
   h->SetLineStyle(kSolid);
   h2->SetLineColor(kRed);
   h2->SetMarkerColor(kRed);
   h2->SetLineStyle(kSolid);
   h->SetStats(0);
   h2->SetStats(0);

   c->cd(1);
   h->DrawClone("HIST E");
   h2->DrawClone("HIST E same");
   c->cd(2);
   h->Scale(1./h->Integral());
   h2->Scale(1./h2->Integral());
   h->GetYaxis()->SetRangeUser(0.,0.7);
   h->Draw("HIST E");
   h2->Draw("HIST E same");
}

```

if it works for you it could be an issue with your histograms. You could also simplify your code to a minimum and start adding lines until you find what breaks the plots.

---

<div class="post-metadata">

**Author:** ![Leo\_Tarbouriech](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/leo_tarbouriech/32/32139_2.png) [@Leo\_Tarbouriech](https://root-forum.cern.ch/u/Leo_Tarbouriech)\
**Post date:** [January 18, 2023, 9:14am UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/12 "2023-01-18T09:14:55Z")

</div>

In fact that is the way I constructed the code. By adding layouts stuff step by step. Finally I did not changed anything and know it is working properly. I am a bit confused… In another code I have, I tried another option which I post here in case it can help someone :

```auto
//Normalisation and clonnig
    TH1F *ptlead_00_cp = (TH1F*) ptlead_00->Clone();
    TH1F *ptlead_01_cp = (TH1F*) ptlead_01->Clone();
    TH1F *ptlead_02_cp = (TH1F*) ptlead_02->Clone();
    ptlead_00_cp->Scale(1./ptlead_00_cp->Integral());
    ptlead_01_cp->Scale(1./ptlead_01_cp->Integral());
    ptlead_02_cp->Scale(1./ptlead_02_cp->Integral());

    //Drawing the brut histograms
    c1->cd();
    ptlead_00->Draw("HIST E");
    ptlead_01->Draw("HIST E same");
    ptlead_02->Draw("HIST E same");
    leg->Draw();
    c1->SaveSource();

    c2->cd();
    ptlead_00_cp->Draw("HIST E");
    ptlead_01_cp->Draw("HIST E same");
    ptlead_02_cp->Draw("HIST E same");
    leg->Draw();
    c2->SaveSource();

```

It is exactly the same but I am explicitly cloning the histograms.

---

<div class="post-metadata">

**Author:** ![Leo\_Tarbouriech](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/leo_tarbouriech/32/32139_2.png) [@Leo\_Tarbouriech](https://root-forum.cern.ch/u/Leo_Tarbouriech)\
**Post date:** [January 18, 2023, 9:20am UTC](https://root-forum.cern.ch/t/th1d-drawclone-seems-to-not-take-the-option-t-into-account/53121/13 "2023-01-18T09:20:15Z")

</div>

I sorry to have not been able to provide a proper working example showing the problem I had.

Another question I had which is more general, is that I see that I often have one plot that is broken when I execute my macro for the first time and when I re-excute it for the second time all the plots are proper. I sounds really weird to me. As if the second time I was reading the variables that have been written in the memory during the first execution.

Is there a “classical beginners mistake” that can lead to this type of behavior?

Thank you in advance for your thoughts,  
Thanks for your answers,  
Leo
