Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HadrontherapyEventAction.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // Hadrontherapy advanced example for Geant4
27 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
28 
29 #include "G4SystemOfUnits.hh"
30 #include "G4Event.hh"
31 #include "G4EventManager.hh"
32 #include "G4HCofThisEvent.hh"
33 #include "G4VHitsCollection.hh"
34 #include "G4SDManager.hh"
35 #include "G4VVisManager.hh"
36 
41 #include "HadrontherapyMatrix.hh"
43 
46  drawFlag("all" ),printModulo(10), pointerEventMessenger(0)
47 {
48  hitsCollectionID = -1;
49  pointerEventMessenger = new HadrontherapyEventActionMessenger(this);
50 }
51 
54 {
55  delete pointerEventMessenger;
56 }
57 
60 {
61  G4int evtNb = evt->GetEventID();
62  //printing survey
63  if (evtNb%printModulo == 0)
64  G4cout << "\n---> Begin of Event: " << evtNb << G4endl;
65 
67  if(hitsCollectionID == -1)
68  hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyDetectorHitsCollection");
69 
70 }
71 
74 {
75  if(hitsCollectionID < 0)
76  return;
77  G4HCofThisEvent* HCE = evt -> GetHCofThisEvent();
78 
79  // Clear voxels hit list
81  if (matrix) matrix -> ClearHitTrack();
82 
83  if(HCE)
84  {
85  HadrontherapyDetectorHitsCollection* CHC = (HadrontherapyDetectorHitsCollection*)(HCE -> GetHC(hitsCollectionID));
86  if(CHC)
87  {
88  if(matrix)
89  {
90  // Fill the matrix with the information: voxel and associated energy deposit
91  // in the detector at the end of the event
92 
93  G4int HitCount = CHC -> entries();
94  for (G4int h=0; h<HitCount; h++)
95  {
96  G4int i = ((*CHC)[h]) -> GetXID();
97  G4int j = ((*CHC)[h]) -> GetYID();
98  G4int k = ((*CHC)[h]) -> GetZID();
99  G4double energyDeposit = ((*CHC)[h]) -> GetEdep();
100  matrix -> Fill(i, j, k, energyDeposit/MeV);
101  }
102  }
103  }
104  }
105 }
106 
int G4int
Definition: G4Types.hh:78
void EndOfEventAction(const G4Event *)
G4int GetEventID() const
Definition: G4Event.hh:151
static HadrontherapyMatrix * GetInstance()
G4GLOB_DLL std::ostream G4cout
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
void BeginOfEventAction(const G4Event *)
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
double G4double
Definition: G4Types.hh:76