File indexing completed on 2026-04-09 07:49:11
0001 #pragma once
0002
0003 #include <string>
0004 #include <vector>
0005 #include <cstdint>
0006
0007 #include "QUDARAP_API_EXPORT.hh"
0008 #include "plog/Severity.h"
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 struct NP ;
0027 struct SSim ;
0028 struct SEvt ;
0029
0030 template <typename T> struct QTex ;
0031 template <typename T> struct QBuf ;
0032 template <typename T> struct QProp ;
0033 template <typename T> struct QPMT ;
0034
0035 struct qsim ;
0036
0037 struct QBase ;
0038 struct QEvt ;
0039 struct QRng ;
0040 struct QScint ;
0041 struct QCerenkov ;
0042 struct QBnd ;
0043 struct QMultiFilm;
0044 struct QOptical ;
0045 struct QEvt ;
0046 struct QDebug ;
0047
0048 struct qdebug ;
0049 struct sstate ;
0050
0051 struct quad4 ;
0052 struct quad2 ;
0053 struct sphoton ;
0054 union quad ;
0055
0056 struct SSimulator ;
0057
0058 struct QUDARAP_API QSim
0059 {
0060 static constexpr const int64_t M = 1000000 ;
0061 static constexpr const int64_t G = 1000000000 ;
0062
0063 static const plog::Severity LEVEL ;
0064 static const char* PREFIX ;
0065 static QSim* INSTANCE ;
0066 static QSim* Get();
0067 static QSim* Create();
0068
0069 static void UploadComponents(const SSim* ssim);
0070
0071 const QBase* base ;
0072 QEvt* qev ;
0073 SEvt* sev ;
0074
0075 const QRng* rng ;
0076 const QScint* scint ;
0077 const QCerenkov* cerenkov ;
0078 const QBnd* bnd ;
0079 const QOptical* optical ;
0080 const QDebug* debug_ ;
0081
0082 const QProp<float>* prop ;
0083 const QPMT<float>* pmt ;
0084 const QMultiFilm* multifilm ;
0085
0086 qsim* sim ;
0087 qsim* d_sim ;
0088
0089 qdebug* dbg ;
0090 qdebug* d_dbg ;
0091
0092 SSimulator* cx ;
0093
0094
0095 dim3 numBlocks ;
0096 dim3 threadsPerBlock ;
0097
0098 private:
0099 QSim();
0100 void init();
0101
0102 static constexpr const char* _QSim__REQUIRE_PMT = "QSim__REQUIRE_PMT" ;
0103 static const bool REQUIRE_PMT;
0104
0105 static constexpr const char* _QSim__SAVE_IGS_EVENTID = "QSim__SAVE_IGS_EVENTID" ;
0106 static const int SAVE_IGS_EVENTID ;
0107
0108 static constexpr const char* _QSim__SAVE_IGS_PATH = "QSim__SAVE_IGS_PATH" ;
0109 static const char* SAVE_IGS_PATH ;
0110
0111 static constexpr const char* _QSim__CONCAT = "QSim__CONCAT" ;
0112 static const bool CONCAT ;
0113
0114 static constexpr const char* _QSim__ALLOC = "QSim__ALLOC" ;
0115 static const bool ALLOC ;
0116
0117
0118 public:
0119 void setLauncher(SSimulator* cx_ );
0120
0121 static constexpr const char* QSim__simulate_KEEP_SUBFOLD = "QSim__simulate_KEEP_SUBFOLD" ;
0122 static bool KEEP_SUBFOLD ;
0123
0124 double simulate(int eventID, bool reset_ );
0125 void simulate_final_merge(int64_t tot_ph, cudaStream_t stream);
0126
0127
0128
0129 NP* simulate(const NP* gs, int eventID );
0130
0131 static void MaybeSaveIGS(int eventID, NP* igs);
0132
0133 unsigned long long get_photon_slot_offset() const ;
0134
0135 void reset( int eventID);
0136
0137 double simtrace(int eventID);
0138
0139
0140 qsim* getDevicePtr() const ;
0141 std::string desc() const ;
0142 std::string descFull() const ;
0143 std::string descComponents() const ;
0144
0145
0146
0147
0148 char getScintTexFilterMode() const ;
0149
0150 void configureLaunch16();
0151 void configureLaunch( unsigned width, unsigned height );
0152 void configureLaunch2D( unsigned width, unsigned height );
0153 void configureLaunch1D(unsigned num, unsigned threads_per_block);
0154 std::string descLaunch() const ;
0155
0156
0157 template<typename T>
0158 void rng_sequence( dim3 numblocks, dim3 threadsPerBlock, qsim* d_sim, T* d_seq, unsigned ni_tranche, unsigned nv, unsigned ioffset );
0159
0160 template<typename T>
0161 void rng_sequence( T* seq, unsigned ni, unsigned nj, unsigned ioffset );
0162
0163 template<typename T>
0164 void rng_sequence( const char* dir, unsigned ni, unsigned nj, unsigned nk, unsigned ni_tranche_size );
0165
0166
0167 NP* scint_wavelength( unsigned num_wavelength, unsigned& hd_factor );
0168
0169 NP* RandGaussQ_shoot(unsigned num_v );
0170
0171
0172
0173 void dump_wavelength( float* wavelength, unsigned num_wavelength, unsigned edgeitems=10 );
0174
0175
0176 NP* dbg_gs_generate(unsigned num_photon, unsigned type );
0177
0178
0179 void dump_photon( quad4* photon, unsigned num_photon, const char* opt="f0,f1,f2,i3", unsigned egdeitems=10 );
0180
0181 void generate_photon();
0182 void fill_state_0(quad6* state, unsigned num_state);
0183 void fill_state_1(sstate* state, unsigned num_state);
0184
0185 NP* quad_launch_generate(unsigned num_quad, unsigned type );
0186 NP* photon_launch_generate(unsigned num_photon, unsigned type );
0187
0188 static constexpr const char* _QSim__photon_launch_mutate_DEBUG_NUM_PHOTON = "QSim__photon_launch_mutate_DEBUG_NUM_PHOTON" ;
0189 static constexpr const char* _QSim__photon_launch_mutate_SKIP_LAUNCH = "QSim__photon_launch_mutate_SKIP_LAUNCH" ;
0190 void photon_launch_mutate( sphoton* photon, unsigned num_photon, unsigned type );
0191
0192
0193 static quad2* UploadFakePRD(const NP* ip, const NP* prd);
0194 void fake_propagate(const NP* prd, unsigned type );
0195
0196 unsigned getBoundaryTexWidth() const ;
0197 unsigned getBoundaryTexHeight() const ;
0198 const NP* getBoundaryTexSrc() const ;
0199
0200 NP* boundary_lookup_all( unsigned width, unsigned height ) ;
0201 NP* boundary_lookup_line( float* domain, unsigned num_lookup, unsigned line, unsigned k ) ;
0202
0203
0204 template<typename T>
0205 void prop_lookup( T* lookup, const T* domain, unsigned domain_width, const std::vector<unsigned>& pids ) ;
0206
0207 template<typename T>
0208 void prop_lookup_onebyone( T* lookup, const T* domain, unsigned domain_width, const std::vector<unsigned>& pids ) ;
0209
0210 void multifilm_lookup_all( quad2* sample , quad2* result , unsigned width, unsigned height );
0211
0212 static std::string Desc(char delim='\n');
0213 static std::string Switches();
0214 };
0215
0216