この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
ja:root:stat [2019/04/17 03:43] kota [2つのヒストグラムの統計情報を並べて書く] |
ja:root:stat [2019/04/18 16:23] (現在) kota [Statistics box内のtextの編集] |
||
---|---|---|---|
ライン 136: | ライン 136: | ||
Double_t FitRangeMax = 2.5; | Double_t FitRangeMax = 2.5; | ||
//hist->Fit("gaus1","","",FitRangeMin,FitRangeMax); | //hist->Fit("gaus1","","",FitRangeMin,FitRangeMax); | ||
- | //hist->Fit("gaus1","N","",FitRangeMin,FitRangeMax); | + | hist->Fit("gaus1","0","",FitRangeMin,FitRangeMax);///// 0はfit関数を描かないようにするため |
- | hist->Fit("gaus1","0","",FitRangeMin,FitRangeMax); | + | |
- | gaus1->SetRange(FitRangeMin,FitRangeMax); | + | gaus1->SetRange(FitRangeMin,FitRangeMax);///// fit rangeでだけ関数を表示するように |
gaus1->Draw("same"); | gaus1->Draw("same"); | ||
Double_t Gaus1Mean = gaus1->GetParameter(1); | Double_t Gaus1Mean = gaus1->GetParameter(1); | ||
Double_t Gaus1Sigma = gaus1->GetParameter(2); | Double_t Gaus1Sigma = gaus1->GetParameter(2); | ||
- | //cout << "Gaus-1 : " << endl; | + | cout << "Gaus-1 : " << endl; |
- | //cout << " Mean = " << Gaus1Mean << endl; | + | cout << " Mean = " << Gaus1Mean << endl; |
- | //cout << " Sigma = " << Gaus1Sigma << endl; | + | cout << " Sigma = " << Gaus1Sigma << endl; |
- | //cout << "Chisq/NDF = " << gaus1->GetChisquare() <<"/"<< gaus1->GetNDF() << endl; | + | cout << "Chisq/NDF = " << gaus1->GetChisquare() <<"/"<< gaus1->GetNDF() << endl; |
//////////////// | //////////////// | ||
///// stat ///// | ///// stat ///// | ||
//////////////// | //////////////// | ||
- | gPad->Modified(); | + | gPad->Modified();/////TPad::Modified()はいらないけどとりあえず呼んでおけばいいんでなかろうか。 |
- | gPad->Update();///// TPad::Update() is needed | + | gPad->Update();///// TPad::Update() is needed <---こちらは必要 |
TPaveStats *st1 = (TPaveStats*)hist->FindObject("stats"); | TPaveStats *st1 = (TPaveStats*)hist->FindObject("stats"); | ||
//TPaveStats *st1 = (TPaveStats*)gPad->GetPrimitive("stats"); | //TPaveStats *st1 = (TPaveStats*)gPad->GetPrimitive("stats"); | ||
- | st1->SetName("mystats");///// <-- name is needed to be changed otherwise the stat box disappears by calling hist->SetStats(0) | + | st1->SetName("mystats");///// <-- 名前を変更しておく必要あり(そうしないと、hist->SetStats(0)で消えてしまう) |
st1->SetOptFit(0); | st1->SetOptFit(0); | ||
///// TPad::Modified() and TPad::Update() are needed to reflect st1->SetOptFit(0) | ///// TPad::Modified() and TPad::Update() are needed to reflect st1->SetOptFit(0) | ||
ライン 183: | ライン 182: | ||
TLatex *TextGaus1Mean = new TLatex(0,0,Form("Gaus Mean = %.2f",Gaus1Mean)); | TLatex *TextGaus1Mean = new TLatex(0,0,Form("Gaus Mean = %.2f",Gaus1Mean)); | ||
TextGaus1Mean->SetTextColor(kRed); | TextGaus1Mean->SetTextColor(kRed); | ||
- | TextGaus1Mean->SetTextSize(0); | + | TextGaus1Mean->SetTextSize(0);///// 0にしておくことで、フォントサイズを自動で調整してくれる |
listOfLines->Add(TextGaus1Mean); | listOfLines->Add(TextGaus1Mean); | ||
TLatex *TextGaus1Sigma = new TLatex(0,0,Form("Gaus Sigma = %.2f",Gaus1Sigma)); | TLatex *TextGaus1Sigma = new TLatex(0,0,Form("Gaus Sigma = %.2f",Gaus1Sigma)); | ||
TextGaus1Sigma->SetTextColor(kRed); | TextGaus1Sigma->SetTextColor(kRed); | ||
- | TextGaus1Sigma->SetTextSize(0); | + | TextGaus1Sigma->SetTextSize(0);///// 0にしておくことで、フォントサイズを自動で調整してくれる |
listOfLines->Add(TextGaus1Sigma); | listOfLines->Add(TextGaus1Sigma); | ||
ライン 201: | ライン 200: | ||
</code> | </code> | ||
---- | ---- | ||
+ | ポイントは、 | ||
+ | * 統計ボックス内のtextにアクセスするには、TList* TPaveStats::GetListOfLines() でtextのリストを取ってきてやる | ||
+ | * TAttText::SetTextSize(0)とすることで、フォントサイズを自動調整 | ||
+ | * TPad::Modified(), TPad::Update()を(こまめに?)呼んでやる | ||
+ | * TPaveStats::SetName("hoge")で名前を変えてやる | ||
+ | * 変更後、TH1::SetStats(0)を呼んでやる | ||
+ | あたりだろうか。 | ||
+ | {{ :ja:root:stat_edit.png?400 |}} | ||
+ | ---- |