00001
00002
00003
00004
00005
00006
00007
00015 void
00016 VA1Response(Int_t n=2, Float_t B=5, Float_t dc=.01, Bool_t errors=kFALSE)
00017 {
00018
00019 TF1* response = new TF1("response", "[0] * (1 - exp(-[1] * x))", 0, 1.4);
00020 response->SetParameters(1, B);
00021 response->SetParNames("A", "B");
00022 response->SetLineColor(2);
00023
00024 TF1* fit = new TF1("fit", "[0] * (1 - exp(-[1] * x))", 0, 1);
00025 fit->SetParameters(.5, B/2);
00026 fit->SetParNames("A", "B");
00027 fit->SetLineColor(3);
00028
00029 TGraph* graph = 0;
00030 if (errors) graph = new TGraphErrors(n);
00031 else graph = new TGraph(n);
00032 for (Int_t i = 0; i < n; i++) {
00033 Float_t t = Float_t(i + 1) / n;
00034 Float_t c = gRandom->Gaus(response->Eval(t), dc);
00035 graph->SetPoint(i, t, c);
00036 if (errors) ((TGraphErrors*)graph)->SetPointError(i, 0, dc);
00037 }
00038
00039 response->Draw();
00040 response->GetHistogram()->GetYaxis()->SetRangeUser(0, 1.4);
00041 response->GetHistogram()->GetXaxis()->SetRangeUser(0, 1.4);
00042 graph->Draw("P*");
00043 TString fitOpt("E");
00044 if (!errors) fitOpt.Append("W");
00045 graph->Fit("fit", fitOpt.Data());
00046 graph->Fit("fit", fitOpt.Data());
00047
00048 std::cout << "Chi^2/NDF = " << fit->GetChisquare() << "/" << fit->GetNDF()
00049 << " = " << std::flush;
00050 if (fit->GetNDF() == 0)
00051 std::cout << " undefined!" << std::endl;
00052 else
00053 std::cout << (fit->GetChisquare() / fit->GetNDF()) << std::endl;
00054 std::cout << "f(t) = "
00055 << fit->GetParameter(0) << "+/-" << fit->GetParError(0)
00056 << " * (1 - exp("
00057 << fit->GetParameter(1) << "+/-" << fit->GetParError(1)
00058 << " * t))" << std::endl;
00059 }
00060
00061
00062
00063