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