1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz 1/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: Software Development, 2000-2009
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MSpline3
|
---|
28 | //
|
---|
29 | // This is a extension of TSpline3. In addition to TSpline3 it allows access
|
---|
30 | // to Xmin, Xman and Np. The construction is a bit simplified because no
|
---|
31 | // title hase to be given (it can be given later by SetTitle anyway)
|
---|
32 | // and is provides constructors which allow to scale the x-values by
|
---|
33 | // pre-defined multiplier (e.g. frequency) to create the spline.
|
---|
34 | //
|
---|
35 | //////////////////////////////////////////////////////////////////////////////
|
---|
36 | #include "MSpline3.h"
|
---|
37 |
|
---|
38 | #include <TF1.h>
|
---|
39 |
|
---|
40 | ClassImp(MSpline3);
|
---|
41 |
|
---|
42 | using namespace std;
|
---|
43 |
|
---|
44 | // --------------------------------------------------------------------------
|
---|
45 | //
|
---|
46 | // Constructor.
|
---|
47 | //
|
---|
48 | MSpline3::MSpline3(const TF1 &f, const char *opt, Double_t valbeg, Double_t valend)
|
---|
49 | : TSpline3("MSpline3", f.GetXmin(), f.GetXmax(), &f, f.GetNpx(), opt, valbeg, valend)
|
---|
50 | {
|
---|
51 | }
|
---|
52 |
|
---|
53 | // --------------------------------------------------------------------------
|
---|
54 | //
|
---|
55 | // This is a helper to convert the x-values by multiplying with freq
|
---|
56 | // before initializing the spline
|
---|
57 | //
|
---|
58 | TGraph *MSpline3::ConvertSpline(const TSpline &s, Float_t freq) const
|
---|
59 | {
|
---|
60 | const UInt_t npx = s.GetNpx();
|
---|
61 |
|
---|
62 | // WARNING: This is a stupid workaround because the TSpline3-
|
---|
63 | // constructor takes a pointer as input! It is not thread-safe!
|
---|
64 | static TGraph g;
|
---|
65 | g.Set(npx);
|
---|
66 |
|
---|
67 | for (UInt_t i=0; i<npx; i++)
|
---|
68 | {
|
---|
69 | Double_t x, y;
|
---|
70 | s.GetKnot(i, x, y);
|
---|
71 | g.SetPoint(i, x*freq, y);
|
---|
72 | }
|
---|
73 |
|
---|
74 | return &g;
|
---|
75 | }
|
---|
76 |
|
---|
77 | // --------------------------------------------------------------------------
|
---|
78 | //
|
---|
79 | // This is a helper to convert the x-values by multiplying with freq
|
---|
80 | // before initializing the spline
|
---|
81 | //
|
---|
82 | TGraph *MSpline3::ConvertGraph(const TGraph &s, Float_t freq) const
|
---|
83 | {
|
---|
84 | const UInt_t npx = s.GetN();
|
---|
85 |
|
---|
86 | // WARNING: This is a stupid workaround because the TSpline3-
|
---|
87 | // constructor takes a pointer as input! It is not thread-safe!
|
---|
88 | static TGraph g;
|
---|
89 | g.Set(npx);
|
---|
90 |
|
---|
91 | for (UInt_t i=0; i<npx; i++)
|
---|
92 | {
|
---|
93 | Double_t x, y;
|
---|
94 | s.GetPoint(i, x, y);
|
---|
95 | g.SetPoint(i, x*freq, y);
|
---|
96 | }
|
---|
97 |
|
---|
98 | return &g;
|
---|
99 | }
|
---|
100 |
|
---|
101 | // --------------------------------------------------------------------------
|
---|
102 | //
|
---|
103 | // This is a helper to convert the x-values by multiplying with freq
|
---|
104 | // before initializing the spline. The conversion from the function to
|
---|
105 | // a discrete binning is done similar to the constructor of TSpline
|
---|
106 | //
|
---|
107 | TGraph *MSpline3::ConvertFunc(const TF1 &f, Float_t freq) const
|
---|
108 | {
|
---|
109 | const UInt_t npx = f.GetNpx();
|
---|
110 |
|
---|
111 | // WARNING: This is a stupid workaround because the TSpline3-
|
---|
112 | // constructor takes a pointer as input! It is not thread-safe!
|
---|
113 | static TGraph g;
|
---|
114 | g.Set(npx);
|
---|
115 |
|
---|
116 | const Double_t step = (f.GetXmax()-f.GetXmin())/(npx-1);
|
---|
117 |
|
---|
118 | for (UInt_t i=0; i<npx; ++i)
|
---|
119 | {
|
---|
120 | const Double_t x = f.GetXmin() + i*step;
|
---|
121 | g.SetPoint(i, x*freq, f.Eval(x));
|
---|
122 | }
|
---|
123 |
|
---|
124 | return &g;
|
---|
125 | }
|
---|