File indexing completed on 2025-10-14 08:09:01
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 #include "Analysis.hh"
0031
0032 #include "G4AnalysisManager.hh"
0033 #include "G4AutoDelete.hh"
0034 #include "G4SystemOfUnits.hh"
0035
0036
0037 G4ThreadLocal G4int Analysis::fincidentFlag = false;
0038 G4ThreadLocal Analysis* the_analysis = 0;
0039
0040
0041 Analysis* Analysis::GetAnalysis()
0042 {
0043 if (!the_analysis) {
0044 the_analysis = new Analysis();
0045 G4AutoDelete::Register(the_analysis);
0046 }
0047 return the_analysis;
0048 }
0049
0050
0051 Analysis::Analysis()
0052 : fincident_x_hist(0),
0053 fincident_map(0),
0054 fdose_hist(0),
0055 fdose_map(0),
0056 fdose_prof(0),
0057 fdose_map_prof(0),
0058 fdose_map3d(0)
0059 {}
0060
0061
0062 void Analysis::Book()
0063 {
0064 G4AnalysisManager* mgr = G4AnalysisManager::Instance();
0065 mgr->SetDefaultFileType("root");
0066 mgr->SetVerboseLevel(1);
0067 fincident_x_hist = mgr->CreateH1("incident_x", "Incident X", 100, -5 * cm, 5 * cm, "cm");
0068 fincident_map = mgr->CreateH2("incident_map", "Incident Map", 50, -5 * cm, 5 * cm, 50, -5 * cm,
0069 5 * cm, "cm", "cm");
0070 fdose_hist = mgr->CreateH1("dose", "Dose distribution", 500, 0, 50 * cm, "cm");
0071 fdose_map = mgr->CreateH2("dose_map", "Dose distribution", 500, 0, 50 * cm, 200, -10 * cm,
0072 10 * cm, "cm", "cm");
0073 fdose_map3d = mgr->CreateH3("dose_map_3d", "Dose distribution", 30, 0, 50 * cm, 20, -10 * cm,
0074 10 * cm, 20, -10 * cm, 10 * cm, "cm", "cm", "cm");
0075 fdose_prof =
0076 mgr->CreateP1("dose_prof", "Dose distribution", 300, 0, 30 * cm, 0, 100 * MeV, "cm", "MeV");
0077 fdose_map_prof = mgr->CreateP2("dose_map_prof", "Dose distribution", 300, 0, 30 * cm, 80, -4 * cm,
0078 4 * cm, 0, 100 * MeV, "cm", "cm", "MeV");
0079 }
0080
0081
0082 Analysis::~Analysis() {}
0083
0084
0085 void Analysis::Update()
0086 {
0087 return;
0088 }
0089
0090
0091 void Analysis::Clear()
0092 {
0093 return;
0094 }
0095
0096
0097 void Analysis::Save(const G4String& fname)
0098 {
0099 G4AnalysisManager* mgr = G4AnalysisManager::Instance();
0100 mgr->OpenFile(fname.c_str());
0101 mgr->Write();
0102 return;
0103 }
0104
0105
0106 void Analysis::Close(G4bool reset)
0107 {
0108 G4AnalysisManager* mgr = G4AnalysisManager::Instance();
0109 mgr->CloseFile(reset);
0110 return;
0111 }
0112
0113
0114 void Analysis::FillIncident(const G4ThreeVector& p)
0115 {
0116 if (!fincidentFlag) {
0117 G4AnalysisManager* mgr = G4AnalysisManager::Instance();
0118 mgr->FillH2(fincident_map, p.x(), p.y());
0119 mgr->FillH1(fincident_x_hist, p.x());
0120 fincidentFlag = true;
0121 }
0122 }
0123
0124
0125 void Analysis::FillDose(const G4ThreeVector& p, G4double dedx)
0126 {
0127 const G4double dxy = 10. * mm;
0128 if (std::abs(p.y()) < dxy) {
0129 G4AnalysisManager* mgr = G4AnalysisManager::Instance();
0130 const G4double Z0 = 25. * cm;
0131
0132 mgr->FillH2(fdose_map, p.z() + Z0, p.x(), dedx / GeV);
0133 mgr->FillP2(fdose_map_prof, p.z() + Z0, p.x(), dedx);
0134 mgr->FillH3(fdose_map3d, p.z() + Z0, p.x(), p.y(), dedx / GeV);
0135 if (std::abs(p.x()) < dxy) {
0136 mgr->FillH1(fdose_hist, p.z() + Z0, dedx / GeV);
0137 mgr->FillP1(fdose_prof, p.z() + Z0, dedx);
0138 }
0139 }
0140 }