Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 U4Stack : classifying SBacktrace stack summaries used from U4Random::getFlatTag 
0004 ==================================================================================
0005 
0006 Notice this makes the assumption that the backtrace of a U4Random::flat call 
0007 is distinctive enough to identify what the random throw is being used for.
0008 Multiple different uses of G4UniformRand within a single method could 
0009 easily break this approach. 
0010 
0011 It would then be necessary to develop some more complicated ways 
0012 to identify the purpose of the random.  
0013 
0014 CAUTION : trailing blanks in the stack summry literal strings could 
0015 easily prevent matches. Use "set list" in vim to check. 
0016 **/
0017 
0018 #include <cassert>
0019 #include <cstring>
0020 #include "stag.h"
0021 
0022 enum 
0023 {
0024     U4Stack_Unclassified            = 0,
0025     U4Stack_RestDiscreteReset       = 1,
0026     U4Stack_DiscreteReset           = 2, 
0027     U4Stack_ScintDiscreteReset      = 3,
0028     U4Stack_BoundaryDiscreteReset   = 4,
0029     U4Stack_RayleighDiscreteReset   = 5,
0030     U4Stack_AbsorptionDiscreteReset = 6,
0031     U4Stack_BoundaryBurn_SurfaceReflectTransmitAbsorb = 7,
0032     U4Stack_BoundaryDiDiTransCoeff  = 8,
0033     U4Stack_AbsorptionEffDetect     = 9,
0034     U4Stack_RayleighScatter         = 10,
0035     U4Stack_BoundaryDiMeReflectivity = 11,
0036     U4Stack_ChooseReflection         = 12,
0037     U4Stack_RandomDirection          = 13,
0038     U4Stack_LambertianRand           = 14,
0039     U4Stack_Reemission               = 15
0040 
0041 };
0042 
0043 struct U4Stack 
0044 {
0045     static const char* Name(unsigned stack); 
0046     static unsigned Code(const char* name); 
0047     static unsigned TagToStack(unsigned tag); 
0048 
0049     static constexpr const char* Unclassified_      = "Unclassified" ;        // 0
0050     static constexpr const char* RestDiscreteReset_ = "RestDiscreteReset" ;   // 1: not used as use Shims to idenify processes in SBacktrace
0051     static constexpr const char* DiscreteReset_ = "DiscreteReset" ; // 2    : G4OpAbsoption G4OpRayleigh but now use Shims to identify 
0052     static constexpr const char* ScintDiscreteReset_ = "ScintDiscreteReset" ;  // 3
0053     static constexpr const char* BoundaryDiscreteReset_ = "BoundaryDiscreteReset" ; // 4
0054     static constexpr const char* RayleighDiscreteReset_ = "RayleighDiscreteReset" ;  // 5
0055     static constexpr const char* AbsorptionDiscreteReset_ = "AbsorptionDiscreteReset" ; // 6
0056     static constexpr const char* BoundaryBurn_SurfaceReflectTransmitAbsorb_ = "BoundaryBurn_SurfaceReflectTransmitAbsorb" ;  // 7
0057     static constexpr const char* BoundaryDiDiTransCoeff_ = "BoundaryDiDiTransCoeff" ;  // 8 
0058     static constexpr const char* AbsorptionEffDetect_ = "AbsorptionEffDetect" ;   // 9 
0059     static constexpr const char* RayleighScatter_ = "RayleighScatter" ;  // 10 
0060     static constexpr const char* BoundaryDiMeReflectivity_ = "BoundaryDiMeReflectivity" ;  // 11 
0061     static constexpr const char* ChooseReflection_ = "ChooseReflection" ; // 12
0062     static constexpr const char* RandomDirection_ = "RandomDirection" ; // 13
0063     static constexpr const char* LambertianRand_ = "LambertianRand" ; // 14
0064     static constexpr const char* Reemission_ = "Reemission" ; // 14
0065 
0066 
0067     static constexpr const char* BoundaryBurn_SurfaceReflectTransmitAbsorb_note = R"(
0068 BoundaryBurn_SurfaceReflectTransmitAbsorb : Chameleon Rand 
0069 ------------------------------------------------------------
0070 
0071 BoundaryBurn
0072     when no surface is associated to a boundary this random does nothing : always a burn 
0073 
0074 SurfaceReflectTransmitAbsorb
0075     when a surface with reflectivity less than 1. is associated this rand comes alive 
0076     and determines the reflect/absorb/transmit decision  
0077 
0078 )" ; 
0079 
0080 
0081 }; 
0082 
0083 
0084 inline const char* U4Stack::Name(unsigned stack)
0085 {
0086     const char* s = nullptr ; 
0087     switch(stack)
0088     {
0089         case U4Stack_Unclassified:                  s = Unclassified_            ; break ; 
0090         case U4Stack_RestDiscreteReset:             s = RestDiscreteReset_       ; break ; 
0091         case U4Stack_DiscreteReset:                 s = DiscreteReset_           ; break ; 
0092         case U4Stack_ScintDiscreteReset:            s = ScintDiscreteReset_      ; break ; 
0093         case U4Stack_BoundaryDiscreteReset:         s = BoundaryDiscreteReset_   ; break ; 
0094         case U4Stack_RayleighDiscreteReset:         s = RayleighDiscreteReset_   ; break ; 
0095         case U4Stack_AbsorptionDiscreteReset:       s = AbsorptionDiscreteReset_ ; break ; 
0096         case U4Stack_BoundaryBurn_SurfaceReflectTransmitAbsorb: s = BoundaryBurn_SurfaceReflectTransmitAbsorb_  ; break ; 
0097         case U4Stack_BoundaryDiDiTransCoeff:        s = BoundaryDiDiTransCoeff_  ; break ; 
0098         case U4Stack_AbsorptionEffDetect:           s = AbsorptionEffDetect_     ; break ; 
0099         case U4Stack_RayleighScatter:               s = RayleighScatter_         ; break ; 
0100         case U4Stack_BoundaryDiMeReflectivity:      s = BoundaryDiMeReflectivity_ ; break ;
0101         case U4Stack_ChooseReflection:              s = ChooseReflection_         ; break ; 
0102         case U4Stack_RandomDirection:               s = RandomDirection_         ; break ; 
0103         case U4Stack_LambertianRand:                s = LambertianRand_         ; break ; 
0104         case U4Stack_Reemission:                    s = Reemission_         ; break ; 
0105     }
0106     if(s) assert( Code(s) == stack ) ; 
0107     return s ; 
0108 }
0109 
0110 inline unsigned U4Stack::Code(const char* name)
0111 {
0112     unsigned stack = U4Stack_Unclassified ; 
0113     if(strcmp(name, Unclassified_) == 0 )                  stack = U4Stack_Unclassified  ; 
0114     if(strcmp(name, RestDiscreteReset_) == 0 )             stack = U4Stack_RestDiscreteReset  ;
0115     if(strcmp(name, DiscreteReset_) == 0)                  stack = U4Stack_DiscreteReset ; 
0116     if(strcmp(name, ScintDiscreteReset_) == 0 )            stack = U4Stack_ScintDiscreteReset  ;
0117     if(strcmp(name, BoundaryDiscreteReset_) == 0)          stack = U4Stack_BoundaryDiscreteReset ; 
0118     if(strcmp(name, RayleighDiscreteReset_) == 0 )         stack = U4Stack_RayleighDiscreteReset  ;
0119     if(strcmp(name, AbsorptionDiscreteReset_) == 0 )       stack = U4Stack_AbsorptionDiscreteReset  ;
0120     if(strcmp(name, BoundaryBurn_SurfaceReflectTransmitAbsorb_) == 0)  stack = U4Stack_BoundaryBurn_SurfaceReflectTransmitAbsorb ; 
0121     if(strcmp(name, BoundaryDiDiTransCoeff_) == 0)         stack = U4Stack_BoundaryDiDiTransCoeff ; 
0122     if(strcmp(name, AbsorptionEffDetect_) == 0)            stack = U4Stack_AbsorptionEffDetect ; 
0123     if(strcmp(name, RayleighScatter_) == 0 )               stack = U4Stack_RayleighScatter  ;
0124     if(strcmp(name, BoundaryDiMeReflectivity_) == 0 )      stack = U4Stack_BoundaryDiMeReflectivity  ;
0125     if(strcmp(name, ChooseReflection_) == 0 )              stack = U4Stack_ChooseReflection ; 
0126     if(strcmp(name, RandomDirection_) == 0 )               stack = U4Stack_RandomDirection ; 
0127     if(strcmp(name, LambertianRand_) == 0 )                stack = U4Stack_LambertianRand ; 
0128     if(strcmp(name, Reemission_) == 0 )                    stack = U4Stack_Reemission ; 
0129 
0130     return stack ; 
0131 }
0132 
0133 /**
0134 U4Stack::TagToStack
0135 --------------------
0136 
0137 Attempt at mapping from A:tag to B:stack 
0138 
0139 * where to use this mapping anyhow ? unkeen to do this at C++ level as it feels like a complication 
0140   and potential info loss that is only not-info loss when are in an aligned state 
0141 
0142 * but inevitably when generalize will get out of alignment and will need to use the A:tag  
0143   and B:stack to regain alignment 
0144 
0145 * hence the right place to use the mapping is in python 
0146 
0147 **/
0148 
0149 inline unsigned U4Stack::TagToStack(unsigned tag)
0150 {
0151     unsigned stack = U4Stack_Unclassified ;
0152     switch(tag)
0153     {
0154         case stag_undef:      stack = U4Stack_Unclassified                              ; break ;        // 0 -> 0
0155         case stag_to_sci:     stack = U4Stack_ScintDiscreteReset                        ; break ;        // 1 -> 3
0156         case stag_to_bnd:     stack = U4Stack_BoundaryDiscreteReset                     ; break ;        // 2 -> 4 
0157         case stag_to_sca:     stack = U4Stack_RayleighDiscreteReset                     ; break ;        // 3 -> 5 
0158         case stag_to_abs:     stack = U4Stack_AbsorptionDiscreteReset                   ; break ;        // 4 -> 6 
0159         case stag_at_burn_sf_sd:    stack = U4Stack_BoundaryBurn_SurfaceReflectTransmitAbsorb ; break ;  // 5 -> 7 
0160         case stag_at_ref:     stack = U4Stack_BoundaryDiDiTransCoeff                    ; break ;        // 6 -> 8 
0161         case stag_sf_burn:    stack = U4Stack_AbsorptionEffDetect                       ; break ;        // 7 -> 9
0162         case stag_sc:         stack = U4Stack_RayleighScatter                           ; break ;        // 8 -> 10
0163         case stag_to_ree:     stack = U4Stack_Unclassified ; break ;  // 9
0164         case stag_re_wl:      stack = U4Stack_Unclassified ; break ;  // 10
0165         case stag_re_mom_ph:  stack = U4Stack_Unclassified ; break ;  // 11
0166         case stag_re_mom_ct:  stack = U4Stack_Unclassified ; break ;  // 12
0167         case stag_re_pol_ph:  stack = U4Stack_Unclassified ; break ;  // 13
0168         case stag_re_pol_ct:  stack = U4Stack_Unclassified ; break ;  // 14
0169         case stag_hp_ph:      stack = U4Stack_Unclassified ; break ;  // 15
0170         //case stag_hp_ct:      stack = U4Stack_Unclassified ; break ;  // 16 
0171     }
0172     return stack ; 
0173 }
0174