File indexing completed on 2026-04-09 07:49:53
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 #include <string>
0052 #include "G4Track.hh"
0053 #include "G4VUserTrackInformation.hh"
0054
0055 #include "spho.h"
0056
0057 struct STrackInfo : public G4VUserTrackInformation
0058 {
0059 spho label ;
0060
0061 STrackInfo(const spho& label);
0062 std::string desc() const ;
0063
0064 static STrackInfo* GetTrackInfo_UNDEFINED(const G4Track* track);
0065 static STrackInfo* GetTrackInfo( const G4Track* track);
0066 static bool Exists(const G4Track* track);
0067 static spho Get( const G4Track* track);
0068 static spho* GetRef(const G4Track* track);
0069 static std::string Desc(const G4Track* track);
0070
0071 static void Set(G4Track* track, const spho& label );
0072 };
0073
0074 inline STrackInfo::STrackInfo(const spho& _label )
0075 :
0076 G4VUserTrackInformation("STrackInfo"),
0077 label(_label)
0078 {
0079 }
0080
0081 inline std::string STrackInfo::desc() const
0082 {
0083 std::stringstream ss ;
0084 ss << *pType << " " << label.desc() ;
0085 std::string s = ss.str();
0086 return s ;
0087 }
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 inline STrackInfo* STrackInfo::GetTrackInfo_UNDEFINED(const G4Track* track)
0100 {
0101 G4VUserTrackInformation* ui = track->GetUserInformation() ;
0102 STrackInfo* trackinfo = ui ? static_cast<STrackInfo*>(ui) : nullptr ;
0103 return trackinfo ;
0104 }
0105
0106 inline STrackInfo* STrackInfo::GetTrackInfo(const G4Track* track)
0107 {
0108 G4VUserTrackInformation* ui = track->GetUserInformation() ;
0109 STrackInfo* trackinfo = ui ? dynamic_cast<STrackInfo*>(ui) : nullptr ;
0110 return trackinfo ;
0111 }
0112
0113
0114
0115
0116 inline bool STrackInfo::Exists(const G4Track* track)
0117 {
0118 STrackInfo* trackinfo = GetTrackInfo(track);
0119 return trackinfo != nullptr ;
0120 }
0121
0122 inline spho STrackInfo::Get(const G4Track* track)
0123 {
0124 STrackInfo* trackinfo = GetTrackInfo(track);
0125 return trackinfo ? trackinfo->label : spho::Placeholder() ;
0126 }
0127
0128 inline spho* STrackInfo::GetRef(const G4Track* track)
0129 {
0130 STrackInfo* trackinfo = GetTrackInfo(track);
0131 return trackinfo ? &(trackinfo->label) : nullptr ;
0132 }
0133
0134 inline std::string STrackInfo::Desc(const G4Track* track)
0135 {
0136 G4VUserTrackInformation* ui = track->GetUserInformation() ;
0137
0138 STrackInfo* trackinfo = GetTrackInfo(track);
0139 STrackInfo* trackinfo_static = GetTrackInfo_UNDEFINED(track);
0140
0141 std::stringstream ss ;
0142 ss << "STrackInfo::Desc"
0143 << std::endl
0144 << " track " << track
0145 << " track.GetUserInformation " << ui
0146 << std::endl
0147 << " trackinfo " << trackinfo
0148 << " trackinfo_static " << trackinfo_static
0149 << std::endl
0150 << " trackinfo.desc " << ( trackinfo ? trackinfo->desc() : "-" )
0151 << std::endl
0152 << " trackinfo_static.desc " << ( trackinfo_static ? trackinfo_static->desc() : "-" )
0153 ;
0154 std::string s = ss.str();
0155 return s ;
0156 }
0157
0158
0159 inline void STrackInfo::Set(G4Track* track, const spho& _label )
0160 {
0161 spho* label = GetRef(track);
0162 if(label == nullptr)
0163 {
0164 track->SetUserInformation(new STrackInfo(_label));
0165 }
0166 else
0167 {
0168 *label = _label ;
0169 }
0170 }
0171