File indexing completed on 2026-09-15 08:28:57
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 #include "SteppingAction.hh"
0030
0031 #include "Run.hh"
0032
0033 #include "G4DecayProducts.hh"
0034 #include "G4DecayTable.hh"
0035 #include "G4LossTableManager.hh"
0036 #include "G4ParticleDefinition.hh"
0037 #include "G4ParticleTypes.hh"
0038 #include "G4Step.hh"
0039 #include "G4StepPoint.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4TouchableHistory.hh"
0042 #include "G4Track.hh"
0043 #include "G4VDecayChannel.hh"
0044 #include "G4VPhysicalVolume.hh"
0045 #include "G4VTouchable.hh"
0046
0047
0048
0049 SteppingAction::SteppingAction() : G4UserSteppingAction()
0050 {
0051 Initialize();
0052 }
0053
0054
0055
0056 SteppingAction::~SteppingAction() {}
0057
0058
0059
0060 void SteppingAction::Initialize()
0061 {
0062
0063 fRunPtr = nullptr;
0064 fToleranceEPviolations = 1.0 * CLHEP::eV;
0065 fPrimaryParticleId = 0;
0066 fPrimaryParticleInitialKineticEnergy = 0.0;
0067 fPrimaryParticleInitialTotalEnergy = 0.0;
0068 fPrimaryParticleInitialMomentum = 0.0;
0069 fPrimaryParticleInitialBeta = 1.0;
0070 fPrimaryParticleInitialGamma = 1.0;
0071 fPrimaryParticleInitial3Momentum = G4ThreeVector(0.0, 0.0, 0.0);
0072 fPrimaryParticleInitialPosition = G4ThreeVector(0.0, 0.0, 0.0);
0073 fMaxEkin_deltaMax = 0.0;
0074 fMaxEtot_deltaMax = 0.0;
0075 fMaxP_deltaMax = 0.0;
0076 fMaxPdir_deltaMax = 0.0;
0077 fMaxMass_deltaMax1 = 0.0;
0078 fMaxMass_deltaMax2 = 0.0;
0079 fMaxMass_deltaMax3 = 0.0;
0080 fMeanMass_deltaMax3 = 0.0;
0081 fMaxBeta_deltaMax1 = 0.0;
0082 fMaxBeta_deltaMax2 = 0.0;
0083 fMaxGamma_deltaMax1 = 0.0;
0084 fMaxGamma_deltaMax2 = 0.0;
0085 fMaxGamma_deltaMax3 = 0.0;
0086 fMaxT_proper_deltaMax = 0.0;
0087 fMaxT_lab_deltaMax = 0.0;
0088 fMaxMc_truth_rPos_deltaMax = 0.0;
0089 fMeanMc_truth_rPos_deltaMax = 0.0;
0090 fMeanDeltaR_primaryDecay = 0.0;
0091 fMinDeltaR_primaryDecay = 9999999.9;
0092 fMaxDeltaR_primaryDecay = -9999999.9;
0093 fMeanR_primaryDecay = 0.0;
0094 fMinR_primaryDecay = 9999999.9;
0095 fMaxR_primaryDecay = -9999999.9;
0096 fMeanX_primaryDecay = 0.0;
0097 fMinX_primaryDecay = 9999999.9;
0098 fMaxX_primaryDecay = -9999999.9;
0099 fMeanY_primaryDecay = 0.0;
0100 fMinY_primaryDecay = 9999999.9;
0101 fMaxY_primaryDecay = -9999999.9;
0102 fMeanZ_primaryDecay = 0.0;
0103 fMinZ_primaryDecay = 9999999.9;
0104 fMaxZ_primaryDecay = -9999999.9;
0105 fMeanDeltaAngle_primaryDecay = 0.0;
0106 fMinDeltaAngle_primaryDecay = 9999999.9;
0107 fMaxDeltaAngle_primaryDecay = -9999999.9;
0108 fMeanDeltaEkin_primaryDecay = 0.0;
0109 fMinDeltaEkin_primaryDecay = 9999999.9;
0110 fMaxDeltaEkin_primaryDecay = -9999999.9;
0111 fMeanEkin_primaryDecay = 0.0;
0112 fMinEkin_primaryDecay = 9999999.9;
0113 fMaxEkin_primaryDecay = -9999999.9;
0114 fMeanPx_primaryDecay = 0.0;
0115 fMinPx_primaryDecay = 9999999.9;
0116 fMaxPx_primaryDecay = -9999999.9;
0117 fMeanPy_primaryDecay = 0.0;
0118 fMinPy_primaryDecay = 9999999.9;
0119 fMaxPy_primaryDecay = -9999999.9;
0120 fMeanPz_primaryDecay = 0.0;
0121 fMinPz_primaryDecay = 9999999.9;
0122 fMaxPz_primaryDecay = -9999999.9;
0123 fMinUnderestimated_mc_truth_rPos_delta = 9999999.9;
0124 fMaxOverestimated_mc_truth_rPos_delta = -9999999.9;
0125 fMeanUnderestimated_mc_truth_rPos_delta = 0.0;
0126 fMeanOverestimated_mc_truth_rPos_delta = 0.0;
0127 fMinUnderestimated_rDeltaPos = 9999999.9;
0128 fMaxOverestimated_rDeltaPos = -9999999.9;
0129 fMeanUnderestimated_rDeltaPos = 0.0;
0130 fMeanOverestimated_rDeltaPos = 0.0;
0131 fMaxFloat_rDeltaPos_deltaMax = -9999999.9;
0132 fMeanViolationE_primaryDecay = 0.0;
0133 fMinViolationE_primaryDecay = 9999999.9;
0134 fMaxViolationE_primaryDecay = -9999999.9;
0135 fMeanViolationPx_primaryDecay = 0.0;
0136 fMinViolationPx_primaryDecay = 9999999.9;
0137 fMaxViolationPx_primaryDecay = -9999999.9;
0138 fMeanViolationPy_primaryDecay = 0.0;
0139 fMinViolationPy_primaryDecay = 9999999.9;
0140 fMaxViolationPy_primaryDecay = -9999999.9;
0141 fMeanViolationPz_primaryDecay = 0.0;
0142 fMinViolationPz_primaryDecay = 9999999.9;
0143 fMaxViolationPz_primaryDecay = -9999999.9;
0144 }
0145
0146
0147
0148 void SteppingAction::UserSteppingAction(const G4Step* theStep)
0149 {
0150
0151
0152
0153 if (theStep->GetTrack()->GetParentID() == 0 && theStep->GetTrack()->GetCurrentStepNumber() == 1) {
0154 fPrimaryParticleId = theStep->GetTrack()->GetDefinition()->GetPDGEncoding();
0155 fPrimaryParticleInitialKineticEnergy = theStep->GetPreStepPoint()->GetKineticEnergy();
0156 fPrimaryParticleInitialTotalEnergy = theStep->GetPreStepPoint()->GetTotalEnergy();
0157 fPrimaryParticleInitial3Momentum = theStep->GetPreStepPoint()->GetMomentum();
0158 fPrimaryParticleInitialMomentum = fPrimaryParticleInitial3Momentum.mag();
0159 fPrimaryParticleInitialPosition = theStep->GetPreStepPoint()->GetPosition();
0160 fPrimaryParticleInitialBeta = theStep->GetPreStepPoint()->GetBeta();
0161 fPrimaryParticleInitialGamma = theStep->GetPreStepPoint()->GetGamma();
0162
0163
0164 if (fToleranceEPviolations < fPrimaryParticleInitialKineticEnergy * 1.0e-9) {
0165 fToleranceEPviolations = fPrimaryParticleInitialKineticEnergy * 1.0e-9;
0166 }
0167
0168 if (fRunPtr) {
0169 fRunPtr->SetPrimaryParticleId(fPrimaryParticleId);
0170 fRunPtr->SetPrimaryParticleInitialKineticEnergy(fPrimaryParticleInitialKineticEnergy);
0171 fRunPtr->SetPrimaryParticleInitialTotalEnergy(fPrimaryParticleInitialTotalEnergy);
0172 fRunPtr->SetPrimaryParticleInitialMomentum(fPrimaryParticleInitialMomentum);
0173 fRunPtr->SetPrimaryParticleInitialBeta(fPrimaryParticleInitialBeta);
0174 fRunPtr->SetPrimaryParticleInitialGamma(fPrimaryParticleInitialGamma);
0175 fRunPtr->SetPrimaryParticleInitial3Momentum(fPrimaryParticleInitial3Momentum);
0176 fRunPtr->SetPrimaryParticleInitialPosition(fPrimaryParticleInitialPosition);
0177 fRunPtr->SetToleranceEPviolations(ToleranceEPviolations());
0178 fRunPtr->SetToleranceDeltaDecayRadius(ToleranceDeltaDecayRadius());
0179 fRunPtr->SetIsPreassignedDecayEnabled(IsPreassignedDecayEnabled());
0180 fRunPtr->SetIsBoostToLabEnabled(IsBoostToLabEnabled());
0181 }
0182
0183 if (IsPreassignedDecayEnabled() && (!theStep->GetTrack()->GetDefinition()->GetPDGStable())) {
0184 G4DynamicParticle* dynamicParent =
0185 const_cast<G4DynamicParticle*>(theStep->GetTrack()->GetDynamicParticle());
0186 if (dynamicParent != nullptr) {
0187 G4DecayProducts* decayProducts =
0188 (G4DecayProducts*)(dynamicParent->GetPreAssignedDecayProducts());
0189 if (decayProducts == nullptr) {
0190 G4ParticleDefinition* parentDef = theStep->GetTrack()->GetDefinition();
0191 G4DecayTable* decayTable = (parentDef == nullptr ? nullptr : parentDef->GetDecayTable());
0192 if (decayTable != nullptr) {
0193 G4double parentMass = dynamicParent->GetMass();
0194 G4VDecayChannel* decayChannel = decayTable->SelectADecayChannel(parentMass);
0195 if (decayChannel != nullptr) {
0196 decayProducts = decayChannel->DecayIt(parentMass);
0197 if (!decayProducts->IsChecked()) decayProducts->DumpInfo();
0198 if (IsBoostToLabEnabled()) {
0199
0200 decayProducts->Boost(dynamicParent->GetTotalEnergy(),
0201 dynamicParent->GetMomentumDirection());
0202 }
0203 }
0204 else {
0205 decayProducts = new G4DecayProducts(*dynamicParent);
0206 }
0207 dynamicParent->SetPreAssignedDecayProducts(decayProducts);
0208 }
0209 }
0210 else {
0211 G4cout << "WARNING : already present preassign decay !" << G4endl;
0212 }
0213 }
0214 }
0215 }
0216
0217
0218
0219
0220 if (theStep->GetTrack()->GetParentID() == 0
0221 && theStep->GetPostStepPoint()->GetProcessDefinedStep() != nullptr
0222 && theStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName().find("Decay")
0223 != std::string::npos)
0224 {
0225
0226
0227
0228
0229 const G4double ekin_dynamicParticle =
0230 theStep->GetTrack()->GetDynamicParticle()->GetKineticEnergy();
0231 const G4double ekin_track = theStep->GetTrack()->GetKineticEnergy();
0232 const G4double ekin_postStepPoint = theStep->GetPostStepPoint()->GetKineticEnergy();
0233 const G4double ekin_deltaMax = std::max(std::abs(ekin_dynamicParticle - ekin_track),
0234 std::abs(ekin_dynamicParticle - ekin_postStepPoint));
0235
0236 const G4double ekin_val = ekin_dynamicParticle;
0237
0238 const G4double etot_dynamicParticle =
0239 theStep->GetTrack()->GetDynamicParticle()->GetTotalEnergy();
0240 const G4double etot_track = theStep->GetTrack()->GetTotalEnergy();
0241 const G4double etot_postStepPoint = theStep->GetPostStepPoint()->GetTotalEnergy();
0242 const G4double etot_deltaMax = std::max(std::abs(etot_dynamicParticle - etot_track),
0243 std::abs(etot_dynamicParticle - etot_postStepPoint));
0244
0245 const G4double etot_val = etot_dynamicParticle;
0246
0247 const G4double p_dynamicParticle =
0248 theStep->GetTrack()->GetDynamicParticle()->GetMomentum().mag();
0249 const G4double p_track = theStep->GetTrack()->GetMomentum().mag();
0250 const G4double p_postStepPoint = theStep->GetPostStepPoint()->GetMomentum().mag();
0251 const G4double p_deltaMax = std::max(std::abs(p_dynamicParticle - p_track),
0252 std::abs(p_dynamicParticle - p_postStepPoint));
0253
0254 const G4double p_val = p_dynamicParticle;
0255
0256 const G4ThreeVector pdir_dynamicParticle =
0257 theStep->GetTrack()->GetDynamicParticle()->GetMomentumDirection();
0258 const G4ThreeVector pdir_track = theStep->GetTrack()->GetMomentumDirection();
0259 const G4ThreeVector pdir_postStepPoint = theStep->GetPostStepPoint()->GetMomentumDirection();
0260 const G4double pdir_x_deltaMax =
0261 std::max(std::abs(pdir_dynamicParticle.x() - pdir_track.x()),
0262 std::abs(pdir_dynamicParticle.x() - pdir_postStepPoint.x()));
0263 const G4double pdir_y_deltaMax =
0264 std::max(std::abs(pdir_dynamicParticle.y() - pdir_track.y()),
0265 std::abs(pdir_dynamicParticle.y() - pdir_postStepPoint.y()));
0266 const G4double pdir_z_deltaMax =
0267 std::max(std::abs(pdir_dynamicParticle.z() - pdir_track.z()),
0268 std::abs(pdir_dynamicParticle.z() - pdir_postStepPoint.z()));
0269 const G4double pdir_deltaMax =
0270 std::max(std::max(pdir_x_deltaMax, pdir_y_deltaMax), pdir_z_deltaMax);
0271
0272
0273 const G4double mass_dynamicParticle = theStep->GetTrack()->GetDynamicParticle()->GetMass();
0274 const G4double mass_preStepPoint = theStep->GetPreStepPoint()->GetMass();
0275 const G4double mass_postStepPoint = theStep->GetPostStepPoint()->GetMass();
0276 const G4double mass_from_etot_ekin = etot_val - ekin_val;
0277 const G4double mass_from4mom = std::sqrt(etot_val * etot_val - p_val * p_val);
0278 G4double mass_deltaMax1 = std::max(std::abs(mass_dynamicParticle - mass_preStepPoint),
0279 std::abs(mass_dynamicParticle - mass_postStepPoint));
0280 G4double mass_deltaMax2 = std::abs(mass_dynamicParticle - mass_from_etot_ekin);
0281 G4double mass_deltaMax3 = std::abs(mass_dynamicParticle - mass_from4mom);
0282 fMeanMass_deltaMax3 += mass_deltaMax3;
0283
0284
0285 const G4double mass_val = mass_dynamicParticle;
0286
0287
0288 const G4double beta_dynamicParticle = theStep->GetTrack()->GetDynamicParticle()->GetBeta();
0289 const G4double beta_postStepPoint = theStep->GetPostStepPoint()->GetBeta();
0290
0291 const G4double beta_velocity_track = theStep->GetTrack()->GetVelocity() / CLHEP::c_light;
0292 const G4double beta_velocity_postStepPoint =
0293 theStep->GetPostStepPoint()->GetVelocity() / CLHEP::c_light;
0294 const G4double beta_p_over_etot = p_val / etot_val;
0295 G4double beta_deltaMax1 = std::max(std::abs(beta_dynamicParticle - beta_postStepPoint),
0296 std::abs(beta_dynamicParticle - beta_velocity_track));
0297 beta_deltaMax1 =
0298 std::max(beta_deltaMax1, std::abs(beta_dynamicParticle - beta_velocity_postStepPoint));
0299 const G4double beta_deltaMax2 = std::abs(beta_dynamicParticle - beta_p_over_etot);
0300
0301 const G4double beta_val = beta_dynamicParticle;
0302
0303 const G4double gamma_postStepPoint = theStep->GetPostStepPoint()->GetGamma();
0304 const G4double gamma_from_e_over_m = etot_val / mass_val;
0305 const G4double gamma_deltaMax1 = std::abs(gamma_postStepPoint - gamma_from_e_over_m);
0306 G4double gamma_from_beta = 0.0;
0307 G4double gamma_deltaMax2 = 0.0;
0308 G4double gamma_deltaMax3 = 0.0;
0309 if (beta_val < 1.0) {
0310 gamma_from_beta = 1.0 / std::sqrt(1.0 - beta_val * beta_val);
0311 gamma_deltaMax2 = std::abs(gamma_postStepPoint - gamma_from_beta);
0312 gamma_deltaMax3 = std::abs(gamma_from_e_over_m - gamma_from_beta);
0313 }
0314 const G4double gamma_val = gamma_postStepPoint;
0315
0316
0317
0318
0319
0320 const G4double t_proper_track = theStep->GetTrack()->GetProperTime();
0321 const G4double t_proper_postStepPoint = theStep->GetPostStepPoint()->GetProperTime();
0322 const G4double t_proper_deltaMax = std::abs(t_proper_track - t_proper_postStepPoint);
0323
0324 const G4double t_proper_val = t_proper_track;
0325
0326
0327
0328
0329
0330
0331 const G4double t_local_track = theStep->GetTrack()->GetLocalTime();
0332 const G4double t_local_postStepPoint = theStep->GetPostStepPoint()->GetLocalTime();
0333 const G4double t_global_track = theStep->GetTrack()->GetGlobalTime();
0334 const G4double t_global_postStepPoint = theStep->GetPostStepPoint()->GetGlobalTime();
0335 G4double t_lab_deltaMax = std::max(std::abs(t_local_track - t_local_postStepPoint),
0336 std::abs(t_local_track - t_global_track));
0337 t_lab_deltaMax = std::max(t_lab_deltaMax, std::abs(t_local_track - t_global_postStepPoint));
0338
0339 const G4double t_lab_val = t_local_track;
0340
0341
0342
0343 const G4double primaryBeta =
0344 fPrimaryParticleInitialMomentum / fPrimaryParticleInitialTotalEnergy;
0345 const G4double mc_truth_rPos1 = t_lab_val * fPrimaryParticleInitialBeta * CLHEP::c_light;
0346 const G4double mc_truth_rPos2 = t_lab_val * primaryBeta * CLHEP::c_light;
0347 const G4double mc_truth_rPos_deltaMax = std::abs(mc_truth_rPos1 - mc_truth_rPos2);
0348 fMeanMc_truth_rPos_deltaMax += mc_truth_rPos_deltaMax;
0349
0350
0351 if (mc_truth_rPos_deltaMax > ToleranceDeltaDecayRadius()) {
0352
0353
0354
0355
0356 if (fRunPtr) fRunPtr->IncrementNumber_mc_truth_rPos_deltaMax_above();
0357 }
0358 const G4double mc_truth_rPos_val = mc_truth_rPos1;
0359
0360 fMaxEkin_deltaMax = std::max(fMaxEkin_deltaMax, ekin_deltaMax);
0361 fMaxEtot_deltaMax = std::max(fMaxEtot_deltaMax, etot_deltaMax);
0362 fMaxP_deltaMax = std::max(fMaxP_deltaMax, p_deltaMax);
0363 fMaxPdir_deltaMax = std::max(fMaxPdir_deltaMax, pdir_deltaMax);
0364 fMaxMass_deltaMax1 = std::max(fMaxMass_deltaMax1, mass_deltaMax1);
0365 fMaxMass_deltaMax2 = std::max(fMaxMass_deltaMax2, mass_deltaMax2);
0366 fMaxMass_deltaMax3 = std::max(fMaxMass_deltaMax3, mass_deltaMax3);
0367 fMaxBeta_deltaMax1 = std::max(fMaxBeta_deltaMax1, beta_deltaMax1);
0368 fMaxBeta_deltaMax2 = std::max(fMaxBeta_deltaMax2, beta_deltaMax2);
0369 fMaxGamma_deltaMax1 = std::max(fMaxGamma_deltaMax1, gamma_deltaMax1);
0370 fMaxGamma_deltaMax2 = std::max(fMaxGamma_deltaMax2, gamma_deltaMax2);
0371 fMaxGamma_deltaMax3 = std::max(fMaxGamma_deltaMax3, gamma_deltaMax3);
0372 fMaxT_lab_deltaMax = std::max(fMaxT_lab_deltaMax, t_lab_deltaMax);
0373 fMaxT_proper_deltaMax = std::max(fMaxT_proper_deltaMax, t_proper_deltaMax);
0374 fMaxMc_truth_rPos_deltaMax = std::max(fMaxMc_truth_rPos_deltaMax, mc_truth_rPos_deltaMax);
0375
0376
0377
0378 const G4double xPos = theStep->GetPostStepPoint()->GetPosition().x();
0379 const G4double yPos = theStep->GetPostStepPoint()->GetPosition().y();
0380 const G4double zPos = theStep->GetPostStepPoint()->GetPosition().z();
0381 const G4double rPos = std::sqrt(xPos * xPos + yPos * yPos + zPos * zPos);
0382
0383
0384
0385 G4double tPos = theStep->GetPostStepPoint()->GetLocalTime();
0386
0387
0388 const G4double mc_truth_rPos = tPos * fPrimaryParticleInitialBeta * CLHEP::c_light;
0389 const G4double rDeltaPos = mc_truth_rPos - rPos;
0390 const G4double eKin = theStep->GetPostStepPoint()->GetKineticEnergy();
0391 const G4double xMom = theStep->GetPostStepPoint()->GetMomentum().x();
0392 const G4double yMom = theStep->GetPostStepPoint()->GetMomentum().y();
0393 const G4double zMom = theStep->GetPostStepPoint()->GetMomentum().z();
0394
0395
0396 G4double xDirection = std::min(theStep->GetPostStepPoint()->GetMomentumDirection().x(), 1.0);
0397 if (xDirection < -1.0) xDirection = -1.0;
0398 const G4double deflection_angle_in_degrees = 57.29 * std::acos(xDirection);
0399 const G4double delta_ekin = fPrimaryParticleInitialKineticEnergy - eKin;
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410 if (std::abs(rDeltaPos) > ToleranceDeltaDecayRadius()) {
0411
0412
0413 if (rDeltaPos < 0.0) {
0414
0415 if (fRunPtr) fRunPtr->IncrementNumberUnexpectedDecays();
0416 }
0417
0418 }
0419 fMeanDeltaR_primaryDecay += rDeltaPos;
0420 fMinDeltaR_primaryDecay = std::min(fMinDeltaR_primaryDecay, rDeltaPos);
0421 fMaxDeltaR_primaryDecay = std::max(fMaxDeltaR_primaryDecay, rDeltaPos);
0422 fMeanR_primaryDecay += rPos;
0423 fMinR_primaryDecay = std::min(fMinR_primaryDecay, rPos);
0424 fMaxR_primaryDecay = std::max(fMaxR_primaryDecay, rPos);
0425 fMeanX_primaryDecay += xPos;
0426 fMinX_primaryDecay = std::min(fMinX_primaryDecay, xPos);
0427 fMaxX_primaryDecay = std::max(fMaxX_primaryDecay, xPos);
0428 fMeanY_primaryDecay += yPos;
0429 fMinY_primaryDecay = std::min(fMinY_primaryDecay, yPos);
0430 fMaxY_primaryDecay = std::max(fMaxY_primaryDecay, yPos);
0431 fMeanZ_primaryDecay += zPos;
0432 fMinZ_primaryDecay = std::min(fMinZ_primaryDecay, zPos);
0433 fMaxZ_primaryDecay = std::max(fMaxZ_primaryDecay, zPos);
0434 fMeanDeltaAngle_primaryDecay += deflection_angle_in_degrees;
0435 fMinDeltaAngle_primaryDecay =
0436 std::min(fMinDeltaAngle_primaryDecay, deflection_angle_in_degrees);
0437 fMaxDeltaAngle_primaryDecay =
0438 std::max(fMaxDeltaAngle_primaryDecay, deflection_angle_in_degrees);
0439 fMeanDeltaEkin_primaryDecay += delta_ekin;
0440 fMinDeltaEkin_primaryDecay = std::min(fMinDeltaEkin_primaryDecay, delta_ekin);
0441 fMaxDeltaEkin_primaryDecay = std::max(fMaxDeltaEkin_primaryDecay, delta_ekin);
0442 fMeanEkin_primaryDecay += eKin;
0443 fMinEkin_primaryDecay = std::min(fMinEkin_primaryDecay, eKin);
0444 fMaxEkin_primaryDecay = std::max(fMaxEkin_primaryDecay, eKin);
0445 fMeanPx_primaryDecay += xMom;
0446 fMinPx_primaryDecay = std::min(fMinPx_primaryDecay, xMom);
0447 fMaxPx_primaryDecay = std::max(fMaxPx_primaryDecay, xMom);
0448 fMeanPy_primaryDecay += yMom;
0449 fMinPy_primaryDecay = std::min(fMinPy_primaryDecay, yMom);
0450 fMaxPy_primaryDecay = std::max(fMaxPy_primaryDecay, yMom);
0451 fMeanPz_primaryDecay += zMom;
0452 fMinPz_primaryDecay = std::min(fMinPz_primaryDecay, zMom);
0453 fMaxPz_primaryDecay = std::max(fMaxPz_primaryDecay, zMom);
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464 const G4double underestimated_mc_truth_rPos =
0465 t_proper_val * gamma_val * beta_val * CLHEP::c_light;
0466 const G4double overestimated_mc_truth_rPos =
0467 t_proper_val * fPrimaryParticleInitialGamma * fPrimaryParticleInitialBeta * CLHEP::c_light;
0468 const G4double underestimated_mc_truth_rPos_delta =
0469 underestimated_mc_truth_rPos - mc_truth_rPos_val;
0470 const G4double overestimated_mc_truth_rPos_delta =
0471 overestimated_mc_truth_rPos - mc_truth_rPos_val;
0472 fMeanUnderestimated_mc_truth_rPos_delta += underestimated_mc_truth_rPos_delta;
0473 fMeanOverestimated_mc_truth_rPos_delta += overestimated_mc_truth_rPos_delta;
0474
0475
0476
0477
0478 if (-underestimated_mc_truth_rPos_delta > ToleranceDeltaDecayRadius()) {
0479
0480
0481
0482
0483
0484 if (fRunPtr) fRunPtr->IncrementNumber_underestimated_mc_truth_rPos_delta_above();
0485 }
0486 if (overestimated_mc_truth_rPos_delta > ToleranceDeltaDecayRadius()) {
0487
0488
0489
0490
0491
0492 if (fRunPtr) fRunPtr->IncrementNumber_overestimated_mc_truth_rPos_delta_above();
0493 }
0494 const G4double underestimated_rDeltaPos = underestimated_mc_truth_rPos - rPos;
0495 const G4double overestimated_rDeltaPos = overestimated_mc_truth_rPos - rPos;
0496 fMeanUnderestimated_rDeltaPos += underestimated_rDeltaPos;
0497 fMeanOverestimated_rDeltaPos += overestimated_rDeltaPos;
0498
0499
0500
0501
0502 if (-underestimated_rDeltaPos > ToleranceDeltaDecayRadius()) {
0503 if (fRunPtr) fRunPtr->IncrementNumberLargeUnderestimates();
0504 }
0505 if (overestimated_rDeltaPos > ToleranceDeltaDecayRadius()) {
0506 if (fRunPtr) fRunPtr->IncrementNumberLargeOverestimates();
0507 }
0508
0509 fMinUnderestimated_mc_truth_rPos_delta =
0510 std::min(fMinUnderestimated_mc_truth_rPos_delta, underestimated_mc_truth_rPos_delta);
0511 fMaxOverestimated_mc_truth_rPos_delta =
0512 std::max(fMaxOverestimated_mc_truth_rPos_delta, overestimated_mc_truth_rPos_delta);
0513 fMinUnderestimated_rDeltaPos = std::min(fMinUnderestimated_rDeltaPos, underestimated_rDeltaPos);
0514 fMaxOverestimated_rDeltaPos = std::max(fMaxOverestimated_rDeltaPos, overestimated_rDeltaPos);
0515
0516
0517
0518
0519 const G4float float_xPos = static_cast<G4float>(theStep->GetPostStepPoint()->GetPosition().x());
0520 const G4float float_yPos = static_cast<G4float>(theStep->GetPostStepPoint()->GetPosition().y());
0521 const G4float float_zPos = static_cast<G4float>(theStep->GetPostStepPoint()->GetPosition().z());
0522 const G4float float_rPos =
0523 std::sqrt(float_xPos * float_xPos + float_yPos * float_yPos + float_zPos * float_zPos);
0524 const G4float float_tPos = static_cast<G4float>(theStep->GetPostStepPoint()->GetLocalTime());
0525 const G4float float_initialBeta1 = static_cast<G4float>(fPrimaryParticleInitialBeta);
0526 const G4float float_initialBeta2 = static_cast<G4float>(fPrimaryParticleInitialMomentum)
0527 / static_cast<G4float>(fPrimaryParticleInitialTotalEnergy);
0528 const G4float float_initialGamma = static_cast<G4float>(fPrimaryParticleInitialGamma);
0529 const G4float float_initialBeta3 =
0530 std::sqrt(float_initialGamma * float_initialGamma - 1.0) / float_initialGamma;
0531 const G4float float_c_light = static_cast<G4float>(CLHEP::c_light);
0532 const G4float float_mc_truth_rPos1 = float_tPos * float_initialBeta1 * float_c_light;
0533 const G4float float_mc_truth_rPos2 = float_tPos * float_initialBeta2 * float_c_light;
0534 const G4float float_mc_truth_rPos3 = float_tPos * float_initialBeta3 * float_c_light;
0535 const G4float float_rDeltaPos_0 = static_cast<G4float>(rDeltaPos);
0536 const G4float float_rDeltaPos_1 = float_mc_truth_rPos1 - float_rPos;
0537 const G4float float_rDeltaPos_2 = float_mc_truth_rPos2 - float_rPos;
0538 const G4float float_rDeltaPos_3 = float_mc_truth_rPos3 - float_rPos;
0539 const G4float float_rDeltaPos_4 = static_cast<G4float>(mc_truth_rPos) - float_rPos;
0540 const G4float float_rDeltaPos_5 = float_mc_truth_rPos1 - static_cast<G4float>(rPos);
0541 const G4float float_rDeltaPos_6 = float_mc_truth_rPos2 - static_cast<G4float>(rPos);
0542 const G4float float_rDeltaPos_7 = float_mc_truth_rPos3 - static_cast<G4float>(rPos);
0543 G4double rDeltaPos_deltaMax =
0544 std::max(std::abs(float_rDeltaPos_0 - rDeltaPos), std::abs(float_rDeltaPos_1 - rDeltaPos));
0545 rDeltaPos_deltaMax = std::max(rDeltaPos_deltaMax, std::abs(float_rDeltaPos_2 - rDeltaPos));
0546 rDeltaPos_deltaMax = std::max(rDeltaPos_deltaMax, std::abs(float_rDeltaPos_3 - rDeltaPos));
0547 rDeltaPos_deltaMax = std::max(rDeltaPos_deltaMax, std::abs(float_rDeltaPos_4 - rDeltaPos));
0548 rDeltaPos_deltaMax = std::max(rDeltaPos_deltaMax, std::abs(float_rDeltaPos_5 - rDeltaPos));
0549 rDeltaPos_deltaMax = std::max(rDeltaPos_deltaMax, std::abs(float_rDeltaPos_6 - rDeltaPos));
0550 rDeltaPos_deltaMax = std::max(rDeltaPos_deltaMax, std::abs(float_rDeltaPos_7 - rDeltaPos));
0551
0552
0553 fMaxFloat_rDeltaPos_deltaMax = std::max(fMaxFloat_rDeltaPos_deltaMax, rDeltaPos_deltaMax);
0554
0555
0556
0557 std::size_t nSec = theStep->GetNumberOfSecondariesInCurrentStep();
0558 const std::vector<const G4Track*>* ptrVecSecondaries = theStep->GetSecondaryInCurrentStep();
0559 G4double deltaE = 0.0, deltaPx = 0.0, deltaPy = 0.0, deltaPz = 0.0;
0560 if (nSec > 0 && ptrVecSecondaries != nullptr) {
0561 G4double sumEsecondaries = 0.0;
0562 G4ThreeVector sumPsecondaries(0.0, 0.0, 0.0);
0563 for (std::size_t i = 0; i < nSec; ++i) {
0564 if ((*ptrVecSecondaries)[i]) {
0565 sumEsecondaries += (*ptrVecSecondaries)[i]->GetTotalEnergy();
0566 sumPsecondaries += (*ptrVecSecondaries)[i]->GetMomentum();
0567 }
0568 }
0569 deltaE = sumEsecondaries - theStep->GetPostStepPoint()->GetTotalEnergy();
0570 fMeanViolationE_primaryDecay += deltaE;
0571 fMinViolationE_primaryDecay = std::min(fMinViolationE_primaryDecay, deltaE);
0572 fMaxViolationE_primaryDecay = std::max(fMaxViolationE_primaryDecay, deltaE);
0573 if (std::abs(deltaE) > ToleranceEPviolations()) {
0574 if (fRunPtr) fRunPtr->IncrementNumberEviolations();
0575 }
0576 deltaPx = sumPsecondaries.x() - xMom;
0577 fMeanViolationPx_primaryDecay += deltaPx;
0578 fMinViolationPx_primaryDecay = std::min(fMinViolationPx_primaryDecay, deltaPx);
0579 fMaxViolationPx_primaryDecay = std::max(fMaxViolationPx_primaryDecay, deltaPx);
0580 deltaPy = sumPsecondaries.y() - yMom;
0581 fMeanViolationPy_primaryDecay += deltaPy;
0582 fMinViolationPy_primaryDecay = std::min(fMinViolationPy_primaryDecay, deltaPy);
0583 fMaxViolationPy_primaryDecay = std::max(fMaxViolationPy_primaryDecay, deltaPy);
0584 deltaPz = sumPsecondaries.z() - zMom;
0585 fMeanViolationPz_primaryDecay += deltaPz;
0586 fMinViolationPz_primaryDecay = std::min(fMinViolationPz_primaryDecay, deltaPz);
0587 fMaxViolationPz_primaryDecay = std::max(fMaxViolationPz_primaryDecay, deltaPz);
0588 if (std::abs(deltaPx) > ToleranceEPviolations() || std::abs(deltaPy) > ToleranceEPviolations()
0589 || std::abs(deltaPz) > ToleranceEPviolations())
0590 {
0591 if (fRunPtr) fRunPtr->IncrementNumberPviolations();
0592 }
0593 }
0594 else {
0595 if (fRunPtr) fRunPtr->IncrementNumberBadPrimaryDecays();
0596 }
0597
0598 if (fRunPtr) {
0599 fRunPtr->IncrementNumberDecays();
0600 fRunPtr->SetDecayT(tPos);
0601 fRunPtr->SetDecayR_mc_truth(mc_truth_rPos);
0602 fRunPtr->SetDecayR(rPos);
0603 fRunPtr->SetDecayX(xPos);
0604 fRunPtr->SetDecayY(yPos);
0605 fRunPtr->SetDecayZ(zPos);
0606 fRunPtr->SetDeltaDecayR(rDeltaPos);
0607 fRunPtr->SetDeflectionAngle(deflection_angle_in_degrees);
0608 fRunPtr->SetDeltaEkin(delta_ekin);
0609 fRunPtr->SetDecayEkin(eKin);
0610 fRunPtr->SetDecayPx(xMom);
0611 fRunPtr->SetDecayPy(yMom);
0612 fRunPtr->SetDecayPz(zMom);
0613 fRunPtr->SetDecayEtotViolation(deltaE);
0614 fRunPtr->SetDecayPxViolation(deltaPx);
0615 fRunPtr->SetDecayPyViolation(deltaPy);
0616 fRunPtr->SetDecayPzViolation(deltaPz);
0617 fRunPtr->SetMaxEkin_deltaMax(ekin_deltaMax);
0618 fRunPtr->SetMaxEtot_deltaMax(etot_deltaMax);
0619 fRunPtr->SetMaxP_deltaMax(p_deltaMax);
0620 fRunPtr->SetMaxPdir_deltaMax(pdir_deltaMax);
0621 fRunPtr->SetMaxMass_deltaMax1(mass_deltaMax1);
0622 fRunPtr->SetMaxMass_deltaMax2(mass_deltaMax2);
0623 fRunPtr->SetMaxMass_deltaMax3(mass_deltaMax3);
0624 fRunPtr->SetMaxBeta_deltaMax1(beta_deltaMax1);
0625 fRunPtr->SetMaxBeta_deltaMax2(beta_deltaMax2);
0626 fRunPtr->SetMaxGamma_deltaMax1(gamma_deltaMax1);
0627 fRunPtr->SetMaxGamma_deltaMax2(gamma_deltaMax2);
0628 fRunPtr->SetMaxGamma_deltaMax3(gamma_deltaMax3);
0629 fRunPtr->SetMaxT_proper_deltaMax(t_proper_deltaMax);
0630 fRunPtr->SetMaxT_lab_deltaMax(t_lab_deltaMax);
0631 fRunPtr->SetMaxMc_truth_rPos_deltaMax(mc_truth_rPos_deltaMax);
0632 fRunPtr->SetMinUnderestimated_mc_truth_rPos_delta(underestimated_mc_truth_rPos_delta);
0633 fRunPtr->SetMaxOverestimated_mc_truth_rPos_delta(overestimated_mc_truth_rPos_delta);
0634 fRunPtr->SetMinUnderestimated_rDeltaPos(underestimated_rDeltaPos);
0635 fRunPtr->SetMaxOverestimated_rDeltaPos(overestimated_rDeltaPos);
0636 fRunPtr->SetMaxFloat_rDeltaPos_deltaMax(fMaxFloat_rDeltaPos_deltaMax);
0637 }
0638 }
0639 }
0640
0641