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 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 EventAction::EventAction() >> 50 {} >> 51 >> 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 53 >> 54 EventAction::~EventAction() >> 55 {} >> 56 >> 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... >> 58 >> 59 CalorHitsCollection* >> 60 EventAction::GetHitsCollection(G4int hcID, >> 61 const G4Event* event) const 49 { 62 { 50 auto hitsCollection = static_cast<CalorHitsC << 63 auto hitsCollection >> 64 = static_cast<CalorHitsCollection*>( >> 65 event->GetHCofThisEvent()->GetHC(hcID)); 51 66 52 if (!hitsCollection) { << 67 if ( ! hitsCollection ) { 53 G4ExceptionDescription msg; 68 G4ExceptionDescription msg; 54 msg << "Cannot access hitsCollection ID " 69 msg << "Cannot access hitsCollection ID " << hcID; 55 G4Exception("EventAction::GetHitsCollectio << 70 G4Exception("EventAction::GetHitsCollection()", >> 71 "MyCode0003", FatalException, msg); 56 } 72 } 57 73 58 return hitsCollection; 74 return hitsCollection; 59 } 75 } 60 76 61 //....oooOO0OOooo........oooOO0OOooo........oo 77 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 62 78 63 void EventAction::PrintEventStatistics(G4doubl << 79 void EventAction::PrintEventStatistics( 64 G4doubl << 80 G4double absoEdep, G4double absoTrackLength, >> 81 G4double gapEdep, G4double gapTrackLength) const 65 { 82 { 66 // print event statistics 83 // print event statistics 67 G4cout << " Absorber: total energy: " << s << 84 G4cout 68 << " total track length: " << s << 85 << " Absorber: total energy: " 69 << G4endl << " Gap: total ener << 86 << std::setw(7) << G4BestUnit(absoEdep, "Energy") 70 << " total track length: " << s << 87 << " total track length: " 71 << G4endl; << 88 << std::setw(7) << G4BestUnit(absoTrackLength, "Length") >> 89 << G4endl >> 90 << " Gap: total energy: " >> 91 << std::setw(7) << G4BestUnit(gapEdep, "Energy") >> 92 << " total track length: " >> 93 << std::setw(7) << G4BestUnit(gapTrackLength, "Length") >> 94 << G4endl; 72 } 95 } 73 96 74 //....oooOO0OOooo........oooOO0OOooo........oo 97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 75 98 76 void EventAction::BeginOfEventAction(const G4E << 99 void EventAction::BeginOfEventAction(const G4Event* /*event*/) >> 100 {} 77 101 78 //....oooOO0OOooo........oooOO0OOooo........oo 102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 103 80 void EventAction::EndOfEventAction(const G4Eve 104 void EventAction::EndOfEventAction(const G4Event* event) 81 { 105 { 82 // Get hits collections IDs (only once) 106 // Get hits collections IDs (only once) 83 if (fAbsHCID == -1) { << 107 if ( fAbsHCID == -1 ) { 84 fAbsHCID = G4SDManager::GetSDMpointer()->G << 108 fAbsHCID 85 fGapHCID = G4SDManager::GetSDMpointer()->G << 109 = G4SDManager::GetSDMpointer()->GetCollectionID("AbsorberHitsCollection"); >> 110 fGapHCID >> 111 = G4SDManager::GetSDMpointer()->GetCollectionID("GapHitsCollection"); 86 } 112 } 87 113 88 // Get hits collections 114 // Get hits collections 89 auto absoHC = GetHitsCollection(fAbsHCID, ev 115 auto absoHC = GetHitsCollection(fAbsHCID, event); 90 auto gapHC = GetHitsCollection(fGapHCID, eve 116 auto gapHC = GetHitsCollection(fGapHCID, event); 91 117 92 // Get hit with total values 118 // Get hit with total values 93 auto absoHit = (*absoHC)[absoHC->entries() - << 119 auto absoHit = (*absoHC)[absoHC->entries()-1]; 94 auto gapHit = (*gapHC)[gapHC->entries() - 1] << 120 auto gapHit = (*gapHC)[gapHC->entries()-1]; 95 121 96 // Print per event (modulo n) 122 // Print per event (modulo n) 97 // 123 // 98 auto eventID = event->GetEventID(); 124 auto eventID = event->GetEventID(); 99 auto printModulo = G4RunManager::GetRunManag 125 auto printModulo = G4RunManager::GetRunManager()->GetPrintProgress(); 100 if ((printModulo > 0) && (eventID % printMod << 126 if ( ( printModulo > 0 ) && ( eventID % printModulo == 0 ) ) { 101 PrintEventStatistics(absoHit->GetEdep(), a << 127 G4cout << "---> End of event: " << eventID << G4endl; 102 gapHit->GetTrackLengt << 128 103 G4cout << "--> End of event: " << eventID << 129 PrintEventStatistics( >> 130 absoHit->GetEdep(), absoHit->GetTrackLength(), >> 131 gapHit->GetEdep(), gapHit->GetTrackLength()); 104 } 132 } 105 133 106 // Fill histograms, ntuple 134 // Fill histograms, ntuple 107 // 135 // 108 136 109 // get analysis manager 137 // get analysis manager 110 auto analysisManager = G4AnalysisManager::In 138 auto analysisManager = G4AnalysisManager::Instance(); 111 139 112 // fill histograms 140 // fill histograms 113 analysisManager->FillH1(0, absoHit->GetEdep( 141 analysisManager->FillH1(0, absoHit->GetEdep()); 114 analysisManager->FillH1(1, gapHit->GetEdep() 142 analysisManager->FillH1(1, gapHit->GetEdep()); 115 analysisManager->FillH1(2, absoHit->GetTrack 143 analysisManager->FillH1(2, absoHit->GetTrackLength()); 116 analysisManager->FillH1(3, gapHit->GetTrackL 144 analysisManager->FillH1(3, gapHit->GetTrackLength()); 117 145 118 // fill ntuple 146 // fill ntuple 119 analysisManager->FillNtupleDColumn(0, absoHi 147 analysisManager->FillNtupleDColumn(0, absoHit->GetEdep()); 120 analysisManager->FillNtupleDColumn(1, gapHit 148 analysisManager->FillNtupleDColumn(1, gapHit->GetEdep()); 121 analysisManager->FillNtupleDColumn(2, absoHi 149 analysisManager->FillNtupleDColumn(2, absoHit->GetTrackLength()); 122 analysisManager->FillNtupleDColumn(3, gapHit 150 analysisManager->FillNtupleDColumn(3, gapHit->GetTrackLength()); 123 analysisManager->AddNtupleRow(); 151 analysisManager->AddNtupleRow(); 124 } 152 } 125 153 126 //....oooOO0OOooo........oooOO0OOooo........oo 154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 127 155 128 } // namespace B4c << 156 } 129 157