]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/scripts/VA1Response.C
0. General code clean-up, including messages, and the like.
[u/mrichter/AliRoot.git] / FMD / scripts / VA1Response.C
1 //____________________________________________________________________
2 // 
3 // $Id$
4 //
5 // Script to try to fit the reponse function of the VA1 signals, based
6 // on a finite number of ALTRO samples. 
7 //
8 void 
9 VA1Response(Int_t n=2, Float_t B=5, Float_t dc=.01, Bool_t errors=kFALSE) 
10 {
11
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);
16   
17   TF1* fit = new TF1("fit",  "[0] * (1 - exp(-[1] * x))",  0, 1);
18   fit->SetParameters(.5, B/2);
19   fit->SetParNames("A", "B");
20   fit->SetLineColor(3);
21   
22   TGraph* graph = 0;
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);
30   }
31   
32   response->Draw();
33   response->GetHistogram()->GetYaxis()->SetRangeUser(0, 1.4);
34   response->GetHistogram()->GetXaxis()->SetRangeUser(0, 1.4);
35   graph->Draw("P*");
36   TString fitOpt("E");
37   if (!errors) fitOpt.Append("W");
38   graph->Fit("fit", fitOpt.Data());
39   graph->Fit("fit", fitOpt.Data());
40
41   std::cout << "Chi^2/NDF = " << fit->GetChisquare() << "/" << fit->GetNDF()
42             << " = " << std::flush;
43   if (fit->GetNDF() == 0) 
44     std::cout << " undefined!" << std::endl;
45   else
46     std::cout << (fit->GetChisquare() / fit->GetNDF()) << std::endl;
47   std::cout << "f(t) = " 
48             << fit->GetParameter(0) << "+/-" << fit->GetParError(0) 
49             << " * (1 - exp(" 
50             << fit->GetParameter(1) << "+/-" << fit->GetParError(1) 
51             << " * t))" << std::endl;
52 }
53 //____________________________________________________________________
54 //
55 // EOF
56 //