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 "TFile.h"
0033 #include "TH1.h"
0034 #include "TH2.h"
0035 #include "TROOT.h"
0036
0037 #include "G4AutoLock.hh"
0038 #include "G4SystemOfUnits.hh"
0039
0040 G4ThreadLocal G4int Analysis::fincidentFlag = false;
0041 G4ThreadLocal Analysis* the_analysis = 0;
0042
0043 G4Mutex rootm = G4MUTEX_INITIALIZER;
0044
0045
0046 Analysis* Analysis::GetAnalysis()
0047 {
0048 if (!the_analysis) the_analysis = new Analysis;
0049 return the_analysis;
0050 }
0051
0052
0053 Analysis::Analysis()
0054 {
0055 G4AutoLock l(&rootm);
0056
0057 fincident_map = new TH2D("incident map", "Incident Distributuon", 50, -5., 5., 50, -5., 5.);
0058 fincident_map->GetXaxis()->SetTitle("X (cm)");
0059 fincident_map->GetYaxis()->SetTitle("Y (cm)");
0060 fincident_map->SetStats(0);
0061
0062 fincident_x_hist = new TH1D("incident x", "Incident X", 100, -5., 5.);
0063 fincident_x_hist->GetXaxis()->SetTitle("X (cm)");
0064 fincident_x_hist->SetFillColor(kRed);
0065
0066 fdose_map = new TH2D("dose map", "Dose Distribution", 500, 0., 50., 200, -10., 10.);
0067 fdose_map->GetXaxis()->SetTitle("Z (cm)");
0068 fdose_map->GetYaxis()->SetTitle("X (cm)");
0069 fdose_map->SetStats(0);
0070
0071 fdose_hist = new TH1D("dose", "Dose Distribution", 500, 0., 50.);
0072 fdose_hist->GetXaxis()->SetTitle("Z (cm)");
0073 fdose_hist->GetYaxis()->SetTitle("Dose (GeV)");
0074 fdose_hist->SetFillColor(kBlue);
0075 fdose_hist->SetStats(0);
0076 }
0077
0078
0079 Analysis::~Analysis()
0080 {
0081 delete fincident_map;
0082 delete fincident_x_hist;
0083 delete fdose_map;
0084 delete fdose_hist;
0085 }
0086
0087
0088 void Analysis::Update()
0089 {
0090 return;
0091 }
0092
0093
0094 void Analysis::Clear()
0095 {
0096 fincident_map->Reset();
0097 fincident_x_hist->Reset();
0098 fdose_map->Reset();
0099 fdose_hist->Reset();
0100
0101 return;
0102 }
0103
0104
0105 void Analysis::Save(const G4String& fname)
0106 {
0107 G4AutoLock l(&rootm);
0108 TFile* file = new TFile(fname.c_str(), "RECREATE", "Geant4 ROOT analysis");
0109
0110 fincident_map->Write();
0111 fincident_x_hist->Write();
0112 fdose_map->Write();
0113 fdose_hist->Write();
0114
0115 file->Close();
0116
0117 delete file;
0118
0119 return;
0120 }
0121
0122
0123 void Analysis::FillIncident(const G4ThreeVector& p)
0124 {
0125 if (!fincidentFlag) {
0126 fincident_map->Fill(p.x() / cm, p.y() / cm);
0127 fincident_x_hist->Fill(p.x() / cm);
0128
0129 fincidentFlag = true;
0130 }
0131 }
0132
0133
0134 void Analysis::FillDose(const G4ThreeVector& p, G4double dedx)
0135 {
0136 const G4double Z0 = 25. * cm;
0137 const G4double dxy = 10. * mm;
0138
0139 if (std::abs(p.y()) < dxy) {
0140 fdose_map->Fill((p.z() + Z0) / cm, p.x() / cm, dedx / GeV);
0141
0142 if (std::abs(p.x()) < dxy) {
0143 fdose_hist->Fill((p.z() + Z0) / cm, dedx / GeV);
0144 }
0145 }
0146 }