]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/scripts/VA1Response.C
Added various ROOT and Shell scripts used for development of the FMD code
[u/mrichter/AliRoot.git] / FMD / scripts / VA1Response.C
1 // 
2 // Script to try to fit the reponse function of the VA1 signals, based
3 // on a finite number of ALTRO samples. 
4 //
5 void 
6 VA1Response(Int_t n=2, Float_t B=5, Float_t dc=.01, Bool_t errors=kFALSE) 
7 {
8
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);
13   
14   TF1* fit = new TF1("fit",  "[0] * (1 - exp(-[1] * x))",  0, 1);
15   fit->SetParameters(.5, B/2);
16   fit->SetParNames("A", "B");
17   fit->SetLineColor(3);
18   
19   TGraph* graph = 0;
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);
27   }
28   
29   response->Draw();
30   response->GetHistogram()->GetYaxis()->SetRangeUser(0, 1.4);
31   response->GetHistogram()->GetXaxis()->SetRangeUser(0, 1.4);
32   graph->Draw("P*");
33   TString fitOpt("E");
34   if (!errors) fitOpt.Append("W");
35   graph->Fit("fit", fitOpt.Data());
36   graph->Fit("fit", fitOpt.Data());
37
38   std::cout << "Chi^2/NDF = " << fit->GetChisquare() << "/" << fit->GetNDF()
39             << " = " << std::flush;
40   if (fit->GetNDF() == 0) 
41     std::cout << " undefined!" << std::endl;
42   else
43     std::cout << (fit->GetChisquare() / fit->GetNDF()) << std::endl;
44   std::cout << "f(t) = " 
45             << fit->GetParameter(0) << "+/-" << fit->GetParError(0) 
46             << " * (1 - exp(" 
47             << fit->GetParameter(1) << "+/-" << fit->GetParError(1) 
48             << " * t))" << std::endl;
49 }