root[0] tree->Draw("coin@.size()")
|
TFrame* frame = gPad->GetFrame();
frame->SetFillStyle(0);
frame->Draw("same");
|
gStyle->SetPadRightMargin(0.15);
gStyle->SetPadLeftMargin(0.15);
gStyle->SetPadTopMargin(0.14);
gStyle->SetPadBottomMargin(0.14);
|
TMath::QuietNaN(); |
TMath::SignalingNaN() |
TH1* hnan = new TH1D("hnan", "title", 100,0,100);
TH1* hnannan = new TH2D("hnannan", "title", 100,0,100, 100,0,100);
TH1* hinfp = new TH1D("hinfp", "title", 100,0,100);
TH1* hinfm = new TH1D("hinfm", "title", 100,0,100);
double x = -1;
double y = 0;
double z = 1;
double nan = sqrt(x);
double infp = z/y;
double infm = x/y;
for(int i=0; i<1000; ++i){
hnan->Fill(nan);
hnannan->Fill(nan,nan);
hinfp->Fill(infp);
hinfm->Fill(infm);
}
|
TTree* tree = new TTree("tree", "title");
double x = -1;
double y = 0;
double z = 1;
double nan = sqrt(x);
double infp = z/y;
double infm = x/y;
tree->Branch("nan", &nan, "nan/D");
tree->Branch("infp", &infp, "infp/D");
tree->Branch("infm", &infm, "infm/D");
for(int i=0; i<1000; ++i){
tree->Fill();
}
|
gDirectory:グローバルなポインタで、現在のディレクトリをあらわす。
gDirectory->cd():そのポインタのディレクトリに移動する。
gDirectory->cd(".."):一個上のディレクトリに移動。
gDirectory->cd("/aaa"):絶対パスで移動もできる。
gDirectory->mkdir("aaa"):ディレクトリを作る。
|
$ g++ -g `root-config --cflags --libs` test.C -o test $ gdb test (gdb) b main (gdb) run (gdb) catch throw (gdb) c (gdb) bt |
static_cast |
ROOTではTGraphの第一引数にファイル名を指定すると、
そのファイルについてPlotを行うというコンストラクタがあります。
------
void graph(char * file)
{
TCanvas *c1 = new TCanvas("c1", "", 1000, 500);
TGraph *gr1 = new TGraph(file, "%lf %lf", "");
gr1->Draw("ap");
}
------
このように、第一引数にファイル名、第二引数に採用するデータ列を入力します。カンマ区切りなら、
"%lf,%lf"
などと指定します。もし、元ファイルのデータが「いらない数, いらない数, x, y」というようになっていたら、
"%*lf,%*lf,%lf,%lf"
と、「*」を入れることにより、Plot対象から外すことができます。
おそらく3次元に対してもできると思います。histgramに対しては、不明です。
最低限、上の3行のコードを覚えれば、最低限のPlotができることになります
(あとはgStyleなどを追加するだけなので)。
|
TChain* ch = new TChain("t;1");
ch->Add("run0.root");
ch->Add("run1.root");
ch->Draw("x");
|
ここから引用(http://rarfaxp.riken.go.jp/~oonishi/tips/root.html)---->
Tree を histgram にする
tree.Draw("a>>h1")
TH1F *hnew = (TH1F*)gDirectory->Get("h1")
とか
TH1F *hnew= new TH1F("hnew","title",80,-3,1);
tree.Draw("a>>hnew")
とすれば、hnew に histgraming されます。
<-----引用ここまで
|
TObject *select = pad->GetSelected();
if (select &&
select->InheritsFrom("TH1")) {
TH1 *h = (TH1*)select;
}
|
while (!gSystem->ProcessEvents() && gROOT->GetSelectedPad()) {
TPad* pad = (TPad*)gROOT->GetSelectedPad();
Int_t event = pad->GetEvent();
if (event == kButton1Double) {
func();//ここで何か処理をする。
return;
}
gSystem->Sleep(10);
}
|
TCutG *cut = c->WaitPrimitive("CUTG", "CutG");
cut->Print();
|
#include |
#include < iostream >
#include "TCanvas.h"
#include "TLine.h"
#include "TSeqCollection.h"
#include "TROOT.h"
TLine* xval()
{
TSeqCollection* tsc = gROOT->GetListOfCanvases();
TCanvas* c = (TCanvas*)tsc->Last();
double x1 = c->GetX1();
double x2 = c->GetX2();
double y1 = c->GetY1();
double y2 = c->GetY2();
// std::cout << x1 << ' ' << x2 << ' ' << y1 << ' ' << y2 << std::endl;
double xm = (x1+x2)/2.0;
// double ym = (y1+y2)/2.0;
// std::cout << xm << ' ' << ym << std::endl;
TLine* l = new TLine(xm,y1,xm,y2);
l->Draw();
c->Update();
c->WaitPrimitive();
std::cout << "xval:" << l->GetX1() << std::endl;
// delete l;
return l;
}
|
> root |
> root -l |
> root hoge.root |
> TFile f("hoge.root");
|
TBrowse c; |
・.?: help ・.!: shell ・.x: マクロの実行、というかファイルの中身を実行。 ・.L: マクロのロード、というかファイルの中身を読む。 ・.L macro.C++: こうすると、コンパイルしてロードになるらしい。 ・.q: rootの終了 ・.ls: 存在しているgraphの表示。 |
1.command line べた 2.macroを実行 2.1 べた書き 2.2 file名と同じ関数から始まる、擬似C++ 2.3 マクロのロード 3. command line上でマクロのコンパイルして使う 4. マクロのライブラリ化してロード 5. c++のコードに埋め込む。 5.1 埋め込んで、関数を呼んで表示とかを、プログラム内で行う。 5.2 treeとかのデータ構造だけ作るとか、graphだけつくって、hoge.rootを作って、あとからrootで解析する。 |
1. コマンドライン(コマンドラインモード) 2. マクロを使った擬似c++(マクロモード) 3. 新のc++(C++モード) |
・ ・複雑な型 例) vector< map |
> .x hoge.cc |
> .L hoge.cc > hoge(); |
//hoge.cc
{
double x(1.0);
cout << x << endl;
}
|
//hoge.cc
{
double x(1.1);
cout << x << endl;
{
double x(2.1);
cout << x << endl;
}
cout << x << endl;
}
|
1.1 2.1 2.1 |
> .x macro.cc |
> .x macro.cc(4.5) |
> .L macro.cc |
typedef vector |
#include "TROOT.h" #include "TH1.h" |
g++ -c hoge.cc `root-config --cflags` |
> gSystem->CompileMacro("hoge.cc");
|
.x hoge.cc++ |
#include |
> gSystem->CompileMacro("hoge.cc");
> hoge();
aaa
>
|
.L macro.cc
gSystem->CompileMacro("macro.cc")
|
//hoge.hh #include |
> gSystem->Load("libhoge");
|
gROOT->ProcessLine("コマンドでうつコマンドをそのまま書く")
|
TFile* file = new TFile("temp.root", "RECREATE", "app");
thd->Write();
|
h->Draw(); |
gROOT->Get何とか |
vector |
#include |
TGraph* graph;
void graph(){
graph = new TGraph(n, x, y);
}
|
.L graph.cc
TGraph* graph;
graph = graph("temp.txt");
|