従って、もし全てを1つのマクロで記述するとすれば、以下のようになります。
// file name = myetst41.cc { TGraph *g = new TGraph("myfile3.dat"); g->SetMarkerStyle( 20 ); g->SetMarkerSize( 0.5 ); g->Draw("AP"); TF1 *f1 = new TF1("f1", "[0]*sin([1]*x+[2])-[3]"); f1->SetParameter(0, 2000.0); f1->SetParameter(1, 0.022); f1->SetParameter(2, 0.0); f1->SetParameter(3, 0.0); f1->SetLineColor(kRed); g->Fit(f1); TGraph *h = new TGraph("myfile4.dat"); h->SetMarkerStyle( 24 ); h->SetMarkerSize( 0.5 ); h->Draw("P"); TF1 *f2 = new TF1("f2", "[0]*sin([1]*x+[2])-[3]"); f2->SetParameter(0, 2000.0); f2->SetParameter(1, 0.022); f2->SetParameter(2, 0.0); f2->SetParameter(3, 0.0); f2->SetLineColor(kYellow); h->Fit(f2); double amp, phase; amp = f2->GetParameter(0) / f1->GetParameter(0); phase = f2->GetParameter(2) - f1->GetParameter(2); std::cout << amp << ", " << phase << std::endl; TComplex v1, v2, v3, Z, z50; v1 = TComplex(1.0, 0.0); v2 = TComplex( amp*TMath::Cos(phase), amp*TMath::Sin(phase) ); v3 = 2.0*v1 - v2; z = v2/v3; z50 = 50.0*z; std::cout << v1 << ", " << v2 << ", " << v3 << ", " << z << ", " << z50 << std::endl; TComplex rho; double vswr; rho = (z-1.0)/(z+1.0); vswr = (1.0+TComplex::Abs(rho)) / (1.0-TComplex::Abs(rho)); std::cout << rho << ", " << vswr << std::endl; }
% root mytest41.cc 0.778415, -0.53185 (1,0i), (0.670893,-0.394757i), (1.32911,0.394757i), (0.382788,-0.410701i), (19.1394,-20.535i) (-0.329107,-0.394757i), 3.1148