File indexing completed on 2025-01-31 09:22:12
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
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055 #include <fstream>
0056 #include <iomanip>
0057
0058 #include "GammaRayTelAnalysis.hh"
0059 #include "GammaRayTelAnalysisMessenger.hh"
0060 #include "GammaRayTelDetectorConstruction.hh"
0061
0062 #include "G4RunManager.hh"
0063
0064
0065
0066 GammaRayTelAnalysis *GammaRayTelAnalysis::instance{nullptr};
0067
0068
0069
0070 GammaRayTelAnalysis::GammaRayTelAnalysis() : detector(nullptr), histo2DMode("strip") {
0071 detector = static_cast<const GammaRayTelDetectorConstruction*>(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0072
0073
0074 analysisMessenger = new GammaRayTelAnalysisMessenger(this);
0075 histogramFileName = "gammaraytel";
0076 }
0077
0078
0079
0080 GammaRayTelAnalysis::~GammaRayTelAnalysis() {
0081 Finish();
0082 }
0083
0084
0085
0086 void GammaRayTelAnalysis::Init() {
0087 }
0088
0089
0090
0091 void GammaRayTelAnalysis::Finish() {
0092 delete analysisMessenger;
0093 analysisMessenger = nullptr;
0094 }
0095
0096
0097
0098 auto GammaRayTelAnalysis::getInstance() -> GammaRayTelAnalysis* {
0099 if (instance == nullptr) {
0100 instance = new GammaRayTelAnalysis();
0101 }
0102 return instance;
0103 }
0104
0105
0106
0107
0108 void GammaRayTelAnalysis::InsertPositionXZ(G4double x, G4double z) {
0109 auto *manager = G4AnalysisManager::Instance();
0110 manager->FillH2(1, x, z);
0111 }
0112
0113
0114
0115
0116 void GammaRayTelAnalysis::InsertPositionYZ(G4double y, G4double z) {
0117 auto *manager = G4AnalysisManager::Instance();
0118 manager->FillH2(2, y, z);
0119 }
0120
0121
0122
0123
0124 void GammaRayTelAnalysis::InsertEnergy(G4double energy) {
0125 auto *manager = G4AnalysisManager::Instance();
0126 manager->FillH1(1, energy);
0127 }
0128
0129
0130
0131
0132 void GammaRayTelAnalysis::InsertHits(G4int planeNumber) {
0133 auto *manager = G4AnalysisManager::Instance();
0134 manager->FillH1(2, planeNumber);
0135 }
0136
0137
0138
0139 void GammaRayTelAnalysis::setNtuple(G4double energy, G4int planeNumber, G4double x, G4double y, G4double z) {
0140 auto *manager = G4AnalysisManager::Instance();
0141 manager->FillNtupleDColumn(0, energy);
0142 manager->FillNtupleDColumn(1, planeNumber);
0143 manager->FillNtupleDColumn(2, x);
0144 manager->FillNtupleDColumn(3, y);
0145 manager->FillNtupleDColumn(4, z);
0146 manager->AddNtupleRow();
0147 }
0148
0149
0150
0151
0152
0153
0154
0155
0156 void GammaRayTelAnalysis::BeginOfRun() {
0157 auto *manager = G4AnalysisManager::Instance();
0158 manager->SetDefaultFileType("root");
0159
0160
0161
0162 G4cout << "Opening output file " << histogramFileName << " ... ";
0163 manager->OpenFile(histogramFileName);
0164 manager->SetFirstHistoId(1);
0165 G4cout << " done" << G4endl;
0166
0167 auto Nplane = detector->GetNbOfTKRLayers();
0168 auto numberOfStrips = detector->GetNbOfTKRStrips();
0169 auto numberOfTiles = detector->GetNbOfTKRTiles();
0170 auto sizeXY = detector->GetTKRSizeXY();
0171 auto sizeZ = detector->GetTKRSizeZ();
0172 auto N = numberOfStrips * numberOfTiles;
0173
0174
0175
0176
0177 constexpr auto NUMBER_OF_BINS{100};
0178 constexpr auto LOWER_BOUND{50};
0179 constexpr auto UPPER_BOUND{200};
0180
0181
0182 manager->CreateH1("1", "Deposited energy in the last X plane (keV)", NUMBER_OF_BINS, LOWER_BOUND, UPPER_BOUND);
0183
0184
0185 manager->CreateH1("2", "Hits distribution in TKR X planes", Nplane, 0, Nplane - 1);
0186
0187
0188
0189
0190
0191
0192 if (histo2DMode == "strip") {
0193 manager->CreateH2("1", "Tracker hits XZ (strip, plane)", N, 0, N - 1, 2 * Nplane, 0, Nplane - 1);
0194 } else {
0195 manager->CreateH2("1", "Tracker hits XZ (x, z) in mm", G4int(sizeXY / 5), -sizeXY / 2, sizeXY / 2, G4int(sizeZ / 5), -sizeZ / 2, sizeZ / 2);
0196 }
0197
0198
0199 if (histo2DMode == "strip") {
0200 manager->CreateH2("2", "Tracker hits YZ (strip, plane)", N, 0, N - 1, 2 * Nplane, 0, Nplane - 1);
0201 } else {
0202 manager->CreateH2("2", "Tracker hits YZ (x, z) in mm", G4int(sizeXY / 5), -sizeXY / 2, sizeXY / 2, G4int(sizeZ / 5), -sizeZ / 2, sizeZ / 2);
0203 }
0204
0205
0206
0207 manager->CreateNtuple("1", "Track n-tuple");
0208 manager->CreateNtupleDColumn("energy");
0209 manager->CreateNtupleDColumn("plane");
0210 manager->CreateNtupleDColumn("x");
0211 manager->CreateNtupleDColumn("y");
0212 manager->CreateNtupleDColumn("z");
0213 manager->FinishNtuple();
0214 }
0215
0216
0217
0218
0219 void GammaRayTelAnalysis::EndOfRun() {
0220
0221 auto *manager = G4AnalysisManager::Instance();
0222 manager->Write();
0223 manager->CloseFile();
0224 }
0225
0226
0227
0228
0229 void GammaRayTelAnalysis::EndOfEvent(G4int ) {
0230 }