All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
ShapeParameters.cc
1 #include "ShapeParameters.h"
2 #include "FFTtools.h"
3 #include "TGraph.h"
4 
5 
6 double UCorrelator::shape::getRiseTime(const TGraph * g, double min, double max, int peak)
7 {
8  int ifirst = -1;
9  int ilast = -1;
10  if (peak < 0 || peak >= g->GetN())
11  {
12  FFTtools::getPeakVal(g,&peak);
13  }
14 
15 
16  for (int i = peak; i >=0; i--)
17  {
18 
19  if (g->GetY()[i] <= min)
20  {
21  ifirst = i;
22  break;
23  }
24  if (g->GetY()[i] <= max && ilast < 0)
25  {
26  ilast = i;
27  }
28  }
29 
30  if (ifirst < 0 || ilast < 0) return -1;
31 
32  return g->GetX()[ilast] - g->GetX()[ifirst];
33 }
34 
35 double UCorrelator::shape::getFallTime(const TGraph * g, double min, double max, int peak)
36 {
37  int ifirst = -1;
38  int ilast = -1;
39  if (peak < 0 || peak >= g->GetN())
40  {
41  FFTtools::getPeakVal(g,&peak);
42  }
43 
44 
45  for (int i = peak; i < g->GetN(); i++)
46  {
47 
48  if (g->GetY()[i] <= min)
49  {
50  ilast = i;
51  break;
52  }
53  if (g->GetY()[i] <= max && ifirst < 0)
54  {
55  ifirst = i;
56  }
57  }
58 
59  if (ifirst < 0 || ilast < 0) return -1;
60 
61  return g->GetX()[ilast] - g->GetX()[ifirst];
62 }
63 
64 
65 double UCorrelator::shape::getWidth(const TGraph * g, double val, int * start, int * end, int peak)
66 {
67 
68  int ifirst = -1;
69  int ilast = -1;
70 
71  if (peak < 0 || peak >= g->GetN())
72  {
73  FFTtools::getPeakVal(g,&peak);
74  }
75 
76 
77  for (int i = peak; i < g->GetN(); i++)
78  {
79  if (g->GetY()[i] <=val)
80  {
81  ilast = i;
82  break;
83 
84  }
85  }
86 
87  for (int i = peak; i >= 0; i--)
88  {
89  if (g->GetY()[i] <=val)
90  {
91  ifirst = i;
92  break;
93  }
94  }
95 
96  if (ifirst < 0)
97  ifirst = 0;
98 
99  if (ilast < 0)
100  ilast = g->GetN()-1;
101 
102  double t0 = g->GetX()[ifirst];
103  double t1 = g->GetX()[ilast];
104 
105  if (start) *start = ifirst;
106  if (end) *end = ilast;
107 
108  return t1-t0;
109 
110 }
Double_t getPeakVal(const TGraph *gr, int *index=0)
Find the peak (maximum positive) in a TGraph.
Definition: FFTtools.cxx:1510