ZhuKun
January 6, 2021, 8:01am
1
The code in $ROOTSYS/tutorials/tree/tree0.C
tree->Draw("a.e"); //energy of det a
tree->Draw("a.e","3*(-.2<b.e && b.e<.2)","same");
Question:
Now , we have two histograms in the same pad.But,how to let the different line with different color in code?
ROOT Version: ROOT 6.14
Platform: Ubuntu
Compiler: default
couet
January 6, 2021, 2:38pm
2
tree->Draw("a.e"); //energy of det a
tree->Draw("a.e","3*(-.2<b.e && b.e<.2)","same");
htemp->SetLineColor(kRed);
ZhuKun
January 9, 2021, 12:48pm
3
There is no “themp” pointer in the code .And although you use the code “tree->SetLineColor(kRed);”,we just change one line.
I usually do:
tree->Draw("a.e"); //energy of det a
tree->Draw("a.e>>histo","3*(-.2<b.e && b.e<.2)","same");
TH1F* h = (TH1F*) gROOT->FindObject("histo");
h->SetLineColor(2);
couet
January 9, 2021, 3:49pm
5
It works for me:
root [1] ntuple->Draw("px")
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [2] htemp->SetLineColor(kRed)
ZhuKun
January 12, 2021, 1:06pm
6
Thanks a lot! I tried and it works.
1 Like
ZhuKun
January 12, 2021, 1:08pm
7
Thanks a lot!But the htemp is not declared in the code,Maybe the code is different.
couet
January 12, 2021, 2:33pm
8
In a macro:
nt->Draw("px");
TH1F *htemp = (TH1F *)gPad->GetPrimitive("htemp");
htemp->SetLineColor(kRed);
ZhuKun
January 13, 2021, 12:57pm
9
I tried and it works in only one line.How can we change the other lines’ color in this way?Why can we find an object “themp” in the code ?
couet
January 13, 2021, 12:58pm
10
what do you mean ? can you post an example ?
ZhuKun
January 13, 2021, 1:47pm
11
As is shown in fifth reply,one line is green and the other is red.
couet
January 14, 2021, 10:19am
12
ok, so what is wrong ? the screen dump is correct according to the commands you displayed on the left.
If we have
tree->Draw("something");
tree->Draw("sometihng_else","same");
doing .ls
shows that both histos are called htemp, and gPad->GetPrimitive("htemp")
only retrieves one of the histos (the first one); the question is how to get the second one in this case (when the Draw line didn’t explicitly create named histos).
couet
January 15, 2021, 1:39pm
14
root [1] ntuple->Draw("px"); htemp->SetName("h1"); h1->SetLineColor(2);
root [2] ntuple->Draw("py","","same"); htemp->SetLineColor(3);
ZhuKun
January 25, 2021, 6:19am
15
But the identifier ‘h1’ is not defined before.
couet
January 25, 2021, 9:24am
16
{
auto f = new TFile("hsimple.root");
TNtuple *n = (TNtuple*)f->Get("ntuple");
n->Draw("px","","nodraw");
TH1F* h1 = (TH1F*) gROOT->FindObject("htemp");
h1->SetName("h1"); h1->SetLineColor(2);
h1->Draw();
ntuple->Draw("py","","same");
TH1F* h2 = (TH1F*) gROOT->FindObject("htemp");
h2->SetLineColor(3);
}
system
Closed
February 8, 2021, 9:24am
17
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.