File indexing completed on 2026-04-09 07:49:17
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "OPTICKS_LOG.hh"
0012
0013 #include "ssys.h"
0014 #include "spath.h"
0015 #include "scuda.h"
0016 #include "squad.h"
0017 #include "sqat4.h"
0018 #include "stran.h"
0019 #include "ssincos.h"
0020
0021 #include "SEvent.hh"
0022 #include "SFrameGenstep.hh"
0023 #include "SCenterExtentGenstep.hh"
0024 #include "SRng.hh"
0025
0026 #include "NP.hh"
0027
0028 const char* FOLD = "${FOLD:-$TMP/sysrap/SEventTest}" ;
0029
0030 struct SEventTest
0031 {
0032 static const char* TEST ;
0033
0034 static int Resolve();
0035 static int MakeCountGenstep();
0036 static int MakeTorchGenstep();
0037
0038 static const Tran<double>* GetTestTransform(int idx);
0039
0040 static int MakeCenterExtentGenstep_();
0041 static const NP* MakeCenterExtentGenstep(int nx, int ny, int nz );
0042
0043 static int GenerateCEG0_();
0044 static int GenerateCEG0( const NP* gsa );
0045
0046 static int GenerateCEG1_();
0047 static int GenerateCEG1( const NP* gsa );
0048
0049 static int Main();
0050 };
0051
0052 const char* SEventTest::TEST = ssys::getenvvar("TEST", "Resolve");
0053
0054 int SEventTest::Resolve()
0055 {
0056 const char* path = spath::Resolve(FOLD);
0057 std::cout
0058 << "SEventTest::Resolve\n"
0059 << " FOLD [" << FOLD << "]\n"
0060 << " path [" << ( path ? path : "-" ) << "]\n"
0061 ;
0062 return 0 ;
0063 }
0064
0065 int SEventTest::MakeCountGenstep()
0066 {
0067 std::vector<int> photon_counts_per_genstep = { 3, 5, 2, 0, 1, 3, 4, 2, 4 };
0068 int x_total = 0 ;
0069 const NP* gs = SEvent::MakeCountGenstep(photon_counts_per_genstep, &x_total ) ;
0070 gs->save(FOLD, "cngs.npy");
0071
0072 std::cout
0073 << "SEventTest::MakeCountGenstep"
0074 << " x_total " << x_total
0075 << " gs " << ( gs ? gs->sstr() : "-" )
0076 << "\n"
0077 ;
0078
0079 return 0 ;
0080 }
0081
0082 int SEventTest::MakeTorchGenstep()
0083 {
0084 const char* path = spath::Resolve(FOLD, "torch.npy");
0085 const NP* gs = SEvent::MakeTorchGenstep() ;
0086 gs->save(path);
0087
0088 std::cout
0089 << "SEventTest::MakeTorchGenstep"
0090 << " path " << ( path ? path : "-" )
0091 << " gs " << ( gs ? gs->sstr() : "-" )
0092 << "\n"
0093 ;
0094
0095 return 0 ;
0096 }
0097
0098
0099
0100
0101
0102
0103
0104 const Tran<double>* SEventTest::GetTestTransform(int idx)
0105 {
0106 const Tran<double>* geotran = nullptr ;
0107
0108 if( idx == 0 )
0109 {
0110 geotran = Tran<double>::make_identity() ;
0111 }
0112 else if( idx < 10 )
0113 {
0114 const char* str_1 = "(-0.585,-0.805, 0.098, 0.000) (-0.809, 0.588, 0.000, 0.000) (-0.057,-0.079,-0.995, 0.000) (1022.116,1406.822,17734.953, 1.000)" ;
0115 const char* str_2 = "(100,100,100)" ;
0116 const char* str_3 = "(0,0,0)" ;
0117 const char* str = nullptr ;
0118 switch(idx)
0119 {
0120 case 1: str = str_1 ; break ;
0121 case 2: str = str_2 ; break ;
0122 case 3: str = str_3 ; break ;
0123 }
0124
0125 qat4* qt = qat4::from_string(str);
0126 geotran = Tran<double>::ConvertToTran(qt);
0127 }
0128 else if( idx == 10 )
0129 {
0130 geotran = Tran<double>::make_rotate( 0., 0., 1., 45. ) ;
0131 }
0132 return geotran ;
0133 }
0134
0135
0136 int SEventTest::MakeCenterExtentGenstep_()
0137 {
0138 const NP* gs = MakeCenterExtentGenstep( 2, 2, 2);
0139 std::cout << " gs " << ( gs ? gs->sstr() : "-" ) << "\n" ;
0140 return 0 ;
0141 }
0142
0143 const NP* SEventTest::MakeCenterExtentGenstep(int nx, int ny, int nz )
0144 {
0145 float4 ce ;
0146 qvals( ce, "CE", "500,0,0,100" );
0147 LOG(info) << " ce " << ce ;
0148
0149 std::vector<int> cegs = {{nx, ny, nz, 10 }} ;
0150 float gridscale = 1.f ;
0151
0152 SFrameGenstep::StandardizeCEGS(cegs);
0153
0154 bool ce_scale = true ;
0155 float3 offset = make_float3(0.f, 0.f, 0.f) ;
0156 std::vector<float3> ce_offset ;
0157 ce_offset.push_back(offset);
0158
0159 const Tran<double>* geotran = GetTestTransform(0) ;
0160
0161 const NP* gs = SFrameGenstep::MakeCenterExtentGenstep(ce, cegs, gridscale, geotran, ce_offset, ce_scale, nullptr );
0162
0163 const char* path = spath::Resolve(FOLD, "cegs.npy");
0164 gs->save(path);
0165
0166 std::cout
0167 << "SEventTest::MakeCenterExtentGenstep"
0168 << " path [" << ( path ? path : "-" ) << "]\n"
0169 << " gs " << ( gs ? gs->sstr() : "-" )
0170 << "\n"
0171 ;
0172
0173 return gs ;
0174 }
0175
0176
0177 int SEventTest::GenerateCEG0_()
0178 {
0179 const NP* gs = MakeCenterExtentGenstep(3, 0, 3) ;
0180 assert( gs );
0181 gs->dump(0,gs->shape[0],4,6);
0182
0183 return GenerateCEG0(gs);
0184 }
0185
0186 int SEventTest::GenerateCEG0( const NP* gsa )
0187 {
0188 LOG(info);
0189
0190 float gridscale = 1.f ;
0191 std::vector<quad4> pp ;
0192 SFrameGenstep::GenerateCenterExtentGenstepPhotons( pp, gsa, gridscale );
0193 NP* ppa = NP::Make<float>( pp.size(), 4, 4 );
0194 memcpy( ppa->bytes(), (float*)pp.data(), ppa->arr_bytes() );
0195
0196 std::cout << "ppa " << ppa->sstr() << std::endl ;
0197 ppa->save(FOLD, "ppa.npy");
0198
0199 return 0 ;
0200 }
0201
0202 int SEventTest::GenerateCEG1_()
0203 {
0204 const NP* gs = MakeCenterExtentGenstep(3, 0, 3) ;
0205 assert( gs );
0206 gs->dump(0,gs->shape[0],4,6);
0207
0208 return GenerateCEG1(gs);
0209 }
0210
0211 int SEventTest::GenerateCEG1( const NP* gsa )
0212 {
0213 LOG(info);
0214 float gridscale = 1.f ;
0215 NP* ppa = SFrameGenstep::GenerateCenterExtentGenstepPhotons_( gsa, gridscale );
0216 LOG(info) << "ppa " << ppa->sstr() << " saving ppa.npy to " << FOLD ;
0217 ppa->save(FOLD, "ppa.npy");
0218 return 0 ;
0219 }
0220
0221 int SEventTest::Main()
0222 {
0223 bool ALL = strcmp(TEST, "ALL") == 0 ;
0224
0225 std::cout << "SEventTest::Main TEST " << TEST << "\n" ;
0226
0227 int rc = 0 ;
0228 if(ALL||0==strcmp(TEST, "Resolve")) rc += Resolve();
0229 if(ALL||0==strcmp(TEST, "MakeCountGenstep")) rc += MakeCountGenstep();
0230 if(ALL||0==strcmp(TEST, "MakeTorchGenstep")) rc += MakeTorchGenstep();
0231
0232 if(ALL||0==strcmp(TEST, "MakeCenterExtentGenstep")) rc += MakeCenterExtentGenstep_();
0233 if(ALL||0==strcmp(TEST, "GenerateCEG0")) rc += GenerateCEG0_();
0234 if(ALL||0==strcmp(TEST, "GenerateCEG1")) rc += GenerateCEG1_();
0235
0236 std::cout << "SEventTest::Main TEST " << TEST << " rc " << rc << "\n" ;
0237 return rc ;
0238 }
0239
0240
0241 int main(int argc, char** argv)
0242 {
0243 OPTICKS_LOG(argc, argv);
0244 return SEventTest::Main() ;
0245 }
0246
0247