faca87
1
Goodmorning, i’m just starting to use root…i need a macro to paint 2D graphics by a color gradient, like this macro:
{
TCanvas *c1 = new TCanvas("c1","c1",600,600);
c1->Divide(1,2);
TH2F *hcol23 = new TH2F("hcol2","Option COLZ example ",40,-4,4,40,-20,20);
TH2F *hcol24 = new TH2F("hcol2","Option COLZ1 example ",40,-4,4,40,-20,20);
Float_t px, py;
for (Int_t i = 0; i < 25000; i++) {
gRandom->Rannor(px,py);
hcol23->Fill(px,5*py);
hcol24->Fill(px,5*py);
}
hcol23->Fill(0.,0.,-200.);
hcol24->Fill(0.,0.,-200.);
gStyle->SetPalette(kBird);
c1->cd(1); hcol23->Draw("COLZ");
c1->cd(2); hcol24->Draw("COLZ1");
return c1;
}

But in my case, the macro must not generate the numbers, but it must open a data file, can somebody help me to write it please?
Your “data file” is what?
Hi pepe and thanks! i mean to open a file with 2 culomns, in first culomn there are x-coordinates and in second culomn y-coordinates.
Something like this:
x y
1 2
2 4
3 6
4 8
{
TGraph *g1 = new TGraph("file_1.txt");
TGraph *g2 = new TGraph("file_2.txt");
TCanvas *c = new TCanvas("c","c");
c->Divide(1, 2);
c->cd(1); g1->Draw("ALP");
c->cd(2); g2->Draw("ALP");
c->cd(0);
}
Hi pepe, thanks…but…maybe this is not the kind of graphic that i want…i want a color graph like this:
I tried to combine your code with other codes, and i wrote this:
TH2F *hcol23 = new TH2F("hcol2","Option COLZ example ",40,-4,4,40,-20,20);
TH2F *hcol24 = new TH2F("hcol2","Option COLZ1 example ",40,-4,4,40,-20,20);
TGraph *c1 = new TGraph("file_1.txt");
TGraph *c2 = new TGraph("file_2.txt");
TCanvas *c = new TCanvas("c","c");
hcol23->Fill(0.,0.,-200.);
hcol24->Fill(0.,0.,-200.);
gStyle->SetPalette(52);
hcol23->Draw("COLZ");
hcol24->Draw("COLZ1");
return c1;
}
but this is the result:

…it doen’t paint all the point of the file!
{
TTree *t1 = new TTree("t1", "tree 1");
t1->ReadFile("file_1.txt", "x/D:y");
TTree *t2 = new TTree("t2", "tree 2");
t2->ReadFile("file_2.txt", "x/D:y");
TCanvas *c = new TCanvas("c","c");
c->Divide(1, 2);
c->cd(1); t1->Draw("y:x", "", "COLZ");
c->cd(2); t2->Draw("y:x", "", "COLZ");
c->cd(0);
}
Thank you! other question please…if i wanna open a corsika file, can i just change the name of the data file, or do i need other macro?
you’ll need to talk to corsikans.
Ok thank you! now i’m just making some prof…next days i will start to use root for graduation thesis, i hope you will help me in the future too
faca87
11
Thanks for your help pepe