Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:53

0001 /**
0002 CSGNodeScanTest.cc
0003 =====================
0004 
0005 For lower level tests see::
0006 
0007    intersect_leaf_box3_test.cc
0008    intersect_leaf_cylinder_test.cc
0009    intersect_leaf_phicut_test.cc  
0010 
0011 **/
0012 
0013 #include <vector>
0014 #include <cmath>
0015 
0016 #include "OPTICKS_LOG.hh"
0017 #include "SSys.hh"
0018 #include "SStr.hh"
0019 #include "SPath.hh"
0020 #include "NP.hh"
0021 
0022 #include "scuda.h"
0023 #include "squad.h"
0024 #include "sqat4.h"
0025 
0026 //#define DEBUG 1 
0027 #include "csg_intersect_leaf.h"
0028 #include "csg_intersect_node.h"
0029 #include "csg_intersect_tree.h"
0030 
0031 struct Scan 
0032 {
0033     const char* geom ; 
0034     CSGNode nd ; 
0035     float t_min ; 
0036     int num ; 
0037     bool shifted ; 
0038     const char* modes_ ; 
0039     const char* axes_ ; 
0040     std::vector<int>* modes ; 
0041     std::vector<int>* axes ; 
0042 
0043     NP* simtrace ; 
0044     quad4* qq ;  
0045     const char* fold ; 
0046 
0047     Scan(); 
0048     void init(); 
0049     std::string desc() const ; 
0050     void save() const ; 
0051 }; 
0052 
0053 Scan::Scan()
0054     :
0055     geom(SSys::getenvvar("CSGNodeScanTest_GEOM", "iphi")),
0056     nd(CSGNode::MakeDemo(geom)),  
0057     t_min(SSys::getenvfloat("TMIN",0.f)),
0058     num(SSys::getenvint("NUM", 200)),
0059     shifted(true),
0060     modes_(SSys::getenvvar("MODES", "0,1,2,3")),
0061     axes_(SSys::getenvvar("AXES", "0,2,1")),  // X,Z,Y  3rd gets set to zero 
0062     modes(SStr::ISplit(modes_, ',')),
0063     axes(SStr::ISplit(axes_, ',')),
0064     simtrace(NP::Make<float>(modes->size(),num,4,4)),
0065     qq((quad4*)simtrace->values<float>()),
0066     fold(SPath::Resolve("$TMP/CSGNodeScanTest", geom, DIRPATH )) 
0067 {
0068     init(); 
0069 }
0070 
0071 std::string Scan::desc() const
0072 {
0073     std::stringstream ss ; 
0074     ss << "Scan::desc" << std::endl 
0075        << " geom " << geom << std::endl
0076        << " num " << num << std::endl
0077        << " modes_ " << modes_ << std::endl
0078        << " axes_ " << axes_ << std::endl
0079        << " simtrace.sstr " << simtrace->sstr() << std::endl
0080        << " fold " << fold << std::endl 
0081        ;
0082 
0083     std::string s = ss.str(); 
0084     return s ; 
0085 }
0086 
0087 void Scan::save() const 
0088 {
0089     simtrace->save(fold, "simtrace.npy");
0090 }
0091 
0092 void Scan::init()
0093 {
0094     assert( axes->size() == 3 ); 
0095     int h = (*axes)[0] ; 
0096     int v = (*axes)[1] ; 
0097     int d = (*axes)[2] ; 
0098 
0099     unsigned offset = 0 ; 
0100     for(unsigned m=0 ; m < modes->size() ; m++)
0101     {
0102         int mode = (*modes)[m]; 
0103         float vx(0.f); 
0104         float vy(0.f); 
0105         float ox(0.f);
0106         float oy(0.f);
0107  
0108         for(int i=0 ; i < num ; i++)
0109         {
0110             int j = i - num/2 ; 
0111             if( mode == 0 )       // shoot upwards from X axis, or shifted line
0112             {
0113                 vx = 0.f ; 
0114                 vy = 1.f ; 
0115                 ox = j*0.1f ; 
0116                 oy = shifted ? -10.f : 0. ; 
0117             }
0118             else if( mode == 1 )  //  shoot downwards from X axis, or shifted line
0119             {
0120                 vx = 0.f ; 
0121                 vy = -1.f ; 
0122                 ox = j*0.1f ; 
0123                 oy = shifted ?  10.f : 0. ; 
0124             }
0125             else if( mode == 2 )   // shoot to right from Y axis, or shifted line 
0126             {
0127                 vx = 1.f ; 
0128                 vy = 0.f ; 
0129                 ox = shifted ? -10.f : 0.  ; 
0130                 oy = j*0.1f ; 
0131             }
0132             else if( mode == 3 )  // shoot to left from Y axis, or shifted line
0133             {
0134                 vx = -1.f ; 
0135                 vy = 0.f ; 
0136                 ox = shifted ? 10.f : 0.  ; 
0137                 oy = j*0.1f ; 
0138             }
0139 
0140 
0141             // standard simtrace layout see sevent.h sevent::add_simtrace
0142             quad4& _qq = qq[m*num+i] ; 
0143             float* oo = (float*)&_qq.q2.f.x ;  // ray_origin
0144             float* dd = (float*)&_qq.q3.f.x ;  // ray_direction
0145 
0146             float3* ray_origin    = (float3*)&_qq.q2.f.x ; 
0147             float3* ray_direction = (float3*)&_qq.q3.f.x ; 
0148             float3* position      = (float3*)&_qq.q1.f.x ; 
0149 
0150             oo[h] = ox ; 
0151             oo[v] = oy ; 
0152             oo[d] = 0.f ; 
0153 
0154             dd[h] = vx ; 
0155             dd[v] = vy ; 
0156             dd[d] = 0.f ; 
0157            
0158             float4* isect = &_qq.q0.f ; 
0159             const float4* plan = nullptr ; 
0160             const qat4* itra = nullptr ; 
0161             const CSGNode* node = &nd ; 
0162             bool dump = false ; 
0163 
0164             bool valid_isect(false) ; 
0165             intersect_node(valid_isect, *isect, node, node, plan, itra, t_min, *ray_origin, *ray_direction, dump ); 
0166             // TODO: this should be using higher level intersect_prim ???
0167 
0168             if(valid_isect)
0169             {
0170                 float t = (*isect).w ;  
0171                 *position = *ray_origin + t*(*ray_direction) ; 
0172             }
0173         }
0174         offset += num ; 
0175     }
0176 }
0177 
0178 int main(int argc, char** argv)
0179 {
0180     OPTICKS_LOG(argc, argv);  
0181 
0182     LOG(info) << " running scan " ; 
0183     Scan s ; 
0184     LOG(info) << s.desc() ; 
0185     s.save(); 
0186     return 0 ; 
0187 }