source: trunk/MagicSoft/Mars/macros/tutorials/spline.C@ 9141

Last change on this file since 9141 was 7159, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 2.7 KB
Line 
1/* This macro is defined as a class for debugging (with CInt) reasons
2
3To use it at the root prompt type:
4
5root [0] .L spline.C
6root [1] TestSpline::sp()
7*/
8/* Example of a spline. You can use it as Test. If you think there are some
9 bugs in the MCubicSpline class please mail to: raducci@fisica.uniud.it */
10
11class TestSpline
12{
13public:
14 void sp();
15};
16
17void TestSpline::sp()
18{
19gROOT -> Reset();
20
21//Here are defined the points. X goes from 0 to 14 (as the fadc slices...)
22//Y are arbitrary values
23
24/* User Change */
25const Byte_t y[]={0x0F,0x10,0x2F,0x7F,0xAA,0x6C,0x14,0x13,0x15,0x18,0x21,0x12,0x11,0x14,0x13};
26/* End user Change */
27const Byte_t x[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E};
28
29/*This cast is needed only to show graphically the output. Don' t needed if you
30 use the spline to calc the arrival times */
31
32Int_t *newX = new Int_t[15];
33Int_t *newY = new Int_t[15];
34
35for (Int_t i = 0; i < 15; i++)
36{
37 newX[i] = (Int_t) x[i];
38 newY[i] = (Int_t) y[i];
39}
40
41//Canvas to display output
42TCanvas *c = new TCanvas ("c1","c1",800,600);
43
44//Graph containting only the points (displayed as stars)
45TGraph *g1 = new TGraph(15,newX,newY);
46
47g1 -> Draw("A*");
48
49//Spline constructor(specialized for 15 slices using Bytes as values. There exist another constructor.
50MCubicSpline *s = new MCubicSpline(y);
51
52//*spline and *ab are two arrays containing some values evaluated from the spline
53Double_t *spline = new Double_t[139];
54Double_t *ab = new Double_t[139];
55Double_t step = 0.0;
56
57for (Int_t i = 0; i < 139; i++)
58{
59 spline[i] = s->Eval(step);
60 ab[i] = step;
61 step += 0.1;
62}
63
64//Graph of the sline. The points calculated are joined with a red line. If the stars lie
65//on the red line, then the Spline class is working properly
66TGraph *g2 = new TGraph(139,ab,spline);
67
68g2 -> SetLineColor(2);
69g2 -> Draw("C");
70
71//Maximum and minimum evaluation
72Double_t *mm = new Double_t[2];
73Double_t *abmm = new Double_t[2];
74
75mm[0] = s->EvalMin();
76mm[1] = s->EvalMax();
77abmm[0] = s->EvalAbMin();
78abmm[1] = s->EvalAbMax();
79
80//Display the max and the min using two black squares. If they lie on the max and min
81//of the red line, then the Spline class is working properly
82
83TGraph *g3 = new TGraph(2,abmm,mm);
84
85g3 -> SetMarkerStyle(21);
86g3 -> Draw("P");
87
88//Test of the Cardan formula. Find the point(abval) where the Spline value is val
89Double_t val = 82.5;
90Double_t abval = s->FindVal(val, abmm[1], 'l');
91
92//Display this point. Again, if it lies on the red line, then we are right.
93//It's a black triangle
94
95TGraph *g4 = new TGraph(1,&abval,&val);
96
97g4 -> SetMarkerStyle(22);
98g4 -> Draw("P");
99
100//Free memory
101s->~MCubicSpline();
102delete [] newX;
103delete [] newY;
104delete [] spline;
105delete [] ab;
106delete [] mm;
107delete [] abmm;
108
109}
Note: See TracBrowser for help on using the repository browser.