Monte Carlo LYSO
Geant4 simulation for the LYSO calorimeter prototype
event.cc
Go to the documentation of this file.
1 
5 #include "event.hh"
6 
7 void MyEventAction::BeginOfEventAction(const G4Event *event)
8 {
9  // Reset all event data
10  fTimeIn = 999999.;
11  fPosXIn = 999999.;
12  fPosYIn = 999999.;
13  fPosZIn = 999999.;
14  fTimeFirstInter = 999999.;
15  fPosXFirstInter = 999999.;
16  fPosYFirstInter = 999999.;
17  fPosZFirstInter = 999999.;
18  fEdep = 0.;
19  fMaxEdep = 0.;
20  fMaxEdepPos = G4ThreeVector(0., 0., 0.);
21  fHitsNum_F = 0.;
22  fHitsNum_B = 0.;
23  fHitsNum_F_Ch.clear();
24  fHitsNum_F_Ch = std::vector<G4int>(GS::nOfSiPMs, 0);
25  fT_F.clear();
26  fX_F.clear();
27  fY_F.clear();
28  fChannel_F.clear();
29  fHitsNum_B_Ch.clear();
30  fHitsNum_B_Ch = std::vector<G4int>(GS::nOfSiPMs, 0);
31  fT_B.clear();
32  fX_B.clear();
33  fY_B.clear();
34  fChannel_B.clear();
35  fDecayTriggerSi = false;
36  fCosmicTriggerUp = false;
37  fCosmicTriggerBottom = false;
38 }
39 
40 
41 
42 void MyEventAction::EndOfEventAction(const G4Event *event)
43 {
44  // Settings depending on run mode type
45  G4int modeType = static_cast<const MyPrimaryGenerator*>(G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction())->GetModeType();
46 
47  switch(modeType)
48  {
49  case 22: // 176Lu decay with trigger
50  if(!fDecayTriggerSi)
51  return;
52  case 30: // Cosmic rays
53  if(!(fCosmicTriggerUp*fCosmicTriggerBottom))
54  return;
55  }
56 
57 
58  // Access the hit collection
59  G4HCofThisEvent *hce = event->GetHCofThisEvent();
60  MyHitsCollection *THC = (MyHitsCollection *)(hce->GetHC(0));
61 
62  if(!THC)
63  return;
64 
65  // Fill vectors of data about hits
66  G4int nHits = THC->entries();
67  for(G4int i = 0; i < nHits; i++)
68  {
69  if((*THC)[i]->GetDetectorPosition().z() < GS::zScintillator)
70  {
71  fHitsNum_F++;
72  fHitsNum_F_Ch[(*THC)[i]->GetDetectorChannel()]++;
73  fT_F.push_back((*THC)[i]->GetDetectionTime());
74  fX_F.push_back((*THC)[i]->GetDetectorPosition().x());
75  fY_F.push_back((*THC)[i]->GetDetectorPosition().y());
76  fChannel_F.push_back((*THC)[i]->GetDetectorChannel());
77  }
78 
79  if((*THC)[i]->GetDetectorPosition().z() > GS::zScintillator)
80  {
81  fHitsNum_B++;
82  fHitsNum_B_Ch[(*THC)[i]->GetDetectorChannel()]++;
83  fT_B.push_back((*THC)[i]->GetDetectionTime());
84  fX_B.push_back((*THC)[i]->GetDetectorPosition().x());
85  fY_B.push_back((*THC)[i]->GetDetectorPosition().y());
86  fChannel_B.push_back((*THC)[i]->GetDetectorChannel());
87  }
88  }
89 
90  // Access info about primary particle
91  G4PrimaryVertex* primaryVertex = event->GetPrimaryVertex();
92  G4PrimaryParticle *primaryParticle = primaryVertex->GetPrimary();
93 
94  // Store data
95  G4AnalysisManager *man = G4AnalysisManager::Instance();
96  G4int evt = event->GetEventID();
97 
98  // Fill the primary gamma branches
99  man->FillNtupleIColumn(0, evt);
100  man->FillNtupleIColumn(1, primaryParticle->GetParticleDefinition()->GetPDGEncoding());
101  man->FillNtupleDColumn(2, primaryParticle->GetTotalEnergy());
102  man->FillNtupleDColumn(3, primaryVertex->GetX0());
103  man->FillNtupleDColumn(4, primaryVertex->GetY0());
104  man->FillNtupleDColumn(5, primaryVertex->GetZ0());
105  man->FillNtupleDColumn(6, primaryParticle->GetMomentumDirection().x());
106  man->FillNtupleDColumn(7, primaryParticle->GetMomentumDirection().y());
107  man->FillNtupleDColumn(8, primaryParticle->GetMomentumDirection().z());
108  man->FillNtupleDColumn(9, fTimeIn);
109  man->FillNtupleDColumn(10, fPosXIn);
110  man->FillNtupleDColumn(11, fPosYIn);
111  man->FillNtupleDColumn(12, fPosZIn);
112  man->FillNtupleDColumn(13, fTimeFirstInter);
113  man->FillNtupleDColumn(14, fPosXFirstInter);
114  man->FillNtupleDColumn(15, fPosYFirstInter);
115  man->FillNtupleDColumn(16, fPosZFirstInter);
116  // Fill the energy deposition branches
117  man->FillNtupleDColumn(17, fEdep);
118  man->FillNtupleDColumn(18, fMaxEdep);
119  man->FillNtupleDColumn(19, fMaxEdepPos.x());
120  man->FillNtupleDColumn(20, fMaxEdepPos.y());
121  man->FillNtupleDColumn(21, fMaxEdepPos.z());
122  // Fill the detectors branches
123  man->FillNtupleIColumn(22, fHitsNum_F);
124  man->FillNtupleIColumn(23, fHitsNum_B);
125  man->FillNtupleIColumn(24, fHitsNum_F + fHitsNum_B);
126  // Close the row
127  man->AddNtupleRow(0);
128 }
G4double fMaxEdep
Maximum deposit of energy per unit length (MeV/mm) in the crystal.
Definition: event.hh:111
G4double fPosXIn
X position of arrival of primary gamma.
Definition: event.hh:101
std::vector< G4double > fT_F
Vector containing times of detection of optical photons on the front face.
Definition: event.hh:117
G4ThreeVector fMaxEdepPos
Position of the maximum deposit of energy per unit length in the crystal.
Definition: event.hh:112
G4double fPosYFirstInter
Y position of first interaction of primary gamma.
Definition: event.hh:106
void EndOfEventAction(const G4Event *event) override
Fills the TTree with the data of the event.
Definition: event.cc:42
G4double fPosXFirstInter
X position of first interaction of primary gamma.
Definition: event.hh:105
std::vector< G4double > fT_B
Vector containing times of detection of optical photons on the back face.
Definition: event.hh:120
G4double fEdep
Total energy deposited inside the crystal.
Definition: event.hh:110
void BeginOfEventAction(const G4Event *event) override
Resets every data containers at the beginning of a new event.
Definition: event.cc:7
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
G4double fTimeFirstInter
Time of first interaction of primary gamma.
Definition: event.hh:104
std::vector< G4int > fChannel_B
Vector containing SiPM channels of detection of optical photons on the back face.
Definition: event.hh:126
G4int fHitsNum_F
Total number of optical photons detected by SiPMs on the front face.
Definition: event.hh:115
G4double fPosYIn
Y position of arrival of primary gamma.
Definition: event.hh:102
G4double fPosZIn
Z position of arrival of primary gamma.
Definition: event.hh:103
G4double fPosZFirstInter
Z position of first interaction of primary gamma.
Definition: event.hh:107
G4int fHitsNum_B
Total number of optical photons detected by SiPMs on the back face.
Definition: event.hh:116
std::vector< G4double > fX_F
Vector containing x-positions of detection of optical photons on the front face.
Definition: event.hh:118
G4double fTimeIn
Time of arrival of primary gamma.
Definition: event.hh:100
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
Mandatory user action concrete class of G4VUserPrimaryGeneratorAction. It defines the settings for th...
Definition: generator.hh:25
Declaration of the class MyEventAction.
G4THitsCollection< MyHit > MyHitsCollection
Concrete hit collection class for MyHit.
Definition: hit.hh:54
constexpr G4double zScintillator
z-position of the scintillator crystal.
constexpr G4int nOfSiPMs
The number of SiPMs on a detector face.