Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /** @class sipm::SiPMSensor SimSiPM/SimSiPM/SiPMSensor.h SiPMSensor.h
0002  *
0003  *  @brief Main class used to simulate a SiPM
0004  *
0005  *  This class provides all the methods to simulate a SiPM sensor.
0006  *
0007  *  @author Edoardo Proserpio
0008  *  @date 2020
0009  */
0010 
0011 #ifndef SIPM_SIPMSENSOR_H
0012 #define SIPM_SIPMSENSOR_H
0013 #include <cstdint>
0014 #include <iostream>
0015 #include <sstream>
0016 #include <vector>
0017 
0018 #include "SiPMAnalogSignal.h"
0019 #include "SiPMDebugInfo.h"
0020 #include "SiPMHit.h"
0021 #include "SiPMProperties.h"
0022 #include "SiPMRandom.h"
0023 #include "SiPMTypes.h"
0024 
0025 namespace sipm {
0026 class SiPMSensor {
0027 public:
0028   /// @brief SiPMSensor constructor from a @ref SiPMProperties instance
0029   /** Instantiates a SiPMSensor with parameter specified in the SiPMProperties.
0030    */
0031   explicit SiPMSensor(const SiPMProperties&);
0032 
0033   SiPMSensor();
0034 
0035   /// @brief Returns the @ref SiPMProperties class stored in the SiPMSensor
0036   const SiPMProperties& properties() const { return m_Properties; }
0037 
0038   /// @brief Returns the @ref SiPMAnalogSignal stored in the SiPMSensor
0039   /** Used to get the generated signal from the sensor. This method should be
0040    * run after @ref runEvent otherwise it will return only electronic noise.
0041    */
0042   SiPMAnalogSignal signal() const { return m_Signal; }
0043 
0044   /// @brief Returns vector containing all SiPMHits
0045   /** This method allows to get all the hits generated in the simulation
0046    * process, including noise hits.
0047    */
0048   std::vector<SiPMHit*> hits() const { return m_Hits; }
0049 
0050   /// @brief Returns the @ref SiPMRandom rng used by SiPMSensor
0051   const SiPMRandom rng() const { return m_rng; }
0052 
0053   SiPMRandom& rng() { return m_rng; }
0054 
0055   /// @brief Returns a @ref SiPMDebugInfo struct with MC-Truth values
0056   SiPMDebugInfo debug() const {
0057     return SiPMDebugInfo{static_cast<uint32_t>(m_PhotonTimes.size()), m_nPe, m_nDcr, m_nXt, m_nDXt, m_nAp};
0058   }
0059 
0060   /// @brief Sets a property using its name
0061   /** For a list of available SiPM properties names @sa SiPMProperties.
0062    * This method uses a key/value to set the corresponding property.
0063    */
0064   void setProperty(const std::string&, const double);
0065 
0066   /// @brief Sets a different SiPMProperties for the SiPMSensor.
0067   /** Changes the underlying SiPMProperties object with a new one.
0068    */
0069   void setProperties(const SiPMProperties&);
0070 
0071   /// @brief Adds a single photon to the list of photons to be simulated
0072   void addPhoton(const double);
0073 
0074   /// @brief Adds a single photon to the list of photons to be simulated
0075   void addPhoton(const double, const double);
0076 
0077   /// @brief Adds multiple photons to the list of photons to be simulated at once
0078   void addPhotons(const std::vector<double>&);
0079 
0080   /// @brief Adds multiple photons to the list of photons to be simulated at once
0081   void addPhotons(const std::vector<double>&, const std::vector<double>&);
0082 
0083   /// @brief Runs a complete SiPM event
0084   void runEvent();
0085 
0086   /// @brief Resets internal state of the SiPMSensor
0087   /** Resets the SiPMSensor to a fresh state
0088    * so it can be used again for a new event. */
0089   void resetState();
0090 
0091   friend std::ostream& operator<<(std::ostream&, const SiPMSensor&);
0092   std::string toString() const {
0093     std::stringstream ss;
0094     ss << *this;
0095     return ss.str();
0096   }
0097 
0098 private:
0099   double evaluatePde(const double) const;
0100   constexpr bool isInSensor(const int32_t r, const int32_t c) const noexcept {
0101     const int32_t nSideCells = m_Properties.nSideCells();
0102     return (r >= 0) & (c >= 0) & (r < nSideCells) & (c < nSideCells);
0103   }
0104   pair<uint32_t> hitUniform() const;
0105   pair<uint32_t> hitCircle() const;
0106   pair<uint32_t> hitGaussian() const;
0107   pair<uint32_t> hitCell() const;
0108   void signalShape();
0109 
0110   void addDcrEvents();
0111   void addPhotoelectrons();
0112   void addCorrelatedNoise();
0113 
0114   SiPMHit* generateXtHit(const SiPMHit*) const;
0115   SiPMHit* generateApHit(const SiPMHit*) const;
0116 
0117   void calculateSignalAmplitudes();
0118   void generateSignal();
0119 
0120   SiPMProperties m_Properties;
0121   mutable SiPMRandom m_rng;
0122 
0123   uint32_t m_nTotalHits = 0;
0124   uint32_t m_nPe = 0;
0125   uint32_t m_nDcr = 0;
0126   uint32_t m_nXt = 0;
0127   uint32_t m_nDXt = 0;
0128   uint32_t m_nAp = 0;
0129 
0130   std::vector<double> m_PhotonTimes;
0131   std::vector<double> m_PhotonWavelengths;
0132   std::vector<SiPMHit*> m_Hits;
0133 
0134   std::vector<float> m_SignalShape;
0135   SiPMAnalogSignal m_Signal;
0136 };
0137 
0138 } // namespace sipm
0139 #endif /* SIPM_SIPMSENSOR_H */