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