File indexing completed on 2025-01-31 09:22:34
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 #include "RunAction.hh"
0036
0037 #include "G4UImanager.hh"
0038 #include "G4AnalysisManager.hh"
0039 #include "Randomize.hh"
0040
0041 RunAction::RunAction(const DetectorConstruction* det)
0042 :fDetector(det)
0043 {
0044 fSaveRndm = 0;
0045 fDose3DDose = nullptr;
0046 fMapVoxels = nullptr;
0047 }
0048
0049 RunAction::~RunAction()
0050 {
0051 if (fDose3DDose) delete[] fDose3DDose;
0052 if (fMapVoxels) delete[] fMapVoxels;
0053 }
0054
0055 void RunAction::BeginOfRunAction(const G4Run*)
0056 {
0057
0058 CellParameterisation* fMyCellParameterisation = CellParameterisation::Instance();
0059
0060
0061
0062 G4cout << "##### Create analysis manager " << " " << this << G4endl;
0063
0064 G4AnalysisManager* man = G4AnalysisManager::Instance();
0065 man->SetDefaultFileType("root");
0066
0067 G4cout << "Using " << man->GetType() << " analysis manager" << G4endl;
0068
0069
0070 man->OpenFile("microbeam");
0071 man->SetFirstNtupleId(1);
0072
0073
0074
0075
0076
0077 man->CreateNtuple("ntuple0", "Stopping power");
0078 man->CreateNtupleDColumn("e");
0079 man->CreateNtupleDColumn("sp");
0080 man->FinishNtuple();
0081
0082
0083
0084
0085
0086 man->CreateNtuple("ntuple1", "Beam position");
0087 man->CreateNtupleDColumn("x");
0088 man->CreateNtupleDColumn("y");
0089 man->FinishNtuple();
0090
0091
0092
0093
0094
0095 man->CreateNtuple("ntuple2", "Range");
0096 man->CreateNtupleDColumn("x");
0097 man->CreateNtupleDColumn("y");
0098 man->CreateNtupleDColumn("z");
0099 man->FinishNtuple();
0100
0101
0102
0103
0104
0105 man->CreateNtuple("ntuple3", "Doses");
0106 man->CreateNtupleDColumn("doseN");
0107 man->CreateNtupleDColumn("doseC");
0108 man->FinishNtuple();
0109
0110
0111
0112
0113
0114 man->CreateNtuple("ntuple4", "3D");
0115 man->CreateNtupleDColumn("x");
0116 man->CreateNtupleDColumn("y");
0117 man->CreateNtupleDColumn("z");
0118 man->CreateNtupleDColumn("doseV");
0119 man->FinishNtuple();
0120
0121
0122 G4cout << "All Ntuples have been created " << G4endl;
0123
0124
0125 if (fSaveRndm > 0)
0126 {
0127 CLHEP::HepRandom::showEngineStatus();
0128 CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
0129 }
0130
0131 fNumEvent = 0;
0132 fNbOfHitsGas = 0;
0133
0134
0135 fDoseN = 0;
0136 fDoseC = 0;
0137
0138 fMassCytoplasm = fDetector->GetMassCytoplasm();
0139 fMassNucleus = fDetector->GetMassNucleus();
0140 fNbOfPixels = fDetector->GetNbOfPixelsInPhantom();
0141
0142 fMapVoxels = new G4ThreeVector[fNbOfPixels];
0143 fDose3DDose = new G4double[fNbOfPixels];
0144
0145 for (G4int i=0; i<fNbOfPixels; i++)
0146 {
0147 fMapVoxels [i]=fMyCellParameterisation->GetVoxelThreeVector(i);
0148 fDose3DDose[i]=0;
0149 }
0150 }
0151
0152 void RunAction::EndOfRunAction(const G4Run* )
0153 {
0154 G4AnalysisManager* man = G4AnalysisManager::Instance();
0155
0156
0157 if (fSaveRndm == 1)
0158 {
0159 CLHEP::HepRandom::showEngineStatus();
0160 CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
0161 }
0162
0163 for (G4int i=0; i<fNbOfPixels; i++)
0164 {
0165 if (fDose3DDose[i]>0)
0166 {
0167 G4ThreeVector v;
0168 v = fMapVoxels[i];
0169 man->FillNtupleDColumn(5,0,v.x());
0170 man->FillNtupleDColumn(5,1,v.y());
0171 man->FillNtupleDColumn(5,2,v.z());
0172 man->FillNtupleDColumn(5,3,fDose3DDose[i]);
0173 man->AddNtupleRow(5);
0174 }
0175 }
0176
0177 G4cout << "-> Total number of particles detected by the gas detector : " << GetNbOfHitsGas() << G4endl;
0178 G4cout << G4endl;
0179
0180
0181 man->Write();
0182 man->CloseFile();
0183
0184
0185 man->Clear();
0186 }