File indexing completed on 2025-01-31 09:22:09
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 <stdlib.h>
0031 #include "AnalysisManager.hh"
0032 #include "G4UnitsTable.hh"
0033 #include "G4SystemOfUnits.hh"
0034
0035 #include "AnalysisMessenger.hh"
0036
0037 AnalysisManager::AnalysisManager(AnalysisMessenger* analysisMessenger)
0038 {
0039 factoryOn = false;
0040
0041
0042
0043
0044
0045
0046 for (G4int k=0; k<MaxNtCol; k++) fNtColId[k] = 0;
0047
0048
0049
0050
0051 messenger = analysisMessenger;
0052 }
0053
0054 AnalysisManager::~AnalysisManager()
0055 {
0056 }
0057
0058 void AnalysisManager::book(G4bool addExtraNt)
0059 {
0060 G4AnalysisManager* manager = G4AnalysisManager::Instance();
0061
0062 manager->SetVerboseLevel(2);
0063
0064 extraNt = addExtraNt;
0065
0066 usingRoot = messenger -> IsRootOutput();
0067
0068
0069 G4String fileName;
0070 if( usingRoot == true ) fileName = "experimental_microdosimetry.root";
0071 else fileName = "experimental_microdosimetry.csv";
0072
0073
0074 if( usingRoot == true ) manager->SetNtupleDirectoryName("experimental_microdosimetry_ntuple");
0075
0076
0077 G4bool fileOpen = manager->OpenFile(fileName);
0078 if (!fileOpen) {
0079 G4cout << "\n---> HistoManager::book(): cannot open "
0080 << fileName << G4endl;
0081 return;
0082 }
0083
0084 manager->SetFirstNtupleId(1);
0085
0086
0087 manager -> CreateNtuple("101", "Primary Energy");
0088 fNtColId[0] = manager -> CreateNtupleDColumn("Ek");
0089 manager -> FinishNtuple();
0090
0091
0092 manager -> CreateNtuple("102", "Edep");
0093 fNtColId[1] = manager -> CreateNtupleDColumn("edep");
0094 fNtColId[2] = manager -> CreateNtupleDColumn("len");
0095 if( extraNt == true ) fNtColId[3] = manager -> CreateNtupleIColumn("eventID");
0096 manager -> FinishNtuple();
0097
0098
0099 manager -> CreateNtuple("103", "secondary");
0100 fNtColId[4] = manager -> CreateNtupleDColumn("AA");
0101 fNtColId[5] = manager -> CreateNtupleDColumn("ZZ");
0102 fNtColId[6] = manager -> CreateNtupleDColumn("KE");
0103 manager -> FinishNtuple();
0104
0105
0106 if( extraNt == true)
0107 {
0108 manager -> CreateNtuple("104", "secondStageE");
0109 fNtColId[7] = manager -> CreateNtupleDColumn("edep");
0110 fNtColId[8] = manager -> CreateNtupleIColumn("eventID");
0111 manager -> FinishNtuple();
0112 }
0113
0114 factoryOn = true;
0115 }
0116
0117
0118 void AnalysisManager::SetPrimaryEnergy(G4double energy)
0119 {
0120 G4AnalysisManager* manager = G4AnalysisManager::Instance();
0121 manager -> FillNtupleDColumn(1, fNtColId[0], energy);
0122 manager -> AddNtupleRow(1);
0123 }
0124
0125 void AnalysisManager::StoreEnergyDeposition(G4double edep, G4double len, G4int eid)
0126 {
0127 G4AnalysisManager* manager = G4AnalysisManager::Instance();
0128 manager -> FillNtupleDColumn(2, fNtColId[1], edep);
0129 manager -> FillNtupleDColumn(2, fNtColId[2], len);
0130 if( extraNt == true ) manager -> FillNtupleIColumn(2, fNtColId[3], eid);
0131
0132 manager -> AddNtupleRow(2);
0133 }
0134
0135 void AnalysisManager::FillSecondaries(G4int AA, G4double charge, G4double energy)
0136 {
0137
0138 G4AnalysisManager* manager = G4AnalysisManager::Instance();
0139 manager -> FillNtupleDColumn(3, fNtColId[4], AA);
0140 manager -> FillNtupleDColumn(3, fNtColId[5], charge);
0141 manager -> FillNtupleDColumn(3, fNtColId[6], energy);
0142 manager -> AddNtupleRow(3);
0143 }
0144
0145 void AnalysisManager::StoreSecondStageEnergyDeposition(G4double edep, G4int eid)
0146 {
0147 if( extraNt == true )
0148 {
0149 G4AnalysisManager* manager = G4AnalysisManager::Instance();
0150 manager -> FillNtupleDColumn(4, fNtColId[7], edep);
0151 manager -> FillNtupleIColumn(4, fNtColId[8], eid);
0152 manager -> AddNtupleRow(4);
0153 }
0154 }
0155
0156 void AnalysisManager::finish()
0157 {
0158 if (factoryOn)
0159 {
0160 G4AnalysisManager* manager = G4AnalysisManager::Instance();
0161 manager -> Write();
0162 manager -> CloseFile();
0163 factoryOn = false;
0164 }
0165 }
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178