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