Belle II Software development
TOPTriggerDigitizerModule.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/TOPDigitizer/TOPTriggerDigitizerModule.h>
11
12// TOP headers.
13#include <top/dataobjects/TOPRawWaveform.h>
14#include <top/dataobjects/TOPTriggerDigit.h>
15#include <top/dataobjects/TOPTriggerMCInfo.h>
16
17// framework - DataStore
18#include <framework/datastore/StoreArray.h>
19#include <framework/datastore/StoreObjPtr.h>
20
21// framework aux
22#include <framework/logging/Logger.h>
23
24// ROOT
25#include <TRandom.h>
26
27
28using namespace std;
29
30namespace Belle2 {
36 //-----------------------------------------------------------------
38 //-----------------------------------------------------------------
39
40 REG_MODULE(TOPTriggerDigitizer);
41
42
43 //-----------------------------------------------------------------
44 // Implementation
45 //-----------------------------------------------------------------
46
48 {
49 // Set description()
50 setDescription("Digitizer that provides time stamps for TOP trigger");
52
53 // Add parameters
54 addParam("threshold", m_threshold,
55 "pulse height threshold [ADC counts]", 27);
56 addParam("hysteresis", m_hysteresis,
57 "pulse height threshold hysteresis [ADC counts]", 10);
58 addParam("gateWidth", m_gateWidth,
59 "width of discriminator gate [samples]", 8);
60 addParam("samplingPhase", m_samplingPhase,
61 "sampling phase [samples]", 7);
62 }
63
65 {
66 }
67
69 {
70 // input
72 waveforms.isRequired();
73
74 // output
76 digits.registerInDataStore();
77 digits.registerRelationTo(waveforms);
79 mcInfo.registerInDataStore();
80
81 if (m_samplingPhase < 0 or m_samplingPhase >= c_SamplingCycle)
82 B2ERROR("samplingPhase must be positive and less than " << c_SamplingCycle);
83
84 }
85
87 {
88 }
89
91 {
92
93 // input: simulated waveforms
95
96 // output: time stamps for trigger input
99 mcInfo.create();
100
101 if (waveforms.getEntries() == 0) {
102 B2ERROR("No waveforms available for digitization");
103 return;
104 }
105 unsigned revo9count = waveforms[0]->getRevo9Counter();
106 int offsetSamples = waveforms[0]->getOffsetWindows() * TOPRawWaveform::c_WindowSize +
107 (revo9count % 6) * TOPRawWaveform::c_WindowSize / 3;
108
109 int bunchTimeStamp = int((revo9count + gRandom->Rndm()) * static_cast<double>(c_SamplingCycle) / 3.0);
110 mcInfo->setBunchTimeStamp(bunchTimeStamp);
111
112 int offset = bunchTimeStamp - offsetSamples / c_SamplingCycle;
113
114 for (const auto& waveform : waveforms) {
115 const auto& data = waveform.getWaveform();
116 int currentThr = m_threshold;
117 bool lastState = false;
118 int gate = 0;
119 TOPTriggerDigit* digit = 0;
120 for (int i = 0; i < (int) data.size(); i++) {
121 gate--;
122 if (data[i] > currentThr) {
123 currentThr = m_threshold - m_hysteresis;
124 if (!lastState) gate = m_gateWidth;
125 lastState = true;
126 } else {
127 currentThr = m_threshold;
128 lastState = false;
129 }
130 if (i % c_SamplingCycle == m_samplingPhase and gate > 0) {
131 if (i / c_SamplingCycle == 0) continue; // first time stamp is not correct
132 if (!digit) {
133 digit = digits.appendNew(waveform.getModuleID(),
134 waveform.getChannel(),
135 waveform.getScrodID());
136 digit->addRelationTo(&waveform);
137 }
138 int timeStamp = i / c_SamplingCycle + offset;
139 while (timeStamp < 0) {timeStamp += c_Frame9Period;};
140 timeStamp = timeStamp % c_Frame9Period;
141 digit->appendTimeStamp(timeStamp);
142 }
143 }
144 }
145
146 }
147
148
150 {
151
152 }
153
155 {
156
157 }
158
159
161} // end Belle2 namespace
162
Base class for Modules.
Definition: Module.h:72
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
@ 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
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.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
@ c_WindowSize
number of samples per ASIC window
Class to store trigger time stamps.
void appendTimeStamp(short timeStamp)
Append time stamp.
int m_hysteresis
pulse height threshold hysteresis [ADC counts]
int m_threshold
pulse height threshold [ADC counts]
int m_gateWidth
width of discriminator gate [samples]
int m_samplingPhase
sampling phase [samples]
@ c_SamplingCycle
timestamp sampling period [samples]
@ c_Frame9Period
number of sampling cycles per frame9 marker
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
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.