Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 
0003 /**
0004 OpticksGenstep.h
0005 =================
0006 
0007 Genstep versioning
0008 
0009 Not using typedef enum for simplicity as
0010 this needs to be used everywhere.
0011 
0012 NB these were formely conflated with photon flags,
0013 but the needs are somewhat different.
0014 
0015 See also: npy/G4StepNPY.cpp  (TODO: consolidate these?)
0016 
0017 **/
0018 
0019 enum
0020 {
0021     OpticksGenstep_INVALID                  = 0,
0022     OpticksGenstep_G4Cerenkov_1042          = 1,
0023     OpticksGenstep_G4Scintillation_1042     = 2,
0024     OpticksGenstep_DsG4Cerenkov_r3971       = 3,
0025     OpticksGenstep_DsG4Scintillation_r3971  = 4,
0026     OpticksGenstep_DsG4Scintillation_r4695  = 5,
0027     OpticksGenstep_TORCH                    = 6,
0028     OpticksGenstep_FABRICATED               = 7,
0029     OpticksGenstep_EMITSOURCE               = 8,
0030     OpticksGenstep_NATURAL                  = 9,
0031     OpticksGenstep_MACHINERY                = 10,
0032     OpticksGenstep_G4GUN                    = 11,
0033     OpticksGenstep_PRIMARYSOURCE            = 12,
0034     OpticksGenstep_GENSTEPSOURCE            = 13,
0035     OpticksGenstep_CARRIER                  = 14,
0036     OpticksGenstep_CERENKOV                 = 15,
0037     OpticksGenstep_SCINTILLATION            = 16,
0038     OpticksGenstep_FRAME                    = 17,
0039     OpticksGenstep_G4Cerenkov_modified      = 18,
0040     OpticksGenstep_INPUT_PHOTON             = 19,
0041     OpticksGenstep_INPUT_PHOTON_SIMTRACE    = 20,
0042     OpticksGenstep_NumType                  = 21
0043 };
0044 
0045 
0046 #if defined(__CUDACC__) || defined(__CUDABE__)
0047 #else
0048 #include <cstring>
0049 #include <string>
0050 #include "OpticksPhoton.h"
0051 
0052 struct OpticksGenstep_
0053 {
0054     static constexpr const char* INVALID_                 = "INVALID" ;
0055     static constexpr const char* G4Cerenkov_1042_         = "G4Cerenkov_1042" ;
0056     static constexpr const char* G4Scintillation_1042_    = "G4Scintillation_1042" ;
0057     static constexpr const char* DsG4Cerenkov_r3971_      = "DsG4Cerenkov_r3971" ;
0058     static constexpr const char* DsG4Scintillation_r3971_ = "DsG4Scintillation_r3971" ;
0059     static constexpr const char* DsG4Scintillation_r4695_ = "DsG4Scintillation_r4695" ;
0060     static constexpr const char* TORCH_                   = "TORCH" ;
0061     static constexpr const char* FABRICATED_              = "FABRICATED" ;
0062     static constexpr const char* EMITSOURCE_              = "EMITSOURCE" ;
0063     static constexpr const char* NATURAL_                 = "NATURAL" ;
0064     static constexpr const char* MACHINERY_               = "MACHINERY" ;
0065     static constexpr const char* G4GUN_                   = "G4GUN" ;
0066     static constexpr const char* PRIMARYSOURCE_           = "PRIMARYSOURCE" ;
0067     static constexpr const char* GENSTEPSOURCE_           = "GENSTEPSOURCE" ;
0068     static constexpr const char* CARRIER_                 = "CARRIER" ;
0069     static constexpr const char* CERENKOV_                = "CERENKOV" ;
0070     static constexpr const char* SCINTILLATION_           = "SCINTILLATION" ;
0071     static constexpr const char* FRAME_                   = "FRAME" ;
0072     static constexpr const char* G4Cerenkov_modified_     = "G4Cerenkov_modified" ;
0073     static constexpr const char* INPUT_PHOTON_            = "INPUT_PHOTON" ;
0074     static constexpr const char* INPUT_PHOTON_SIMTRACE_   = "INPUT_PHOTON_SIMTRACE" ;
0075 
0076     static unsigned Type(const char* name);
0077     static unsigned Type(const std::string& name);
0078     static const char* Name(unsigned type);
0079 
0080     static bool IsValid(int gentype);
0081 
0082     static bool IsCerenkov(int gentype);
0083     static bool IsScintillation(int gentype);
0084     static bool IsTorchLike(int gentype);
0085     static bool IsInputPhoton(int gentype);
0086     static bool IsInputPhotonSimtrace(int gentype);
0087     static bool IsExpected(int gentype);
0088 
0089     static bool IsEmitSource(int gentype);
0090     static bool IsMachinery(int gentype);
0091     static bool IsFrame(int gentype);
0092     static unsigned GenstepToPhotonFlag(int gentype);
0093     static unsigned GentypeToPhotonFlag(char gentype); // 'C' 'S' 'T' -> CK, SI, TO
0094 
0095 };
0096 
0097 inline unsigned OpticksGenstep_::Type(const char* name)
0098 {
0099     unsigned type = OpticksGenstep_INVALID  ;
0100     if(strcmp(name,G4Cerenkov_1042_ )==0)         type = OpticksGenstep_G4Cerenkov_1042 ;
0101     if(strcmp(name,G4Scintillation_1042_ )==0)    type = OpticksGenstep_G4Scintillation_1042 ;
0102     if(strcmp(name,DsG4Cerenkov_r3971_ )==0)      type = OpticksGenstep_DsG4Cerenkov_r3971 ;
0103     if(strcmp(name,G4Cerenkov_modified_ )==0)     type = OpticksGenstep_G4Cerenkov_modified ;
0104     if(strcmp(name,DsG4Scintillation_r3971_ )==0) type = OpticksGenstep_DsG4Scintillation_r3971 ;
0105     if(strcmp(name,DsG4Scintillation_r4695_ )==0) type = OpticksGenstep_DsG4Scintillation_r4695 ;
0106     if(strcmp(name,TORCH_)==0)                    type = OpticksGenstep_TORCH ;
0107     if(strcmp(name,FABRICATED_)==0)               type = OpticksGenstep_FABRICATED ;
0108     if(strcmp(name,EMITSOURCE_)==0)               type = OpticksGenstep_EMITSOURCE ;
0109     if(strcmp(name,NATURAL_)==0)                  type = OpticksGenstep_NATURAL ;
0110     if(strcmp(name,MACHINERY_)==0)                type = OpticksGenstep_MACHINERY ;
0111     if(strcmp(name,G4GUN_)==0)                    type = OpticksGenstep_G4GUN ;
0112     if(strcmp(name,PRIMARYSOURCE_)==0)            type = OpticksGenstep_PRIMARYSOURCE ;
0113     if(strcmp(name,GENSTEPSOURCE_)==0)            type = OpticksGenstep_GENSTEPSOURCE ;
0114     if(strcmp(name,CARRIER_)==0)                  type = OpticksGenstep_CARRIER ;
0115     if(strcmp(name,CERENKOV_)==0)                 type = OpticksGenstep_CERENKOV ;
0116     if(strcmp(name,SCINTILLATION_)==0)            type = OpticksGenstep_SCINTILLATION ;
0117     if(strcmp(name,FRAME_)==0)                    type = OpticksGenstep_FRAME ;
0118     if(strcmp(name,INPUT_PHOTON_)==0)             type = OpticksGenstep_INPUT_PHOTON ;
0119     if(strcmp(name,INPUT_PHOTON_SIMTRACE_)==0)    type = OpticksGenstep_INPUT_PHOTON_SIMTRACE ;
0120     return type ;
0121 }
0122 
0123 inline unsigned OpticksGenstep_::Type(const std::string& name)
0124 {
0125     return Type(name.c_str());
0126 }
0127 
0128 inline const char* OpticksGenstep_::Name(unsigned type)
0129 {
0130     const char* n = INVALID_ ;
0131     switch(type)
0132     {
0133         case OpticksGenstep_INVALID:                 n = INVALID_                 ; break ;
0134         case OpticksGenstep_G4Cerenkov_1042:         n = G4Cerenkov_1042_         ; break ;
0135         case OpticksGenstep_G4Scintillation_1042:    n = G4Scintillation_1042_    ; break ;
0136         case OpticksGenstep_DsG4Cerenkov_r3971:      n = DsG4Cerenkov_r3971_      ; break ;
0137         case OpticksGenstep_G4Cerenkov_modified:     n = G4Cerenkov_modified_     ; break ;
0138         case OpticksGenstep_DsG4Scintillation_r3971: n = DsG4Scintillation_r3971_ ; break ;
0139         case OpticksGenstep_DsG4Scintillation_r4695: n = DsG4Scintillation_r4695_ ; break ;
0140         case OpticksGenstep_TORCH:                   n = TORCH_                   ; break ;
0141         case OpticksGenstep_FABRICATED:              n = FABRICATED_              ; break ;
0142         case OpticksGenstep_EMITSOURCE:              n = EMITSOURCE_              ; break ;
0143         case OpticksGenstep_NATURAL:                 n = NATURAL_                 ; break ;
0144         case OpticksGenstep_MACHINERY:               n = MACHINERY_               ; break ;
0145         case OpticksGenstep_G4GUN:                   n = G4GUN_                   ; break ;
0146         case OpticksGenstep_PRIMARYSOURCE:           n = PRIMARYSOURCE_           ; break ;
0147         case OpticksGenstep_GENSTEPSOURCE:           n = GENSTEPSOURCE_           ; break ;
0148         case OpticksGenstep_CARRIER:                 n = CARRIER_                 ; break ;
0149         case OpticksGenstep_CERENKOV:                n = CERENKOV_                ; break ;
0150         case OpticksGenstep_SCINTILLATION:           n = SCINTILLATION_           ; break ;
0151         case OpticksGenstep_FRAME:                   n = FRAME_                   ; break ;
0152         case OpticksGenstep_INPUT_PHOTON:            n = INPUT_PHOTON_            ; break ;
0153         case OpticksGenstep_INPUT_PHOTON_SIMTRACE:   n = INPUT_PHOTON_SIMTRACE_   ; break ;
0154         case OpticksGenstep_NumType:                 n = INVALID_                 ; break ;
0155         default:                                     n = INVALID_                 ; break ;
0156     }
0157     return n ;
0158 }
0159 
0160 
0161 inline bool OpticksGenstep_::IsValid(int gentype)   // static
0162 {
0163    const char* s = Name(gentype);
0164    bool invalid = strcmp(s, INVALID_) == 0 ;
0165    return !invalid ;
0166 }
0167 
0168 inline bool OpticksGenstep_::IsCerenkov(int gentype)  // static
0169 {
0170    return gentype == OpticksGenstep_G4Cerenkov_1042  ||
0171           gentype == OpticksGenstep_DsG4Cerenkov_r3971 ||
0172           gentype == OpticksGenstep_CERENKOV ||
0173           gentype == OpticksGenstep_G4Cerenkov_modified
0174           ;
0175 }
0176 inline bool OpticksGenstep_::IsScintillation(int gentype)  // static
0177 {
0178    return gentype == OpticksGenstep_G4Scintillation_1042 ||
0179           gentype == OpticksGenstep_DsG4Scintillation_r3971 ||
0180           gentype == OpticksGenstep_DsG4Scintillation_r4695 ||
0181           gentype == OpticksGenstep_SCINTILLATION
0182          ;
0183 }
0184 inline bool OpticksGenstep_::IsTorchLike(int gentype)   // static
0185 {
0186    return gentype == OpticksGenstep_TORCH ||
0187           gentype == OpticksGenstep_FABRICATED ||
0188           gentype == OpticksGenstep_EMITSOURCE ||
0189           gentype == OpticksGenstep_FRAME     ||
0190           gentype == OpticksGenstep_INPUT_PHOTON ||
0191           gentype == OpticksGenstep_INPUT_PHOTON_SIMTRACE
0192           ;
0193 }
0194 
0195 inline bool OpticksGenstep_::IsInputPhoton(int gentype)   // static
0196 {
0197     return gentype == OpticksGenstep_INPUT_PHOTON ;
0198 }
0199 inline bool OpticksGenstep_::IsInputPhotonSimtrace(int gentype)   // static
0200 {
0201     return gentype == OpticksGenstep_INPUT_PHOTON_SIMTRACE ;
0202 }
0203 
0204 
0205 inline bool OpticksGenstep_::IsExpected(int gentype) // static
0206 {
0207     return IsCerenkov(gentype) || IsScintillation(gentype) || IsTorchLike(gentype) ;
0208 }
0209 
0210 inline bool OpticksGenstep_::IsEmitSource(int gentype)   // static
0211 {
0212    return gentype == OpticksGenstep_EMITSOURCE ;
0213 }
0214 inline bool OpticksGenstep_::IsMachinery(int gentype)  // static
0215 {
0216    return gentype == OpticksGenstep_MACHINERY ;
0217 }
0218 inline bool OpticksGenstep_::IsFrame(int gentype)  // static
0219 {
0220    return gentype == OpticksGenstep_FRAME ;
0221 }
0222 
0223 
0224 
0225 inline unsigned OpticksGenstep_::GenstepToPhotonFlag(int gentype)  // static
0226 {
0227     unsigned phcode = 0 ;
0228     if(!IsValid(gentype))
0229     {
0230         phcode = NAN_ABORT ;
0231     }
0232     else if(IsCerenkov(gentype))
0233     {
0234         phcode = CERENKOV ;
0235     }
0236     else if(IsScintillation(gentype))
0237     {
0238         phcode = SCINTILLATION ;
0239     }
0240     else if(IsTorchLike(gentype))
0241     {
0242         phcode = TORCH ;
0243     }
0244     else
0245     {
0246         phcode = NAN_ABORT ;
0247     }
0248     return phcode ;
0249 }
0250 
0251 inline unsigned OpticksGenstep_::GentypeToPhotonFlag(char gentype)  // static
0252 {
0253     unsigned phcode = 0 ;
0254     switch(gentype)
0255     {
0256         case 'C': phcode = CERENKOV          ; break ;
0257         case 'S': phcode = SCINTILLATION     ; break ;
0258         case 'T': phcode = TORCH             ; break ;
0259         default:  phcode = NAN_ABORT         ; break ;
0260     }
0261     return phcode ;
0262 }
0263 
0264 
0265 #endif
0266 
0267