File indexing completed on 2025-04-01 09:06:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef SIPM_SIPMHITS_H
0014 #define SIPM_SIPMHITS_H
0015
0016 #include <cstdint>
0017 #include <iomanip>
0018 #include <iostream>
0019 #include <memory>
0020 #include <sstream>
0021
0022 namespace sipm {
0023 class SiPMHit {
0024 public:
0025
0026
0027
0028 enum class HitType : uint8_t {
0029 kPhotoelectron,
0030 kDarkCount,
0031 kOpticalCrosstalk,
0032 kDelayedOpticalCrosstalk,
0033 kFastAfterPulse,
0034 kSlowAfterPulse
0035 };
0036
0037 constexpr SiPMHit(double time, float amp, uint32_t row, uint32_t col, HitType type,
0038 const SiPMHit* parentPtr = nullptr) noexcept
0039 : m_Time(time), m_Amplitude(amp), m_Row(row), m_Col(col), m_HitType(type), m_ParentPtr(parentPtr) {}
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 constexpr bool operator<(const SiPMHit& rhs) const noexcept { return m_Time < rhs.m_Time; }
0050 constexpr bool operator<=(const SiPMHit& rhs) const noexcept { return !(rhs < *this); }
0051 constexpr bool operator>(const SiPMHit& rhs) const noexcept { return rhs < *this; }
0052 constexpr bool operator>=(const SiPMHit& rhs) const noexcept { return !(*this < rhs); }
0053
0054
0055
0056
0057
0058
0059 constexpr bool operator==(const SiPMHit& rhs) const noexcept { return m_Row == rhs.m_Row && m_Col == rhs.m_Col; }
0060
0061
0062 constexpr double time() const noexcept { return m_Time; }
0063
0064 constexpr uint32_t row() const noexcept { return m_Row; }
0065
0066 constexpr uint32_t col() const noexcept { return m_Col; }
0067
0068 float amplitude() const noexcept { return m_Amplitude; }
0069 float& amplitude() { return m_Amplitude; }
0070
0071 constexpr HitType hitType() const noexcept { return m_HitType; }
0072 constexpr const SiPMHit* parent() const noexcept { return m_ParentPtr; }
0073
0074 friend std::ostream& operator<<(std::ostream&, const SiPMHit&);
0075 std::string toString() const {
0076 std::stringstream ss;
0077 ss << *this;
0078 return ss.str();
0079 }
0080
0081
0082 SiPMHit() = delete;
0083
0084 private:
0085
0086
0087 const double m_Time;
0088 const SiPMHit* m_ParentPtr;
0089 float m_Amplitude;
0090 const uint32_t m_Row;
0091 const uint32_t m_Col;
0092 const HitType m_HitType;
0093 };
0094
0095 inline std::ostream& operator<<(std::ostream& out, const SiPMHit& obj) {
0096 out << std::setprecision(2) << std::fixed;
0097 out << "===> SiPM Hit <===\n";
0098 out << "Address: " << std::hex << std::addressof(obj) << "\n";
0099 out << "Hit time: " << std::dec << obj.m_Time << "\n";
0100 out << "Hit relative amplitude: " << obj.m_Amplitude << "\n";
0101 out << "Hit position on sensor: " << obj.m_Row << " - " << obj.m_Col << "\n";
0102 out << "Hit type: ";
0103 switch (obj.m_HitType) {
0104 case SiPMHit::HitType::kPhotoelectron:
0105 out << "Photoelectron\n";
0106 break;
0107 case SiPMHit::HitType::kDarkCount:
0108 out << "Dark count\n";
0109 break;
0110 case SiPMHit::HitType::kOpticalCrosstalk:
0111 out << "Optical crosstalk\n";
0112 break;
0113 case SiPMHit::HitType::kFastAfterPulse:
0114 out << "Afterpulse (fast)\n";
0115 break;
0116 case SiPMHit::HitType::kSlowAfterPulse:
0117 out << "Afterpulse (slow)\n";
0118 break;
0119 case SiPMHit::HitType::kDelayedOpticalCrosstalk:
0120 out << "Delayed optical crosstalk\n";
0121 break;
0122 }
0123 return out;
0124 }
0125 }
0126 #endif