CMS 3D CMS Logo

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