source: trunk/MagicSoft/Mars/melectronics/MPulseShape.cc@ 9278

Last change on this file since 9278 was 9274, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.3 KB
Line 
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
41ClassImp(MPulseShape);
42
43using namespace std;
44
45// --------------------------------------------------------------------------
46//
47// Default Constructor.
48//
49MPulseShape::MPulseShape(const char* name, const char *title)
50: fSpline(0), fFunction("exp(-(x/2)^2/2)"), fNpx(25), fXmin(-25), fXmax(25)
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//
62MPulseShape::~MPulseShape()
63{
64 Clear();
65}
66
67// --------------------------------------------------------------------------
68//
69// Delete fSpline if set and set it to 0
70//
71void 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//
82Float_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//
91Float_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//
100Float_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//
110Bool_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 return kTRUE;
131}
132
133void MPulseShape::SetFunction(const TF1 &f)
134{
135 // FIXME: Use TF1 directly? (In most cases this seems to be slower)
136
137 // option: b1/e1 b2/e2 (first second derivative?)
138 // option: valbeg/valend (first second derivative?)
139
140 // if (f.GetNpar()==0)
141 // No SUPPORT
142
143 Clear();
144 fSpline = new MSpline3(f);//, fRunHeader->GetFreqSampling()/1000.);
145
146 fFunction = f.GetTitle();
147}
148
149Bool_t MPulseShape::SetFunction(const char *func, Int_t n, Double_t xmin, Double_t xmax)
150{
151 // FIXME: Use TF1 directly? (In most cases this seems to be slower)
152 TF1 f("f", func, xmin, xmax);
153 f.SetNpx(n);
154
155 SetFunction(f);
156
157 return kTRUE;
158}
159
160// --------------------------------------------------------------------------
161//
162// FileName: pulse-shape.txt
163// Function.Name: gaus
164// Function.Npx: 50
165// Function.Xmin: -5
166// Function.Xmax: 5
167//
168Int_t MPulseShape::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
169{
170 Bool_t rc = kFALSE;
171 if (IsEnvDefined(env, prefix, "FileName", print))
172 {
173 rc = kTRUE;
174 SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
175 if (!fFileName.IsNull())
176 if (ReadFile(fFileName))
177 return kERROR;
178 }
179
180 if (IsEnvDefined(env, prefix, "Function.Name", print))
181 {
182 rc = kTRUE;
183
184 if (IsEnvDefined(env, prefix, "Function.Npx", print))
185 fNpx = GetEnvValue(env, prefix, "Function.Npx", fNpx);
186 if (IsEnvDefined(env, prefix, "Function.Xmin", print))
187 fXmin = GetEnvValue(env, prefix, "Function.Xmin", fXmin);
188 if (IsEnvDefined(env, prefix, "Function.Xmax", print))
189 fXmax = GetEnvValue(env, prefix, "Function.Xmax", fXmax);
190
191 SetFunction(GetEnvValue(env, prefix, "Function.Name", fFunction), fNpx, fXmin, fXmax);
192 }
193
194 return rc;
195}
Note: See TracBrowser for help on using the repository browser.