File indexing completed on 2026-04-09 07:49:37
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 struct NP ;
0022 struct SGenerate
0023 {
0024 static constexpr const char* RNG_PRECOOKED = "SGenerate__GeneratePhotons_RNG_PRECOOKED" ;
0025 static NP* GeneratePhotons(const NP* gs);
0026 };
0027
0028
0029 #include "scuda.h"
0030 #include "squad.h"
0031 #include "sphoton.h"
0032
0033 #include "srngcpu.h"
0034 using RNG = srngcpu ;
0035
0036 #include "storch.h"
0037 #include "scarrier.h"
0038
0039 #include "SGenstep.h"
0040 #include "SEvt.hh"
0041 #include "SEvent.hh"
0042 #include "OpticksGenstep.h"
0043 #include "NP.hh"
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 inline NP* SGenerate::GeneratePhotons(const NP* gs_ )
0063 {
0064 bool rng_precooked = ssys::getenvbool(RNG_PRECOOKED);
0065 std::cerr
0066 << "SGenerate::GeneratePhotons"
0067 << " " << RNG_PRECOOKED
0068 << " : "
0069 << ( rng_precooked ? "YES" : "NO " )
0070 << std::endl
0071 ;
0072
0073 const quad6* gg = (quad6*)gs_->bytes() ;
0074 NP* se = SEvent::MakeSeed(gs_) ;
0075 const int* seed = (int*)se->bytes() ;
0076
0077 int tot_photon = se->shape[0] ;
0078 NP* ph = NP::Make<float>( tot_photon, 4, 4);
0079 sphoton* pp = (sphoton*)ph->bytes() ;
0080
0081 unsigned rng_seed = 1u ;
0082 RNG rng ;
0083 rng.seed = rng_seed ;
0084
0085 for(int i=0 ; i < tot_photon ; i++ )
0086 {
0087 unsigned photon_id = i ;
0088 unsigned genstep_id = seed[photon_id] ;
0089 sphoton& p = pp[photon_id] ;
0090 const quad6& gs = gg[genstep_id] ;
0091 int gencode = SGenstep::GetGencode(gs);
0092
0093 if(rng_precooked) rng.setSequenceIndex(i);
0094 switch(gencode)
0095 {
0096 case OpticksGenstep_CARRIER: scarrier::generate( p, rng, gs, photon_id, genstep_id) ; break ;
0097 case OpticksGenstep_TORCH: storch::generate( p, rng, gs, photon_id, genstep_id ) ; break ;
0098 case OpticksGenstep_INPUT_PHOTON: assert(0) ; break ;
0099 }
0100 if(rng_precooked) rng.setSequenceIndex(-1);
0101 }
0102 delete se ;
0103 return ph ;
0104 }
0105
0106