Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 U4Track.h
0004 ===========
0005 
0006 Several static methods take templated photon label types such as::
0007 
0008     spho.h
0009     C4Pho.h (same impl as spho.h but from CUSTOM4)
0010 
0011 **/
0012 
0013 
0014 
0015 #include <string>
0016 class G4Track ;
0017 
0018 struct U4Track
0019 {
0020     static G4Track* MakePhoton();
0021     static int Id(const G4Track* track);
0022     static void SetId(G4Track* track, int id);
0023     static bool IsOptical(const G4Track* track);
0024     static void SetStopAndKill(const G4Track* track);
0025 
0026     static std::string Desc(const G4Track* track);
0027     static void SetFabricatedLabel(const G4Track* track);
0028 
0029 };
0030 
0031 
0032 #include <sstream>
0033 #include "G4Track.hh"
0034 #include "G4OpticalPhoton.hh"
0035 
0036 inline G4Track* U4Track::MakePhoton()
0037 {
0038     G4ParticleMomentum momentum(0., 0., 1.);
0039     G4DynamicParticle* particle = new G4DynamicParticle(G4OpticalPhoton::Definition(),momentum);
0040     particle->SetPolarization(0., 1., 0. );
0041 
0042     G4double time(0.);
0043 
0044     G4ThreeVector position(0., 0., 0.);
0045 
0046     G4Track* track = new G4Track(particle,time,position);
0047     return track ;
0048 }
0049 
0050 /**
0051 U4Track::Id
0052 -------------
0053 
0054 0-based Id (unlike original G4Track::GetTrackID which is 1-based)
0055 
0056 **/
0057 
0058 inline int U4Track::Id(const G4Track* track)
0059 {
0060     return track->GetTrackID() - 1 ;
0061 }
0062 
0063 /**
0064 U4Track::SetId
0065 ----------------
0066 
0067 NB *id* is 0-based but Geant4 uses a 1-based TrackId
0068 
0069 **/
0070 inline void U4Track::SetId(G4Track* track, int id)
0071 {
0072     track->SetTrackID( id + 1 );
0073 }
0074 
0075 inline bool U4Track::IsOptical(const G4Track* track)
0076 {
0077     G4ParticleDefinition* particle = track->GetDefinition();
0078     return particle == G4OpticalPhoton::OpticalPhotonDefinition() ;
0079 }
0080 
0081 inline void U4Track::SetStopAndKill(const G4Track* track)
0082 {
0083     G4Track* track_ = const_cast<G4Track*>(track);
0084     track_->SetTrackStatus(fStopAndKill);
0085 }
0086 
0087 
0088 #ifdef WITH_CUSTOM4
0089 #include "C4Pho.h"
0090 #include "C4TrackInfo.h"
0091 #else
0092 #include "STrackInfo.h"
0093 #endif
0094 
0095 inline void U4Track::SetFabricatedLabel(const G4Track* track)
0096 {
0097     int trackID = Id(track) ;
0098     assert( trackID >= 0 );
0099     G4Track* _track = const_cast<G4Track*>(track);
0100 
0101 #ifdef WITH_CUSTOM4_OLD
0102     C4Pho fab = C4Pho::Fabricate(trackID);
0103     C4TrackInfo<C4Pho>::Set(_track, fab );
0104 #elif WITH_CUSTOM4
0105     C4Pho fab = C4Pho::Fabricate(trackID);
0106     C4TrackInfo::Set(_track, fab );
0107 #else
0108     spho fab = spho::Fabricate(trackID);
0109     STrackInfo::Set(_track, fab );
0110 #endif
0111 }
0112 
0113 inline std::string U4Track::Desc(const G4Track* track)
0114 {
0115 #ifdef WITH_CUSTOM4_OLD
0116     C4Pho* label = C4TrackInfo<C4Pho>::GetRef(track);
0117 #elif WITH_CUSTOM4
0118     C4Pho* label = C4TrackInfo::GetRef(track);
0119 #else
0120     spho* label = STrackInfo::GetRef(track);
0121 #endif
0122 
0123     std::stringstream ss ;
0124     ss << "U4Track::Desc"
0125        << " Id " << std::setw(5) << Id(track)
0126        << " Op " << std::setw(1) << IsOptical(track)
0127        << " label  " << ( label ? label->desc() : "-" )
0128        ;
0129 
0130     std::string s = ss.str();
0131     return s ;
0132 }
0133