[807] | 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 | // $Id: HadrontherapyEventAction.cc; May 2005 |
---|
| 27 | // ---------------------------------------------------------------------------- |
---|
| 28 | // GEANT 4 - Hadrontherapy example |
---|
| 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 | // -------------------------------------------------------------- |
---|
| 40 | #include "G4Event.hh" |
---|
| 41 | #include "G4EventManager.hh" |
---|
| 42 | #include "G4HCofThisEvent.hh" |
---|
| 43 | #include "G4VHitsCollection.hh" |
---|
| 44 | #include "G4TrajectoryContainer.hh" |
---|
| 45 | #include "G4Trajectory.hh" |
---|
| 46 | #include "G4VVisManager.hh" |
---|
| 47 | #include "G4SDManager.hh" |
---|
| 48 | #include "G4VVisManager.hh" |
---|
| 49 | #include "HadrontherapyEventAction.hh" |
---|
| 50 | #include "HadrontherapyPhantomHit.hh" |
---|
| 51 | #include "HadrontherapyPhantomSD.hh" |
---|
| 52 | #include "HadrontherapyDetectorConstruction.hh" |
---|
| 53 | #include "HadrontherapyMatrix.hh" |
---|
| 54 | |
---|
| 55 | HadrontherapyEventAction::HadrontherapyEventAction(HadrontherapyMatrix* matrixPointer) : |
---|
| 56 | drawFlag("all" ) |
---|
| 57 | { |
---|
| 58 | hitsCollectionID = -1; |
---|
| 59 | matrix = matrixPointer; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | HadrontherapyEventAction::~HadrontherapyEventAction() |
---|
| 63 | { |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | void HadrontherapyEventAction::BeginOfEventAction(const G4Event* ) |
---|
| 67 | { |
---|
| 68 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); |
---|
| 69 | if(hitsCollectionID == -1) |
---|
| 70 | hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyPhantomHitsCollection"); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void HadrontherapyEventAction::EndOfEventAction(const G4Event* evt) |
---|
| 74 | { |
---|
| 75 | if(hitsCollectionID < 0) |
---|
| 76 | return; |
---|
| 77 | |
---|
| 78 | G4HCofThisEvent* HCE = evt -> GetHCofThisEvent(); |
---|
| 79 | HadrontherapyPhantomHitsCollection* CHC = NULL; |
---|
| 80 | |
---|
| 81 | if(HCE) |
---|
| 82 | CHC = (HadrontherapyPhantomHitsCollection*)(HCE -> GetHC(hitsCollectionID)); |
---|
| 83 | |
---|
| 84 | if(CHC) |
---|
| 85 | { |
---|
| 86 | if(matrix) |
---|
| 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++) |
---|
| 112 | { |
---|
| 113 | G4Trajectory* trj = (G4Trajectory*) |
---|
| 114 | ((*(evt -> GetTrajectoryContainer()))[i]); |
---|
| 115 | if(drawFlag == "all") trj -> DrawTrajectory(50); |
---|
| 116 | else if((drawFlag == "charged")&&(trj -> GetCharge() != 0.)) |
---|
| 117 | trj -> DrawTrajectory(50); |
---|
| 118 | else if ((drawFlag == "neutral")&&(trj -> GetCharge() == 0.)) |
---|
| 119 | trj -> DrawTrajectory(50); |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|