Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /geant4/examples/extended/runAndEvent/RE07/src/SpecializedTrackingManager.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file SpecializedTrackingManager.cc
0027 /// \brief Implementation of the SpecializedTrackingManager class
0028 
0029 #include "SpecializedTrackingManager.hh"
0030 
0031 #include "G4EventManager.hh"
0032 #include "G4ProcessManager.hh"
0033 #include "G4RegionStore.hh"
0034 #include "G4StackManager.hh"
0035 #include "G4SystemOfUnits.hh"
0036 #include "G4TrackingManager.hh"
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 SpecializedTrackingManager::SpecializedTrackingManager() {}
0041 
0042 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 SpecializedTrackingManager::~SpecializedTrackingManager() {}
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 void SpecializedTrackingManager::BuildPhysicsTable(const G4ParticleDefinition& part)
0049 {
0050   if (fBackRegion == nullptr) {
0051     fBackRegion = G4RegionStore::GetInstance()->GetRegion("Back", false);
0052   }
0053 
0054   G4ProcessManager* pManager = part.GetProcessManager();
0055   G4ProcessManager* pManagerShadow = part.GetMasterProcessManager();
0056 
0057   G4ProcessVector* pVector = pManager->GetProcessList();
0058   for (std::size_t j = 0; j < pVector->size(); ++j) {
0059     if (pManagerShadow == pManager) {
0060       (*pVector)[j]->BuildPhysicsTable(part);
0061     }
0062     else {
0063       (*pVector)[j]->BuildWorkerPhysicsTable(part);
0064     }
0065   }
0066 }
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0069 
0070 void SpecializedTrackingManager::PreparePhysicsTable(const G4ParticleDefinition& part)
0071 {
0072   G4ProcessManager* pManager = part.GetProcessManager();
0073   G4ProcessManager* pManagerShadow = part.GetMasterProcessManager();
0074 
0075   G4ProcessVector* pVector = pManager->GetProcessList();
0076   for (std::size_t j = 0; j < pVector->size(); ++j) {
0077     if (pManagerShadow == pManager) {
0078       (*pVector)[j]->PreparePhysicsTable(part);
0079     }
0080     else {
0081       (*pVector)[j]->PrepareWorkerPhysicsTable(part);
0082     }
0083   }
0084 }
0085 
0086 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0087 
0088 void SpecializedTrackingManager::HandOverOneTrack(G4Track* aTrack)
0089 {
0090   if (aTrack->GetKineticEnergy() < 100 * MeV) {
0091     // If the particle energy is lower than 100 MeV, track it immediately by
0092     // passing to the generic G4TrackingManager. This avoids storing lower
0093     // energy particles in the buffer and feeding it through the specialized
0094     // tracking.
0095     G4EventManager* eventManager = G4EventManager::GetEventManager();
0096     G4TrackingManager* trackManager = eventManager->GetTrackingManager();
0097 
0098     trackManager->ProcessOneTrack(aTrack);
0099     if (aTrack->GetTrackStatus() != fStopAndKill) {
0100       G4Exception("SpecializedTrackingManager::HandOverOneTrack", "NotStopped", FatalException,
0101                   "track was not stopped");
0102     }
0103 
0104     G4TrackVector* secondaries = trackManager->GimmeSecondaries();
0105     eventManager->StackTracks(secondaries);
0106     delete aTrack;
0107     return;
0108   }
0109 
0110   fBufferedTracks.push_back(aTrack);
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0114 
0115 void SpecializedTrackingManager::FlushEvent()
0116 {
0117   G4EventManager* eventManager = G4EventManager::GetEventManager();
0118   G4TrackingManager* trackManager = eventManager->GetTrackingManager();
0119   G4SteppingManager* steppingManager = trackManager->GetSteppingManager();
0120   G4TrackVector* secondaries = trackManager->GimmeSecondaries();
0121 
0122   for (G4Track* aTrack : fBufferedTracks) {
0123     // Clear secondary particle vector
0124     for (std::size_t itr = 0; itr < secondaries->size(); ++itr) {
0125       delete (*secondaries)[itr];
0126     }
0127     secondaries->clear();
0128 
0129     steppingManager->SetInitialStep(aTrack);
0130 
0131     G4UserTrackingAction* userTrackingAction = trackManager->GetUserTrackingAction();
0132     if (userTrackingAction != nullptr) {
0133       userTrackingAction->PreUserTrackingAction(aTrack);
0134     }
0135 
0136     // Give SteppingManger the maxmimum number of processes
0137     steppingManager->GetProcessNumber();
0138 
0139     // Give track the pointer to the Step
0140     aTrack->SetStep(steppingManager->GetStep());
0141 
0142     // Inform beginning of tracking to physics processes
0143     aTrack->GetDefinition()->GetProcessManager()->StartTracking(aTrack);
0144 
0145     // Track the particle Step-by-Step while it is alive
0146     while ((aTrack->GetTrackStatus() == fAlive) || (aTrack->GetTrackStatus() == fStopButAlive)) {
0147       G4Region* region = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
0148       if (region == fBackRegion) {
0149         StepInBackRegion(aTrack);
0150       }
0151       else {
0152         StepOutside(aTrack);
0153       }
0154     }
0155 
0156     aTrack->GetDefinition()->GetProcessManager()->EndTracking();
0157 
0158     if (userTrackingAction != nullptr) {
0159       userTrackingAction->PostUserTrackingAction(aTrack);
0160     }
0161 
0162     eventManager->StackTracks(secondaries);
0163     delete aTrack;
0164   }
0165 
0166   fBufferedTracks.clear();
0167 }
0168 
0169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0170 
0171 void SpecializedTrackingManager::StepInBackRegion(G4Track* aTrack)
0172 {
0173   G4EventManager* eventManager = G4EventManager::GetEventManager();
0174   G4TrackingManager* trackManager = eventManager->GetTrackingManager();
0175   G4SteppingManager* steppingManager = trackManager->GetSteppingManager();
0176 
0177   // Track the particle Step-by-Step while it is alive and inside the "Back"
0178   // region of the detector. Implement a low-energy cut-off for particles
0179   // below 100 MeV. More specialized handling would also be possible, such
0180   // as only killing particles in non-sensitive materials / volumes.
0181   while ((aTrack->GetTrackStatus() == fAlive) || (aTrack->GetTrackStatus() == fStopButAlive)) {
0182     aTrack->IncrementCurrentStepNumber();
0183     steppingManager->Stepping();
0184 
0185     if (aTrack->GetTrackStatus() != fStopAndKill) {
0186       // Switch the touchable to update the volume, which is checked in the
0187       // condition below and at the call site.
0188       aTrack->SetTouchableHandle(aTrack->GetNextTouchableHandle());
0189       G4Region* region = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
0190       if (region != fBackRegion) {
0191         return;
0192       }
0193 
0194       if (aTrack->GetKineticEnergy() < 100 * MeV) {
0195         // Kill the particle.
0196         aTrack->SetTrackStatus(fStopAndKill);
0197       }
0198     }
0199   }
0200 }
0201 
0202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0203 
0204 void SpecializedTrackingManager::StepOutside(G4Track* aTrack)
0205 {
0206   G4EventManager* eventManager = G4EventManager::GetEventManager();
0207   G4TrackingManager* trackManager = eventManager->GetTrackingManager();
0208   G4SteppingManager* steppingManager = trackManager->GetSteppingManager();
0209 
0210   // Track the particle Step-by-Step while it is alive and still outside of
0211   // the "Back" region.
0212   while ((aTrack->GetTrackStatus() == fAlive) || (aTrack->GetTrackStatus() == fStopButAlive)) {
0213     aTrack->IncrementCurrentStepNumber();
0214     steppingManager->Stepping();
0215 
0216     if (aTrack->GetTrackStatus() != fStopAndKill) {
0217       // Switch the touchable to update the volume, which is checked in the
0218       // condition below and at the call site.
0219       aTrack->SetTouchableHandle(aTrack->GetNextTouchableHandle());
0220       G4Region* region = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
0221       if (region == fBackRegion) {
0222         return;
0223       }
0224     }
0225   }
0226 }