Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:50:35

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