Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:50:27

0001 /**
0002 U4HitTest.cc
0003 ==============
0004 
0005 ::
0006 
0007     ~/o/u4/tests/U4HitTest.sh run_cat
0008 
0009 
0010 **/
0011 
0012 #include "OPTICKS_LOG.hh"
0013 #include "SEvt.hh"
0014 #include "ssys.h"
0015 #include "SSim.hh"
0016 #include "SProf.hh"
0017 #include "spath.h"
0018 
0019 #include "CSGFoundry.h"
0020 
0021 #include "U4Hit.h"
0022 #include "U4HitGet.h"
0023 
0024 
0025 struct U4HitTest
0026 {
0027     const char* METHOD ;
0028     const char* rel ;
0029     int ins ;   // SEvt::EGPU
0030     int idx ;   // 1st valid index : A000
0031     SEvt* sev ;
0032     unsigned num_hit ;
0033     const char* cfbase ;
0034     const CSGFoundry* fd ;
0035     const SSim* sim ;
0036 
0037     sphoton global = {} ;
0038     sphit ht = {}  ;
0039     sphoton local = {}  ;
0040     U4Hit hit = {} ;
0041 
0042     sphit ht_alt = {}  ;
0043     sphoton local_alt = {}  ;
0044 
0045 
0046     int32_t delta_rs ;
0047     int32_t range_rs ;
0048     unsigned hit_idx ;
0049 
0050     std::string desc() const ;
0051 
0052     U4HitTest();
0053     void init();
0054 
0055     std::string dump() const ;
0056     std::string brief() const ;
0057     std::string smry() const ;
0058 
0059     void convertHit(unsigned hidx, bool is_repeat);
0060     void convertHit_LEAKY(unsigned hidx, bool is_repeat);
0061     void convertHit_COMPARE(unsigned hidx, bool is_repeat);
0062 
0063     void convertHits();
0064     void save() const ;
0065 };
0066 
0067 
0068 inline std::string U4HitTest::desc() const
0069 {
0070     std::stringstream ss ;
0071     ss << "U4HitTest::desc" << std::endl
0072        << "  sev   " << ( sev ? "YES" : "NO " ) << std::endl
0073        << " num_hit " << num_hit << std::endl
0074        << " cfbase " << ( cfbase ? cfbase : "-" ) << std::endl
0075        << " fd     " << ( fd ? "YES" : "NO " ) << std::endl
0076        ;
0077     std::string str = ss.str();
0078     return str ;
0079 }
0080 
0081 inline U4HitTest::U4HitTest()
0082     :
0083     METHOD(ssys::getenvvar("METHOD", "convertHit")),
0084     rel(nullptr),
0085     ins(0),
0086     idx(0),
0087     sev(SEvt::LoadRelative(rel, ins, idx)),
0088     num_hit(sev ? sev->getNumHit() : 0),
0089     cfbase(sev ? sev->getSearchCFBase() : nullptr),
0090     fd(cfbase ? CSGFoundry::Load(cfbase) : nullptr ),
0091     sim(fd ? fd->getSim() : nullptr ),
0092     delta_rs(0),
0093     range_rs(0),
0094     hit_idx(0)
0095 {
0096     init();
0097 }
0098 
0099 inline void U4HitTest::init()
0100 {
0101 #ifdef WITH_OLD_FRAME
0102     sev->setGeo(fd);
0103 #else
0104     sev->setSim(sim);
0105 #endif
0106 
0107     assert( sev->hasInstance() );  // check that the instance is persisted and retrieved (via domain metadata)
0108     assert( sev == SEvt::Get(sev->instance) );  // check the loaded SEvt got slotted in expected slot
0109 }
0110 
0111 
0112 inline std::string U4HitTest::dump() const
0113 {
0114     std::stringstream ss ;
0115     ss << "U4HitTest::dump" << std::endl
0116        << " hit_idx " << hit_idx
0117        << " Delta_RS " << delta_rs
0118        << std::endl
0119        << " global " << global.desc() << std::endl
0120        << " local " << local.desc() << std::endl
0121        << " hit " << hit.desc() << std::endl
0122        << " ht " << ht.desc() << std::endl
0123        ;
0124     std::string str = ss.str();
0125     return str ;
0126 }
0127 
0128 inline std::string U4HitTest::brief() const
0129 {
0130     std::stringstream ss ;
0131     ss << "U4HitTest::brief"
0132        << " hit_idx " << hit_idx
0133        << " Delta_RS " << delta_rs
0134        ;
0135     std::string str = ss.str();
0136     return str ;
0137 }
0138 
0139 inline std::string U4HitTest::smry() const
0140 {
0141     std::stringstream ss ;
0142     ss << "U4HitTest::smry" << std::endl
0143        << " METHOD " << METHOD
0144        << " num_hit " << num_hit
0145        << " SProf::Range_RS " << range_rs
0146        << " SProf::Range_RS/num_hit " << std::setw(10) << std::fixed << std::setprecision(4) << double(range_rs)/double(num_hit)
0147        << std::endl
0148        ;
0149     std::string str = ss.str();
0150     return str ;
0151 }
0152 
0153 
0154 inline void U4HitTest::convertHit(unsigned hidx, bool is_repeat)
0155 {
0156     SProf::SetTag(hidx);
0157     SProf::Add("Head");
0158 
0159     sev->getHit(global, hidx);
0160     sev->getLocalHit( ht, local,  hidx);
0161 
0162     U4HitGet::ConvertFromPhoton(hit,global,local, ht);
0163 
0164     SProf::Add("Tail");
0165     delta_rs = SProf::Delta_RS();
0166     range_rs = SProf::Range_RS();
0167     //LOG_IF(info, delta_rs > 0) << dump() ;
0168     LOG_IF(info, delta_rs > 0 || is_repeat) << brief() ;
0169 }
0170 
0171 inline void U4HitTest::convertHit_LEAKY(unsigned hidx, bool is_repeat)
0172 {
0173     SProf::SetTag(hidx);
0174     SProf::Add("Head");
0175 
0176     sev->getHit(global, hidx);
0177     sev->getLocalHit_LEAKY( ht_alt, local_alt,  hidx);
0178 
0179     U4HitGet::ConvertFromPhoton(hit,global,local_alt, ht_alt);
0180 
0181     SProf::Add("Tail");
0182     delta_rs = SProf::Delta_RS();
0183     range_rs = SProf::Range_RS();
0184     //LOG_IF(info, delta_rs > 0) << dump() ;
0185     LOG_IF(info, delta_rs > 0 || is_repeat) << brief() ;
0186 }
0187 
0188 inline void U4HitTest::convertHit_COMPARE(unsigned hidx, bool is_repeat)
0189 {
0190     SProf::SetTag(hidx);
0191     SProf::Add("Head");
0192 
0193     sev->getHit(global, hidx);
0194     sev->getLocalHit( ht, local,  hidx);
0195     sev->getLocalHit_LEAKY( ht_alt, local_alt,  hidx);
0196 
0197     bool local_equal_flags = sphoton::EqualFlags(local, local_alt) ;
0198 
0199     LOG_IF(fatal, !local_equal_flags)
0200          << "sphoton::EqualFlags FAIL "
0201          << " hidx : " << hidx
0202          << " local_equal_flags " << local_equal_flags
0203          << std::endl
0204          << " local " << std::endl << local << std::endl
0205          << " local_alt " << std::endl << local_alt << std::endl
0206          ;
0207 
0208     float4 local_delta = sphoton::DeltaMax(local, local_alt ) ;
0209     std::cout << " local_delta " << local_delta << std::endl ;
0210 
0211     bool ht_match = ht == ht_alt ;
0212     LOG_IF(fatal, !ht_match )
0213          << " hidx : " << hidx
0214          << " FATAL : NOT ht_match "
0215          << std::endl
0216          << " ht     : " << ht.desc()
0217          << std::endl
0218          << " ht_alt : " << ht_alt.desc()
0219          ;
0220 
0221 
0222     U4HitGet::ConvertFromPhoton(hit,global,local, ht);
0223 
0224     SProf::Add("Tail");
0225     delta_rs = SProf::Delta_RS();
0226     range_rs = SProf::Range_RS();
0227     //LOG_IF(info, delta_rs > 0) << dump() ;
0228     LOG_IF(info, delta_rs > 0 || is_repeat) << brief() ;
0229 
0230 }
0231 
0232 /**
0233 U4HitTest::convertHits
0234 ------------------------
0235 
0236 Trying to repeat a leaky hit, but the repeat doesnt leak
0237 Maybe cached/consolidated free or something. Means cannot
0238 fully trust RSS changes ?
0239 
0240 **/
0241 
0242 inline void U4HitTest::convertHits()
0243 {
0244     for(hit_idx=0 ; hit_idx < num_hit ; hit_idx++ )
0245     {
0246         delta_rs = 0 ;
0247 
0248         if(strcmp(METHOD, "convertHit") == 0 )
0249         {
0250             convertHit(hit_idx, false);
0251         }
0252         else if(strcmp(METHOD, "convertHit_COMPARE") == 0 )
0253         {
0254             convertHit_COMPARE(hit_idx, false);
0255         }
0256         else if(strcmp(METHOD, "convertHit_LEAKY") == 0 )
0257         {
0258             convertHit_LEAKY(hit_idx, false);
0259         }
0260 
0261         // if( delta_rs > 0 ) convertHit(hit_idx, true);
0262         // for leaky hit, do it again to check reproducibility : it doesnt reproduce the leak
0263     }
0264 }
0265 
0266 inline void U4HitTest::save() const
0267 {
0268     bool append = false ;
0269     //const char* _path = "$TMP/U4HitTest/U4HitTest.txt" ;
0270     //const char* path = spath::Resolve(_path) ;
0271     SProf::Write(append);
0272 }
0273 
0274 int main(int argc, char** argv)
0275 {
0276     OPTICKS_LOG(argc, argv);
0277     LOG(info) ;
0278 
0279     // SSim Create/Load needed before CSGFoundry::Load
0280 
0281     //SSim::Create();    // this creates an empty stree
0282     SSim::Load();   // imports GEOM default persisted stree
0283 
0284     U4HitTest test ;
0285 
0286     LOG(info) << test.desc() ;
0287     //LOG(info) << "test.sev->descFull" << std::endl << test.sev->descFull() ;
0288 
0289     if(test.num_hit == 0) return 0 ;
0290 
0291     test.convertHits();
0292     test.save();
0293 
0294     LOG(info) << test.smry() ;
0295 
0296     return 0 ;
0297 }
0298