|
| 1 | +// Copyright 2019-2025 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 ALICEO2_FD3_DIGITIZER_H |
| 13 | +#define ALICEO2_FD3_DIGITIZER_H |
| 14 | + |
| 15 | +#include "CommonDataFormat/InteractionRecord.h" |
| 16 | +#include "DataFormatsFD3/Digit.h" |
| 17 | +#include "DataFormatsFD3/ChannelData.h" |
| 18 | +#include "DataFormatsFD3/MCLabel.h" |
| 19 | +#include "FD3Simulation/Detector.h" |
| 20 | +#include "FD3Base/Constants.h" |
| 21 | +#include "SimulationDataFormat/MCTruthContainer.h" |
| 22 | +#include "FD3Simulation/DigitizationConstants.h" |
| 23 | +#include <array> |
| 24 | +#include <vector> |
| 25 | + |
| 26 | +namespace o2 |
| 27 | +{ |
| 28 | +namespace fd3 |
| 29 | +{ |
| 30 | +class Digitizer |
| 31 | +{ |
| 32 | + private: |
| 33 | + using DP = DigitizationConstants; |
| 34 | + |
| 35 | + public: |
| 36 | + Digitizer() |
| 37 | + : mTimeStamp(0), mIntRecord(), mEventId(-1), mSrcId(-1), mMCLabels(), mCache(), mPmtChargeVsTime(), mNBins(), mNTimeBinsPerBC(), mPmtResponseGlobalRings(), mPmtResponseTemp(), mLastBCCache(), mCfdStartIndex() |
| 38 | + { |
| 39 | + } |
| 40 | + |
| 41 | + /// Destructor |
| 42 | + ~Digitizer() = default; |
| 43 | + |
| 44 | + Digitizer(const Digitizer&) = delete; |
| 45 | + Digitizer& operator=(const Digitizer&) = delete; |
| 46 | + |
| 47 | + void clear(); |
| 48 | + void init(); |
| 49 | + |
| 50 | + void setTimeStamp(long t) { mTimeStamp = t; } |
| 51 | + void setEventId(Int_t id) { mEventId = id; } |
| 52 | + void setSrcId(Int_t id) { mSrcId = id; } |
| 53 | + void setInteractionRecord(const InteractionTimeRecord& ir) { mIntRecord = ir; } |
| 54 | + |
| 55 | + void process(const std::vector<o2::fd3::Hit>& hits, std::vector<o2::fd3::Digit>& digitsBC, |
| 56 | + std::vector<o2::fd3::ChannelData>& digitsCh, std::vector<o2::fd3::DetTrigInput>& digitsTrig, |
| 57 | + o2::dataformats::MCTruthContainer<o2::fd3::MCLabel>& labels); |
| 58 | + |
| 59 | + void flush(std::vector<o2::fd3::Digit>& digitsBC, |
| 60 | + std::vector<o2::fd3::ChannelData>& digitsCh, |
| 61 | + std::vector<o2::fd3::DetTrigInput>& digitsTrig, |
| 62 | + o2::dataformats::MCTruthContainer<o2::fd3::MCLabel>& labels); |
| 63 | + |
| 64 | + const InteractionRecord& getInteractionRecord() const { return mIntRecord; } |
| 65 | + InteractionRecord& getInteractionRecord(InteractionRecord& src) { return mIntRecord; } |
| 66 | + uint32_t getOrbit() const { return mIntRecord.orbit; } |
| 67 | + uint16_t getBC() const { return mIntRecord.bc; } |
| 68 | + |
| 69 | + using ChannelDigitF = std::vector<float>; |
| 70 | + |
| 71 | + struct BCCache : public o2::InteractionRecord { |
| 72 | + std::vector<o2::fd3::MCLabel> labels; |
| 73 | + std::array<ChannelDigitF, DP::NCELLSTOT> mPmtChargeVsTime = {}; |
| 74 | + |
| 75 | + void clear() |
| 76 | + { |
| 77 | + for (auto& channel : mPmtChargeVsTime) { |
| 78 | + std::fill(std::begin(channel), std::end(channel), 0.); |
| 79 | + } |
| 80 | + labels.clear(); |
| 81 | + } |
| 82 | + |
| 83 | + BCCache& operator=(const o2::InteractionRecord& ir) |
| 84 | + { |
| 85 | + o2::InteractionRecord::operator=(ir); |
| 86 | + return *this; |
| 87 | + } |
| 88 | + void print() const; |
| 89 | + }; |
| 90 | + |
| 91 | + private: |
| 92 | + static constexpr int BCCacheMin = 0, BCCacheMax = 7, NBC2Cache = 1 + BCCacheMax - BCCacheMin; |
| 93 | + /// Create signal pulse based on MC hit |
| 94 | + /// \param mipFraction Fraction of the MIP energy deposited in the cell |
| 95 | + /// \param parID Particle ID |
| 96 | + /// \param hitTime Time of the hit |
| 97 | + /// \param hitR Length to IP from the position of the hit |
| 98 | + /// \param cachedIR Cached interaction records |
| 99 | + /// \param nCachedIR Number of cached interaction records |
| 100 | + /// \param detID Detector cell ID |
| 101 | + void createPulse(float mipFraction, int parID, const double hitTime, const float hitR, |
| 102 | + std::array<o2::InteractionRecord, NBC2Cache> const& cachedIR, int nCachedIR, const int detID); |
| 103 | + |
| 104 | + long mTimeStamp; // TF (run) timestamp |
| 105 | + InteractionTimeRecord mIntRecord; // Interaction record (orbit, bc) -> InteractionTimeRecord |
| 106 | + Int_t mEventId; // ID of the current event |
| 107 | + Int_t mSrcId; // signal, background or QED |
| 108 | + std::deque<fd3::MCLabel> mMCLabels; |
| 109 | + std::deque<BCCache> mCache; |
| 110 | + |
| 111 | + BCCache& setBCCache(const o2::InteractionRecord& ir); |
| 112 | + BCCache* getBCCache(const o2::InteractionRecord& ir); |
| 113 | + |
| 114 | + void storeBC(const BCCache& bc, |
| 115 | + std::vector<o2::fd3::Digit>& digitsBC, |
| 116 | + std::vector<o2::fd3::ChannelData>& digitsCh, |
| 117 | + std::vector<o2::fd3::DetTrigInput>& digitsTrig, |
| 118 | + o2::dataformats::MCTruthContainer<o2::fd3::MCLabel>& labels); |
| 119 | + |
| 120 | + std::array<std::vector<float>, DigitizationConstants::NCELLSTOT> mPmtChargeVsTime; // Charge time series aka analogue signal pulse from PM |
| 121 | + unsigned int mNBins; // |
| 122 | + unsigned int mNTimeBinsPerBC; |
| 123 | + float mBinSize; // Time width of the pulse bin - HPTDC resolution |
| 124 | + |
| 125 | + /// vectors to store the PMT signal from cosmic muons |
| 126 | + std::vector<double> mPmtResponseGlobalRings; |
| 127 | + std::vector<double> mPmtResponseTemp; |
| 128 | + |
| 129 | + /// for CFD |
| 130 | + BCCache mLastBCCache; // buffer for the last BC |
| 131 | + std::array<int, DigitizationConstants::NCELLSTOT> mCfdStartIndex; // start indices for the CFD detector |
| 132 | + |
| 133 | + /// Internal helper methods related to conversion of energy-deposition into el. signal |
| 134 | + Int_t SimulateLightYield(Int_t pmt, Int_t nPhot) const; |
| 135 | + float SimulateTimeCfd(int& startIndex, const ChannelDigitF& pulseLast, const ChannelDigitF& pulse) const; |
| 136 | + float IntegrateCharge(const ChannelDigitF& pulse) const; |
| 137 | + |
| 138 | + ClassDefNV(Digitizer, 1); |
| 139 | +}; |
| 140 | +} // namespace fd3 |
| 141 | +} // namespace o2 |
| 142 | + |
| 143 | +#endif |
0 commit comments