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