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 {
35
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 // input
68 waveforms.isRequired();
69
70 // output
72 digits.registerInDataStore();
73 digits.registerRelationTo(waveforms);
75 mcInfo.registerInDataStore();
76
78 B2ERROR("samplingPhase must be positive and less than " << c_SamplingCycle);
79
80 }
81
83 {
84
85 // input: simulated waveforms
87
88 // output: time stamps for trigger input
91 mcInfo.create();
92
93 if (waveforms.getEntries() == 0) {
94 B2ERROR("No waveforms available for digitization");
95 return;
96 }
97 unsigned revo9count = waveforms[0]->getRevo9Counter();
98 int offsetSamples = waveforms[0]->getOffsetWindows() * TOPRawWaveform::c_WindowSize +
99 (revo9count % 6) * TOPRawWaveform::c_WindowSize / 3;
100
101 int bunchTimeStamp = int((revo9count + gRandom->Rndm()) * static_cast<double>(c_SamplingCycle) / 3.0);
102 mcInfo->setBunchTimeStamp(bunchTimeStamp);
103
104 int offset = bunchTimeStamp - offsetSamples / c_SamplingCycle;
105
106 for (const auto& waveform : waveforms) {
107 const auto& data = waveform.getWaveform();
108 int currentThr = m_threshold;
109 bool lastState = false;
110 int gate = 0;
111 TOPTriggerDigit* digit = 0;
112 for (int i = 0; i < (int) data.size(); i++) {
113 gate--;
114 if (data[i] > currentThr) {
115 currentThr = m_threshold - m_hysteresis;
116 if (!lastState) gate = m_gateWidth;
117 lastState = true;
118 } else {
119 currentThr = m_threshold;
120 lastState = false;
121 }
122 if (i % c_SamplingCycle == m_samplingPhase and gate > 0) {
123 if (i / c_SamplingCycle == 0) continue; // first time stamp is not correct
124 if (!digit) {
125 digit = digits.appendNew(waveform.getModuleID(),
126 waveform.getChannel(),
127 waveform.getScrodID());
128 digit->addRelationTo(&waveform);
129 }
130 int timeStamp = i / c_SamplingCycle + offset;
131 while (timeStamp < 0) {timeStamp += c_Frame9Period;};
132 timeStamp = timeStamp % c_Frame9Period;
133 digit->appendTimeStamp(timeStamp);
134 }
135 }
136 }
137
138 }
139
141} // end Belle2 namespace
142
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
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]
@ c_SamplingCycle
timestamp sampling period [samples]
@ c_Frame9Period
number of sampling cycles per frame9 marker
int m_gateWidth
width of discriminator gate [samples]
int m_samplingPhase
sampling phase [samples]
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
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
Abstract base class for different kinds of events.
STL namespace.