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
73
75 {
76
77 const auto* geo = TOPGeometryPar::Instance()->getGeometry();
78 const auto& tdc = geo->getNominalTDC();
79 int sampleDivisions = 0x1 << tdc.getSubBits();
80
82 int initSize = rawDigits.getEntries();
83
84 for (int i = 0; i < initSize; i++) {
85 auto& rawDigit = *rawDigits[i];
86 const auto* waveform = rawDigit.getRelated<TOPRawWaveform>();
87 if (!waveform) continue;
88 if (m_setIntegral) {
89 auto integral = waveform->getIntegral(rawDigit.getSampleRise(),
90 rawDigit.getSamplePeak(),
91 rawDigit.getSampleFall());
92 rawDigit.setIntegral(integral);
93 }
95 const auto& features = waveform->getFeatureExtractionData();
96 int sampleRise = rawDigit.getSampleRise();
97 int sampleFall = rawDigit.getSampleFall() + 1;
98 for (const auto& feature : features) {
99
100 // skip it, if hit already in rawDigits
101 int sRise = feature.sampleRise;
102 if (sRise >= sampleRise and sRise <= sampleFall) continue;
103 int sFall = feature.sampleFall + 1;
104 if (sFall >= sampleRise and sFall <= sampleFall) continue;
105
106 // if not, append it
107 auto* newDigit = rawDigits.appendNew(rawDigit);
108 newDigit->setOfflineFlag();
109 newDigit->setSampleRise(feature.sampleRise);
110 newDigit->setDeltaSamplePeak(feature.samplePeak - feature.sampleRise);
111 newDigit->setDeltaSampleFall(feature.sampleFall - feature.sampleRise);
112 newDigit->setValueRise0(feature.vRise0);
113 newDigit->setValueRise1(feature.vRise1);
114 newDigit->setValueFall0(feature.vFall0);
115 newDigit->setValueFall1(feature.vFall1);
116 newDigit->setValuePeak(feature.vPeak);
117 newDigit->setIntegral(feature.integral);
118 double rawTime = newDigit->getCFDLeadingTime();
119 int tfine = int(rawTime * sampleDivisions) % sampleDivisions;
120 if (tfine < 0) tfine += sampleDivisions;
121 newDigit->setTFine(tfine);
122 newDigit->addRelationTo(waveform);
123 }
124 }
125
126 B2DEBUG(20, "TOPWaveformFeatureExtractor: appended " << rawDigits.getEntries() - initSize
127 << " raw digits to initial " << initSize);
128
129 }
130
132} // end Belle2 namespace
133
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.
Abstract base class for different kinds of events.
STL namespace.