Belle II Software development
TOPWaveformFeatureExtractorModule.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 <top/modules/TOPWaveformFeatureExtractor/TOPWaveformFeatureExtractorModule.h>
11
12// framework - DataStore
13#include <framework/datastore/StoreArray.h>
14
15// framework aux
16#include <framework/logging/Logger.h>
17
18// Dataobject classes
19#include <top/dataobjects/TOPRawDigit.h>
20#include <top/dataobjects/TOPRawWaveform.h>
21
22#include <top/geometry/TOPGeometryPar.h>
23
24using namespace std;
25
26namespace Belle2 {
31
32 using namespace TOP;
33
34 //-----------------------------------------------------------------
36 //-----------------------------------------------------------------
37
38 REG_MODULE(TOPWaveformFeatureExtractor);
39
40 //-----------------------------------------------------------------
41 // Implementation
42 //-----------------------------------------------------------------
43
45
46 {
47 // set module description (e.g. insert text)
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.");
52
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);
63
64 }
65
69
77
81
83 {
84
85 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
86 const auto& tdc = geo->getNominalTDC();
87 int sampleDivisions = 0x1 << tdc.getSubBits();
88
90 int initSize = rawDigits.getEntries();
91
92 for (int i = 0; i < initSize; i++) {
93 auto& rawDigit = *rawDigits[i];
94 const auto* waveform = rawDigit.getRelated<TOPRawWaveform>();
95 if (!waveform) continue;
96 if (m_setIntegral) {
97 auto integral = waveform->getIntegral(rawDigit.getSampleRise(),
98 rawDigit.getSamplePeak(),
99 rawDigit.getSampleFall());
100 rawDigit.setIntegral(integral);
101 }
103 const auto& features = waveform->getFeatureExtractionData();
104 int sampleRise = rawDigit.getSampleRise();
105 int sampleFall = rawDigit.getSampleFall() + 1;
106 for (const auto& feature : features) {
107
108 // skip it, if hit already in rawDigits
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;
113
114 // if not, append it
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; // TODO: <0 ?
128 newDigit->setTFine(tfine);
129 newDigit->addRelationTo(waveform);
130 }
131 }
132
133 int finalSize = rawDigits.getEntries();
134 B2DEBUG(20, "TOPWaveformFeatureExtractor: appended " << finalSize - initSize
135 << " raw digits to initial " << initSize);
136
137 }
138
139
143
147
148
150} // end Belle2 namespace
151
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Definition StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition StoreArray.h:216
const TOPNominalTDC & getNominalTDC() const
Returns nominal time-to-digit conversion parameters.
unsigned getSubBits() const
Returns number of bits per sample.
Class to store raw data waveforms.
int m_hysteresis
pulse height threshold hysteresis [ADC counts]
bool m_setIntegral
calculate and set integral for FW-extracted hits
std::string m_inputRawDigitsName
name of TOPRawDigit store array
int m_thresholdCount
minimal number of samples above threshold
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using basf2 units.
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
int featureExtraction(int threshold, int hysteresis, int thresholdCount) const
Do feature extraction.
virtual void initialize() override
Initialize the Module.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
Abstract base class for different kinds of events.
STL namespace.