Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 SPhoton_Debug.h
0004 ================
0005 
0006 Include into a compilation unit with::
0007 
0008     #include "SPhoton_Debug.h"
0009     template<> std::vector<SPhoton_Debug<'A'>> SPhoton_Debug<'A'>::record = {} ;
0010 
0011 The template char allows multiple static "instances" to be used simultaneously, 
0012 eg in different implementations that are being compared. The char is used to 
0013 prefix the output filename. 
0014 
0015 Also add static Save method within the same compilation unit, eg::
0016 
0017     void junoPMTOpticalModel::Save(const char* fold) // static 
0018     {
0019         SPhoton_Debug<'A'>::Save(fold);   
0020     }
0021 
0022 Doing all the direct access to the SPhoton_Debug::record from 
0023 only one compilation unit avoids complications of symbol access and 
0024 allows SPhoton_Debug.h to stay headeronly which allows to void 
0025 SysRap needing to depend on Geant4.  
0026 Then from the main, eg u4/tests/U4PMTFastSimTest.cc invoke the Save::
0027 
0028      76     evt->save();
0029      77     const char* savedir = evt->getSaveDir();
0030      78     SFastSim_Debug::Save(savedir);
0031      79     junoPMTOpticalModel::Save(savedir);
0032   
0033 Essentially what this is doing is adopting a single home 
0034 for the record any only directly accessing it from there.  
0035 
0036 Add entries with::
0037  
0038     SPhoton_Debug<'A'> dbg ; 
0039 
0040     dbg.pos = ...
0041     dbg.normal = ...
0042 
0043     dbg.add()
0044 
0045 **/
0046 
0047 #include <cstdint>
0048 #include <vector>
0049 #include <string>
0050 #include "G4ThreeVector.hh"
0051 #include "NP.hh"    
0052 
0053 template<char N>
0054 struct SPhoton_Debug
0055 {
0056     static std::vector<SPhoton_Debug> record ;   
0057     static constexpr const char* NAME = "SPhoton_Debug.npy" ; 
0058     static constexpr const unsigned NUM_QUAD = 5u ; 
0059 
0060     static int Count(); 
0061     static std::string Name(); 
0062     static void Save(const char* dir); 
0063     void add(); 
0064     void fill(double value); 
0065 
0066     G4ThreeVector pos ;     // 0
0067     G4double     time ; 
0068 
0069     G4ThreeVector mom ;     // 1 
0070     uint64_t     iindex ; 
0071 
0072     G4ThreeVector pol ;     // 2 
0073     G4double      wavelength ; 
0074 
0075     G4ThreeVector nrm ;     // 3
0076     G4double      spare ; 
0077 
0078     G4double      u0 ;      // 4
0079     G4double      x1 ; 
0080     G4double      x2 ; 
0081     uint64_t      u0_idx ; 
0082 
0083 }; 
0084 
0085 template<char N>
0086 inline std::string SPhoton_Debug<N>::Name() // static
0087 {
0088     std::string name ; 
0089     name += N ; 
0090     name += '_' ; 
0091     name += NAME ; 
0092     return name ; 
0093 }
0094 
0095 template<char N>
0096 inline void SPhoton_Debug<N>::Save(const char* dir) // static
0097 {
0098     std::string name = Name(); 
0099     std::cout  
0100         << "SPhoton_Debug::Save"
0101         << " dir " << dir 
0102         << " name " << name
0103         << " num_record " << record.size() 
0104         << std::endl 
0105         ;
0106 
0107     if( record.size() > 0) NP::Write<double>(dir, name.c_str(), (double*)record.data(), record.size(), NUM_QUAD, 4 );  
0108     record.clear(); 
0109 }
0110 
0111 template<char N>
0112 inline int SPhoton_Debug<N>::Count()  // static
0113 {
0114     return record.size() ; 
0115 }
0116 
0117 template<char N>
0118 inline void SPhoton_Debug<N>::fill(double value)
0119 {
0120     for(unsigned i=0 ; i < 4*NUM_QUAD ; i++)  *((double*)&pos + i) = value ; 
0121 }
0122 
0123 template<char N>
0124 inline void SPhoton_Debug<N>::add()
0125 { 
0126     record.push_back(*this);  
0127 }
0128 
0129