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