File indexing completed on 2025-01-31 09:21:54
0001
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 #include <G4ParticleDefinition.hh>
0045 #include <G4VProcess.hh>
0046 #include <G4Track.hh>
0047 #include <G4RunManager.hh>
0048 #include "CexmcTrackingAction.hh"
0049 #include "CexmcTrackInfo.hh"
0050 #include "CexmcIncidentParticleTrackInfo.hh"
0051 #include "CexmcProductionModel.hh"
0052 #include "CexmcPhysicsManager.hh"
0053 #include "CexmcSetup.hh"
0054 #include "CexmcException.hh"
0055 #include "CexmcCommon.hh"
0056
0057
0058 CexmcTrackingAction::CexmcTrackingAction(
0059 CexmcPhysicsManager * physicsManager_ ) :
0060 physicsManager( physicsManager_ ), targetVolume( NULL ),
0061 outputParticleTrackId( CexmcInvalidTrackId ),
0062 outputParticleDecayProductCopyNumber( 0 ), incidentParticle( NULL ),
0063 outputParticle( NULL ), nucleusOutputParticle( NULL )
0064 {
0065 CexmcProductionModel * productionModel(
0066 physicsManager->GetProductionModel() );
0067 if ( ! productionModel )
0068 throw CexmcException( CexmcWeirdException );
0069
0070 incidentParticle = productionModel->GetIncidentParticle();
0071 outputParticle = productionModel->GetOutputParticle();
0072 nucleusOutputParticle = productionModel->GetNucleusOutputParticle();
0073
0074 if ( ! incidentParticle || ! outputParticle || ! nucleusOutputParticle )
0075 throw CexmcException( CexmcIncompleteProductionModel );
0076
0077 G4RunManager * runManager( G4RunManager::GetRunManager() );
0078 const CexmcSetup * setup( static_cast< const CexmcSetup * >(
0079 runManager->GetUserDetectorConstruction() ) );
0080 targetVolume = setup->GetVolume( CexmcSetup::Target );
0081 }
0082
0083
0084 void CexmcTrackingAction::PreUserTrackingAction( const G4Track * track )
0085 {
0086 CexmcTrackInfo * trackInfo( static_cast< CexmcTrackInfo * >(
0087 track->GetUserInformation() ) );
0088
0089 if ( trackInfo )
0090 return;
0091
0092 G4Track * theTrack( const_cast< G4Track * >( track ) );
0093
0094 do
0095 {
0096 if ( track->GetParentID() == 0 )
0097 {
0098 if ( *track->GetDefinition() == *incidentParticle )
0099 {
0100 trackInfo = new CexmcIncidentParticleTrackInfo(
0101 CexmcBeamParticleTrack );
0102 theTrack->SetUserInformation( trackInfo );
0103 SetupIncidentParticleTrackInfo( track );
0104 }
0105 else
0106 {
0107 trackInfo = new CexmcTrackInfo( CexmcBeamParticleTrack );
0108 }
0109 break;
0110 }
0111
0112 if ( track->GetCreatorProcess()->GetProcessName() ==
0113 CexmcStudiedProcessFullName )
0114 {
0115 do
0116 {
0117 if ( *track->GetDefinition() == *outputParticle )
0118 {
0119 outputParticleTrackId = track->GetTrackID();
0120 trackInfo = new CexmcTrackInfo( CexmcOutputParticleTrack );
0121 break;
0122 }
0123 if ( *track->GetDefinition() == *nucleusOutputParticle )
0124 {
0125 trackInfo = new CexmcTrackInfo( CexmcNucleusParticleTrack );
0126 break;
0127 }
0128 } while ( false );
0129 break;
0130 }
0131
0132 if ( track->GetParentID() == outputParticleTrackId )
0133 {
0134 trackInfo = new CexmcTrackInfo(
0135 CexmcOutputParticleDecayProductTrack,
0136 outputParticleDecayProductCopyNumber++ );
0137 break;
0138 }
0139
0140 if ( *track->GetDefinition() == *incidentParticle )
0141 {
0142 if ( physicsManager->OnlyBeamParticleCanTriggerStudiedProcess() )
0143 break;
0144 trackInfo = new CexmcIncidentParticleTrackInfo( CexmcInsipidTrack );
0145 theTrack->SetUserInformation( trackInfo );
0146 SetupIncidentParticleTrackInfo( track );
0147 break;
0148 }
0149 } while ( false );
0150
0151 if ( ! trackInfo )
0152 return;
0153
0154 if ( ! track->GetUserInformation() )
0155 theTrack->SetUserInformation( trackInfo );
0156 }
0157
0158
0159 void CexmcTrackingAction::SetupIncidentParticleTrackInfo(
0160 const G4Track * track )
0161 {
0162 CexmcIncidentParticleTrackInfo * trackInfo(
0163 static_cast< CexmcIncidentParticleTrackInfo * >(
0164 track->GetUserInformation() ) );
0165
0166 if ( ! trackInfo )
0167 return;
0168
0169 G4VPhysicalVolume * volume( track->GetVolume() );
0170
0171 if ( volume && volume->GetLogicalVolume() == targetVolume )
0172 {
0173 physicsManager->ResampleTrackLengthInTarget( track );
0174 trackInfo->ActivateStudiedProcess();
0175 }
0176 }
0177