bin/ dev/ home/ proc/ sbin/ tmp/ var/
etc/ lib/ root/ srv/ usr/
source /root/bin/thisroot.sh
/root/libになっていることを確認する。
root[0] h = new TH1F("h","title",10,0.,20.);
root[1] h -> Fill(2.8);
root[2] h -> Fill(12.5,3);
root[3] h -> Draw();
root[4] c1 -> Print("test.png");
Draw() コマンドで右図のようなヒストグラムが描かれる。Print("test.png")では描いたc1キャンパスをファイルtest.pngに落としているので、X-Windowが起動できずroot -bで入った場合にはこのファイルを他の方法で開いて見ることができる。
{
h = new TH1F("h","title",10,0.,20.);
h -> Fill(2.8);
h -> Fill(12.5,3);
h -> Draw();
c1 -> Print("test.png");
}
ofstream fout("data.txt");
for (int i = 1 ; i < 101 ; i++) {
fout << h1->GetXaxis()->GetBinCenter(i) << " " << h1->GetBinContent(i) << endl;
}
fout.close();
{
c1 = new TCanvas("c1","c1 title", 200, 100, 400, 300);
h1 = new TH1F("h1","h1 title",100,0., 500.);
//
ifstream fin("data.txt");
double x,y;
while (fin >> x >> y ){
h1 -> Fill(x,y);
}
fin.close();
h1 -> Draw();
c1->Print("plot_data.png");
}
ここで while (fin >> x >> y ){......} は入力ファイルfinにデータがある限り読み続けて{.....}内を実行する部分で、この演習ではすべてこの入力方式を用いる。
{
c1 = new TCanvas("c1","c1 title", 200, 100, 800, 600);
int n=0;
double x[2000], y[2000];
ifstream fin("data.txt");
while (fin >> x[n] >> y[n] ) {
if( n == 1999) break;
n++;
}
fin.close();
g1 = new TGraph(n, x, y);
g1 -> Draw("ALP"); //A=軸を描く,L=線でつなぐ,P=点で表示
c1->Print("plotGraph.png");
}