Monte Carlo LYSO
Geant4 simulation for the LYSO calorimeter prototype
run.cc
Go to the documentation of this file.
1 
5 #include "run.hh"
6 
7 MyRunAction::MyRunAction(G4int theMCID, MyEventAction *eventAction) : fMCID(theMCID), fEventAction(eventAction)
8 {
9  G4AnalysisManager *man = G4AnalysisManager::Instance();
10 
11  // Create the TTree
12  man->CreateNtuple("lyso", "Primary Gamma, energy deposition inside the crystal and detectors output");
13  // Data of primary gamma
14  man->CreateNtupleIColumn("Event"); // entry 0
15  man->CreateNtupleIColumn("PID_gun");
16  man->CreateNtupleDColumn("E_gun");
17  man->CreateNtupleDColumn("X_gun");
18  man->CreateNtupleDColumn("Y_gun");
19  man->CreateNtupleDColumn("Z_gun"); // entry 5
20  man->CreateNtupleDColumn("MomX_gun");
21  man->CreateNtupleDColumn("MomY_gun");
22  man->CreateNtupleDColumn("MomZ_gun");
23  man->CreateNtupleDColumn("ToA");
24  man->CreateNtupleDColumn("XoA"); // entry 10
25  man->CreateNtupleDColumn("YoA");
26  man->CreateNtupleDColumn("ZoA");
27  man->CreateNtupleDColumn("ToFI");
28  man->CreateNtupleDColumn("XoFI");
29  man->CreateNtupleDColumn("YoFI"); // entry 15
30  man->CreateNtupleDColumn("ZoFI");
31  // Data of energy deposition inside the crystal
32  man->CreateNtupleDColumn("Edep");
33  man->CreateNtupleDColumn("MaxEdep");
34  man->CreateNtupleDColumn("MaxEdepPosX");
35  man->CreateNtupleDColumn("MaxEdepPosY"); // entry 20
36  man->CreateNtupleDColumn("MaxEdepPosZ");
37  // Data of detectors
38  man->CreateNtupleIColumn("NHits_F");
39  man->CreateNtupleIColumn("NHits_B");
40  man->CreateNtupleIColumn("NHits_Tot");
41  man->CreateNtupleIColumn("NHits_F_Ch", fEventAction->fHitsNum_F_Ch); // entry 25
42  man->CreateNtupleDColumn("T_F", fEventAction->fT_F);
43  man->CreateNtupleDColumn("X_F", fEventAction->fX_F);
44  man->CreateNtupleDColumn("Y_F", fEventAction->fY_F);
45  man->CreateNtupleIColumn("Ch_F", fEventAction->fChannel_F);
46  man->CreateNtupleIColumn("NHits_B_Ch", fEventAction->fHitsNum_B_Ch);
47  man->CreateNtupleDColumn("T_B", fEventAction->fT_B); // entry 30
48  man->CreateNtupleDColumn("X_B", fEventAction->fX_B);
49  man->CreateNtupleDColumn("Y_B", fEventAction->fY_B);
50  man->CreateNtupleIColumn("Ch_B", fEventAction->fChannel_B);
51 
52  man->FinishNtuple(0);
53 }
54 
55 
56 
57 void MyRunAction::BeginOfRunAction(const G4Run* run)
58 {
59  // Create and open the file root
60  G4AnalysisManager *man = G4AnalysisManager::Instance();
61 
62  std::stringstream strMCID;
63  strMCID << fMCID;
64 
65  G4int runID = run->GetRunID();
66  std::stringstream strRunID;
67  strRunID << runID;
68 
69  if(!runID)
70  man->OpenFile("MCID_" + strMCID.str() + ".root");
71  else
72  {
73  man->OpenFile("MCID_" + strMCID.str() + "_RunID_" + strRunID.str() + ".root");
74  }
75 }
76 
77 
78 
79 void MyRunAction::EndOfRunAction(const G4Run* run)
80 {
81  // Write TTree and close root file
82  G4AnalysisManager *man = G4AnalysisManager::Instance();
83 
84  man->Write();
85  man->CloseFile();
86 }
User action concrete class of G4UserEventAction. In addition to defining procedures executed at the s...
Definition: event.hh:26
std::vector< G4double > fT_F
Vector containing times of detection of optical photons on the front face.
Definition: event.hh:117
std::vector< G4double > fT_B
Vector containing times of detection of optical photons on the back face.
Definition: event.hh:120
std::vector< G4double > fY_F
Vector containing y-positions of detection of optical photons on the front face.
Definition: event.hh:119
std::vector< G4double > fX_B
Vector containing x-positions of detection of optical photons on the back face.
Definition: event.hh:121
std::vector< G4int > fChannel_B
Vector containing SiPM channels of detection of optical photons on the back face.
Definition: event.hh:126
std::vector< G4double > fX_F
Vector containing x-positions of detection of optical photons on the front face.
Definition: event.hh:118
std::vector< G4double > fY_B
Vector containing y-positions of detection of optical photons on the back face.
Definition: event.hh:122
std::vector< G4int > fChannel_F
Vector containing SiPM channels of detection of optical photons on the front face.
Definition: event.hh:124
void BeginOfRunAction(const G4Run *run) override
Creates and accesses the output root file at the beginning of the run.
Definition: run.cc:57
MyEventAction * fEventAction
Pointer to the MyEventAction object.
Definition: run.hh:50
G4int fMCID
The Monte Carlo ID.
Definition: run.hh:49
MyRunAction(G4int theMCID, MyEventAction *eventAction)
Constructor of the class.
Definition: run.cc:7
void EndOfRunAction(const G4Run *run) override
Writes the TTree to the output root file and closes it at the end of the run.
Definition: run.cc:79
Declaration of the class MyRunAction.