CMS 3D CMS Logo

TPNPulse.cc
Go to the documentation of this file.
1 /*
2  * \class TPNPulse
3  *
4  * \author: Julie Malcles - CEA/Saclay
5  */
6 
8 
9 #include <TMath.h>
10 #include <iostream>
11 #include <cassert>
12 using namespace std;
13 
14 //ClassImp(TPNPulse)
15 
16 // Default Constructor...
17 TPNPulse::TPNPulse() { init(50, 6); }
18 
19 // Constructor...
20 TPNPulse::TPNPulse(int nsamples, int presample) { init(nsamples, presample); }
21 
22 // Destructor
24 
25 void TPNPulse::init(int nsamples, int presample) {
26  _nsamples = 50;
27  assert(nsamples == _nsamples);
28  assert(presample != 0);
29  adc_ = new double[50];
30 
31  _presample = presample;
32 
33  for (int i = 0; i < _nsamples; i++) {
34  adc_[i] = 0.0;
35  }
36 
37  adcMax_ = 0;
38  iadcMax_ = 0;
39  pedestal_ = 0;
40 
41  isMaxFound_ = false;
42  isPedCalc_ = false;
43 }
44 
45 bool TPNPulse::setPulse(double *adc) {
46  bool done = false;
47  adc_ = adc;
48  done = true;
49  isMaxFound_ = false;
50  isPedCalc_ = false;
51  return done;
52 }
53 double TPNPulse::getMax() {
54  if (isMaxFound_)
55  return adcMax_;
56 
57  int iadcmax = 0;
58  double adcmax = 0.0;
59  for (int i = 0; i < _nsamples; i++) {
60  if (adc_[i] > adcmax) {
61  iadcmax = i;
62  adcmax = adc_[i];
63  }
64  }
65  iadcMax_ = iadcmax;
66  adcMax_ = adcmax;
67  return adcMax_;
68 }
69 
71  if (!isMaxFound_)
72  getMax();
73  return iadcMax_;
74 }
75 
77  if (isPedCalc_)
78  return pedestal_;
79  double ped = 0;
80  for (int i = 0; i < _presample; i++) {
81  ped += adc_[i];
82  }
83  ped /= double(_presample);
84  pedestal_ = ped;
85  isPedCalc_ = true;
86  return pedestal_;
87 }
88 
90  double ped;
91  if (!isPedCalc_)
92  ped = getPedestal();
93  else
94  ped = pedestal_;
95 
96  double *adcNoPed = new double[50];
97  for (int i = 0; i < _nsamples; i++) {
98  adcNoPed[i] = adc_[i] - ped;
99  }
100  return adcNoPed;
101 }
102 
103 void TPNPulse::setPresamples(int presample) {
104  isPedCalc_ = false;
105  _presample = presample;
106 }
double getPedestal()
Definition: TPNPulse.cc:76
void init(int, int)
Definition: TPNPulse.cc:25
double getMax()
Definition: TPNPulse.cc:53
int init
Definition: HydjetWrapper.h:66
double * getAdcWithoutPedestal()
Definition: TPNPulse.cc:89
assert(be >=bs)
bool setPulse(double *)
Definition: TPNPulse.cc:45
~TPNPulse() override
Definition: TPNPulse.cc:23
TPNPulse()
Definition: TPNPulse.cc:17
void setPresamples(int)
Definition: TPNPulse.cc:103
int getMaxSample()
Definition: TPNPulse.cc:70
uint16_t *__restrict__ uint16_t const *__restrict__ adc