File indexing completed on 2026-04-05 07:50:33
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 "TrackingAction.hh"
0030
0031 #include "DetectorConstruction.hh"
0032 #include "HistoManager.hh"
0033 #include "Run.hh"
0034
0035 #include "G4PhysicalConstants.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4Track.hh"
0039
0040
0041
0042 TrackingAction::TrackingAction(DetectorConstruction* DET) : fDetector(DET)
0043 {
0044 fZend = 0.5 * (fDetector->GetThicknessWorld());
0045 }
0046
0047
0048
0049 void TrackingAction::PreUserTrackingAction(const G4Track*) {}
0050
0051
0052
0053 void TrackingAction::PostUserTrackingAction(const G4Track* track)
0054 {
0055 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0056
0057 G4double charge = track->GetDefinition()->GetPDGCharge();
0058 G4ThreeVector position = track->GetPosition();
0059 G4ThreeVector direction = track->GetMomentumDirection();
0060
0061 if (charge == 0.0) return;
0062 if (position.z() < fZend) return;
0063 if (direction.z() <= 0.) return;
0064
0065 G4double rmin, dr, ds;
0066 G4int ih = 1;
0067
0068
0069
0070 G4double ux = direction.x(), uy = direction.y(), uz = direction.z();
0071 G4double thetax = std::atan(ux / uz);
0072 G4double thetay = std::atan(uy / uz);
0073 analysisManager->FillH1(ih, thetax);
0074 analysisManager->FillH1(ih, thetay);
0075
0076
0077
0078 G4double x = position.x(), y = position.y();
0079 G4double r = std::sqrt(x * x + y * y);
0080 ih = 2;
0081 dr = analysisManager->GetH1Width(ih);
0082 rmin = ((int)(r / dr)) * dr;
0083 ds = twopi * (rmin + 0.5 * dr) * dr;
0084 analysisManager->FillH1(ih, r, 1 / ds);
0085
0086
0087
0088 ih = 3;
0089 dr = analysisManager->GetH1Width(ih);
0090 rmin = ((int)(r / dr)) * dr;
0091 ds = twopi * (rmin + 0.5 * dr) * dr;
0092 analysisManager->FillH1(ih, r, 1 / (uz * ds));
0093
0094
0095
0096 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0097
0098 run->SumFluence(r, 1 / uz);
0099
0100
0101
0102 ih = 5;
0103 G4double theta = std::acos(uz);
0104 if (theta > 0.) {
0105 G4double dtheta = analysisManager->GetH1Width(ih);
0106 G4double unit = analysisManager->GetH1Unit(ih);
0107 if (dtheta > 0.) {
0108 G4double weight = unit * unit / (twopi * std::sin(theta) * dtheta);
0109 analysisManager->FillH1(ih, theta, weight);
0110 }
0111 }
0112
0113
0114
0115 ih = 6;
0116 const G4double dist = fDetector->GetZdist_foil_detector();
0117 G4double thetam = std::atan(r / dist);
0118 if (thetam > 0.) {
0119 G4double dtheta = analysisManager->GetH1Width(ih);
0120 G4double unit = analysisManager->GetH1Unit(ih);
0121 if (dtheta > 0.) {
0122 G4double weight = unit * unit / (twopi * std::sin(thetam) * dtheta);
0123 analysisManager->FillH1(ih, thetam, weight);
0124 }
0125 }
0126 }
0127
0128