[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 | // |
---|
[1230] | 26 | // $Id: HadrontherapyEventAction.cc; |
---|
| 27 | // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy |
---|
| 28 | |
---|
[807] | 29 | #include "G4Event.hh" |
---|
| 30 | #include "G4EventManager.hh" |
---|
| 31 | #include "G4HCofThisEvent.hh" |
---|
| 32 | #include "G4VHitsCollection.hh" |
---|
| 33 | #include "G4TrajectoryContainer.hh" |
---|
| 34 | #include "G4Trajectory.hh" |
---|
| 35 | #include "G4VVisManager.hh" |
---|
| 36 | #include "G4SDManager.hh" |
---|
| 37 | #include "G4VVisManager.hh" |
---|
| 38 | #include "HadrontherapyEventAction.hh" |
---|
[1230] | 39 | #include "HadrontherapyDetectorHit.hh" |
---|
| 40 | #include "HadrontherapyDetectorSD.hh" |
---|
[807] | 41 | #include "HadrontherapyDetectorConstruction.hh" |
---|
| 42 | #include "HadrontherapyMatrix.hh" |
---|
[1230] | 43 | #include "HadrontherapyEventActionMessenger.hh" |
---|
[807] | 44 | |
---|
[1230] | 45 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 46 | HadrontherapyEventAction::HadrontherapyEventAction() : |
---|
| 47 | drawFlag("all" ),printModulo(1000), pointerEventMessenger(0) |
---|
[807] | 48 | { |
---|
| 49 | hitsCollectionID = -1; |
---|
[1230] | 50 | pointerEventMessenger = new HadrontherapyEventActionMessenger(this); |
---|
[807] | 51 | } |
---|
| 52 | |
---|
[1230] | 53 | ///////////////////////////////////////////////////////////////////////////// |
---|
[807] | 54 | HadrontherapyEventAction::~HadrontherapyEventAction() |
---|
| 55 | { |
---|
[1230] | 56 | delete pointerEventMessenger; |
---|
[807] | 57 | } |
---|
| 58 | |
---|
[1230] | 59 | ///////////////////////////////////////////////////////////////////////////// |
---|
| 60 | void HadrontherapyEventAction::BeginOfEventAction(const G4Event* evt) |
---|
| 61 | { |
---|
| 62 | G4int evtNb = evt->GetEventID(); |
---|
| 63 | |
---|
| 64 | //printing survey |
---|
| 65 | if (evtNb%printModulo == 0) |
---|
| 66 | G4cout << "\n---> Begin of Event: " << evtNb << G4endl; |
---|
| 67 | |
---|
| 68 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); |
---|
| 69 | if(hitsCollectionID == -1) |
---|
| 70 | hitsCollectionID = pSDManager -> GetCollectionID("HadrontherapyDetectorHitsCollection"); |
---|
[807] | 71 | } |
---|
| 72 | |
---|
[1230] | 73 | ///////////////////////////////////////////////////////////////////////////// |
---|
[807] | 74 | void HadrontherapyEventAction::EndOfEventAction(const G4Event* evt) |
---|
| 75 | { |
---|
| 76 | if(hitsCollectionID < 0) |
---|
[1230] | 77 | return; |
---|
[807] | 78 | G4HCofThisEvent* HCE = evt -> GetHCofThisEvent(); |
---|
| 79 | |
---|
| 80 | if(HCE) |
---|
[1230] | 81 | { |
---|
| 82 | HadrontherapyDetectorHitsCollection* CHC = (HadrontherapyDetectorHitsCollection*)(HCE -> GetHC(hitsCollectionID)); |
---|
| 83 | if(CHC) |
---|
| 84 | { |
---|
| 85 | matrix = HadrontherapyMatrix::getInstance(); |
---|
| 86 | if(matrix) |
---|
| 87 | { |
---|
| 88 | // Fill the matrix with the information: voxel and associated energy deposit |
---|
| 89 | // in the detector at the end of the event |
---|
[807] | 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 | } |
---|
[1230] | 100 | } |
---|
[807] | 101 | } |
---|
[1230] | 102 | } |
---|
[807] | 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 | |
---|