1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of CheObs, the Modular 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 appears 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: CheObs Software Development, 2000-2009
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MPulseShape
|
---|
28 | //
|
---|
29 | // This container describes the pulse shape of a pulse.
|
---|
30 | //
|
---|
31 | //////////////////////////////////////////////////////////////////////////////
|
---|
32 | #include "MPulseShape.h"
|
---|
33 |
|
---|
34 | #include <TF1.h>
|
---|
35 |
|
---|
36 | #include "MLog.h"
|
---|
37 | #include "MLogManip.h"
|
---|
38 |
|
---|
39 | #include "MSpline3.h"
|
---|
40 |
|
---|
41 | ClassImp(MPulseShape);
|
---|
42 |
|
---|
43 | using namespace std;
|
---|
44 |
|
---|
45 | // --------------------------------------------------------------------------
|
---|
46 | //
|
---|
47 | // Default Constructor.
|
---|
48 | //
|
---|
49 | MPulseShape::MPulseShape(const char* name, const char *title)
|
---|
50 | : fSpline(0), fFunction("exp(-(x/2)^2/2)"), fNpx(25), fXmin(-8), fXmax(8)
|
---|
51 | {
|
---|
52 | fName = name ? name : "MPulseShape";
|
---|
53 | fTitle = title ? title : "";
|
---|
54 |
|
---|
55 | SetFunction(fFunction, fNpx, fXmin, fXmax);
|
---|
56 | }
|
---|
57 |
|
---|
58 | // --------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | // Call Clear()
|
---|
61 | //
|
---|
62 | MPulseShape::~MPulseShape()
|
---|
63 | {
|
---|
64 | Clear();
|
---|
65 | }
|
---|
66 |
|
---|
67 | // --------------------------------------------------------------------------
|
---|
68 | //
|
---|
69 | // Delete fSpline if set and set it to 0
|
---|
70 | //
|
---|
71 | void MPulseShape::Clear(Option_t *)
|
---|
72 | {
|
---|
73 | if (fSpline)
|
---|
74 | delete fSpline;
|
---|
75 | fSpline=0;
|
---|
76 | }
|
---|
77 |
|
---|
78 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // Return the width of the range in which the spline is defined.
|
---|
81 | //
|
---|
82 | Float_t MPulseShape::GetPulseWidth() const
|
---|
83 | {
|
---|
84 | return fSpline ? fSpline->GetXmax()-fSpline->GetXmin() : 0;
|
---|
85 | }
|
---|
86 |
|
---|
87 | // --------------------------------------------------------------------------
|
---|
88 | //
|
---|
89 | // Return the lower edge of the range in which the spline is defined.
|
---|
90 | //
|
---|
91 | Float_t MPulseShape::GetXmin() const
|
---|
92 | {
|
---|
93 | return fSpline ? fSpline->GetXmin() : 0;
|
---|
94 | }
|
---|
95 |
|
---|
96 | // --------------------------------------------------------------------------
|
---|
97 | //
|
---|
98 | // Return the upper edge of the range in which the spline is defined.
|
---|
99 | //
|
---|
100 | Float_t MPulseShape::GetXmax() const
|
---|
101 | {
|
---|
102 | return fSpline ? fSpline->GetXmax() : 0;
|
---|
103 | }
|
---|
104 |
|
---|
105 | // --------------------------------------------------------------------------
|
---|
106 | //
|
---|
107 | // Read the intended pulse shape from a file and initialize the spline
|
---|
108 | // accordingly
|
---|
109 | //
|
---|
110 | Bool_t MPulseShape::ReadFile(const char *fname)
|
---|
111 | {
|
---|
112 | if (fname)
|
---|
113 | fFileName = fname;
|
---|
114 |
|
---|
115 | *fLog << inf << "Reading pulse shape from " << fFileName << endl;
|
---|
116 |
|
---|
117 | const TGraph g(fFileName);
|
---|
118 | if (g.GetN()==0)
|
---|
119 | {
|
---|
120 | *fLog << err << "ERROR - No data points from " << fFileName << "." << endl;
|
---|
121 | return kFALSE;
|
---|
122 | }
|
---|
123 |
|
---|
124 | // option: b1/e1 b2/e2 (first second derivative?)
|
---|
125 | // option: valbeg/valend (first second derivative?)
|
---|
126 |
|
---|
127 | Clear();
|
---|
128 | fSpline = new MSpline3(g);//, fRunHeader->GetFreqSampling()/1000.);
|
---|
129 |
|
---|
130 | // FIXME: Make a boundary condition e1b1,0,0 (First der, at Xmin and Xmax==0)
|
---|
131 | // FIXME: Force the spline to be 0 at Xmin and Xmax?
|
---|
132 |
|
---|
133 | return kTRUE;
|
---|
134 | }
|
---|
135 |
|
---|
136 | void MPulseShape::SetFunction(const TF1 &f)
|
---|
137 | {
|
---|
138 | // FIXME: Use TF1 directly? (In most cases this seems to be slower)
|
---|
139 |
|
---|
140 | // option: b1/e1 b2/e2 (first second derivative?)
|
---|
141 | // option: valbeg/valend (first second derivative?)
|
---|
142 |
|
---|
143 | // if (f.GetNpar()==0)
|
---|
144 | // No SUPPORT
|
---|
145 |
|
---|
146 | Clear();
|
---|
147 | fSpline = new MSpline3(f);//, fRunHeader->GetFreqSampling()/1000.);
|
---|
148 |
|
---|
149 | // FIXME: Make a boundary condition e1b1,0,0 (First der, at Xmin and Xmax==0)
|
---|
150 | // FIXME: Force the spline to be 0 at Xmin and Xmax?
|
---|
151 |
|
---|
152 | fFunction = f.GetTitle();
|
---|
153 | }
|
---|
154 |
|
---|
155 | Bool_t MPulseShape::SetFunction(const char *func, Int_t n, Double_t xmin, Double_t xmax)
|
---|
156 | {
|
---|
157 | // FIXME: Use TF1 directly? (In most cases this seems to be slower)
|
---|
158 | TF1 f("f", func, xmin, xmax);
|
---|
159 | f.SetNpx(n);
|
---|
160 |
|
---|
161 | SetFunction(f);
|
---|
162 |
|
---|
163 | return kTRUE;
|
---|
164 | }
|
---|
165 |
|
---|
166 | // --------------------------------------------------------------------------
|
---|
167 | //
|
---|
168 | // FileName: pulse-shape.txt
|
---|
169 | // Function.Name: gaus
|
---|
170 | // Function.Npx: 50
|
---|
171 | // Function.Xmin: -5
|
---|
172 | // Function.Xmax: 5
|
---|
173 | //
|
---|
174 | Int_t MPulseShape::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
175 | {
|
---|
176 | Bool_t rc = kFALSE;
|
---|
177 | if (IsEnvDefined(env, prefix, "FileName", print))
|
---|
178 | {
|
---|
179 | rc = kTRUE;
|
---|
180 | SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
|
---|
181 | if (!fFileName.IsNull())
|
---|
182 | if (ReadFile(fFileName))
|
---|
183 | return kERROR;
|
---|
184 | }
|
---|
185 |
|
---|
186 | if (IsEnvDefined(env, prefix, "Function.Name", print))
|
---|
187 | {
|
---|
188 | rc = kTRUE;
|
---|
189 |
|
---|
190 | if (IsEnvDefined(env, prefix, "Function.Npx", print))
|
---|
191 | fNpx = GetEnvValue(env, prefix, "Function.Npx", fNpx);
|
---|
192 | if (IsEnvDefined(env, prefix, "Function.Xmin", print))
|
---|
193 | fXmin = GetEnvValue(env, prefix, "Function.Xmin", fXmin);
|
---|
194 | if (IsEnvDefined(env, prefix, "Function.Xmax", print))
|
---|
195 | fXmax = GetEnvValue(env, prefix, "Function.Xmax", fXmax);
|
---|
196 |
|
---|
197 | SetFunction(GetEnvValue(env, prefix, "Function.Name", fFunction), fNpx, fXmin, fXmax);
|
---|
198 | }
|
---|
199 |
|
---|
200 | return rc;
|
---|
201 | }
|
---|