File indexing completed on 2025-01-31 09:21:52
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 <G4ParticleChange.hh>
0045 #include <G4ParticleDefinition.hh>
0046 #include <G4HadronicInteraction.hh>
0047 #include <G4Track.hh>
0048 #include <G4Step.hh>
0049 #include <G4Element.hh>
0050 #include <G4StableIsotopes.hh>
0051 #include <G4TrackStatus.hh>
0052 #include "CexmcHadronicProcess.hh"
0053 #include "CexmcProductionModel.hh"
0054 #include "CexmcIncidentParticleTrackInfo.hh"
0055 #include "CexmcException.hh"
0056
0057
0058 CexmcHadronicProcess::CexmcHadronicProcess( const G4String & name ) :
0059 G4HadronicProcess( name ), productionModel( NULL ), interaction( NULL ),
0060 theTotalResult( NULL ), isInitialized( false )
0061 {
0062 theTotalResult = new G4ParticleChange();
0063 SetIntegral(false);
0064 }
0065
0066
0067 CexmcHadronicProcess::~CexmcHadronicProcess()
0068 {
0069 delete theTotalResult;
0070 }
0071
0072
0073 void CexmcHadronicProcess::RegisterProductionModel(
0074 CexmcProductionModel * model )
0075 {
0076 productionModel = model;
0077
0078 interaction = dynamic_cast< G4HadronicInteraction * >( productionModel );
0079
0080 if ( ! interaction )
0081 throw CexmcException( CexmcIncompatibleProductionModel );
0082
0083 G4HadronicProcess::RegisterMe( interaction );
0084 }
0085
0086
0087 void CexmcHadronicProcess::CalculateTargetNucleus(
0088 const G4Material * material )
0089 {
0090 G4int numberOfElements( material->GetNumberOfElements() );
0091 if ( numberOfElements > 1 )
0092 {
0093 G4cout << CEXMC_LINE_START "WARNING: Number of elements in target "
0094 "material is more than 1.\n Only the first "
0095 "element will be chosen for target nucleus" << G4endl;
0096 }
0097
0098 const G4Element * element( material->GetElement( 0 ) );
0099 G4double ZZ( element->GetZ() );
0100 G4int Z( G4int( ZZ + 0.5 ) );
0101
0102 G4StableIsotopes stableIsotopes;
0103 G4int index( stableIsotopes.GetFirstIsotope( Z ) );
0104 G4double AA( stableIsotopes.GetIsotopeNucleonCount( index ) );
0105
0106 targetNucleus.SetParameters( AA, ZZ );
0107 }
0108
0109
0110 void CexmcHadronicProcess::FillTotalResult( G4HadFinalState * hadFinalState,
0111 const G4Track & track )
0112 {
0113 G4int numberOfSecondaries( hadFinalState->GetNumberOfSecondaries() );
0114
0115 theTotalResult->Clear();
0116 theTotalResult->Initialize( track );
0117 theTotalResult->SetSecondaryWeightByProcess( true );
0118 theTotalResult->ProposeLocalEnergyDeposit(
0119 hadFinalState->GetLocalEnergyDeposit() );
0120 theTotalResult->SetNumberOfSecondaries( numberOfSecondaries );
0121 theTotalResult->ProposeEnergy( hadFinalState->GetEnergyChange() );
0122 theTotalResult->ProposeTrackStatus( fAlive );
0123 if ( hadFinalState->GetStatusChange() == stopAndKill )
0124 theTotalResult->ProposeTrackStatus( fStopAndKill );
0125
0126 for ( G4int i( 0 ); i < numberOfSecondaries; ++i )
0127 {
0128 G4double time( hadFinalState->GetSecondary( i )->GetTime() );
0129 if ( time < 0 )
0130 time = track.GetGlobalTime();
0131
0132 G4Track * newTrack( new G4Track(
0133 hadFinalState->GetSecondary( i )->GetParticle(),
0134 time, track.GetPosition() ) );
0135
0136 G4double newWeight( track.GetWeight() *
0137 hadFinalState->GetSecondary( i )->GetWeight() );
0138 newTrack->SetWeight( newWeight );
0139 newTrack->SetTouchableHandle( track.GetTouchableHandle() );
0140 theTotalResult->AddSecondary( newTrack );
0141 }
0142
0143 hadFinalState->Clear();
0144 }
0145
0146
0147 G4VParticleChange * CexmcHadronicProcess::PostStepDoIt( const G4Track & track,
0148 const G4Step & )
0149 {
0150 G4TrackStatus trackStatus( track.GetTrackStatus() );
0151
0152 if ( trackStatus != fAlive && trackStatus != fSuspend )
0153 {
0154 theTotalResult->Clear();
0155 theTotalResult->Initialize( track );
0156
0157 return theTotalResult;
0158 }
0159
0160
0161
0162
0163
0164
0165
0166
0167 if ( ! isInitialized )
0168 {
0169 CalculateTargetNucleus( track.GetMaterial() );
0170 isInitialized = true;
0171 }
0172
0173 G4HadProjectile projectile( track );
0174 G4HadFinalState * result( interaction->ApplyYourself( projectile,
0175 targetNucleus ) );
0176 FillTotalResult( result, track );
0177
0178 if ( theTotalResult->GetTrackStatus() != fStopAndKill )
0179 {
0180 CexmcTrackInfo * trackInfo( static_cast< CexmcTrackInfo * >(
0181 track.GetUserInformation() ) );
0182
0183 if ( trackInfo &&
0184 trackInfo->GetTypeInfo() == CexmcIncidentParticleTrackType )
0185 {
0186 CexmcIncidentParticleTrackInfo * theTrackInfo(
0187 static_cast< CexmcIncidentParticleTrackInfo * >( trackInfo ) );
0188 theTrackInfo->SetNeedsTrackLengthResampling();
0189 }
0190 }
0191
0192 return theTotalResult;
0193 }
0194
0195
0196 G4bool CexmcHadronicProcess::IsApplicable(
0197 const G4ParticleDefinition & particle )
0198 {
0199 if ( ! productionModel )
0200 return false;
0201
0202 G4ParticleDefinition * incidentParticle(
0203 productionModel->GetIncidentParticle() );
0204
0205 if ( ! incidentParticle )
0206 return false;
0207
0208 return particle == *incidentParticle;
0209 }
0210