LDMX Software
CompositePulse.cxx
1#include "Recon/Event/CompositePulse.h"
2
4
5namespace ldmx {
6void CompositePulse::addOrMerge(const std::pair<double, double>& hit,
7 double hit_merge_ns) {
8 auto imerge{hits_.begin()};
9 for (; imerge != hits_.end(); imerge++)
10 if (fabs(imerge->second - hit.second) < hit_merge_ns) break;
11 if (imerge == hits_.end()) { // didn't find a match, add to the list
12 hits_.push_back(hit);
13 } else { // merge hits_, shifting time to average
14 imerge->second = (imerge->second * imerge->first + hit.first * hit.second);
15 imerge->first += hit.first;
16 imerge->second /= imerge->first;
17 }
18}
19
20double CompositePulse::findCrossing(double low, double high, double level,
21 double prec) {
22 // use midpoint algorithm, assumes low is below and high is above
23 double step = high - low;
24 double pt = (high + low) / 2;
25 while (step > prec) {
26 double vmid = at(pt);
27 if (vmid < level) {
28 low = pt;
29 } else {
30 high = pt;
31 }
32 step = high - low;
33 pt = (high + low) / 2;
34 }
35 return pt;
36}
37
38} // namespace ldmx
CompositePulse.
std::vector< std::pair< double, double > > hits_
pulses entering the chip
double at(double time) const
Measure the voltage at the input time.
void addOrMerge(const std::pair< double, double > &hit, double hit_merge_ns)
Put another hit into this composite pulse.
double findCrossing(double low, double high, double level, double prec=0.01)
Find the time at which we cross the input level.