Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:17

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // Hadrontherapy advanced example for Geant4
0027 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
0028 
0029 #include "G4SystemOfUnits.hh"
0030 #include "G4Event.hh"
0031 #include "G4EventManager.hh"
0032 #include "G4HCofThisEvent.hh"
0033 #include "G4VHitsCollection.hh"
0034 #include "G4SDManager.hh"
0035 #include "G4VVisManager.hh"
0036 
0037 #include "HadrontherapyEventAction.hh"
0038 #include "HadrontherapyDetectorHit.hh"
0039 #include "HadrontherapyDetectorSD.hh"
0040 #include "HadrontherapyDetectorConstruction.hh"
0041 #include "HadrontherapyMatrix.hh"
0042 #include "HadrontherapyEventActionMessenger.hh"
0043 
0044 /////////////////////////////////////////////////////////////////////////////
0045 HadrontherapyEventAction::HadrontherapyEventAction() :
0046 drawFlag("all" ),printModulo(10), pointerEventMessenger(0)
0047 {
0048     hitsCollectionID = -1;
0049     pointerEventMessenger = new HadrontherapyEventActionMessenger(this);
0050 }
0051 
0052 /////////////////////////////////////////////////////////////////////////////
0053 HadrontherapyEventAction::~HadrontherapyEventAction()
0054 {
0055     delete pointerEventMessenger;
0056 }
0057 
0058 /////////////////////////////////////////////////////////////////////////////
0059 void HadrontherapyEventAction::BeginOfEventAction(const G4Event*)
0060 {
0061     G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
0062     if(hitsCollectionID == -1)
0063         hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyDetectorHitsCollection");
0064 }
0065 
0066 /////////////////////////////////////////////////////////////////////////////
0067 void HadrontherapyEventAction::EndOfEventAction(const G4Event* evt)
0068 {
0069     if(hitsCollectionID < 0)
0070         return;
0071     G4HCofThisEvent* HCE = evt -> GetHCofThisEvent();
0072     
0073     // Clear voxels hit list
0074     HadrontherapyMatrix* matrix = HadrontherapyMatrix::GetInstance();
0075     if (matrix) matrix -> ClearHitTrack();
0076     
0077     if(HCE)
0078     {
0079         HadrontherapyDetectorHitsCollection* CHC = (HadrontherapyDetectorHitsCollection*)(HCE -> GetHC(hitsCollectionID));
0080         if(CHC)
0081         {
0082             if(matrix)
0083             {
0084                 // Fill the matrix with the information: voxel and associated energy deposit
0085                 // in the detector at the end of the event
0086                 
0087                 size_t HitCount = CHC -> entries();
0088                 for (size_t h=0; h<HitCount; h++)
0089                 {
0090                     G4int i = ((*CHC)[h]) -> GetXID();
0091                     G4int j = ((*CHC)[h]) -> GetYID();
0092                     G4int k = ((*CHC)[h]) -> GetZID();
0093                     G4double energyDeposit = ((*CHC)[h]) -> GetEdep();
0094                     matrix -> Fill(i, j, k, energyDeposit/MeV);
0095                 }
0096             }
0097         }
0098     }
0099 }