// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // This is the modified version of the example electromagnetic/TestEm7/src/EventAction.cc #include "EventAction.hh" #include "EventActionMessenger.hh" #include "RunAction.hh" #include "G4Event.hh" #include "Hit.hh" #include "G4SteppingManager.hh" #include "G4RunManager.hh" #include "G4Step.hh" #include "G4StepPoint.hh" #include "PrimaryGeneratorAction.hh" #include "G4Event.hh" #include "G4EventManager.hh" #include "G4HCofThisEvent.hh" #include "G4VHitsCollection.hh" #include "G4TrajectoryContainer.hh" #include "G4Trajectory.hh" #include "G4VVisManager.hh" #include "G4TrajectoryContainer.hh" #include "G4SDManager.hh" #include "G4UImanager.hh" #include "G4UnitsTable.hh" #include "Randomize.hh" #include "G4ios.hh" #include #include #include EventAction::EventAction(PrimaryGeneratorAction* PGA) : genAction(PGA) { //hits collections detectorCollID = -1; filename="hits.out"; stopperfilename = "sensitiveDetectors.out"; } EventAction::~EventAction() {;} void EventAction::BeginOfEventAction(const G4Event* evt) { // primary energy primEnergy = genAction->GetParticleEnergy(); evtNb = evt->GetEventID(); //printing survey if (evtNb%1000 == 0) G4cout << "\n---> Begin of Event: " << evtNb << G4endl; if(IDs.empty()){ // get ID for hits collection //if (detectorCollID==-1) { G4SDManager *SDman = G4SDManager::GetSDMpointer(); G4int detectorCollID_1 = SDman->GetCollectionID("detectorCollection"); G4int detectorCollID_2 = SDman->GetCollectionID("detectorCollection2"); IDs.push_back(detectorCollID_1); IDs.push_back(detectorCollID_2); } } void EventAction::EndOfEventAction(const G4Event* evt) { G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); G4int n_trajectories = 0; if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); // std::cout << "There were " << n_trajectories << " trajectories" << std::endl; //*************************** // check that hits collections has been defined and address it if(IDs.empty()) return; for(G4int j=0; j<2; j++){ HitsCollection* PTHC = NULL; G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); if(HCE){ PTHC = (HitsCollection*)(HCE->GetHC(IDs[j])); } G4int PT_hits = 0; G4double PT_edep = 0.; // total energy if(PTHC) { PT_hits = PTHC->entries(); for (G4int i=0; iGetEdep(); if(evtNb%1000==0 || (evtNb%100==0 && evtNb<1000)) { // G4cout << " Size of hit collection: " << PT_hits << G4endl; // G4cout << " Edep PT: " << PT_edep/CLHEP::keV << " keV" << G4endl; } std::ofstream hitsfile(stopperfilename, std::ios::app); if(hitsfile.is_open()){ hitsfile << IDs[j] << "\t" << PT_edep/CLHEP::MeV << G4endl; } hitsfile.close(); } } // write to file std::ofstream hitsfile(filename, std::ios::app); if(hitsfile.is_open()) { } // draw tracks G4VVisManager* pVisManager = G4VVisManager::GetConcreteInstance(); if (pVisManager) { G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); // G4int n_trajectories = 0; if (trajectoryContainer) n_trajectories = trajectoryContainer->entries(); for (G4int i=0; iGetTrajectoryContainer()))[i]); if (trj->GetParticleName() == "proton") { G4double stoppingDistance; stoppingDistance = trj->GetPoint(trj->GetPointEntries()-1)->GetPosition().z(); //pVisManager->Draw(*trj,1000); // geant v9 pVisManager->Draw(*trj); // geant v10 //Write stopping distance to file hitsfile << stoppingDistance << G4endl; hitsfile.close(); } } } }