Belle II Software development
ScintillatorFirmware.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9/* Own header. */
10#include <klm/simulation/ScintillatorFirmware.h>
11
12using namespace Belle2;
13
15 m_nPoints(nPoints)
16{
17}
18
20{
21}
22
23enum KLM::ScintillatorFirmwareFitStatus KLM::ScintillatorFirmware::fit(
24 const int* amp, int threshold, KLMScintillatorFirmwareFitResult* fitData)
25{
26 /*
27 * Upper bound of the background region: number of points before threshold
28 * crossing.
29 */
30 const int nPointsSigBg = 10;
31 double bg;
32 float sigAmp;
33 int i, ithr, ibg, sum, bgSum, min;
34 sum = 0;
35 bgSum = 0;
36 /* Get threshold crossing time, sum of ADC outputs and minimal output. */
37 ithr = -1;
38 min = 0; /* To avoid warning, re-initialized at the first cycle. */
39 for (i = 0; i < m_nPoints; i++) {
40 if (amp[i] < threshold) {
41 if (ithr < 0)
42 ithr = i;
43 }
44 sum = sum + amp[i];
45 if (i == 0)
46 min = amp[i];
47 else if (amp[i] < min)
48 min = amp[i];
49 }
50 /* No signal. */
51 if (ithr < 0)
52 return c_ScintillatorFirmwareNoSignal;
53 /* Region for background (pedestal) level. */
54 ibg = std::max(ithr - nPointsSigBg, 0);
55 /* Cannot determine background level, no data before signal. */
56 if (ibg == 0)
57 return c_ScintillatorFirmwareNoSignal;
58 /* Determine background (pedestal) level. */
59 for (i = 0; i < ibg; i++)
60 bgSum = bgSum + amp[i];
61 bg = float(bgSum) / i;
62 sigAmp = bg * m_nPoints - sum;
63 if (sigAmp < 0)
64 sigAmp = 0;
65 fitData->setStartTime(ithr);
66 fitData->setBackgroundAmplitude(bg);
67 fitData->setAmplitude(sigAmp);
68 fitData->setMinimalAmplitude(min);
69 return c_ScintillatorFirmwareSuccessfulFit;
70}
71
ScintillatorFirmware(int nPoints)
Constructor.
enum ScintillatorFirmwareFitStatus fit(const int *amp, int threshold, KLMScintillatorFirmwareFitResult *fitData)
FPGA fitter.
Abstract base class for different kinds of events.