-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunaction.cc
executable file
·142 lines (107 loc) · 4.6 KB
/
runaction.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "runaction.hh"
// define the constructor
runaction::runaction(){
// add new units for dose
//
const G4double milligray = 1.e-3*gray;
const G4double microgray = 1.e-6*gray;
const G4double nanogray = 1.e-9*gray;
const G4double picogray = 1.e-12*gray;
new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray);
new G4UnitDefinition("microgray", "microGy" , "Dose", microgray);
new G4UnitDefinition("nanogray" , "nanoGy" , "Dose", nanogray);
new G4UnitDefinition("picogray" , "picoGy" , "Dose", picogray);
// Register accumulable to the accumulable manager
G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
accumulableManager->RegisterAccumulable(fEvEdep1);
accumulableManager->RegisterAccumulable(fEvEdep2);
accumulableManager->RegisterAccumulable(fEvEdep3);
accumulableManager->RegisterAccumulable(fEvEdep4);
G4AnalysisManager*man = G4AnalysisManager::Instance();
//man->SetVerboseLevel(1);
man->SetNtupleMerging(true,0);
}
// define the destructor
runaction::~runaction(){
// delete G4AnalysisManager::Instance();
}
void runaction::BeginOfRunAction(const G4Run* run){
// inform the runManager to save random number seed
G4RunManager::GetRunManager()->SetRandomNumberStore(false);
// reset accumulables to their initial values
G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
accumulableManager->Reset();
// initializate the run manager to store the hits
G4AnalysisManager*man = G4AnalysisManager::Instance();
//man->SetHistoDictoryName("histograms");
// create a file for each run
G4int RunID = run->GetRunID();
std::stringstream strRunID;
strRunID<<RunID;
man->OpenFile("output"+strRunID.str()+".root");
man->CreateNtuple("Detector_1","Edep");
man->CreateNtupleDColumn("fedep1");
man->FinishNtuple(0);
man->CreateNtuple("Detector_2","Edep");
man->CreateNtupleDColumn("fedep2");
man->FinishNtuple(1);
man->CreateNtuple("Detector_3","Edep");
man->CreateNtupleDColumn("fedep3");
man->FinishNtuple(2);
man->CreateNtuple("Detector_4","Edep");
man->CreateNtupleDColumn("fedep4");
man->FinishNtuple(3);
man->CreateNtuple("TOF_Det1","TOF");
man->CreateNtupleDColumn("TOF1");
man->FinishNtuple(4);
man->CreateNtuple("TOF_Det2","TOF");
man->CreateNtupleDColumn("TOF2");
man->FinishNtuple(5);
man->CreateNtuple("TOF_Det3","TOF");
man->CreateNtupleDColumn("TOF3");
man->FinishNtuple(6);
man->CreateNtuple("TOF_Det4","TOF");
man->CreateNtupleDColumn("TOF4");
man->FinishNtuple(7);
}
void runaction::EndOfRunAction(const G4Run*){
// Merge accumulables
G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
accumulableManager->Merge();
// Compute dose = total energy deposit in a run and its variance
//
G4double edep1 = fEvEdep1.GetValue();
G4double edep2 = fEvEdep2.GetValue();
G4double edep3 = fEvEdep3.GetValue();
G4double edep4 = fEvEdep4.GetValue();
const detectorconstruction* detectorConstruction = static_cast<const detectorconstruction*>
(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
// get mass of detectors
G4double mass1 = detectorConstruction->GetScoringVolume1()->GetMass();
G4double mass2 = detectorConstruction->GetScoringVolume2()->GetMass();
G4double mass3 = detectorConstruction->GetScoringVolume3()->GetMass();
G4double mass4 = detectorConstruction->GetScoringVolume4()->GetMass();
//mass=mass/kg;
//edep=edep/joule;
G4double dose1=edep1/mass1;
G4double dose2=edep2/mass2;
G4double dose3=edep3/mass3;
G4double dose4=edep4/mass4;
// initializate the run manager to store the hits
G4AnalysisManager*man = G4AnalysisManager::Instance();
// write all the edep in the root file
man->Write();
// close root file
man->CloseFile();
#ifndef G4MULTITHREADED
G4cout<<"Radioactive Particle Tracking Application"<<G4endl;
G4cout<<"This example simulates a radioactive source inside a pipe"<<G4endl;
G4cout<<"Code made by: Sebastian Sarasti Zambonino"<<G4endl;
G4cout<<"Nuclear Science Department"<<G4endl;
G4cout<<"Escuela Politecnica Nacional"<<G4endl;
#endif
G4cout<<"Dose deposited in detector 1 is: "<< G4BestUnit(dose1,"Dose")<<G4endl;
G4cout<<"Dose deposited in detector 2 is: "<< G4BestUnit(dose2,"Dose")<<G4endl;
G4cout<<"Dose deposited in detector 3 is: "<< G4BestUnit(dose3,"Dose")<<G4endl;
G4cout<<"Dose deposited in detector 4 is: "<< G4BestUnit(dose4,"Dose")<<G4endl;
}