2 // Script to try to fit the reponse function of the VA1 signals, based
3 // on a finite number of ALTRO samples.
6 VA1Response(Int_t n=2, Float_t B=5, Float_t dc=.01, Bool_t errors=kFALSE)
9 TF1* response = new TF1("response", "[0] * (1 - exp(-[1] * x))", 0, 1.4);
10 response->SetParameters(1, B);
11 response->SetParNames("A", "B");
12 response->SetLineColor(2);
14 TF1* fit = new TF1("fit", "[0] * (1 - exp(-[1] * x))", 0, 1);
15 fit->SetParameters(.5, B/2);
16 fit->SetParNames("A", "B");
20 if (errors) graph = new TGraphErrors(n);
21 else graph = new TGraph(n);
22 for (Int_t i = 0; i < n; i++) {
23 Float_t t = Float_t(i + 1) / n;
24 Float_t c = gRandom->Gaus(response->Eval(t), dc);
25 graph->SetPoint(i, t, c);
26 if (errors) ((TGraphErrors*)graph)->SetPointError(i, 0, dc);
30 response->GetHistogram()->GetYaxis()->SetRangeUser(0, 1.4);
31 response->GetHistogram()->GetXaxis()->SetRangeUser(0, 1.4);
34 if (!errors) fitOpt.Append("W");
35 graph->Fit("fit", fitOpt.Data());
36 graph->Fit("fit", fitOpt.Data());
38 std::cout << "Chi^2/NDF = " << fit->GetChisquare() << "/" << fit->GetNDF()
39 << " = " << std::flush;
40 if (fit->GetNDF() == 0)
41 std::cout << " undefined!" << std::endl;
43 std::cout << (fit->GetChisquare() / fit->GetNDF()) << std::endl;
44 std::cout << "f(t) = "
45 << fit->GetParameter(0) << "+/-" << fit->GetParError(0)
47 << fit->GetParameter(1) << "+/-" << fit->GetParError(1)
48 << " * t))" << std::endl;