Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-01 09:06:28

0001 /** @class sipm::SiPMHit SimSiPM/SimSiPM/SiPMHit.h SiPMHit.h
0002  *
0003  * @brief Class storing informations relative to a single SiPM hitted cell.
0004  *
0005  * This class is used mainly to store informations relative to a single hit on a
0006  * SiPM cell. Informations stored in thiss class will be used to generate the
0007  * signal for each SiPM cell.
0008  *
0009  *  @author Edoardo Proserpio
0010  *  @date 2020
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   /** @enum HitType
0026    * Defines the generating process for the hit
0027    */
0028   enum class HitType : uint8_t {
0029     kPhotoelectron,           ///< Hit generated by a photoelectron
0030     kDarkCount,               ///< Hit generated by a dark count event
0031     kOpticalCrosstalk,        ///< Hit generated by an optical crosstalk
0032     kDelayedOpticalCrosstalk, ///< Hit generated by a delayed optical crosstalk
0033     kFastAfterPulse,          ///< Hit generated by a fast afterpulse
0034     kSlowAfterPulse           ///< Hit generated by a slow afterpulse
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   /// @brief Comparison operator for hits
0043   /**
0044    * Hits are ordered based on their time:
0045    * @f[Hit_1 < Hit_2 \Leftrightarrow Hit_1.time < Hit_2.time @f]
0046    * Sorting a vector of hits gives the chronological order of hits by
0047    * arrving/generating time.
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   /// @brief Operator used to check if the hit is generated in the same cell
0055   /**
0056    * Hits are considered equal if they have same row and column,
0057    * hence the same SiPM cell
0058    */
0059   constexpr bool operator==(const SiPMHit& rhs) const noexcept { return m_Row == rhs.m_Row && m_Col == rhs.m_Col; }
0060 
0061   /// @brief Returns hit time
0062   constexpr double time() const noexcept { return m_Time; }
0063   /// @brief Returns row of hitted cell
0064   constexpr uint32_t row() const noexcept { return m_Row; }
0065   /// @brief Returns column of hitted cell
0066   constexpr uint32_t col() const noexcept { return m_Col; }
0067   /// @brief Returns amplitude of the signal produced by the hit
0068   float amplitude() const noexcept { return m_Amplitude; }
0069   float& amplitude() { return m_Amplitude; }
0070   /// @brief Returns hit type to identify the hits
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   // Always construct hits with values and no default constructor
0082   SiPMHit() = delete;
0083 
0084 private:
0085   // Once a hit is constructed only
0086   // amplitude can be changed
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 } // namespace sipm
0126 #endif /* SIPM_SIPMHITS_H */