[1199] | 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: A01EventAction.cc,v 1.2 2006/12/13 15:49:05 gunter Exp $ |
---|
| 27 | // -------------------------------------------------------------- |
---|
| 28 | // |
---|
| 29 | |
---|
| 30 | #include "A01EventAction.hh" |
---|
| 31 | |
---|
| 32 | #include "G4Event.hh" |
---|
| 33 | #include "G4HCofThisEvent.hh" |
---|
| 34 | #include "G4SDManager.hh" |
---|
| 35 | |
---|
| 36 | A01EventAction::A01EventAction(G4bool val) |
---|
| 37 | { |
---|
| 38 | ifPara = val; |
---|
| 39 | for(int i=0;i<4;i++) |
---|
| 40 | { |
---|
| 41 | realWorldID[i] = -1; |
---|
| 42 | paraWorldID[i] = -1; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | A01EventAction::~A01EventAction() |
---|
| 47 | { |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | void A01EventAction::BeginOfEventAction(const G4Event*) |
---|
| 51 | { |
---|
| 52 | G4String colName; |
---|
| 53 | if(realWorldID[0]<0) |
---|
| 54 | { |
---|
| 55 | realWorldID[0] = G4SDManager::GetSDMpointer()->GetCollectionID(colName="MassWorld/NofStep"); |
---|
| 56 | realWorldID[1] = G4SDManager::GetSDMpointer()->GetCollectionID(colName="MassWorld/TrackLength"); |
---|
| 57 | realWorldID[2] = G4SDManager::GetSDMpointer()->GetCollectionID(colName="MassWorld/NofSecondary"); |
---|
| 58 | realWorldID[3] = G4SDManager::GetSDMpointer()->GetCollectionID(colName="MassWorld/EnergyDeposit"); |
---|
| 59 | if(ifPara) { |
---|
| 60 | paraWorldID[0] = G4SDManager::GetSDMpointer()->GetCollectionID(colName="ParallelWorld/NofStep"); |
---|
| 61 | paraWorldID[1] = G4SDManager::GetSDMpointer()->GetCollectionID(colName="ParallelWorld/TrackLength"); |
---|
| 62 | paraWorldID[2] = G4SDManager::GetSDMpointer()->GetCollectionID(colName="ParallelWorld/NofSecondary"); |
---|
| 63 | paraWorldID[3] = G4SDManager::GetSDMpointer()->GetCollectionID(colName="ParallelWorld/EnergyDeposit"); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void A01EventAction::EndOfEventAction(const G4Event* evt) |
---|
| 69 | { |
---|
| 70 | G4HCofThisEvent * HCE = evt->GetHCofThisEvent(); |
---|
| 71 | if(!HCE) return; |
---|
| 72 | |
---|
| 73 | G4double rw[4]; |
---|
| 74 | G4double pw[4]; |
---|
| 75 | |
---|
| 76 | for(int i=0;i<4;i++) |
---|
| 77 | { |
---|
| 78 | rw[i] = 0.; |
---|
| 79 | pw[i] = 0.; |
---|
| 80 | G4THitsMap<G4double>* hm = (G4THitsMap<G4double>*)(HCE->GetHC(realWorldID[i])); |
---|
| 81 | if(hm) rw[i] = Total(hm); |
---|
| 82 | if(ifPara) { |
---|
| 83 | hm = (G4THitsMap<G4double>*)(HCE->GetHC(paraWorldID[i])); |
---|
| 84 | if(hm) pw[i] = Total(hm); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | G4PrimaryParticle* primary = evt->GetPrimaryVertex(0)->GetPrimary(0); |
---|
| 89 | G4cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl; |
---|
| 90 | G4cout << ">>> Event " << evt->GetEventID() << " >>> Simulation truth : " |
---|
| 91 | << primary->GetG4code()->GetParticleName() |
---|
| 92 | << " momentum : " << primary->GetMomentum()/MeV << " (MeV)" << G4endl; |
---|
| 93 | G4cout << "No. of steps in REAL world : " << std::setw(8) << rw[0] |
---|
| 94 | << " --- in PARALLEL world : " << std::setw(8) << pw[0] << G4endl; |
---|
| 95 | G4cout << "Total track length (mm) in REAL world : " << std::setw(8) << rw[1]/mm |
---|
| 96 | << " --- in PARALLEL world : " << std::setw(8) << pw[1]/mm << G4endl; |
---|
| 97 | G4cout << "No. of secondaries in REAL world : " << std::setw(8) << rw[2] |
---|
| 98 | << " --- in PARALLEL world : " << std::setw(8) << pw[2] << G4endl; |
---|
| 99 | G4cout << "Total energy deposit (MeV) in REAL world : " << std::setw(8) << rw[3]/MeV |
---|
| 100 | << " --- in PARALLEL world : " << std::setw(8) << pw[3]/MeV << G4endl; |
---|
| 101 | G4cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | G4double A01EventAction::Total(G4THitsMap<G4double>* hm) |
---|
| 105 | { |
---|
| 106 | G4double tot = 0.; |
---|
| 107 | std::map<G4int,G4double*>::iterator itr = hm->GetMap()->begin(); |
---|
| 108 | for(;itr!=hm->GetMap()->end();itr++) |
---|
| 109 | { tot += *(itr->second); } |
---|
| 110 | return tot; |
---|
| 111 | } |
---|