Drawing ntuples

Hi i’ve a simple montecarlo of particle scattering which genereate a Ntuple containing x,y,part_id. If I want to plot the path of the “i” particle:

ntuplename->Draw(“x:y”,“part_id==i”,“L”)

Now, if I want to plot not only the i particle but 10 particle on the same canvas I must create a canvas, create a Frame (-100,-100,100,100 in my case, because my “universe” range was 100) and plot all the 10 particles (superimposing). If I cycle and plot from 0 to 10 I have what I desire, but it is all black…I can’t distinguish one path from one other. How can I change the color line each time I draw and superimpose?

my cycle is:
{
TCanvas *myc = new TCanvas(“montecarlo”,“montecarlo”,1);
myc->DrawFrame(-100,-100,100,100,“xVSy”);
for (int i = 0; i<10,i++) {
ntuplename->Draw(“x:y”,“part_id==i”,“LSAME”);
}
}

Thanks Luca

The object generated by TTree::Draw inherits its graphics properties from the Tree.
do
ntuplename->SetLineColor(color[i]);
ntuplename->Draw(“x:y”,“part_id==i”,“L”)

Rene

Ok, thanks, this problem is solved, but there is another one:

my cycle is:
{
TCanvas *myc = new TCanvas(“montecarlo”,“montecarlo”,1);
myc->DrawFrame(-100,-100,100,100,“xVSy”);
for (int i = 0; i<10,i++) {
ntuplename->Draw(“x:y”,“part_id==i”,“LSAME”);
}
}

part_id==i, however, is not a valid condition, because it recognizes i as char and not my integer i(0,1,2,…,9)… how can I solve this problem?

Instead of :

ntuplename->Draw(“x:y”,“part_id==i”,“LSAME”);
do:
ntuplename->Draw(“x:y”,Form(“part_id==%d”,i),“LSAME”);

Rene

Ok, now it works, can you briefly explain me what is and how does Form() works?
Thanks a lot
Luca

Ehm, and one other thing, if I set ntuplename->SetLineColor(2) for example it draws all the (x,y) points in red, but not the polyline which is always black (I used the chopt “L”) how can I change it?

Form is a ROOT function (in TString) that returns a character string formatted a la printf.

In your version, to set the line color of the graph, after having called ntuplename->Draw(…
do
TGraph gr = (TGraph)gPad->GetPrimitive(“Graph”);
gr->SetLineColor(2);

In the CVS version the graph inherits all the graphics properties from the Tree.

Rene

hmm… it doesn’t work… However I managed to do wath I want (differents path with diffferent color on the same canvas) doing in the cycle
gStyle->SetLineColor(i)
now all is solved
Thanks
Luca

The feature with TGraph works only in Root version 4.

Unfortunately, you did not indicate which version you are using

Rene