Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:48

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