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