10 #include <top/modules/TOPWaveformFeatureExtractor/TOPWaveformFeatureExtractorModule.h>
13 #include <framework/datastore/StoreArray.h>
16 #include <framework/logging/Logger.h>
19 #include <top/dataobjects/TOPRawDigit.h>
20 #include <top/dataobjects/TOPRawWaveform.h>
22 #include <top/geometry/TOPGeometryPar.h>
48 setDescription(
"Module adds raw digits that are found in waveforms "
49 "but not already present in TOPRawDigits. "
50 "Only waveforms related to TOPRawDigits are used.");
51 setPropertyFlags(c_ParallelProcessingCertified);
53 addParam(
"inputRawDigitsName", m_inputRawDigitsName,
54 "name of TOPRawDigit store array",
string(
""));
55 addParam(
"threshold", m_threshold,
56 "pulse height threshold [ADC counts]", 40);
57 addParam(
"hysteresis", m_hysteresis,
58 "threshold hysteresis [ADC counts]", 10);
59 addParam(
"thresholdCount", m_thresholdCount,
60 "minimal number of samples above threshold", 3);
61 addParam(
"setIntegral", m_setIntegral,
62 "calculate and set integral for online-extracted hits",
true);
66 TOPWaveformFeatureExtractorModule::~TOPWaveformFeatureExtractorModule()
70 void TOPWaveformFeatureExtractorModule::initialize()
78 void TOPWaveformFeatureExtractorModule::beginRun()
82 void TOPWaveformFeatureExtractorModule::event()
85 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
86 const auto& tdc = geo->getNominalTDC();
87 int sampleDivisions = 0x1 << tdc.getSubBits();
92 for (
int i = 0; i < initSize; i++) {
93 auto& rawDigit = *rawDigits[i];
95 if (!waveform)
continue;
97 auto integral = waveform->
getIntegral(rawDigit.getSampleRise(),
98 rawDigit.getSamplePeak(),
99 rawDigit.getSampleFall());
100 rawDigit.setIntegral(integral);
102 waveform->featureExtraction(m_threshold, m_hysteresis, m_thresholdCount);
103 const auto& features = waveform->getFeatureExtractionData();
104 int sampleRise = rawDigit.getSampleRise();
105 int sampleFall = rawDigit.getSampleFall() + 1;
106 for (
const auto& feature : features) {
109 int sRise = feature.sampleRise;
110 if (sRise >= sampleRise and sRise <= sampleFall)
continue;
111 int sFall = feature.sampleFall + 1;
112 if (sFall >= sampleRise and sFall <= sampleFall)
continue;
115 auto* newDigit = rawDigits.
appendNew(rawDigit);
116 newDigit->setOfflineFlag();
117 newDigit->setSampleRise(feature.sampleRise);
118 newDigit->setDeltaSamplePeak(feature.samplePeak - feature.sampleRise);
119 newDigit->setDeltaSampleFall(feature.sampleFall - feature.sampleRise);
120 newDigit->setValueRise0(feature.vRise0);
121 newDigit->setValueRise1(feature.vRise1);
122 newDigit->setValueFall0(feature.vFall0);
123 newDigit->setValueFall1(feature.vFall1);
124 newDigit->setValuePeak(feature.vPeak);
125 newDigit->setIntegral(feature.integral);
126 double rawTime = newDigit->getCFDLeadingTime();
127 unsigned tfine = int(rawTime * sampleDivisions) % sampleDivisions;
128 newDigit->setTFine(tfine);
129 newDigit->addRelationTo(waveform);
134 B2DEBUG(20,
"TOPWaveformFeatureExtractor: appended " << finalSize - initSize
135 <<
" raw digits to initial " << initSize);
140 void TOPWaveformFeatureExtractorModule::endRun()
144 void TOPWaveformFeatureExtractorModule::terminate()
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
T * appendNew()
Construct a new T object at the end of the array.
int getEntries() const
Get the number of objects in the array.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
int getIntegral(int sampleRise, int samplePeak, int sampleFall) const
Returns integral of a peak.
Abstract base class for different kinds of events.