Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 
0003 /**
0004 SProcessHits_EPH.h
0005 ====================
0006 
0007 ~/o/sysrap/tests/SProcessHits_EPH_test.sh
0008 
0009 **/
0010 
0011 
0012 #include <string>
0013 #include <sstream>
0014 #include <iomanip>
0015 #include <vector>
0016 #include <cstdint>
0017 #include "NP.hh"
0018 
0019 namespace EPH
0020 {
0021     // enumerate ProcessHits return
0022     enum {
0023        UNSET,        // 0
0024        NDIS,         // 1
0025        NOPT,         // 2
0026        NEDEP,        // 3
0027        NBOUND,       // 4
0028        NPROC,        // 5
0029        NDETECT,      // 6
0030        NDECULL,      // 7
0031        YMERGE,       // 8
0032        YSAVE,        // 9
0033        SAVENORM,     // 10
0034        SAVEMUON      // 11
0035     };
0036 
0037     static constexpr const char* UNSET_   = "EPH_UNSET" ;   // 0
0038     static constexpr const char* NDIS_    = "EPH_NDIS" ;    // 1
0039     static constexpr const char* NOPT_    = "EPH_NOPT" ;    // 2
0040     static constexpr const char* NEDEP_   = "EPH_NEDEP" ;   // 3
0041     static constexpr const char* NBOUND_  = "EPH_NBOUND" ;  // 4
0042     static constexpr const char* NPROC_   = "EPH_NPROC" ;   // 5
0043     static constexpr const char* NDETECT_ = "EPH_NDETECT" ; // 6
0044     static constexpr const char* NDECULL_ = "EPH_NDECULL" ; // 7
0045     static constexpr const char* YMERGE_  = "EPH_YMERGE" ;  // 8
0046     static constexpr const char* YSAVE_   = "EPH_YSAVE" ;   // 9
0047     static constexpr const char* SAVENORM_ = "EPH_SAVENORM" ; // 10
0048     static constexpr const char* SAVEMUON_ = "EPH_SAVEMUON" ; // 11
0049 
0050 
0051     static const char* Name(int eph)
0052     {
0053         const char* sn = nullptr ;
0054         switch(eph)
0055         {
0056             case UNSET:   sn = UNSET_    ; break ;  // 0
0057             case NDIS:    sn = NDIS_     ; break ;  // 1
0058             case NOPT:    sn = NOPT_     ; break ;  // 2
0059             case NEDEP:   sn = NEDEP_    ; break ;  // 3
0060             case NBOUND:  sn = NBOUND_   ; break ;  // 4
0061             case NPROC:   sn = NPROC_    ; break ;  // 5
0062             case NDETECT: sn = NDETECT_  ; break ;  // 6
0063             case NDECULL: sn = NDECULL_  ; break ;  // 7
0064             case YMERGE:  sn = YMERGE_   ; break ;  // 8
0065             case YSAVE:   sn = YSAVE_    ; break ;  // 9
0066             case SAVENORM: sn = SAVENORM_  ; break ;  // 10
0067             case SAVEMUON: sn = SAVEMUON_  ; break ;  // 11
0068         }
0069         return sn ;
0070     }
0071 
0072     static void GetNames(std::vector<std::string>& names)
0073     {
0074         names.push_back(Name(UNSET));   // 0
0075         names.push_back(Name(NDIS));    // 1
0076         names.push_back(Name(NOPT));    // 2
0077         names.push_back(Name(NEDEP));   // 3
0078         names.push_back(Name(NBOUND));  // 4
0079         names.push_back(Name(NPROC));   // 5
0080         names.push_back(Name(NDETECT)); // 6
0081         names.push_back(Name(NDECULL)); // 7
0082         names.push_back(Name(YMERGE));  // 8
0083         names.push_back(Name(YSAVE));   // 9
0084         names.push_back(Name(SAVENORM)); // 10
0085         names.push_back(Name(SAVEMUON)); // 11
0086     }
0087     // end of EPH namespace
0088 }
0089 
0090 
0091 struct SProcessHits_EPH
0092 {
0093     static constexpr const char* ProcessHits_count_ = "ProcessHits_count" ;
0094     static constexpr const char* ProcessHits_true_  = "ProcessHits_true" ;
0095     static constexpr const char* ProcessHits_false_ = "ProcessHits_false" ;
0096     static constexpr const char* SaveNormHit_count_ = "SaveNormHit_count" ;
0097     static constexpr const char* SaveMuonHit_count_ = "SaveMuonHit_count" ;
0098 
0099     static constexpr const char* Initialize_G4HCofThisEvent_opticksMode_ = "Initialize_G4HCofThisEvent_opticksMode" ;
0100     static constexpr const char* Initialize_G4HCofThisEvent_count_ = "Initialize_G4HCofThisEvent_count" ;
0101 
0102     static constexpr const char* EndOfEvent_Simulate_eventID_         = "EndOfEvent_Simulate_eventID" ;
0103     static constexpr const char* EndOfEvent_Simulate_count_           = "EndOfEvent_Simulate_count" ;
0104     static constexpr const char* EndOfEvent_Simulate_EGPU_hit_        = "EndOfEvent_Simulate_EGPU_hit" ;
0105     static constexpr const char* EndOfEvent_Simulate_merged_count_    = "EndOfEvent_Simulate_merged_count" ;
0106     static constexpr const char* EndOfEvent_Simulate_savehit_count_   = "EndOfEvent_Simulate_savehit_count" ;
0107     static constexpr const char* EndOfEvent_Simulate_merged_total_    = "EndOfEvent_Simulate_merged_total" ;
0108     static constexpr const char* EndOfEvent_Simulate_savehit_total_   = "EndOfEvent_Simulate_savehit_total" ;
0109 
0110 
0111     static constexpr const char* EndOfEvent_hitCollection_entries0_ = "EndOfEvent_hitCollection_entries0" ;
0112     static constexpr const char* EndOfEvent_hitCollection_entries1_ = "EndOfEvent_hitCollection_entries1" ;
0113     static constexpr const char* EndOfEvent_hitCollectionAlt_entries0_ = "EndOfEvent_hitCollectionAlt_entries0" ;
0114     static constexpr const char* EndOfEvent_hitCollectionAlt_entries1_ = "EndOfEvent_hitCollectionAlt_entries1" ;
0115 
0116     static constexpr const char* SUM_merged_count_savehit_count_   = "SUM_merged_count_savehit_count" ;
0117     static constexpr const char* SUM_merged_total_savehit_total_   = "SUM_merged_total_savehit_total" ;
0118 
0119 
0120     static constexpr const char* NOTES = R"LITERAL(
0121 SProcessHits_EPH::NOTES
0122 ------------------------
0123 
0124 ProcessHits_count
0125 ProcessHits_true
0126 ProcessHits_false
0127     number of calls to *SProcessHits_EPH::add* and sub-counts where is_hit is true/false,
0128     done from junoSD_PMT_v2::ProcessHits
0129 
0130 SaveNormHit_count
0131 SaveMuonHit_count
0132     counts collected from junoSD_PMT_v2::SaveNormHit junoSD_PMT_v2::SaveMuonHit
0133 
0134 All 7 EndOfEvent_Simulate values are collected from junoSD_PMT_v2_Opticks::EndOfEvent_Simulate
0135 
0136 EndOfEvent_Simulate_EGPU_hit
0137     Opticks GPU num_hit returned from SEvt::GetNumHit_EGPU() immediately following G4CXOpticks::simulate call
0138 
0139 EndOfEvent_Simulate_merged_count
0140 EndOfEvent_Simulate_savehit_count
0141     The sum of merged_count and savehit_count should sum to EGPU_hit in opticksMode:1
0142 
0143 EndOfEvent_Simulate_merged_total
0144 EndOfEvent_Simulate_savehit_total
0145     The totals sum over all events
0146 
0147 EndOfEvent_hitCollection_entries0
0148 EndOfEvent_hitCollection_entries1
0149 EndOfEvent_hitCollectionAlt_entries0
0150 EndOfEvent_hitCollectionAlt_entries1
0151     entries into hitCollection and hitCollectionAlt before and after the
0152     call to junoSD_PMT_v2_Opticks::EndOfEvent.
0153     This is recorded from junoSD_PMT_v2::EndOfEvent.
0154 
0155     In all cases entries0 are expected to be zero with entries1
0156     for the active collection matching the savehit_count
0157 
0158     For opticksMode:1 only hitCollection should be active,
0159     it contains the GPU originated hits.
0160 
0161     For opticksMode:3 both hitCollection and hitCollectionAlt should
0162     be active with hitCollection containing CPU hits and
0163     hitCollectionAlt containing GPU hits.
0164 
0165 )LITERAL" ;
0166 
0167 
0168     int64_t ProcessHits_count ;
0169     int64_t ProcessHits_true  ;
0170     int64_t ProcessHits_false ;
0171     int64_t SaveNormHit_count ;
0172     int64_t SaveMuonHit_count ;
0173 
0174     int64_t UNSET ;         // 0
0175     int64_t NDIS ;          // 1
0176     int64_t NOPT ;          // 2
0177     int64_t NEDEP ;         // 3
0178     int64_t NBOUND ;        // 4
0179     int64_t NPROC ;         // 5
0180     int64_t NDETECT ;       // 6
0181     int64_t NDECULL ;       // 7
0182     int64_t YMERGE ;        // 8
0183     int64_t YSAVE ;         // 9
0184     int64_t SAVENORM ;       // 10
0185     int64_t SAVEMUON ;       // 11
0186 
0187 
0188     int64_t Initialize_G4HCofThisEvent_opticksMode ;
0189     int64_t Initialize_G4HCofThisEvent_count ;
0190 
0191     int64_t EndOfEvent_Simulate_eventID ;
0192     int64_t EndOfEvent_Simulate_count ;
0193     int64_t EndOfEvent_Simulate_EGPU_hit ;
0194     int64_t EndOfEvent_hitCollection_entries0 ;
0195     int64_t EndOfEvent_hitCollection_entries1 ;
0196     int64_t EndOfEvent_hitCollectionAlt_entries0 ;
0197     int64_t EndOfEvent_hitCollectionAlt_entries1 ;
0198     int64_t EndOfEvent_Simulate_merged_count ;
0199     int64_t EndOfEvent_Simulate_savehit_count ;
0200     int64_t EndOfEvent_Simulate_merged_total ;
0201     int64_t EndOfEvent_Simulate_savehit_total ;
0202 
0203     SProcessHits_EPH();
0204     void zero() ;
0205 
0206     int64_t SUM_merged_count_savehit_count() const ;
0207     int64_t SUM_merged_total_savehit_total() const ;
0208     std::string desc_kv(const char* key, int64_t value) const ;
0209     std::string desc() const ;
0210     void add(int eph, bool processHits);
0211     void get_kvs( std::vector<std::pair<std::string, int64_t>>& kv ) const ;
0212 
0213     NP* get_meta_array() const ;  // dummy array that carries metadata
0214 
0215 };
0216 
0217 
0218 inline SProcessHits_EPH::SProcessHits_EPH()
0219 {
0220     zero();
0221 }
0222 inline void SProcessHits_EPH::zero()
0223 {
0224     ProcessHits_count = 0 ;
0225     ProcessHits_true = 0 ;
0226     ProcessHits_false = 0 ;
0227     SaveNormHit_count = 0 ;
0228     SaveMuonHit_count = 0 ;
0229 
0230     UNSET = 0 ;
0231     NDIS = 0 ;
0232     NOPT = 0 ;
0233     NEDEP = 0 ;
0234     NBOUND = 0 ;
0235     NPROC = 0 ;
0236     NDETECT = 0 ;
0237     NDECULL = 0 ;
0238     YMERGE = 0 ;
0239     YSAVE = 0 ;
0240     SAVENORM = 0 ;
0241     SAVEMUON = 0 ;
0242 
0243     Initialize_G4HCofThisEvent_opticksMode = 0 ;
0244     Initialize_G4HCofThisEvent_count = 0 ;
0245 
0246     EndOfEvent_Simulate_eventID = 0 ;
0247     EndOfEvent_Simulate_count = 0 ;
0248     EndOfEvent_Simulate_EGPU_hit = 0 ;
0249     EndOfEvent_hitCollection_entries0 = 0 ;
0250     EndOfEvent_hitCollection_entries1 = 0 ;
0251     EndOfEvent_hitCollectionAlt_entries0 = 0 ;
0252     EndOfEvent_hitCollectionAlt_entries1 = 0 ;
0253     EndOfEvent_Simulate_merged_count = 0 ;
0254     EndOfEvent_Simulate_savehit_count = 0 ;
0255     EndOfEvent_Simulate_merged_total = 0 ;
0256     EndOfEvent_Simulate_savehit_total = 0 ;
0257 }
0258 
0259 inline int64_t SProcessHits_EPH::SUM_merged_count_savehit_count() const
0260 {
0261     return EndOfEvent_Simulate_merged_count + EndOfEvent_Simulate_savehit_count ;
0262 }
0263 inline int64_t SProcessHits_EPH::SUM_merged_total_savehit_total() const
0264 {
0265     return EndOfEvent_Simulate_merged_total + EndOfEvent_Simulate_savehit_total ;
0266 }
0267 
0268 inline std::string SProcessHits_EPH::desc_kv(const char* key, int64_t value) const
0269 {
0270     int wk = 50 ;
0271     int wv = 15 ;
0272     std::stringstream ss ;
0273     ss << std::setw(wk) << key 
0274        << std::setw(wv) << value 
0275        << "       "
0276        << std::setw(wv) << std::fixed << std::setprecision(6) << double(value)/1.e6   
0277        << "    /M "
0278        ;
0279     std::string str = ss.str();
0280     return str ;
0281 }
0282 
0283 inline std::string SProcessHits_EPH::desc() const
0284 {
0285     typedef std::pair<std::string, int64_t> SI ;
0286     typedef std::vector<SI> VSI ;
0287     VSI kvs ;
0288     get_kvs(kvs);
0289     std::stringstream ss ;
0290     ss << "[SProcessHits_EPH::desc\n" ;
0291     for(int i=0 ; i < int(kvs.size()) ; i++)
0292     {
0293          const char* key = kvs[i].first.c_str();
0294          int64_t value = kvs[i].second ;
0295 
0296          if(strcmp(key,Initialize_G4HCofThisEvent_opticksMode_)==0) ss << "\n" ;
0297          if(strcmp(key,EndOfEvent_Simulate_EGPU_hit_)==0)           ss << "\n" ;
0298          if(strcmp(key,EndOfEvent_Simulate_merged_count_)==0)       ss << "\n" ;
0299          if(strcmp(key,EndOfEvent_Simulate_merged_total_)==0)       ss << "\n" ;
0300 
0301          ss << desc_kv( key, value ) << "\n" ; 
0302 
0303          if(strcmp(key,EndOfEvent_Simulate_savehit_count_)==0)
0304              ss << desc_kv( SUM_merged_count_savehit_count_, SUM_merged_count_savehit_count()) << "\n" ;
0305 
0306          if(strcmp(key,EndOfEvent_Simulate_savehit_total_)==0)
0307              ss << desc_kv( SUM_merged_total_savehit_total_, SUM_merged_total_savehit_total()) << "\n" ;
0308     }
0309     ss << NOTES ;
0310     ss << "]SProcessHits_EPH::desc\n" ;
0311     std::string str = ss.str();
0312     return str ;
0313 }
0314 
0315 
0316 inline void SProcessHits_EPH::add(int eph, bool is_hit )
0317 {
0318     ProcessHits_count  += 1 ;
0319     ProcessHits_true   += int(is_hit) ;
0320     ProcessHits_false  += int(!is_hit) ;
0321 
0322     switch(eph)
0323     {
0324         case EPH::UNSET:   UNSET   += 1 ; break ;  // 0
0325         case EPH::NDIS:    NDIS    += 1 ; break ;  // 1
0326         case EPH::NOPT:    NOPT    += 1 ; break ;  // 2
0327         case EPH::NEDEP:   NEDEP   += 1 ; break ;  // 3
0328         case EPH::NBOUND:  NBOUND  += 1 ; break ;  // 4
0329         case EPH::NPROC:   NPROC   += 1 ; break ;  // 5
0330         case EPH::NDETECT: NDETECT += 1 ; break ;  // 6
0331         case EPH::NDECULL: NDECULL += 1 ; break ;  // 7
0332         case EPH::YMERGE:  YMERGE  += 1 ; break ;  // 8
0333         case EPH::YSAVE:   YSAVE   += 1 ; break ;  // 9
0334         case EPH::SAVENORM: SAVENORM += 1 ; break ;  // 10
0335         case EPH::SAVEMUON: SAVEMUON += 1 ; break ;  // 11
0336     }
0337 }
0338 
0339 
0340 
0341 
0342 inline void SProcessHits_EPH::get_kvs( std::vector<std::pair<std::string, int64_t>>& kvs ) const
0343 {
0344     typedef std::pair<std::string, int64_t> KV ;
0345     kvs.push_back(KV(ProcessHits_count_, ProcessHits_count));
0346     kvs.push_back(KV(ProcessHits_true_, ProcessHits_true));
0347     kvs.push_back(KV(ProcessHits_false_, ProcessHits_false));
0348     kvs.push_back(KV(SaveNormHit_count_, SaveNormHit_count));
0349     kvs.push_back(KV(SaveMuonHit_count_, SaveMuonHit_count));
0350 
0351     kvs.push_back(KV(EPH::UNSET_, UNSET));
0352     kvs.push_back(KV(EPH::NDIS_, NDIS));
0353     kvs.push_back(KV(EPH::NOPT_, NOPT));
0354     kvs.push_back(KV(EPH::NEDEP_, NEDEP));
0355     kvs.push_back(KV(EPH::NBOUND_, NBOUND));
0356     kvs.push_back(KV(EPH::NPROC_, NPROC));
0357     kvs.push_back(KV(EPH::NDETECT_, NDETECT));
0358     kvs.push_back(KV(EPH::NDECULL_, NDECULL));
0359     kvs.push_back(KV(EPH::YMERGE_, YMERGE));
0360     kvs.push_back(KV(EPH::YSAVE_, YSAVE));
0361     kvs.push_back(KV(EPH::SAVENORM_, SAVENORM));
0362     kvs.push_back(KV(EPH::SAVEMUON_, SAVEMUON));
0363 
0364     kvs.push_back(KV(Initialize_G4HCofThisEvent_opticksMode_, Initialize_G4HCofThisEvent_opticksMode));
0365     kvs.push_back(KV(Initialize_G4HCofThisEvent_count_, Initialize_G4HCofThisEvent_count));
0366 
0367     kvs.push_back(KV(EndOfEvent_Simulate_eventID_,    EndOfEvent_Simulate_eventID));
0368     kvs.push_back(KV(EndOfEvent_Simulate_count_,    EndOfEvent_Simulate_count));
0369     kvs.push_back(KV(EndOfEvent_Simulate_EGPU_hit_, EndOfEvent_Simulate_EGPU_hit));
0370     kvs.push_back(KV(EndOfEvent_hitCollection_entries0_, EndOfEvent_hitCollection_entries0));
0371     kvs.push_back(KV(EndOfEvent_hitCollection_entries1_, EndOfEvent_hitCollection_entries1));
0372     kvs.push_back(KV(EndOfEvent_hitCollectionAlt_entries0_, EndOfEvent_hitCollectionAlt_entries0));
0373     kvs.push_back(KV(EndOfEvent_hitCollectionAlt_entries1_, EndOfEvent_hitCollectionAlt_entries1));
0374     kvs.push_back(KV(EndOfEvent_Simulate_merged_count_,  EndOfEvent_Simulate_merged_count));
0375     kvs.push_back(KV(EndOfEvent_Simulate_savehit_count_, EndOfEvent_Simulate_savehit_count));
0376     kvs.push_back(KV(EndOfEvent_Simulate_merged_total_,  EndOfEvent_Simulate_merged_total));
0377     kvs.push_back(KV(EndOfEvent_Simulate_savehit_total_, EndOfEvent_Simulate_savehit_total));
0378 }
0379 
0380 
0381 inline NP* SProcessHits_EPH::get_meta_array() const
0382 {
0383     NP* meta = NP::Make<int>(1) ;
0384     EPH::GetNames(meta->names) ;
0385 
0386     std::vector<std::pair<std::string, int64_t>> kvs ;
0387     get_kvs(kvs);
0388     meta->set_meta_kv(kvs);
0389     return meta ;
0390 }
0391 
0392