-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
SimpleRunAction.cpp
120 lines (97 loc) · 3.76 KB
/
SimpleRunAction.cpp
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
// File modified by Deepak Samuel on 25 Sep 2019
#include "SimpleRunAction.h"
#include "G4CsvAnalysisManager.hh"
//#include "G4RootAnalysisManager.hh"
#include "SimpleDetectorConstruction.h"
#include <G4coutDestination.hh>
#include <g4root.hh>
#include <QDebug>
SimpleRunAction::SimpleRunAction() : G4UserRunAction()
{
G4RunManager::GetRunManager()->SetPrintProgress(10000);
run_id=0;
}
SimpleRunAction::~SimpleRunAction()
{}
//void SimpleRunAction::setRecordParameters(bool rec_pos, bool rec_time, bool rec_energy, bool rec_mom, bool rec_process)
//{
//// save_position = rec_pos;
//// save_time = rec_time;
//// save_energy = rec_energy;
//// save_momentum = rec_mom;
//// save_process = rec_process;
//}
void SimpleRunAction::SetOutputFile(QString file)
{
fileName =file;
qDebug()<<"Output file set to: "<<file;
}
void SimpleRunAction::BeginOfRunAction(const G4Run*)
{
//setRecordParameters();
const SimpleDetectorConstruction* det
= static_cast<const SimpleDetectorConstruction*> (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
G4AnalysisManager* man = G4AnalysisManager::Instance();
man->SetNtupleMerging(true); // very important
// enum rec{eid, pid, det_id, is_primary,
// posx, posy, posz,
// del_posx, del_posy, del_posz,
// ni_edep, tot_edep, tot_energy, tot_ke,
// momx, momy, momz,
// px,py,pz,
// del_t, globTime, propTime, locTime,
// process};
// Open an output file
//QString fileName = QString("data/run%1-det-output").arg(QString::number(run_id).rightJustified(3, '0'));
//man->OpenFile("data/temp-det-output");
man->OpenFile(fileName.toLatin1().data());
man->CreateNtuple("simple","out_data");
man->CreateNtupleDColumn("eid"); // column Id = 0
man->CreateNtupleDColumn("pid"); // column Id = 1
man->CreateNtupleSColumn("detectorId"); // column Id = 2
man->CreateNtupleDColumn("is_primary"); // column Id = 3
if(det->recordPosition()){
man->CreateNtupleDColumn("posx"); // column Id = 4
man->CreateNtupleDColumn("posy"); // column Id = 5
man->CreateNtupleDColumn("posz"); // column Id = 6
man->CreateNtupleDColumn("del_posx"); // column Id = 7
man->CreateNtupleDColumn("del_posy"); // column Id = 8
man->CreateNtupleDColumn("del_posz"); // column Id = 9
}
if(det->recordTime()){
man->CreateNtupleDColumn("del_t"); // column Id = 10
man->CreateNtupleDColumn("globTime"); // column Id = 11
man->CreateNtupleDColumn("propTime"); // column Id = 12
man->CreateNtupleDColumn("localTime"); // column Id = 13
}
if(det->recordEnergy())
{
man->CreateNtupleDColumn("ni_edep"); // column Id = 14
man->CreateNtupleDColumn("tot_edep"); // column Id = 15
man->CreateNtupleDColumn("tot_E"); // column Id =16
man->CreateNtupleDColumn("tot_KE"); // column Id=17
}
if(det->recordMomentum())
{
man->CreateNtupleDColumn("momx"); // column Id = 18
man->CreateNtupleDColumn("momy"); // column Id = 19
man->CreateNtupleDColumn("momz"); // column Id = 20
man->CreateNtupleDColumn("px"); // column Id = 21
man->CreateNtupleDColumn("py"); // column Id = 22
man->CreateNtupleDColumn("pz"); // column Id = 23
}
if(det->recordProcess())
{
man->CreateNtupleSColumn("process"); // columnId =24
}
man->FinishNtuple();
G4cout<<"Begin run...\n";
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SimpleRunAction::EndOfRunAction(const G4Run* run)
{
G4AnalysisManager* man = G4AnalysisManager::Instance();
man->Write();
man->CloseFile();
G4cout<<"End of run...\n";
}