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

Last change on this file since 9337 was 9312, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.9 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(-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//
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 fSpline->SetTitle("MPulseShape");
130
131 // FIXME: Make a boundary condition e1b1,0,0 (First der, at Xmin and Xmax==0)
132 // FIXME: Force the spline to be 0 at Xmin and Xmax?
133
134 return kTRUE;
135}
136
137void MPulseShape::SetFunction(const TF1 &f)
138{
139 // FIXME: Use TF1 directly? (In most cases this seems to be slower)
140
141 // option: b1/e1 b2/e2 (first second derivative?)
142 // option: valbeg/valend (first second derivative?)
143
144 // if (f.GetNpar()==0)
145 // No SUPPORT
146
147 Clear();
148 fSpline = new MSpline3(f);//, fRunHeader->GetFreqSampling()/1000.);
149 fSpline->SetTitle("MPulseShape");
150
151 // FIXME: Make a boundary condition e1b1,0,0 (First der, at Xmin and Xmax==0)
152 // FIXME: Force the spline to be 0 at Xmin and Xmax?
153
154 fFunction = f.GetTitle();
155}
156
157Bool_t MPulseShape::SetFunction(const char *func, Int_t n, Double_t xmin, Double_t xmax)
158{
159 // FIXME: Use TF1 directly? (In most cases this seems to be slower)
160 TF1 f("f", func, xmin, xmax);
161 f.SetNpx(n);
162
163 SetFunction(f);
164
165 return kTRUE;
166}
167
168// --------------------------------------------------------------------------
169//
170// FileName: pulse-shape.txt
171// Function.Name: gaus
172// Function.Npx: 50
173// Function.Xmin: -5
174// Function.Xmax: 5
175//
176Int_t MPulseShape::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
177{
178 Bool_t rc = kFALSE;
179 if (IsEnvDefined(env, prefix, "FileName", print))
180 {
181 rc = kTRUE;
182 SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));
183 if (!fFileName.IsNull())
184 if (ReadFile(fFileName))
185 return kERROR;
186 }
187
188 if (IsEnvDefined(env, prefix, "Function.Name", print))
189 {
190 rc = kTRUE;
191
192 if (IsEnvDefined(env, prefix, "Function.Npx", print))
193 fNpx = GetEnvValue(env, prefix, "Function.Npx", fNpx);
194 if (IsEnvDefined(env, prefix, "Function.Xmin", print))
195 fXmin = GetEnvValue(env, prefix, "Function.Xmin", fXmin);
196 if (IsEnvDefined(env, prefix, "Function.Xmax", print))
197 fXmax = GetEnvValue(env, prefix, "Function.Xmax", fXmax);
198
199 SetFunction(GetEnvValue(env, prefix, "Function.Name", fFunction), fNpx, fXmin, fXmax);
200 }
201
202 return rc;
203}
204
205void MPulseShape::Paint(Option_t *)
206{
207 fSpline->SetMarkerStyle(kFullDotMedium);
208
209 if (!fSpline->GetHistogram())
210 fSpline->Paint();
211
212 TH1 *h = fSpline->GetHistogram();
213 if (!h)
214 return;
215
216 h->SetXTitle("t [ns]");
217 h->SetYTitle("a.u.");
218
219 fSpline->Paint("PC");
220}
Note: See TracBrowser for help on using the repository browser.