Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:04

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 // This example is provided by the Geant4-DNA collaboration
0027 // Any report or published results obtained using the Geant4-DNA software
0028 // shall cite the following Geant4-DNA collaboration publication:
0029 // Med. Phys. 37 (2010) 4692-4708
0030 // and papers
0031 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507
0032 // O. Belov et al. Physica Medica 32 (2016) 1510-1520
0033 // The Geant4-DNA web site is available at http://geant4-dna.org
0034 //
0035 // -------------------------------------------------------------------
0036 // November 2016
0037 // -------------------------------------------------------------------
0038 //
0039 //
0040 /// \file ITTrackingInteractivity.hh
0041 /// \brief Implementation of the ITTrackingInteractivity class
0042 
0043 #include "ITTrackingInteractivity.hh"
0044 
0045 #include "G4Event.hh"
0046 #include "G4EventManager.hh"
0047 #include "G4IT.hh"
0048 #include "G4RichTrajectory.hh"
0049 #include "G4SmoothTrajectory.hh"
0050 #include "G4TrackingInformation.hh"
0051 #include "G4Trajectory.hh"
0052 #include "G4UserSteppingAction.hh"
0053 #include "G4UserTrackingAction.hh"
0054 #include "G4VSteppingVerbose.hh"
0055 #include "G4VTrajectory.hh"
0056 #include "G4VisManager.hh"
0057 
0058 class G4Trajectory_Lock
0059 {
0060     friend class ITTrackingInteractivity;
0061 
0062     G4Trajectory_Lock() : fpTrajectory(0) { ; }
0063 
0064     ~G4Trajectory_Lock() { ; }
0065 
0066     G4VTrajectory* fpTrajectory;
0067 };
0068 
0069 ITTrackingInteractivity::ITTrackingInteractivity()
0070 {
0071   fStoreTrajectory = 0;
0072   fVerboseLevel = 0;
0073 
0074   fpUserTrackingAction = 0;
0075   fpUserSteppingAction = 0;
0076 
0077   ////////////////////////////
0078   // In case you want to use same tracking/stepping action
0079   // for normal and IT stepping
0080   /*
0081     fpUserTrackingAction =
0082       trackingManager->GetUserTrackingAction();
0083     fpUserSteppingAction =
0084       G4EventManager::GetEventManager()->GetUserSteppingAction();
0085    */
0086   ////////////////////////////
0087 }
0088 
0089 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0090 
0091 ITTrackingInteractivity::~ITTrackingInteractivity()
0092 {
0093   G4EventManager* eventManager = G4EventManager::GetEventManager();
0094 
0095   if (eventManager) {
0096     G4UserTrackingAction* std_trackAct = eventManager->GetUserTrackingAction();
0097     if (fpUserTrackingAction != std_trackAct && fpUserTrackingAction) delete fpUserTrackingAction;
0098 
0099     G4UserSteppingAction* std_stepAct = eventManager->GetUserSteppingAction();
0100     if (fpUserSteppingAction != std_stepAct && fpUserSteppingAction) delete fpUserSteppingAction;
0101   }
0102   else {
0103     if (fpUserSteppingAction) {
0104       delete fpUserSteppingAction;
0105     }
0106 
0107     if (fpUserTrackingAction) {
0108       delete fpUserTrackingAction;
0109     }
0110   }
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0114 
0115 void ITTrackingInteractivity::Initialize()
0116 {
0117   G4TrackingManager* trackingManager = G4EventManager::GetEventManager()->GetTrackingManager();
0118   fStoreTrajectory = trackingManager->GetStoreTrajectory();
0119   fVerboseLevel = trackingManager->GetVerboseLevel();
0120 }
0121 
0122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0123 
0124 void ITTrackingInteractivity::StartTracking(G4Track* track)
0125 {
0126 #ifdef G4VERBOSE
0127   if (fVerboseLevel) {
0128     TrackBanner(track, "G4ITTrackingManager::StartTracking : ");
0129   }
0130 #endif
0131 
0132   if (fVerboseLevel > 0 && (G4VSteppingVerbose::GetSilent() != 1)) TrackBanner(track);
0133 
0134   // Pre tracking user intervention process.
0135   if (fpUserTrackingAction != 0) {
0136     fpUserTrackingAction->PreUserTrackingAction(track);
0137   }
0138   // #ifdef G4_STORE_TRAJECTORY
0139   G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0140   G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0141 
0142   // Construct a trajectory if it is requested
0143   if (fStoreTrajectory && (!trajectory_lock)) {
0144     trajectory_lock = new G4Trajectory_Lock();
0145     trackingInfo->SetTrajectory_Lock(trajectory_lock);
0146     G4VTrajectory* trajectory = 0;
0147     // default trajectory concrete class object
0148     switch (fStoreTrajectory) {
0149       default:
0150       case 1:
0151         trajectory = new G4Trajectory(track);
0152         break;
0153       case 2:
0154         trajectory = new G4SmoothTrajectory(track);
0155         break;
0156       case 3:
0157         trajectory = new G4RichTrajectory(track);
0158         break;
0159     }
0160     trajectory_lock->fpTrajectory = trajectory;
0161   }
0162   // #endif
0163 }
0164 
0165 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0166 
0167 void ITTrackingInteractivity::AppendStep(G4Track* track, G4Step* step)
0168 {
0169   ////////////////////////////
0170   // If you want to use sensitive detector
0171   /*
0172     G4VPhysicalVolume* currentVolume =
0173     step->GetPreStepPoint()->GetPhysicalVolume();
0174     G4SteppingControl stepControlFlag =  step->GetControlFlag();
0175 
0176     if( currentVolume  != 0 && stepControlFlag != AvoidHitInvocation)
0177     {
0178         G4VSensitiveDetector* sensitive = step->GetPreStepPoint()->
0179                 GetSensitiveDetector();
0180         if( sensitive != 0 )
0181         {
0182             sensitive->Hit(fpStep);
0183         }
0184     }
0185    */
0186   ////////////////////////////
0187 
0188   if (fpUserSteppingAction) fpUserSteppingAction->UserSteppingAction(step);
0189 
0190   ////////////////////////////
0191   // If you want to use regional stepping action
0192   /*
0193     G4UserSteppingAction* regionalAction
0194             = fpStep->GetPreStepPoint()->GetPhysicalVolume()->
0195                   GetLogicalVolume()->GetRegion()->
0196                   GetRegionalSteppingAction();
0197     if( regionalAction ) regionalAction->UserSteppingAction(fpStep);
0198    */
0199   ////////////////////////////
0200 
0201   if (fStoreTrajectory) {
0202     G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0203     G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0204     trajectory_lock->fpTrajectory->AppendStep(step);
0205   }
0206 }
0207 
0208 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0209 
0210 void ITTrackingInteractivity::EndTracking(G4Track* track)
0211 {
0212 #ifdef G4VERBOSE
0213   if (fVerboseLevel) {
0214     TrackBanner(track, "G4ITTrackingManager::EndTracking : ");
0215   }
0216 #endif
0217   // Post tracking user intervention process.
0218   if (fpUserTrackingAction != 0) {
0219     fpUserTrackingAction->PostUserTrackingAction(track);
0220   }
0221 
0222   // #ifdef G4_STORE_TRAJECTORY
0223   G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0224   G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0225 
0226   if (trajectory_lock) {
0227     G4VTrajectory*& trajectory = trajectory_lock->fpTrajectory;
0228 
0229     if (fStoreTrajectory && trajectory) {
0230 #ifdef G4VERBOSE
0231       if (fVerboseLevel > 10) trajectory->ShowTrajectory();
0232 #endif
0233       G4TrackStatus istop = track->GetTrackStatus();
0234 
0235       if (trajectory && (istop != fStopButAlive) && (istop != fSuspend)) {
0236         G4Event* currentEvent = G4EventManager::GetEventManager()->GetNonconstCurrentEvent();
0237 
0238         if (currentEvent) {
0239           G4TrajectoryContainer* trajectoryContainer = currentEvent->GetTrajectoryContainer();
0240 
0241           if (!trajectoryContainer) {
0242             trajectoryContainer = new G4TrajectoryContainer;
0243             currentEvent->SetTrajectoryContainer(trajectoryContainer);
0244           }
0245           trajectoryContainer->insert(trajectory);
0246         }
0247         else {
0248           fTrajectories.push_back(trajectory);
0249         }
0250       }
0251     }
0252     // Destruct the trajectory if it was created
0253     else if ((!fStoreTrajectory) && trajectory) {
0254       delete trajectory;
0255       trajectory = 0;
0256     }
0257     delete trajectory_lock;
0258     trackingInfo->SetTrajectory_Lock(0);
0259   }
0260   // #endif
0261 }
0262 
0263 void ITTrackingInteractivity::Finalize()
0264 {
0265   for (std::vector<G4VTrajectory*>::iterator it = fTrajectories.begin(); it != fTrajectories.end();
0266        it++)
0267   {
0268     G4VisManager::GetConcreteInstance()->Draw(**it);
0269   }
0270 }