File indexing completed on 2026-04-09 07:48:58
0001 #include "SLOG.hh"
0002 #include "SEventConfig.hh"
0003 #include "SSys.hh"
0004 #include "SEvt.hh"
0005 #include "SSim.hh"
0006 #include "CSGFoundry.h"
0007 #include "CSGSimtrace.hh"
0008 #include "CSGQuery.h"
0009 #include "CSGDraw.h"
0010 #include "NP.hh"
0011 #include "NPFold.h"
0012
0013 const plog::Severity CSGSimtrace::LEVEL = SLOG::EnvLevel("CSGSimtrace", "DEBUG");
0014
0015 int CSGSimtrace::Preinit()
0016 {
0017 SEventConfig::SetRGModeSimtrace();
0018 return 0 ;
0019 }
0020
0021 CSGSimtrace::CSGSimtrace()
0022 :
0023 prc(Preinit()),
0024 geom(SSys::getenvvar("GEOM", "nmskSolidMaskTail")),
0025 sim(SSim::Create()),
0026 fd(CSGFoundry::Load()),
0027 sev(SEvt::Create_ECPU()),
0028 outdir(sev->getDir()),
0029 q(new CSGQuery(fd)),
0030 d(new CSGDraw(q,'Z')),
0031 SELECTION(getenv("SELECTION")),
0032 selection(SSys::getenvintvec("SELECTION",',')),
0033 num_selection(selection && selection->size() > 0 ? selection->size() : 0 ),
0034 selection_simtrace(num_selection > 0 ? NP::Make<float>(num_selection, 4, 4) : nullptr ),
0035 qss(selection_simtrace ? (quad4*)selection_simtrace->bytes() : nullptr)
0036 {
0037 init();
0038 }
0039
0040 void CSGSimtrace::init()
0041 {
0042 LOG(LEVEL) << d->desc();
0043
0044 float4 ce = q->select_prim_ce ;
0045 LOG(LEVEL) << " ce " << ce ;
0046
0047 #ifdef WITH_OLD_FRAME
0048 frame.set_hostside_simtrace();
0049 frame.ce = ce ;
0050 sev->setFrame(frame);
0051 #else
0052 fr.set_hostside_simtrace();
0053 fr.set_ce( &ce.x );
0054 sev->setFr(fr);
0055 #endif
0056
0057 LOG(LEVEL) << " SELECTION " << SELECTION << " num_selection " << num_selection << " outdir " << outdir ;
0058 if(selection_simtrace)
0059 {
0060 selection_simtrace->set_meta<std::string>("SELECTION", SELECTION) ;
0061 }
0062
0063 }
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073 int CSGSimtrace::simtrace()
0074 {
0075 int eventID = 0 ;
0076
0077 sev->beginOfEvent(eventID);
0078
0079 int num_intersect = qss ? simtrace_selection() : simtrace_all() ;
0080
0081 sev->gather();
0082 sev->topfold->concat();
0083 sev->topfold->clear_subfold();
0084
0085 sev->endOfEvent(eventID);
0086
0087 LOG(LEVEL)
0088 << " outdir [" << ( outdir ? outdir : "-" ) << "]"
0089 << " num_selection " << num_selection
0090 << " selection_simtrace.sstr " << ( selection_simtrace ? selection_simtrace->sstr() : "-" )
0091 ;
0092
0093 if(num_selection > 0)
0094 {
0095 selection_simtrace->save(outdir, "simtrace_selection.npy") ;
0096 }
0097 q->post(outdir);
0098
0099 return num_intersect ;
0100
0101 }
0102
0103 int CSGSimtrace::simtrace_all()
0104 {
0105 int num_simtrace = sev->simtrace.size() ;
0106 int num_intersect = 0 ;
0107 for(int i=0 ; i < num_simtrace ; i++)
0108 {
0109 quad4& p = sev->simtrace[i] ;
0110 bool valid_intersect = q->simtrace(p);
0111 if(valid_intersect) num_intersect += 1 ;
0112 }
0113 LOG(LEVEL)
0114 << " num_simtrace " << num_simtrace
0115 << " num_intersect " << num_intersect
0116 ;
0117 return num_intersect ;
0118 }
0119
0120 int CSGSimtrace::simtrace_selection()
0121 {
0122 int num_intersect = 0 ;
0123 for(int i=0 ; i < num_selection ; i++)
0124 {
0125 int j = (*selection)[i] ;
0126 const quad4& p0 = sev->simtrace[j] ;
0127 quad4& p = qss[i] ;
0128 p = p0 ;
0129 bool valid_intersect = q->simtrace(p);
0130 if(valid_intersect) num_intersect += 1 ;
0131 }
0132 LOG(LEVEL)
0133 << " num_selection " << num_selection
0134 << " num_intersect " << num_intersect
0135 ;
0136 return num_intersect ;
0137 }
0138
0139