1 | /* This macro is defined as a class for debugging (with CInt) reasons
|
---|
2 |
|
---|
3 | To use it at the root prompt type:
|
---|
4 |
|
---|
5 | root [0] .L spline.C
|
---|
6 | root [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 |
|
---|
11 | class TestSpline
|
---|
12 | {
|
---|
13 | public:
|
---|
14 | void sp();
|
---|
15 | };
|
---|
16 |
|
---|
17 | void TestSpline::sp()
|
---|
18 | {
|
---|
19 | gROOT -> 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 */
|
---|
25 | const Byte_t y[]={0x0F,0x10,0x2F,0x7F,0xAA,0x6C,0x14,0x13,0x15,0x18,0x21,0x12,0x11,0x14,0x13};
|
---|
26 | /* End user Change */
|
---|
27 | const 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 |
|
---|
32 | Int_t *newX = new Int_t[15];
|
---|
33 | Int_t *newY = new Int_t[15];
|
---|
34 |
|
---|
35 | for (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
|
---|
42 | TCanvas *c = new TCanvas ("c1","c1",800,600);
|
---|
43 |
|
---|
44 | //Graph containting only the points (displayed as stars)
|
---|
45 | TGraph *g1 = new TGraph(15,newX,newY);
|
---|
46 |
|
---|
47 | g1 -> Draw("A*");
|
---|
48 |
|
---|
49 | //Spline constructor(specialized for 15 slices using Bytes as values. There exist another constructor.
|
---|
50 | MCubicSpline *s = new MCubicSpline(y);
|
---|
51 |
|
---|
52 | //*spline and *ab are two arrays containing some values evaluated from the spline
|
---|
53 | Double_t *spline = new Double_t[139];
|
---|
54 | Double_t *ab = new Double_t[139];
|
---|
55 | Double_t step = 0.0;
|
---|
56 |
|
---|
57 | for (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
|
---|
66 | TGraph *g2 = new TGraph(139,ab,spline);
|
---|
67 |
|
---|
68 | g2 -> SetLineColor(2);
|
---|
69 | g2 -> Draw("C");
|
---|
70 |
|
---|
71 | //Maximum and minimum evaluation
|
---|
72 | Double_t *mm = new Double_t[2];
|
---|
73 | Double_t *abmm = new Double_t[2];
|
---|
74 |
|
---|
75 | mm[0] = s->EvalMin();
|
---|
76 | mm[1] = s->EvalMax();
|
---|
77 | abmm[0] = s->EvalAbMin();
|
---|
78 | abmm[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 |
|
---|
83 | TGraph *g3 = new TGraph(2,abmm,mm);
|
---|
84 |
|
---|
85 | g3 -> SetMarkerStyle(21);
|
---|
86 | g3 -> Draw("P");
|
---|
87 |
|
---|
88 | //Test of the Cardan formula. Find the point(abval) where the Spline value is val
|
---|
89 | Double_t val = 82.5;
|
---|
90 | Double_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 |
|
---|
95 | TGraph *g4 = new TGraph(1,&abval,&val);
|
---|
96 |
|
---|
97 | g4 -> SetMarkerStyle(22);
|
---|
98 | g4 -> Draw("P");
|
---|
99 |
|
---|
100 | //Free memory
|
---|
101 | s->~MCubicSpline();
|
---|
102 | delete [] newX;
|
---|
103 | delete [] newY;
|
---|
104 | delete [] spline;
|
---|
105 | delete [] ab;
|
---|
106 | delete [] mm;
|
---|
107 | delete [] abmm;
|
---|
108 |
|
---|
109 | }
|
---|