9 #include <top/modules/TOPDigitizer/TOPTriggerDigitizerModule.h>
12 #include <top/dataobjects/TOPRawWaveform.h>
13 #include <top/dataobjects/TOPTriggerDigit.h>
14 #include <top/dataobjects/TOPTriggerMCInfo.h>
17 #include <framework/datastore/StoreArray.h>
18 #include <framework/datastore/StoreObjPtr.h>
21 #include <framework/logging/Logger.h>
49 setDescription(
"Digitizer that provides time stamps for TOP trigger");
50 setPropertyFlags(c_ParallelProcessingCertified);
53 addParam(
"threshold", m_threshold,
54 "pulse height threshold [ADC counts]", 27);
55 addParam(
"hysteresis", m_hysteresis,
56 "pulse height threshold hysteresis [ADC counts]", 10);
57 addParam(
"gateWidth", m_gateWidth,
58 "width of discriminator gate [samples]", 8);
59 addParam(
"samplingPhase", m_samplingPhase,
60 "sampling phase [samples]", 7);
63 TOPTriggerDigitizerModule::~TOPTriggerDigitizerModule()
67 void TOPTriggerDigitizerModule::initialize()
75 digits.registerInDataStore();
76 digits.registerRelationTo(waveforms);
80 if (m_samplingPhase < 0 or m_samplingPhase >= c_SamplingCycle)
81 B2ERROR(
"samplingPhase must be positive and less than " << c_SamplingCycle);
85 void TOPTriggerDigitizerModule::beginRun()
89 void TOPTriggerDigitizerModule::event()
101 B2ERROR(
"No waveforms available for digitization");
104 unsigned revo9count = waveforms[0]->getRevo9Counter();
105 int offsetSamples = waveforms[0]->getOffsetWindows() * TOPRawWaveform::c_WindowSize +
106 (revo9count % 6) * TOPRawWaveform::c_WindowSize / 3;
108 int bunchTimeStamp = int((revo9count + gRandom->Rndm()) * c_SamplingCycle / 3.0);
109 mcInfo->setBunchTimeStamp(bunchTimeStamp);
111 int offset = bunchTimeStamp - offsetSamples / c_SamplingCycle;
113 for (
const auto& waveform : waveforms) {
114 const auto& data = waveform.getWaveform();
115 int currentThr = m_threshold;
116 bool lastState =
false;
119 for (
int i = 0; i < (int) data.size(); i++) {
121 if (data[i] > currentThr) {
122 currentThr = m_threshold - m_hysteresis;
123 if (!lastState) gate = m_gateWidth;
126 currentThr = m_threshold;
129 if (i % c_SamplingCycle == m_samplingPhase and gate > 0) {
130 if (i / c_SamplingCycle == 0)
continue;
132 digit = digits.appendNew(waveform.getModuleID(),
133 waveform.getChannel(),
134 waveform.getScrodID());
137 int timeStamp = i / c_SamplingCycle + offset;
138 while (timeStamp < 0) {timeStamp += c_Frame9Period;};
139 timeStamp = timeStamp % c_Frame9Period;
148 void TOPTriggerDigitizerModule::endRun()
153 void TOPTriggerDigitizerModule::terminate()
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
bool create(bool replace=false)
Create a default object in the data store.
Accessor to arrays stored in the data store.
int getEntries() const
Get the number of objects in the array.
Type-safe access to single objects in the data store.
Class to store trigger time stamps.
void appendTimeStamp(short timeStamp)
Append time stamp.
Digitizer that provides time stamps for TOP trigger.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.