AlcapDAQ  1
TOctalFADCIsland.cpp
Go to the documentation of this file.
1 #include "TOctalFADCIsland.h"
2 #include <algorithm>
3 #include <iostream>
4 #include <cmath>
5 #include <math.h>
6 #include <TH1I.h>
7 #include <TF1.h>
8 
9 
10 using std::cout; using std::cerr; using std::endl;
11 using std::vector;
12 
14  : fTime(0)
15 {}
16 
17 int TOctalFADCIsland::GetMax(int first, int last) const
18 {
19  if(last < first || last >= fData.size() || first < 0){
20  cerr << "TOctalFADCIsland::GetMax() : Error! arguments out of range." << endl;
21  }
22  // max_element returns an iterator to the maximum element in the range.
23  return *(std::max_element(fData.begin() + first, fData.begin() + last + 1));
24 }
25 
26 int TOctalFADCIsland::GetMaxBin(int first, int last) const
27 {
28  if(last < first || last >= fData.size() || first < 0)
29  {
30  cout << "first = " << first << " last : " << last << " size : " << fData.size() << endl;
31  cerr << "TOctalFADCIsland::GetMaxBin() : Error! arguments out of range." << endl;
32  }
33  return std::max_element(fData.begin()+first,fData.begin()+last+1)
34  - fData.begin();
35 }
36 
42 double TOctalFADCIsland::GetAverageMax(int nAv, int first, int last) const
43 {
44  if(last < first || last >= fData.size() || first < 0 || nAv < 0){
45  cerr << "TOctalFADCIsland::GetAverageMax() : Error! arguments out of range."
46  << endl;
47  }
48 
49  int maxbin = GetMaxBin(first,last);
50  int sum = *(std::max_element(fData.begin()+first,fData.begin()+last+1));
51  int skipped = 0;
52  int ind;
53 
54  for(int i=1; i<=nAv; i++)
55  {
56  ind = maxbin + static_cast<int>((i/2.+ 0.5)*pow(-1,i));
57  if(ind > first && ind < last){sum = sum + fData[ind];}
58  else{skipped++;}
59  }
60 
61  return static_cast<double>(sum)/(nAv+1.-skipped);
62 }
63 
64 int TOctalFADCIsland::GetMaxBinTime(int first, int last) const
65 {
66  if(last < first || last >= fData.size() || first < 0){
67  cerr << "TOctalFADCIsland::GetMaxBinTime() : Error! arguments out of range."
68  << endl;
69  }
70  return GetTime() + GetMaxBin(first,last);
71 }
72 
73 int TOctalFADCIsland::GetCFBlockTime(int first, int last) const
74 {
75  if(last < first || last >= fData.size() || first < 0){
76  cerr << "TOctalFADCIsland::GetCFBlockTime() : Error! arguments out of range."
77  << endl;
78  }
79  return GetCFBin(first,last)+GetTime();
80 }
81 
85 int TOctalFADCIsland::GetCFBin(int first, int last) const
86 {
87  if(last < first || last >= fData.size() || first < 0){
88  cerr << "TOctalFADCIsland::GetCFBlockTime() : Error! arguments out of range."
89  << endl;
90  }
91 
92  // Take the non-zero pedestal into account
93  int max = GetMax(first,last) - fData[first];
94  int maxbin = GetMaxBin(first,last);
95  double halfmax = max/2.;
96  int constantFraction = first;
97  double value = -1.;
98 
99  while( value < halfmax && constantFraction < maxbin)
100  {
101  value = static_cast<double>(fData[constantFraction]);
102  constantFraction++;
103  }
104 
105  return constantFraction;
106 }
107 
108 double TOctalFADCIsland::GetAverage(int first, int last) const
109 {
110  if(last < first ){return -1.;}
111  if(first<0){first=0;}
112  if(last >= fData.size()){last = fData.size();}
113 
114  int sum = 0;
115  int N = 0;
116 
117  for(int i = first; i <= last; i++)
118  {
119  sum += fData[i];
120  N += 1;
121  }
122 
123  return static_cast<double>(sum)/N;
124 }
125 
126 double TOctalFADCIsland::GetIntegral(int first, int last) const
127 {
128  if(last < first ){return -1.;}
129  if(first<0) { first=0; }
130  if(last >= fData.size()) { last = fData.size() - 1; }
131 
132  int sum = 0;
133 
134  for(int i = first; i <= last; i++)
135  {
136  sum += fData[i];
137  }
138 
139  return static_cast<double>(sum);
140 }