source: trunk/Mars/melectronics/MPulseShape.cc@ 19976

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