Histogram is not printing on the canvas

I am trying to draw 3 histograms on the same canvas. The problem is with the first histogram (V2hist_rebin1). It is not there in the canvas. Only two histograms are there. But when I write it to root file it works. ( Actually it is *V2hist_rebin1 )

gStyle->SetOptStat(kFALSE); 
// Declaring New Rebin histograms
TProfile *V2hist_rebin1 = (TProfile *) V2hist->Rebin(5, "V2hist_rebin1");
TProfile *V2hist211_rebin = (TProfile *) V2hist->Rebin(5, "V2hist211_rebin");
TProfile *V2hist2212_rebin = (TProfile *) V2hist2212->Rebin(5, "V2hist2212_rebin");
//  ****************  Setting Histogram Axis Title*********************
V2hist_rebin1->SetTitle("p_{T} dependence of v_{2} for '#Kappa^{+} + #Kappa^{-}'"); 
V2hist_rebin1->SetMarkerStyle(kFullTriangleDown);
V2hist_rebin1->SetMarkerColor(20);
V2hist_rebin1->SetMarkerSize(1.4);
V2hist_rebin1->GetYaxis()->SetTitleOffset(1.4);
V2hist_rebin1->GetYaxis()->CenterTitle(true);
V2hist_rebin1->GetYaxis()->SetTitle("v_{2}");
V2hist_rebin1->GetXaxis()->SetTitleOffset(1.4);
V2hist_rebin1->GetXaxis()->CenterTitle(true);
V2hist_rebin1->GetXaxis()->SetTitle("p_{T}(GeV/c)");
// Setting Pion Markers
V2hist211_rebin->SetMarkerStyle( kFullSquare);
V2hist211_rebin->SetMarkerSize(1.4);
V2hist211_rebin->SetMarkerColor(8);
//// Setting Proton Markers
V2hist2212_rebin->SetMarkerStyle(kFullCircle);
V2hist2212_rebin->SetMarkerSize(1.4);
V2hist2212_rebin->SetMarkerColor(9);
TCanvas *Ell_flow = new TCanvas ("Elliptic Flow kaon","flow",15,15,700,500);
V2hist_rebin1->Draw();
V2hist211_rebin->Draw("same");
V2hist2212_rebin->Draw("same");

Thank you :slight_smile:

Well, “V2hist_rebin1” seems to be equal to “V2hist211_rebin” so remove V2hist211_rebin->Draw(“same”); and you will see the first one.

BTW. When you post “output” or “source code” here, do remember to enclose them into two lines which contain just three characters ``` (see how your posts have been edited above).

Silly Mistake… Thank you :relieved:

Hello Wile,
Now there, I am getting the results fine, but one of the histogram is going out of the range of canvas while I have set the range -1 to +1.

You can see the blue dotted curve.
Thank you :wink:

How have you done that ? nor the X axis or the Y xis have a such range.

1 Like

Try:

THStack *hs = new THStack("hs", "p_{T} dependence of v_{2} for '#Kappa^{+} + #Kappa^{-}';p_{T}(GeV/c);v_{2}");
hs->Add(V2hist_rebin1);
hs->Add(V2hist211_rebin);
hs->Add(V2hist2212_rebin);
hs->Draw("nostack");
2 Likes

Thank You :smile:
It works!!

Can you please tell how to join these data points with the lines.
i.e. we can do hs -> Draw(“L”);
But it is not working :sweat:

hs->Add(V2hist_rebin1, "L");
hs->Add(V2hist211_rebin, "L");
hs->Add(V2hist2212_rebin, "L");
1 Like

Not Working!!! I tried… :roll_eyes:

can you post you macro here ?

// Declaring New Rebin histograms
V2hist_rebin = (TProfile *)       V2hist -> Rebin(5, "V2hist_rebin");
V2hist211_rebin = (TProfile *)    V2hist211 -> Rebin(5, "V2hist211_rebin");
V2hist2212_rebin = (TProfile *)   V2hist2212 -> Rebin(5, "V2hist2212_rebin");
// Setting Pion Markers
V2hist211_rebin->SetMarkerStyle( kFullSquare);
V2hist211_rebin->SetMarkerSize(1.4);
V2hist211_rebin->SetMarkerColor(8);
//// Setting Proton Markers
V2hist2212_rebin->SetMarkerStyle(kFullCircle);
V2hist2212_rebin->SetMarkerSize(1.4);
V2hist2212_rebin->SetMarkerColor(9);
//======================================
V2hist_rebin->SetMarkerStyle(kStar);
V2hist_rebin->SetMarkerColor(kRed);
V2hist_rebin->SetMarkerSize(1.4);
TCanvas *Ell_flow = new TCanvas ("Elliptic Flow kaon","flow",15,15,700,500);
THStack *hs = new THStack("hs", "p_{T} dependence of v_{2} for '#Kappa^{+} + #Kappa^{-}';p_{T}(GeV/c);v_{2}");
hs->Add(V2hist_rebin, "L");
hs->Add(V2hist211_rebin, "L");
hs->Add(V2hist2212_rebin, "L");
hs->Draw("nostack");

I cannot runt that … :frowning:

Anyway try:

hs->Add(V2hist_rebin, "HIST L");
hs->Add(V2hist211_rebin, "HIST L");
hs->Add(V2hist2212_rebin, "HIST L");
1 Like

Yes!! It worked. But there are only lines without data points with same color. Can we do something for it? I need data points too with different colors ( as you can see in the above graph)
Thanks :slight_smile:

Okay! I got it. I used …

hs->Add(V2hist_rebin, “HIST LP”);
hs->Add(V2hist211_rebin, “HIST LP”);
hs->Add(V2hist2212_rebin, “HIST LP”);

Thankyou :wink:

Yes … good you found it yourself :wink: …

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.