この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
ja:root:tgrapherrors [2014/08/19 09:19] kota [例1] |
ja:root:tgrapherrors [2017/02/02 14:25] (現在) kota [コンストラクタ] |
||
---|---|---|---|
ライン 6: | ライン 6: | ||
===== コンストラクタ ===== | ===== コンストラクタ ===== | ||
+ | <code cpp> | ||
TGraphErrors(Int_t n, const Float_t* x, const Float_t* y, const Float_t* ex = 0, const Float_t* ey = 0) | TGraphErrors(Int_t n, const Float_t* x, const Float_t* y, const Float_t* ex = 0, const Float_t* ey = 0) | ||
TGraphErrors(Int_t n, const Double_t* x, const Double_t* y, const Double_t* ex = 0, const Double_t* ey = 0) | TGraphErrors(Int_t n, const Double_t* x, const Double_t* y, const Double_t* ex = 0, const Double_t* ey = 0) | ||
ライン 15: | ライン 15: | ||
TGraphErrors(const TH1* h) | TGraphErrors(const TH1* h) | ||
TGraphErrors(const char* filename, const char* format = "%lg %lg %lg %lg", Option_t* option = "") | TGraphErrors(const char* filename, const char* format = "%lg %lg %lg %lg", Option_t* option = "") | ||
+ | </code> | ||
など色々ある。\\ | など色々ある。\\ | ||
4つの変数は全て同じ型でないといけない(はず)。\\ | 4つの変数は全て同じ型でないといけない(はず)。\\ | ||
ライン 48: | ライン 48: | ||
==== 例3 ==== | ==== 例3 ==== | ||
- | 以下のようなデータファイルを用意する。 | + | 以下のようなデータファイル data.dat を用意する。 |
<code c> | <code c> | ||
1.0 10.0 0.1 1.0 | 1.0 10.0 0.1 1.0 | ||
ライン 74: | ライン 74: | ||
} | } | ||
</code> | </code> | ||
+ | {{:ja:root:tgrapherrors_ex3.png?600|}} | ||
+ | ==== 例4 ==== | ||
+ | 例3と同じ data.dat を使って、 | ||
+ | <code c> | ||
+ | void example4() | ||
+ | { | ||
+ | TCanvas *c = new TCanvas("c","c",600,600); | ||
+ | c->cd(); | ||
+ | TH1F *frame = gPad->DrawFrame( 0. , 0. , 12. , 120. ); | ||
+ | |||
+ | const Int_t NPOINT = 10; | ||
+ | ifstream fin("data.dat"); | ||
+ | Float_t X[NPOINT],Y[NPOINT],eX[NPOINT],eY[NPOINT]; | ||
+ | Int_t i = 0; | ||
+ | while(!fin.eof()){ | ||
+ | fin >> X[i] >> Y[i] >> eX[i] >> eY[i]; | ||
+ | i++; | ||
+ | } | ||
+ | |||
+ | TGraphErrors *g = new TGraphErrors(NPOINT,X,Y,eX,eY); | ||
+ | g->SetMarkerStyle( 20 ); | ||
+ | g->SetMarkerSize( 1.0 ); | ||
+ | g->Draw("PC"); | ||
+ | } | ||
+ | </code> | ||
+ | のようにしても同じグラフが描ける |