File indexing completed on 2026-03-31 07:50:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "RE01StackingAction.hh"
0030
0031 #include "RE01CalorimeterHit.hh"
0032 #include "RE01TrackInformation.hh"
0033
0034 #include "G4Event.hh"
0035 #include "G4HCofThisEvent.hh"
0036 #include "G4ParticleDefinition.hh"
0037 #include "G4ParticleTypes.hh"
0038 #include "G4RunManager.hh"
0039 #include "G4SDManager.hh"
0040 #include "G4SystemOfUnits.hh"
0041 #include "G4Track.hh"
0042 #include "G4TrackStatus.hh"
0043 #include "G4ios.hh"
0044
0045
0046 RE01StackingAction::RE01StackingAction()
0047 : G4UserStackingAction(), fStage(0), fCalorimeterHitsColID(-1)
0048 {
0049 ;
0050 }
0051
0052
0053 RE01StackingAction::~RE01StackingAction()
0054 {
0055 ;
0056 }
0057
0058
0059 G4ClassificationOfNewTrack RE01StackingAction ::ClassifyNewTrack(const G4Track* aTrack)
0060 {
0061 G4ClassificationOfNewTrack classification = fUrgent;
0062
0063 if (fStage == 0) {
0064 RE01TrackInformation* trackInfo;
0065 if (aTrack->GetTrackStatus() == fSuspend)
0066 {
0067 trackInfo = (RE01TrackInformation*)(aTrack->GetUserInformation());
0068 trackInfo->SetTrackingStatus(0);
0069 trackInfo->SetSourceTrackInformation(aTrack);
0070
0071
0072
0073
0074 classification = fWaiting;
0075 }
0076 else if (aTrack->GetParentID() == 0)
0077 {
0078 trackInfo = new RE01TrackInformation(aTrack);
0079 trackInfo->SetTrackingStatus(1);
0080 G4Track* theTrack = (G4Track*)aTrack;
0081 theTrack->SetUserInformation(trackInfo);
0082 }
0083 }
0084 return classification;
0085 }
0086
0087
0088 G4VHitsCollection* RE01StackingAction::GetCalCollection()
0089 {
0090 G4SDManager* SDMan = G4SDManager::GetSDMpointer();
0091 G4RunManager* runMan = G4RunManager::GetRunManager();
0092 if (fCalorimeterHitsColID < 0) {
0093 fCalorimeterHitsColID = SDMan->GetCollectionID("calCollection");
0094 }
0095 if (fCalorimeterHitsColID >= 0) {
0096 const G4Event* currentEvent = runMan->GetCurrentEvent();
0097 G4HCofThisEvent* HCE = currentEvent->GetHCofThisEvent();
0098 return HCE->GetHC(fCalorimeterHitsColID);
0099 }
0100 return 0;
0101 }
0102
0103
0104 void RE01StackingAction::NewStage()
0105 {
0106
0107 if (fStage == 0) {
0108
0109 G4cout << G4endl;
0110 G4cout << "Tracks in tracking region have been processed. -- Stage 0 over." << G4endl;
0111 G4cout << G4endl;
0112 }
0113 else {
0114
0115
0116
0117
0118
0119
0120 RE01CalorimeterHitsCollection* CHC = (RE01CalorimeterHitsCollection*)GetCalCollection();
0121 if (CHC) {
0122 int n_hit = CHC->entries();
0123 G4double totE = 0;
0124 G4int n_hitByATrack = 0;
0125 for (int i = 0; i < n_hit; i++) {
0126 G4double edepByATrack = (*CHC)[i]->GetEdepByATrack();
0127 if (edepByATrack > 0.) {
0128 totE += edepByATrack;
0129 if (n_hitByATrack == 0) {
0130 (*CHC)[i]->GetTrackInformation()->Print();
0131 }
0132 n_hitByATrack++;
0133 G4cout << "Cell[" << (*CHC)[i]->GetZ() << "," << (*CHC)[i]->GetPhi() << "] "
0134 << edepByATrack / GeV << " [GeV]" << G4endl;
0135 (*CHC)[i]->ClearEdepByATrack();
0136 }
0137 }
0138 if (n_hitByATrack > 0) {
0139 G4cout << "### Total energy deposition in calorimeter by a source track in "
0140 << n_hitByATrack << " cells : " << totE / GeV << " (GeV)" << G4endl;
0141 G4cout << G4endl;
0142 }
0143 }
0144 }
0145
0146 if (stackManager->GetNUrgentTrack()) {
0147
0148
0149
0150 stackManager->TransferStackedTracks(fUrgent, fWaiting);
0151
0152
0153 stackManager->TransferOneStackedTrack(fWaiting, fUrgent);
0154
0155 fStage++;
0156 }
0157 }
0158
0159
0160 void RE01StackingAction::PrepareNewEvent()
0161 {
0162 fStage = 0;
0163 }