この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 次のリビジョン | 前のリビジョン | ||
|
ja:root:tgrapherrors [2014/08/19 06:23] kota 作成 |
ja:root:tgrapherrors [2017/02/02 14:25] (現在) kota [コンストラクタ] |
||
|---|---|---|---|
| ライン 5: | ライン 5: | ||
| ---- | ---- | ||
| + | ===== コンストラクタ ===== | ||
| + | <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 Double_t* x, const Double_t* y, const Double_t* ex = 0, const Double_t* ey = 0) | ||
| + | TGraphErrors(const TVectorF& vx, const TVectorF& vy, const TVectorF& vex, const TVectorF& vey) | ||
| + | TGraphErrors(const TVectorD& vx, const TVectorD& vy, const TVectorD& vex, const TVectorD& vey) | ||
| + | TGraphErrors(const TGraphErrors& gr) | ||
| + | TGraphErrors& operator=(const TGraphErrors& gr) | ||
| + | TGraphErrors(const TH1* h) | ||
| + | TGraphErrors(const char* filename, const char* format = "%lg %lg %lg %lg", Option_t* option = "") | ||
| + | </code> | ||
| + | など色々ある。\\ | ||
| + | 4つの変数は全て同じ型でないといけない(はず)。\\ | ||
| + | |||
| + | ===== 使い方 ===== | ||
| + | |||
| + | ==== 例1 ==== | ||
| + | <code c> | ||
| + | void example1() | ||
| + | { | ||
| + | TCanvas *c = new TCanvas("c","c",600,600); | ||
| + | c->cd(); | ||
| + | TH1F *frame = gPad->DrawFrame( 0. , 0. , 12. , 120. ); | ||
| + | |||
| + | const Int_t NPOINT = 5; | ||
| + | Float_t X[NPOINT] = { 1. , 3. , 5. , 8. , 10. }; | ||
| + | Float_t Y[NPOINT] = { 10. , 30. , 50. , 80. , 100. }; | ||
| + | Float_t eX[NPOINT] = { 0.1 , 0.3 , 0.5 , 0.8 , 1. }; | ||
| + | Float_t eY[NPOINT] = { 1. , 3. , 5. , 8. , 10. }; | ||
| + | |||
| + | TGraphErrors *g = new TGraphErrors(NPOINT,X,Y,eX,eY); | ||
| + | g->SetMarkerStyle( 20 ); | ||
| + | g->SetMarkerSize( 1.0 ); | ||
| + | g->Draw("PC"); | ||
| + | } | ||
| + | </code> | ||
| + | {{:ja:root:tgrapherrors_ex1.png?600|}} | ||
| + | |||
| + | ==== 例2 ==== | ||
| + | |||
| + | |||
| + | ==== 例3 ==== | ||
| + | 以下のようなデータファイル data.dat を用意する。 | ||
| + | <code c> | ||
| + | 1.0 10.0 0.1 1.0 | ||
| + | 2.0 20.0 0.2 2.0 | ||
| + | 3.0 30.0 0.3 3.0 | ||
| + | 4.0 40.0 0.4 4.0 | ||
| + | 5.0 50.0 0.5 5.0 | ||
| + | 6.0 60.0 0.6 6.0 | ||
| + | 7.0 70.0 0.7 7.0 | ||
| + | 8.0 80.0 0.8 8.0 | ||
| + | 9.0 90.0 0.9 9.0 | ||
| + | 10.0 100.0 1.0 10.0 | ||
| + | </code> | ||
| + | <code c> | ||
| + | void example3() | ||
| + | { | ||
| + | TCanvas *c = new TCanvas("c","c",600,600); | ||
| + | c->cd(); | ||
| + | TH1F *frame = gPad->DrawFrame( 0. , 0. , 12. , 120. ); | ||
| + | |||
| + | TGraphErrors *g = new TGraphErrors("data.dat","%lg %lg %lg %lg",""); | ||
| + | g->SetMarkerStyle( 20 ); | ||
| + | g->SetMarkerSize( 1.0 ); | ||
| + | g->Draw("PC"); | ||
| + | } | ||
| + | </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> | ||
| + | のようにしても同じグラフが描ける | ||