CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TAPDPulse.cc
Go to the documentation of this file.
1 /*
2  * \class TAPDPulse
3  *
4  * \author: Julie Malcles - CEA/Saclay
5  */
6 
8 #include <TMath.h>
9 #include <iostream>
10 #include <cassert>
11 using namespace std;
12 
13 //ClassImp(TAPDPulse)
14 
15 
16 // Default Constructor...
18 {
19  init(10,3,1,2,2,9,3,8,0.4,0.95,0.8);
20 }
21 
22 // Constructor...
23 TAPDPulse::TAPDPulse( int nsamples, int presample, int firstsample, int lastsample, int timingcutlow, int timingcuthigh, int timingquallow, int timingqualhigh, double ratiomincutlow, double ratiomincuthigh, double ratiomaxcutlow)
24 {
25  init( nsamples, presample, firstsample, lastsample, timingcutlow, timingcuthigh, timingquallow, timingqualhigh,ratiomincutlow,ratiomincuthigh, ratiomaxcutlow );
26 }
27 
28 // Destructor
30 {
31 }
32 
33 void TAPDPulse::init(int nsamples, int presample, int firstsample, int lastsample, int timingcutlow, int timingcuthigh, int timingquallow, int timingqualhigh, double ratiomincutlow, double ratiomincuthigh, double ratiomaxcutlow)
34 {
35  _nsamples=10;
36  assert(nsamples==_nsamples);
37  assert(presample!=0);
38  adc_ = new double[10];
39 
40  _presample=presample;
41  _firstsample=firstsample;
42  _lastsample=lastsample;
43 
44  _timingcutlow=timingcutlow;
45  _timingcuthigh=timingcuthigh;
46  _timingquallow=timingquallow;
47  _timingqualhigh=timingqualhigh;
48  _ratiomincutlow=ratiomincutlow;
49  _ratiomincuthigh=ratiomincuthigh;
50  _ratiomaxcutlow=ratiomaxcutlow;
51 
52  for(int i=0;i<_nsamples;i++){
53  adc_[i]=0.0;
54  }
55 
56  adcMax_=0;
57  iadcMax_=0;
58  pedestal_=0;
59 
60  isMaxFound_=false;
61  isPedCalc_=false;
62 }
63 
64 bool TAPDPulse::setPulse(double *adc){
65 
66  bool done=false;
67  adc_=adc;
68  done=true;
69  isMaxFound_=false;
70  isPedCalc_=false;
71  return done;
72 }
74 
75  if(isMaxFound_) return adcMax_;
76 
77  int iadcmax=0;
78  double adcmax=0.0;
79  for(int i=0;i<_nsamples;i++){
80  if(adc_[i]>adcmax){
81  iadcmax=i;
82  adcmax=adc_[i];
83  }
84  }
85  iadcMax_=iadcmax;
86  adcMax_=adcmax;
87  return adcMax_;
88 }
89 
91  if(!isMaxFound_) getMax();
92  return iadcMax_;
93 
94 }
95 double TAPDPulse::getDelta(int n1, int n2){
96 
97  assert (n1<_nsamples && n1>=0);
98  assert (n2<_nsamples && n2>=0);
99 
100  double delta=adc_[n1]-adc_[n2];
101  return delta;
102 }
103 double TAPDPulse::getRatio(int n1, int n2){
104 
105  assert (n1<_nsamples && n1>=0);
106  assert (n2<_nsamples && n2>=0);
107 
108  double ped=0;
109  if(isPedCalc_)ped=pedestal_;
110  else ped=adc_[0];
111 
112  double ratio=(adc_[n1]-ped)/(adc_[n2]-ped);
113  return ratio;
114 }
115 
117 
118  bool ok=true;
119  if(!isMaxFound_) getMax();
120  if(iadcMax_<=_timingcutlow || iadcMax_>=_timingcuthigh) ok=false;
121  return ok;
122 }
124 
125  bool ok=true;
126  if(!isMaxFound_) getMax();
127  if(iadcMax_<=_timingquallow || iadcMax_>=_timingqualhigh) ok=false;
128  return ok;
129 }
130 
132 
133  bool ok=true;
134  if(!isMaxFound_) getMax();
135  if ((iadcMax_-_firstsample)<_presample || (iadcMax_+_lastsample)>_nsamples-1) ok=false;
136  return ok;
137 
138 }
140 
141  bool okSamples=areFitSamplesOK();
142  bool okTiming=isTimingOK();
143  bool okPulse=arePulseRatioOK();
144 
145  bool ok=(okSamples && okTiming && okPulse);
146 
147  return ok;
148 }
150 
151  bool ok=true;
152 
153  if(!isMaxFound_) getMax();
154  if(iadcMax_<1 || iadcMax_>=_nsamples-1) return false;
155 
156  double ratioNm1=getRatio(iadcMax_-1,iadcMax_);
157  double ratioNp1=getRatio(iadcMax_+1,iadcMax_);
158  double ratioMax=TMath::Max(ratioNm1,ratioNp1);
159  double ratioMin=TMath::Min(ratioNm1,ratioNp1);
160 
161  if(ratioMax<_ratiomaxcutlow) ok=false;
162  if(ratioMin<_ratiomincutlow || ratioMin>_ratiomincuthigh) ok=false;
163 
164  return ok;
165 
166 }
168 
169  bool ok=true;
170 
171  if(!isMaxFound_) getMax();
172  if(iadcMax_<1 || iadcMax_>=_nsamples-1) return false;
173 
174  double ratioNm1=getRatio(iadcMax_-1,iadcMax_);
175  double ratioNp1=getRatio(iadcMax_+1,iadcMax_);
176  double ratioMax=TMath::Max(ratioNm1,ratioNp1);
177 
178  if(ratioMax<_ratiomaxcutlow) ok=false;
179  return ok;
180 
181 }
183 
184  bool ok=true;
185 
186  if(!isMaxFound_) getMax();
187  if(iadcMax_<1 || iadcMax_>=_nsamples-1) return false;
188 
189  double ratioNm1=getRatio(iadcMax_-1,iadcMax_);
190  double ratioNp1=getRatio(iadcMax_+1,iadcMax_);
191  double ratioMin=TMath::Min(ratioNm1,ratioNp1);
192 
193  if(ratioMin<_ratiomincutlow || ratioMin>_ratiomincuthigh) ok=false;
194  return ok;
195 }
196 
198  if(isPedCalc_) return pedestal_;
199  double ped=0;
200  for(int i=0;i<_presample;i++){
201  ped+=adc_[i];
202  }
203  ped/=double(_presample);
204  pedestal_=ped;
205  isPedCalc_=true;
206  return pedestal_;
207 }
208 
210 
211  double ped;
212  if(!isPedCalc_) ped=getPedestal();
213  else ped=pedestal_;
214 
215  double *adcNoPed= new double[10];
216  for (int i=0;i<_nsamples;i++){
217  adcNoPed[i]=adc_[i]-ped;
218  }
219  return adcNoPed;
220 }
221 
222 void TAPDPulse::setPresamples(int presample){
223  isPedCalc_=false;
224  _presample=presample;
225 }
int adc(sample_type sample)
get the ADC sample (12 bits)
bool isPulseRatioMaxOK()
Definition: TAPDPulse.cc:167
dbl * delta
Definition: mlp_gen.cc:36
int i
Definition: DBlmapReader.cc:9
double getRatio(int, int)
Definition: TAPDPulse.cc:103
bool areFitSamplesOK()
Definition: TAPDPulse.cc:131
double getDelta(int, int)
Definition: TAPDPulse.cc:95
bool setPulse(double *)
Definition: TAPDPulse.cc:64
assert(m_qm.get())
int init
Definition: HydjetWrapper.h:67
double getPedestal()
Definition: TAPDPulse.cc:197
T Min(T a, T b)
Definition: MathUtil.h:39
virtual ~TAPDPulse()
Definition: TAPDPulse.cc:29
double * getAdcWithoutPedestal()
Definition: TAPDPulse.cc:209
T Max(T a, T b)
Definition: MathUtil.h:44
int getMaxSample()
Definition: TAPDPulse.cc:90
double getMax()
Definition: TAPDPulse.cc:73
bool isTimingQualOK()
Definition: TAPDPulse.cc:123
void init(int, int, int, int, int, int, int, int, double, double, double)
Definition: TAPDPulse.cc:33
bool isPulseRatioMinOK()
Definition: TAPDPulse.cc:182
bool isTimingOK()
Definition: TAPDPulse.cc:116
void setPresamples(int)
Definition: TAPDPulse.cc:222
bool isPulseOK()
Definition: TAPDPulse.cc:139
bool arePulseRatioOK()
Definition: TAPDPulse.cc:149