```TH1D::DrawClone()``` seems to not take the ```Option_t``` into account

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:

//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".


_ROOT Version: 6.22/09
_Platform: lxplus, C++
_Compiler: slc7_amd64_gcc900


I’m sure @couet will take care of this

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?

This is the full function:

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();
}

It takes the histograms from a file that contains histograms.

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.

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.

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

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

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

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:

{
   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.

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 :

//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.

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