Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:50:01

0001 #pragma once
0002 /**
0003 U4Recorder
0004 ===========
0005 
0006 This is used from tests/U4App.h (the Geant4 application in a header)
0007 
0008 U4Recorder is NOT a G4UserRunAction, G4UserEventAction,
0009 ... despite having the corresponding method names.
0010 
0011 The U4Recorder relies on the RunAction, EventAction  etc.. classes
0012 calling those lifecycle methods.
0013 
0014 
0015 Using G4VUserTrackInformation photon label info without accessing them
0016 ------------------------------------------------------------------------
0017 
0018 As detector simulation frameworks will be using the
0019 G4VUserTrackInformation for other purposes it causes
0020 incompatibility to require that the track info is
0021 solely used by Opticks.
0022 
0023 To workaround this problem have added partner lower level
0024 track methods with names ending with "_" that take an int* label.
0025 The int* label is a pointer back to the photon label data
0026 back in the Geant4 track info of each track.
0027 
0028 Passing that int* pointer as a parameter alongside the track
0029 avoids needing to have detector framework track info
0030 classes to delve into the track info here.  Instead
0031 that access to the label can to be done in the detector
0032 framework. This avoids conflicts over the use of the track
0033 info by enabling it to be shared.
0034 
0035 **/
0036 
0037 #include <vector>
0038 #include <string>
0039 
0040 class G4Run ;
0041 class G4Event ;
0042 class G4Track ;
0043 class G4Step ;
0044 class G4VSolid ;
0045 class G4StepPoint ;
0046 
0047 struct U4Tree ;
0048 struct NP ;
0049 struct spho ;
0050 struct quad4 ;
0051 struct SEvt ;
0052 struct stimer ;
0053 
0054 #include "NPU.hh"  // UName
0055 
0056 #include "plog/Severity.h"
0057 #include "G4TrackStatus.hh"
0058 #include "U4_API_EXPORT.hh"
0059 
0060 struct U4_API U4Recorder
0061 {
0062     static const plog::Severity LEVEL ;
0063     static UName SPECS ;      // collect unique U4Step::Spec strings
0064 
0065     static const int STATES ; // configures number of g4states to persist
0066     static const int RERUN  ;
0067     static constexpr int STATE_ITEMS = 2*17+4 ; // 2*17+4 is appropriate for MixMaxRng
0068     static const bool SEvt_NPFold_VERBOSE ;
0069     static const bool PIDX_ENABLED ;
0070     static const bool EndOfRunAction_Simtrace ;
0071     static const int  UseGivenVelocity_KLUDGE ;
0072     static constexpr const char* _UseGivenVelocity_KLUDGE = "U4Recorder__PreUserTrackingAction_Optical_UseGivenVelocity_KLUDGE" ;
0073 
0074     static const char* REPLICA_NAME_SELECT ;
0075     static const int PIDX ;   // used to control debug printout for idx
0076     static const int EIDX ;   // used to enable U4Recorder for an idx, skipping all others
0077     static const int GIDX ;
0078 
0079     static std::string Desc();
0080     static std::string DescFull();
0081     static std::string Switches();
0082     static std::string EnabledLabel();
0083     static bool Enabled(const spho& label);
0084     std::string desc() const ;
0085 
0086     static U4Recorder* INSTANCE ;
0087     static U4Recorder* Get();
0088 
0089     U4Recorder();
0090 private:
0091     void init();
0092     void init_SEvt();
0093 public:
0094     void addProcessHits_EPH(NP* eph_stats);
0095 
0096     int eventID ;
0097     const G4Track* transient_fSuspend_track ;
0098     NP* rerun_rand ;
0099     SEvt* sev ;   // HMM: Not used as much as it should ? Lots of SEvt::Get_ECPU() instead, WHY ?
0100     const U4Tree* tree ;
0101 
0102     void setU4Tree(const U4Tree* _tree);
0103     const U4Tree* getU4Tree() const ;
0104 
0105     void BeginOfRunAction(const G4Run*);
0106     void EndOfRunAction(const G4Run*);
0107 
0108     void BeginOfEventAction(const G4Event*);
0109     void EndOfEventAction(const G4Event*);
0110 
0111     void BeginOfEventAction_(int eventID_);
0112     void EndOfEventAction_(int eventID_);
0113 
0114     void PreUserTrackingAction(const G4Track* );
0115     void PostUserTrackingAction(const G4Track* );
0116 
0117     void PreUserTrackingAction_( const G4Track*, int* label );
0118     void PostUserTrackingAction_(const G4Track*, int* label );
0119 
0120     void PreUserTrackingAction_Optical(const G4Track*);
0121     void PreUserTrackingAction_Optical_(const G4Track*, int* label );
0122 
0123     void PreUserTrackingAction_Optical_GetLabel( spho& ulabel, const G4Track* track );
0124     void PreUserTrackingAction_Optical_FabricateLabel( const G4Track* track ) ;
0125     void PreUserTrackingAction_Optical_FabricateLabel_( const G4Track* track, int* label );
0126 
0127     void GetLabel( spho& ulabel, const G4Track* track );
0128 
0129 
0130     void saveOrLoadStates(int id);
0131     void saveRerunRand(const char* dir) const ;
0132 
0133     static NP* MakeMetaArray() ;
0134     static void SaveMeta(const char* savedir);
0135 
0136     void PostUserTrackingAction_Optical( const G4Track*);
0137     void PostUserTrackingAction_Optical_(const G4Track*, int* label);
0138 
0139 
0140     void UserSteppingAction(const G4Step*);
0141 
0142     // boundary process template type
0143     template<typename T>
0144     void UserSteppingAction_Optical(const G4Step*);
0145 
0146     static unsigned EPH_EFFICIENCY_COLLECT_OR_CULL(unsigned eph);
0147     static void     EPH_FlagCheck(unsigned original_flag, unsigned eph);
0148 
0149 
0150     /**
0151     export U4Recorder__UserSteppingAction_Optical_ClearNumberOfInteractionLengthLeft=1
0152 
0153     This setting is not appropriate for gun running. It is only appropriate with
0154     input photon running when doing optical only random aligned comparisons.
0155 
0156     This setting makes it easier to random align Opticks and Geant4 based optical simulations
0157     because it makes the Geant4 pattern of random consumption more regular.
0158     However this has side effects:
0159 
0160     1. increases the randoms consumed by 20-30% (can check this with S4RandomArray.h)
0161     2. changes the events simulated, as the randoms consumed are changed
0162 
0163     **/
0164     static constexpr const char* UserSteppingAction_Optical_ClearNumberOfInteractionLengthLeft_ = "U4Recorder__UserSteppingAction_Optical_ClearNumberOfInteractionLengthLeft" ;
0165     static const bool UserSteppingAction_Optical_ClearNumberOfInteractionLengthLeft ;
0166 
0167 
0168     template <typename T>
0169     static void CollectBoundaryAux(quad4* current_aux );
0170 
0171 
0172     static const double EPSILON ;
0173     static const bool ClassifyFake_FindPV_r ;
0174     static stimer* TIMER ;
0175 
0176     unsigned ClassifyFake(const G4Step* step, unsigned flag, const char* spec, bool dump, double* duration );
0177 
0178     static const double SLOW_FAKE ;                // envvar U4Recorder__SLOW_FAKE
0179     static std::vector<std::string>* FAKES ;       // envvar U4Recorder__FAKES
0180     static bool                      FAKES_SKIP ;  // envvar U4Recorder__FAKES_SKIP
0181 
0182     static bool IsListed( const std::vector<std::string>* LIST, const char* spec ) ;
0183     static bool IsListedFake( const char* spec );
0184     static std::string DescFakes();
0185 
0186 
0187     void Check_TrackStatus_Flag(G4TrackStatus tstat, unsigned flag, const char* from );
0188 };
0189