Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:47

0001 #pragma once
0002 /**
0003 SSimtrace : aiming to replace X4Simtrace
0004 =============================================
0005 
0006 SSimtrace.h is very local centric it populates a default sframe with ce
0007 from the G4VSolid.
0008 
0009 This is used from U4Tree::simtrace_scan (u4/test/U4SimtraceTest.sh)
0010 for all distinct solids in a geometry saving the simtrace SEvt
0011 with reldir for each solid name.
0012 
0013 In addition stree::save_trs is used to save the placement transforms
0014 
0015 
0016 Quick Check of simtrace positions
0017 ----------------------------------
0018 
0019 For a quick check of simtrace positions, run the below from an SEvt folder::
0020 
0021     ~/opticks/sysrap/tests/SSimtrace_check.sh
0022 
0023 That runs something like the below with ipython::
0024 
0025     #!/usr/bin/env python
0026     import os, numpy as np, matplotlib.pyplot as plt
0027     SIZE = np.array([1280, 720])
0028 
0029     title = os.getcwd()
0030     s = np.load("simtrace.npy")
0031     lpos = s[:,1,:3]
0032 
0033     fig,ax = plt.subplots(figsize=SIZE/100)
0034     ax.set_aspect('equal')
0035     fig.suptitle(title)
0036     ax.scatter( lpos[:,0], lpos[:,2] )
0037     fig.show()
0038 
0039 **/
0040 #include <cstring>
0041 #include "plog/Severity.h"
0042 
0043 #ifdef WITH_OLD_FRAME
0044 #include "sframe.h"
0045 #else
0046 #include "sfr.h"
0047 #endif
0048 
0049 class G4VSolid ;
0050 struct SEvt ;
0051 
0052 struct SSimtrace
0053 {
0054     static constexpr const plog::Severity LEVEL = info ;
0055     static void Scan( const G4VSolid* solid );
0056 
0057     const G4VSolid* solid ;
0058     SEvt* sev ;
0059 #ifdef WITH_OLD_FRAME
0060     sframe frame = {} ;
0061 #else
0062     sfr fr = {} ;
0063 #endif
0064 
0065     SSimtrace();
0066     ~SSimtrace();
0067 
0068     void setSolid(const G4VSolid* solid);
0069     void simtrace();
0070 };
0071 
0072 #include "SEvt.hh"
0073 #include "SEventConfig.hh"
0074 #include "ssolid.h"
0075 #include "SLOG.hh"
0076 #include "NPFold.h"
0077 
0078 inline void SSimtrace::Scan(const G4VSolid* solid )
0079 {
0080     G4String soname_ = solid->GetName();
0081     const char* soname = soname_.c_str() ;
0082     //LOG(LEVEL) << "[ " << soname ;
0083 
0084     SEventConfig::SetEventReldir(soname);
0085 
0086     SSimtrace t ;
0087     t.setSolid(solid);
0088     t.simtrace();
0089 
0090     //LOG(LEVEL) << "] " << soname ;
0091 }
0092 
0093 inline SSimtrace::SSimtrace()
0094     :
0095     solid(nullptr),
0096     sev(nullptr)
0097 {
0098 }
0099 
0100 inline SSimtrace::~SSimtrace()
0101 {
0102     delete sev ;
0103 }
0104 
0105 inline void SSimtrace::setSolid(const G4VSolid* solid_)
0106 {
0107     solid = solid_ ;
0108 
0109     float4 ce = {} ;
0110 
0111     ssolid::GetCenterExtent(ce, solid );
0112 
0113 #ifdef WITH_OLD_FRAME
0114     frame.ce = ce ;
0115     LOG(LEVEL) << " frame.ce.w " << frame.ce.w ;
0116 #else
0117     fr.set_ce( &ce.x );
0118     LOG(LEVEL) << " fr.ce.w " << fr.ce.w ;
0119 #endif
0120 
0121 }
0122 
0123 /**
0124 SSimtrace::simtrace
0125 ---------------------
0126 
0127 SEvt::setFrame
0128 
0129 
0130 1. creates gensteps with SFrameGenstep::MakeCenterExtentGensteps and adds them to SEvt
0131 2. as frame.is_hostside_simtrace also generates simtrace "photons"
0132 
0133 
0134 SEvt::beginOfEvent invokes SEvt::addFrameGenstep
0135 which in RGModeSimtrace adds simtrace gensteps configured via envvars
0136 especially::
0137 
0138 CEGS : CenterExtentGensteps
0139     eg 16:0:9:5000 : specifies grid and photons per grid point
0140 
0141 Because SSimtrace::simtrace gets called for each solid with U4SimtraceTest.sh
0142 the instanciation of SEvt here in SSimtrace::simtrace is unusual,
0143 
0144 With simulate running SEvt is usually only ever instanciated once.
0145 
0146 **/
0147 
0148 inline void SSimtrace::simtrace()
0149 {
0150     SEventConfig::SetRGModeSimtrace();
0151 
0152 
0153 #ifdef WITH_OLD_FRAME
0154     frame.set_hostside_simtrace();
0155 #else
0156     fr.set_hostside_simtrace();
0157 #endif
0158 
0159     // set_hostside_simtrace into frame which
0160     // influences the action of SEvt::setFrame
0161     // especially SEvt::setFrame_HostsideSimtrace which
0162     // generates simtrace photons
0163 
0164     sev = SEvt::Create_ECPU() ;
0165 
0166 #ifdef WITH_OLD_FRAME
0167     sev->setFrame(frame);
0168 #else
0169     sev->setFr(fr);
0170 #endif
0171 
0172     int eventID = 0 ;
0173 
0174     sev->beginOfEvent(eventID);   // invokes SEvt::addFrameGenstep for RGModeSimtrace
0175 
0176     unsigned num_simtrace = sev->simtrace.size() ;
0177     LOG(LEVEL) << " num_simtrace " << num_simtrace ;
0178 
0179     bool dump = false ;
0180     for(unsigned i=0 ; i < num_simtrace ; i++)
0181     {
0182         quad4& p = sev->simtrace[i] ;
0183         ssolid::Simtrace(p, solid, dump);
0184     }
0185 
0186     sev->gather();
0187     sev->topfold->concat();
0188     sev->topfold->clear_subfold();
0189 
0190     sev->endOfEvent(eventID);
0191 }
0192 
0193