Back to home page

EIC code displayed by LXR

 
 

    


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

0001 
0002 #include <vector>
0003 #include <array>
0004 #include <cstdlib>
0005 
0006 #include "ssys.h"
0007 #include "NP.hh"
0008 
0009 #include "SSim.hh"
0010 
0011 #include "CSGFoundry.h"
0012 #include "CSGQuery.h"
0013 #include "CSGDraw.h"
0014 
0015 #include "CSGSimtraceSample.h"
0016 #include "SLOG.hh"
0017 
0018 
0019 const plog::Severity CSGSimtraceSample::LEVEL = SLOG::EnvLevel("CSGSimtraceSample", "DEBUG"); 
0020 
0021 CSGSimtraceSample::CSGSimtraceSample()
0022     :
0023     sim(SSim::Create()),
0024     fd(CSGFoundry::Load()),      // via GEOM envvar 
0025     vv(fd ? fd->loadAux("Values/values.npy") : nullptr ),
0026     path(ssys::getenvvar("SAMPLE_PATH","/tmp/simtrace_sample.npy")),
0027     simtrace(NP::LoadIfExists(path)),
0028     qq(simtrace ? (quad4*)simtrace->bytes() : nullptr),  
0029     q(fd ? new CSGQuery(fd) : nullptr ),
0030     d(q  ? new CSGDraw(q,'Z') : nullptr)
0031 {
0032     init(); 
0033 }
0034 
0035 void CSGSimtraceSample::init()
0036 {
0037     LOG_IF( fatal, fd == nullptr ) << " fd NULL " ; 
0038     assert( fd ); 
0039 
0040     LOG(LEVEL) << " d(CSGDraw) " << ( d ? d->desc() : "-" )  ; 
0041     LOG(LEVEL) << " fd.cfbase " << ( fd ? fd->cfbase : "-" ) ; 
0042     LOG(LEVEL) << " vv " << ( vv ? vv->sstr() : "-" ) ; 
0043     LOG(LEVEL) << "vv.lpath [" << ( vv ? vv->lpath : "-" ) << "]"  ; 
0044     LOG(LEVEL) << "vv.descValues " << std::endl << ( vv ? vv->descValues() : "-" ) ; 
0045 }
0046  
0047 std::string CSGSimtraceSample::desc() const
0048 {
0049     std::stringstream ss ; 
0050     ss << "CSGSimtraceSample::desc" << std::endl 
0051        << " fd " << ( fd ? "Y" : "N" ) << std::endl 
0052        << " fd.geom " << (( fd && fd->geom ) ? fd->geom : "-" ) << std::endl 
0053        << " " << CSGQuery::Label() << std::endl 
0054        << " path " << ( path ? path : "-" ) << std::endl 
0055        << " simtrace " << ( simtrace ? simtrace->sstr() : "-" ) << std::endl 
0056        ;
0057 
0058     std::string s = ss.str(); 
0059     return s ; 
0060 }
0061 
0062 int CSGSimtraceSample::intersect()
0063 {
0064     LOG_IF(fatal, q == nullptr ) << " q NULL " ; 
0065     if(q == nullptr) return 0 ; 
0066 
0067     unsigned n = simtrace ? simtrace->shape[0] : 0u ; 
0068     int num_intersect = 0 ; 
0069     for(unsigned i=0 ; i < n ; i++) 
0070     {
0071         quad4& st = qq[i] ;
0072         bool valid_intersect = q->simtrace(st); 
0073 
0074         std::cout << CSGQuery::Desc(st, "-", &valid_intersect) << std::endl; 
0075 
0076         if(valid_intersect)
0077         {
0078             const float4& o = st.q2.f ; 
0079             const float4& v = st.q3.f ; 
0080 
0081             float t0 = -o.x/v.x ;  
0082             float z0 = o.z + t0*v.z ;  
0083             std::cout 
0084                 << " o.x          " << std::setw(10) << std::fixed << std::setprecision(4) << o.x 
0085                 << " v.x          " << std::setw(10) << std::fixed << std::setprecision(4) << v.x 
0086                 << " t0(-o.x/v.x) " << std::setw(10) << std::fixed << std::setprecision(4) << t0 
0087                 << " z0           " << std::setw(10) << std::fixed << std::setprecision(4) << z0 
0088                 << std::endl
0089                 ; 
0090         }
0091 
0092         if(valid_intersect) num_intersect += 1 ; 
0093     }
0094 
0095     LOG(LEVEL) << desc() << " n " << n << " num_intersect " << num_intersect ; 
0096     return num_intersect ; 
0097 }
0098 
0099