Project
Loading...
Searching...
No Matches
Digitizer.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef DETECTORS_ZDC_DIGITIZER_H_
13#define DETECTORS_ZDC_DIGITIZER_H_
14
15#include "DataFormatsZDC/Hit.h" // for the hit
23#include <vector>
24#include <array>
25#include <deque>
26#include <bitset>
27
28namespace o2
29{
30namespace zdc
31{
32
33class SimCondition;
34
36{
37 using ChannelBCDataF = std::array<float, NTimeBinsPerBC>;
38
39 public:
41 std::array<ChannelBCDataF, NChannels> data = {};
42 std::array<ChannelBCDataF, NDigiChannels> digi = {};
43 std::vector<o2::zdc::MCLabel> labels;
44 bool digitized = false;
45 bool triggerChecked = false;
46 uint32_t trigChanMask = 0; // mask of triggered channels
47 uint8_t extTrig = 0; // external trigger
48 static constexpr uint32_t AllChannelsMask = 0x80000000;
49
50 BCCache();
51
52 void clear()
53 {
54 digitized = false;
55 triggerChecked = false;
56 trigChanMask = 0;
57 for (auto& chan : data) {
58 chan.fill(0.);
59 }
60 }
61
67 void print() const;
68 };
69
71 int id = 0;
72 uint32_t readChannels = 0; // channels to read
73 uint32_t trigChannels = 0; // trigger channels
74 ModuleConfAux() = default;
75 ModuleConfAux(const Module& md);
76 };
77
78 void init();
79
80 // set event time
81 void setEventID(int eventID) { mEventID = eventID; }
82 void setSrcID(int sID) { mSrcID = sID; }
84 void setTimeStamp(long t) { mTimeStamp = t; }
85
87 {
88 // RS TODO: this method should be called e.g. from the steering DPL device in the triggered mode
89 if (mIRExternalTrigger.empty() || mIRExternalTrigger.back() != ir) {
90 mIRExternalTrigger.push_back(ir); // add new trigger if there was no already trigger in the same BC
91 }
92 }
93
94 void process(const std::vector<o2::zdc::Hit>& hits,
95 std::vector<o2::zdc::BCData>& digitsBC,
96 std::vector<o2::zdc::ChannelData>& digitsCh,
98
99 void flush(std::vector<o2::zdc::BCData>& digitsBC,
100 std::vector<o2::zdc::ChannelData>& digitsCh,
102
103 const SimCondition* getSimCondition() const { return mSimCondition; }
104 const ModuleConfig* getModuleConfig() const { return mModuleConfig; }
105 void setSimCondition(const SimCondition* cfg) { mSimCondition = cfg; }
106 void setModuleConfig(const ModuleConfig* cfg) { mModuleConfig = cfg; }
107
108 void setContinuous(bool v = true) { mIsContinuous = v; }
109 bool isContinuous() const { return mIsContinuous; }
111 void findEmptyBunches(const std::bitset<o2::constants::lhc::LHCMaxBunches>& bunchPattern);
112 int getNEmptyBunches() const { return mNEmptyBCs; }
113 void assignTriggerBits(uint32_t ibc, std::vector<BCData>& bcData); // Assign trigger bits for nearby bunch crossings
114 void Finalize(std::vector<BCData>& bcData, std::vector<o2::zdc::OrbitData>& pData); // Mask trigger bits for current bunch crossing
115 void setMaskTriggerBits(bool v = true) { mMaskTriggerBits = v; }
116 bool getMaskTriggerBits() { return mMaskTriggerBits; }
117 void setSkipMCLabels(bool v = true) { mSkipMCLabels = v; }
118 bool getSkipMCLabels() { return mSkipMCLabels; }
119
120 private:
121 static constexpr int BCCacheMin = -1, BCCacheMax = 5, NBC2Cache = 1 + BCCacheMax - BCCacheMin;
122
123 std::bitset<NChannels> chanPattern(uint32_t v) const
124 {
125 return std::bitset<NChannels>(v);
126 }
127 void phe2Sample(int nphe, int parID, double timeHit, std::array<o2::InteractionRecord, NBC2Cache> const& cachedIR, int nCachedIR, int channel);
128 BCCache& getCreateBCCache(const o2::InteractionRecord& ir);
129 BCCache* getBCCache(const o2::InteractionRecord& ir);
130 void setTriggerMask();
131 void setReadoutMask();
132 void generatePedestal();
133 void digitizeBC(BCCache& bc);
134 bool triggerBC(int ibc);
135 void storeBC(const BCCache& bc, uint32_t chan2Store,
136 std::vector<o2::zdc::BCData>& digitsBC, std::vector<o2::zdc::ChannelData>& digitsCh,
138
139 bool mIsContinuous = true; // continuous (self-triggered) or externally-triggered readout
140 int mEventID = 0;
141 int mSrcID = 0;
142 long mTimeStamp = 0; // TF (run) timestamp
144 std::deque<o2::InteractionRecord> mIRExternalTrigger; // IRs of externally provided triggered (at the moment MC sampled interactions)
145
146 std::deque<BCCache> mCache; // cached BCs data
147 std::array<std::vector<int16_t>, NChannels> mTrigChannelsData; // buffer for fast access to triggered channels data
148 int mTrigBinMin = 0xffff; // prefetched min and max
149 int mTrigBinMax = -0xffff; // bins to be checked for trigger
150 int mNBCAHead = 0; // when storing triggered BC, store also mNBCAHead BCs
151 uint32_t mTriggerMask = 0; // Trigger mask from ModuleConfig
152 uint32_t mReadoutMask = 0; // Readout mask from ModuleConfig
153 int32_t mNEmptyBCs = -1; // Number of clean empty bunches for pedestal evaluation
154 float mPedFactor = 1; // Pedestal scaling factor in digitization
155 bool mMaskTriggerBits = true; // Mask trigger bits with readout mask
156 bool mSkipMCLabels = false; // Skip MC labels in output
157
158 const SimCondition* mSimCondition = nullptr;
159 const ModuleConfig* mModuleConfig = nullptr;
160 std::vector<TriggerChannelConfig> mTriggerConfig;
161 uint32_t mTriggerableChanMask = 0;
162 std::vector<ModuleConfAux> mModConfAux;
163 std::vector<BCCache*> mFastCache;
164 std::vector<uint32_t> mStoreChanMask;
165 BCCache mDummyBC;
166 std::array<float, NChannels> mPedestalBLFluct;
167
168 // helper for inspection of bins in preceding or following BC: if we are at the cached BC = I and we need to
169 // inspect the bin = ib, we have to look in the binInSiftedBC of BC I-binHelper(ib,binInSiftedBC);
170 static constexpr int binHelper(int ib, int& binInSiftedBC)
171 {
172 if (ib < 0) {
173 binInSiftedBC = NTimeBinsPerBC - 1 + (1 + ib) % NTimeBinsPerBC;
174 return (ib - (NTimeBinsPerBC - 1)) / NTimeBinsPerBC;
175 } else {
176 binInSiftedBC = ib % NTimeBinsPerBC;
177 return ib / NTimeBinsPerBC;
178 }
179 }
180 ClassDefNV(Digitizer, 1);
181};
182} // namespace zdc
183} // namespace o2
184
185#endif /* DETECTORS_ZDC_DIGITIZER_H_ */
Class to describe fired triggered and/or stored channels for the BC and to refer to channel data.
Definition of the ZDC Hit class.
uint64_t bc
Definition RawEventData.h:5
Definition of a container to keep Monte Carlo truth external to simulation objects.
Class to describe pedestal data accumulated over the orbit.
Container class to store NTimeBinsPerBC ADC values of single ZDC channel.
A container to hold and manage MC truth information/labels.
void updatePedestalReference(OrbitData &pdata)
void setContinuous(bool v=true)
Definition Digitizer.h:108
void flush(std::vector< o2::zdc::BCData > &digitsBC, std::vector< o2::zdc::ChannelData > &digitsCh, o2::dataformats::MCTruthContainer< o2::zdc::MCLabel > &labels)
void setEventID(int eventID)
Definition Digitizer.h:81
void addTriggeredBC(const o2::InteractionRecord &ir)
Definition Digitizer.h:86
void setInteractionRecord(const o2::InteractionTimeRecord &ir)
Definition Digitizer.h:83
void setSkipMCLabels(bool v=true)
Definition Digitizer.h:117
void setSrcID(int sID)
Definition Digitizer.h:82
const SimCondition * getSimCondition() const
Definition Digitizer.h:103
bool getMaskTriggerBits()
Definition Digitizer.h:116
void setTimeStamp(long t)
Definition Digitizer.h:84
void Finalize(std::vector< BCData > &bcData, std::vector< o2::zdc::OrbitData > &pData)
void assignTriggerBits(uint32_t ibc, std::vector< BCData > &bcData)
void setMaskTriggerBits(bool v=true)
Definition Digitizer.h:115
void setModuleConfig(const ModuleConfig *cfg)
Definition Digitizer.h:106
void setSimCondition(const SimCondition *cfg)
Definition Digitizer.h:105
int getNEmptyBunches() const
Definition Digitizer.h:112
const ModuleConfig * getModuleConfig() const
Definition Digitizer.h:104
void findEmptyBunches(const std::bitset< o2::constants::lhc::LHCMaxBunches > &bunchPattern)
bool isContinuous() const
Definition Digitizer.h:109
const GLdouble * v
Definition glcorearb.h:832
GLboolean * data
Definition glcorearb.h:298
struct o2::upgrades_utils::@463 zdc
structure to keep FT0 information
constexpr int NTimeBinsPerBC
Definition Constants.h:53
constexpr int NChannels
Definition Constants.h:65
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
InteractionRecord & operator=(const InteractionRecord &src)=default
std::vector< o2::zdc::MCLabel > labels
Definition Digitizer.h:43
static constexpr uint32_t AllChannelsMask
Definition Digitizer.h:48
BCCache & operator=(const o2::InteractionRecord &ir)
Definition Digitizer.h:62
std::array< ChannelBCDataF, NChannels > data
Definition Digitizer.h:41
std::array< ChannelBCDataF, NDigiChannels > digi
Definition Digitizer.h:42
o2::InteractionRecord ir(0, 0)