Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // Hadrontherapy advanced example for Geant4 << 26 // $Id: HadrontherapyEventAction.cc; May 2005 27 // See more at: https://twiki.cern.ch/twiki/bi << 27 // ---------------------------------------------------------------------------- 28 << 28 // GEANT 4 - Hadrontherapy example 29 #include "G4SystemOfUnits.hh" << 29 // ---------------------------------------------------------------------------- >> 30 // Code developed by: >> 31 // >> 32 // G.A.P. Cirrone(a)*, G. Candiano, F. Di Rosa(a), S. Guatelli(b), G. Russo(a) >> 33 // >> 34 // (a) Laboratori Nazionali del Sud >> 35 // of the National Institute for Nuclear Physics, Catania, Italy >> 36 // (b) National Institute for Nuclear Physics Section of Genova, genova, Italy >> 37 // >> 38 // * cirrone@lns.infn.it >> 39 // -------------------------------------------------------------- 30 #include "G4Event.hh" 40 #include "G4Event.hh" 31 #include "G4EventManager.hh" 41 #include "G4EventManager.hh" 32 #include "G4HCofThisEvent.hh" 42 #include "G4HCofThisEvent.hh" 33 #include "G4VHitsCollection.hh" 43 #include "G4VHitsCollection.hh" >> 44 #include "G4TrajectoryContainer.hh" >> 45 #include "G4Trajectory.hh" >> 46 #include "G4VVisManager.hh" 34 #include "G4SDManager.hh" 47 #include "G4SDManager.hh" 35 #include "G4VVisManager.hh" 48 #include "G4VVisManager.hh" 36 << 37 #include "HadrontherapyEventAction.hh" 49 #include "HadrontherapyEventAction.hh" 38 #include "HadrontherapyDetectorHit.hh" << 50 #include "HadrontherapyPhantomHit.hh" 39 #include "HadrontherapyDetectorSD.hh" << 51 #include "HadrontherapyPhantomSD.hh" 40 #include "HadrontherapyDetectorConstruction.hh 52 #include "HadrontherapyDetectorConstruction.hh" 41 #include "HadrontherapyMatrix.hh" 53 #include "HadrontherapyMatrix.hh" 42 #include "HadrontherapyEventActionMessenger.hh << 43 54 44 ////////////////////////////////////////////// << 55 HadrontherapyEventAction::HadrontherapyEventAction(HadrontherapyMatrix* matrixPointer) : 45 HadrontherapyEventAction::HadrontherapyEventAc << 56 drawFlag("all" ) 46 drawFlag("all" ),printModulo(10), pointerEvent << 57 { 47 { << 58 hitsCollectionID = -1; 48 hitsCollectionID = -1; << 59 matrix = matrixPointer; 49 pointerEventMessenger = new HadrontherapyE << 50 } 60 } 51 61 52 ////////////////////////////////////////////// << 53 HadrontherapyEventAction::~HadrontherapyEventA 62 HadrontherapyEventAction::~HadrontherapyEventAction() 54 { 63 { 55 delete pointerEventMessenger; << 56 } 64 } 57 65 58 ////////////////////////////////////////////// << 66 void HadrontherapyEventAction::BeginOfEventAction(const G4Event* ) 59 void HadrontherapyEventAction::BeginOfEventAct << 60 { 67 { 61 G4SDManager* pSDManager = G4SDManager::Get << 68 G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); 62 if(hitsCollectionID == -1) << 69 if(hitsCollectionID == -1) 63 hitsCollectionID = pSDManager -> GetCo << 70 hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyPhantomHitsCollection"); 64 } 71 } 65 72 66 ////////////////////////////////////////////// << 67 void HadrontherapyEventAction::EndOfEventActio 73 void HadrontherapyEventAction::EndOfEventAction(const G4Event* evt) 68 { << 74 { 69 if(hitsCollectionID < 0) << 75 if(hitsCollectionID < 0) 70 return; << 76 return; 71 G4HCofThisEvent* HCE = evt -> GetHCofThisE << 77 72 << 78 G4HCofThisEvent* HCE = evt -> GetHCofThisEvent(); 73 // Clear voxels hit list << 79 HadrontherapyPhantomHitsCollection* CHC = NULL; 74 HadrontherapyMatrix* matrix = Hadrontherap << 80 75 if (matrix) matrix -> ClearHitTrack(); << 81 if(HCE) 76 << 82 CHC = (HadrontherapyPhantomHitsCollection*)(HCE -> GetHC(hitsCollectionID)); 77 if(HCE) << 83 >> 84 if(CHC) 78 { 85 { 79 HadrontherapyDetectorHitsCollection* C << 86 if(matrix) 80 if(CHC) << 87 { >> 88 // Fill the matrix with the information: voxel and associated energy deposit >> 89 // in the phantom at the end of the event >> 90 >> 91 G4int HitCount = CHC -> entries(); >> 92 for (G4int h=0; h<HitCount; h++) >> 93 { >> 94 G4int i = ((*CHC)[h]) -> GetXID(); >> 95 G4int j = ((*CHC)[h]) -> GetYID(); >> 96 G4int k = ((*CHC)[h]) -> GetZID(); >> 97 G4double energyDeposit = ((*CHC)[h]) -> GetEdep(); >> 98 matrix -> Fill(i, j, k, energyDeposit/MeV); >> 99 } >> 100 } >> 101 } >> 102 >> 103 // Extract the trajectories and draw them in the visualisation >> 104 >> 105 if (G4VVisManager::GetConcreteInstance()) >> 106 { >> 107 G4TrajectoryContainer * trajectoryContainer = evt -> GetTrajectoryContainer(); >> 108 G4int n_trajectories = 0; >> 109 if (trajectoryContainer) n_trajectories = trajectoryContainer -> entries(); >> 110 >> 111 for (G4int i = 0; i < n_trajectories; i++) 81 { 112 { 82 if(matrix) << 113 G4Trajectory* trj = (G4Trajectory*) 83 { << 114 ((*(evt -> GetTrajectoryContainer()))[i]); 84 // Fill the matrix with the in << 115 if(drawFlag == "all") trj -> DrawTrajectory(50); 85 // in the detector at the end << 116 else if((drawFlag == "charged")&&(trj -> GetCharge() != 0.)) 86 << 117 trj -> DrawTrajectory(50); 87 size_t HitCount = CHC -> entri << 118 else if ((drawFlag == "neutral")&&(trj -> GetCharge() == 0.)) 88 for (size_t h=0; h<HitCount; h << 119 trj -> DrawTrajectory(50); 89 { << 120 } 90 G4int i = ((*CHC)[h]) -> G << 91 G4int j = ((*CHC)[h]) -> G << 92 G4int k = ((*CHC)[h]) -> G << 93 G4double energyDeposit = ( << 94 matrix -> Fill(i, j, k, en << 95 } << 96 } << 97 } << 98 } 121 } 99 } 122 } >> 123 100 124