Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 /// \file B4/B4c/src/EventAction.cc 27 /// \file B4/B4c/src/EventAction.cc 28 /// \brief Implementation of the B4c::EventAct 28 /// \brief Implementation of the B4c::EventAction class 29 29 30 #include "EventAction.hh" 30 #include "EventAction.hh" 31 << 31 #include "CalorimeterSD.hh" 32 #include "CalorHit.hh" 32 #include "CalorHit.hh" 33 33 34 #include "G4AnalysisManager.hh" 34 #include "G4AnalysisManager.hh" 35 #include "G4Event.hh" << 36 #include "G4HCofThisEvent.hh" << 37 #include "G4RunManager.hh" 35 #include "G4RunManager.hh" >> 36 #include "G4Event.hh" 38 #include "G4SDManager.hh" 37 #include "G4SDManager.hh" >> 38 #include "G4HCofThisEvent.hh" 39 #include "G4UnitsTable.hh" 39 #include "G4UnitsTable.hh" 40 40 >> 41 #include "Randomize.hh" 41 #include <iomanip> 42 #include <iomanip> 42 43 43 namespace B4c 44 namespace B4c 44 { 45 { 45 46 46 //....oooOO0OOooo........oooOO0OOooo........oo 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 47 48 48 CalorHitsCollection* EventAction::GetHitsColle << 49 CalorHitsCollection* >> 50 EventAction::GetHitsCollection(G4int hcID, >> 51 const G4Event* event) const 49 { 52 { 50 auto hitsCollection = static_cast<CalorHitsC << 53 auto hitsCollection >> 54 = static_cast<CalorHitsCollection*>( >> 55 event->GetHCofThisEvent()->GetHC(hcID)); 51 56 52 if (!hitsCollection) { << 57 if ( ! hitsCollection ) { 53 G4ExceptionDescription msg; 58 G4ExceptionDescription msg; 54 msg << "Cannot access hitsCollection ID " 59 msg << "Cannot access hitsCollection ID " << hcID; 55 G4Exception("EventAction::GetHitsCollectio << 60 G4Exception("EventAction::GetHitsCollection()", >> 61 "MyCode0003", FatalException, msg); 56 } 62 } 57 63 58 return hitsCollection; 64 return hitsCollection; 59 } 65 } 60 66 61 //....oooOO0OOooo........oooOO0OOooo........oo 67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 62 68 63 void EventAction::PrintEventStatistics(G4doubl << 69 void EventAction::PrintEventStatistics( 64 G4doubl << 70 G4double absoEdep, G4double absoTrackLength, >> 71 G4double gapEdep, G4double gapTrackLength) const 65 { 72 { 66 // print event statistics 73 // print event statistics 67 G4cout << " Absorber: total energy: " << s << 74 G4cout 68 << " total track length: " << s << 75 << " Absorber: total energy: " 69 << G4endl << " Gap: total ener << 76 << std::setw(7) << G4BestUnit(absoEdep, "Energy") 70 << " total track length: " << s << 77 << " total track length: " 71 << G4endl; << 78 << std::setw(7) << G4BestUnit(absoTrackLength, "Length") >> 79 << G4endl >> 80 << " Gap: total energy: " >> 81 << std::setw(7) << G4BestUnit(gapEdep, "Energy") >> 82 << " total track length: " >> 83 << std::setw(7) << G4BestUnit(gapTrackLength, "Length") >> 84 << G4endl; 72 } 85 } 73 86 74 //....oooOO0OOooo........oooOO0OOooo........oo 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 75 88 76 void EventAction::BeginOfEventAction(const G4E << 89 void EventAction::BeginOfEventAction(const G4Event* /*event*/) >> 90 {} 77 91 78 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 93 80 void EventAction::EndOfEventAction(const G4Eve 94 void EventAction::EndOfEventAction(const G4Event* event) 81 { 95 { 82 // Get hits collections IDs (only once) 96 // Get hits collections IDs (only once) 83 if (fAbsHCID == -1) { << 97 if ( fAbsHCID == -1 ) { 84 fAbsHCID = G4SDManager::GetSDMpointer()->G << 98 fAbsHCID 85 fGapHCID = G4SDManager::GetSDMpointer()->G << 99 = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection"); >> 100 fGapHCID >> 101 = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection"); 86 } 102 } 87 103 88 // Get hits collections 104 // Get hits collections 89 auto absoHC = GetHitsCollection(fAbsHCID, ev 105 auto absoHC = GetHitsCollection(fAbsHCID, event); 90 auto gapHC = GetHitsCollection(fGapHCID, eve 106 auto gapHC = GetHitsCollection(fGapHCID, event); 91 107 92 // Get hit with total values 108 // Get hit with total values 93 auto absoHit = (*absoHC)[absoHC->entries() - << 109 auto absoHit = (*absoHC)[absoHC->entries()-1]; 94 auto gapHit = (*gapHC)[gapHC->entries() - 1] << 110 auto gapHit = (*gapHC)[gapHC->entries()-1]; 95 111 96 // Print per event (modulo n) 112 // Print per event (modulo n) 97 // 113 // 98 auto eventID = event->GetEventID(); 114 auto eventID = event->GetEventID(); 99 auto printModulo = G4RunManager::GetRunManag 115 auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress(); 100 if ((printModulo > 0) && (eventID % printMod << 116 if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) { 101 PrintEventStatistics(absoHit->GetEdep(), a << 117 PrintEventStatistics( 102 gapHit->GetTrackLengt << 118 absoHit->GetEdep(), absoHit->GetTrackLength(), 103 G4cout << "--> End of event: " << eventID << 119 gapHit->GetEdep(), gapHit->GetTrackLength()); >> 120 G4cout << "--> End of event: " << eventID << "\n" << G4endl; 104 } 121 } 105 122 106 // Fill histograms, ntuple 123 // Fill histograms, ntuple 107 // 124 // 108 125 109 // get analysis manager 126 // get analysis manager 110 auto analysisManager = G4AnalysisManager::In 127 auto analysisManager = G4AnalysisManager::Instance(); 111 128 112 // fill histograms 129 // fill histograms 113 analysisManager->FillH1(0, absoHit->GetEdep( 130 analysisManager->FillH1(0, absoHit->GetEdep()); 114 analysisManager->FillH1(1, gapHit->GetEdep() 131 analysisManager->FillH1(1, gapHit->GetEdep()); 115 analysisManager->FillH1(2, absoHit->GetTrack 132 analysisManager->FillH1(2, absoHit->GetTrackLength()); 116 analysisManager->FillH1(3, gapHit->GetTrackL 133 analysisManager->FillH1(3, gapHit->GetTrackLength()); 117 134 118 // fill ntuple 135 // fill ntuple 119 analysisManager->FillNtupleDColumn(0, absoHi 136 analysisManager->FillNtupleDColumn(0, absoHit->GetEdep()); 120 analysisManager->FillNtupleDColumn(1, gapHit 137 analysisManager->FillNtupleDColumn(1, gapHit->GetEdep()); 121 analysisManager->FillNtupleDColumn(2, absoHi 138 analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength()); 122 analysisManager->FillNtupleDColumn(3, gapHit 139 analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength()); 123 analysisManager->AddNtupleRow(); 140 analysisManager->AddNtupleRow(); 124 } 141 } 125 142 126 //....oooOO0OOooo........oooOO0OOooo........oo 143 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 127 144 128 } // namespace B4c << 145 } 129 146