Back to home page

EIC code displayed by LXR

 
 

    


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

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 //
0027 /// \file ITTrackingInteractivity.hh
0028 /// \brief Implementation of the ITTrackingInteractivity class
0029 
0030 #include "ITTrackingInteractivity.hh"
0031 
0032 #include "G4Event.hh"
0033 #include "G4EventManager.hh"
0034 #include "G4IT.hh"
0035 #include "G4RichTrajectory.hh"
0036 #include "G4SmoothTrajectory.hh"
0037 #include "G4TrackingInformation.hh"
0038 #include "G4Trajectory.hh"
0039 #include "G4VSteppingVerbose.hh"
0040 #include "G4VTrajectory.hh"
0041 #include "G4VisManager.hh"
0042 
0043 class G4Trajectory_Lock
0044 {
0045     friend class ITTrackingInteractivity;
0046     G4Trajectory_Lock() : fpTrajectory(0) { ; }
0047 
0048     ~G4Trajectory_Lock() { ; }
0049 
0050     G4VTrajectory* fpTrajectory;
0051 };
0052 
0053 ITTrackingInteractivity::ITTrackingInteractivity()
0054   : G4ITTrackingInteractivity(), fStoreTrajectory(0)
0055 {
0056   fpUserTrackingAction.reset(
0057     G4EventManager::GetEventManager()->GetTrackingManager()->GetUserTrackingAction());
0058 }
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 ITTrackingInteractivity::~ITTrackingInteractivity() {}
0063 
0064 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0065 
0066 void ITTrackingInteractivity::Initialize()
0067 {
0068   G4TrackingManager* trackingManager = G4EventManager::GetEventManager()->GetTrackingManager();
0069   fStoreTrajectory = trackingManager->GetStoreTrajectory();
0070   fVerboseLevel = trackingManager->GetVerboseLevel();
0071 }
0072 
0073 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0074 
0075 void ITTrackingInteractivity::StartTracking(G4Track* track)
0076 {
0077 #ifdef G4VERBOSE
0078   if (fVerboseLevel) {
0079     TrackBanner(track, "G4ITTrackingManager::StartTracking : ");
0080   }
0081 #endif
0082 
0083   if (fVerboseLevel > 0 && (G4VSteppingVerbose::GetSilent() != 1)) {
0084     TrackBanner(track);
0085   }
0086   if (fpUserTrackingAction != nullptr) {
0087     fpUserTrackingAction->PreUserTrackingAction(track);
0088   }
0089 
0090   G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0091   G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0092 
0093   if (fStoreTrajectory && (!trajectory_lock)) {
0094     trajectory_lock = new G4Trajectory_Lock();
0095     trackingInfo->SetTrajectory_Lock(trajectory_lock);
0096     G4VTrajectory* trajectory = 0;
0097     switch (fStoreTrajectory) {
0098       default:
0099       case 1:
0100         trajectory = new G4Trajectory(track);
0101         break;
0102       case 2:
0103         trajectory = new G4SmoothTrajectory(track);
0104         break;
0105       case 3:
0106         trajectory = new G4RichTrajectory(track);
0107         break;
0108     }
0109     trajectory_lock->fpTrajectory = trajectory;
0110   }
0111 }
0112 
0113 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0114 
0115 void ITTrackingInteractivity::AppendStep(G4Track* track, G4Step* step)
0116 {
0117   if (fpUserSteppingAction != nullptr) {
0118     fpUserSteppingAction->UserSteppingAction(step);
0119   }
0120 
0121   if (fStoreTrajectory) {
0122     G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0123     G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0124     trajectory_lock->fpTrajectory->AppendStep(step);
0125   }
0126 }
0127 
0128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0129 
0130 void ITTrackingInteractivity::EndTracking(G4Track* track)
0131 {
0132 #ifdef G4VERBOSE
0133   if (fVerboseLevel) {
0134     TrackBanner(track, "G4ITTrackingManager::EndTracking : ");
0135   }
0136 #endif
0137   if (fpUserTrackingAction != nullptr) {
0138     fpUserTrackingAction->PostUserTrackingAction(track);
0139   }
0140   G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0141   G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0142 
0143   if (trajectory_lock) {
0144     G4VTrajectory*& trajectory = trajectory_lock->fpTrajectory;
0145 
0146     if (fStoreTrajectory && trajectory) {
0147 #ifdef G4VERBOSE
0148       if (fVerboseLevel > 10) {
0149         trajectory->ShowTrajectory();
0150       }
0151 #endif
0152       G4TrackStatus istop = track->GetTrackStatus();
0153 
0154       if (trajectory && (istop != fStopButAlive) && (istop != fSuspend)) {
0155         G4Event* currentEvent = G4EventManager::GetEventManager()->GetNonconstCurrentEvent();
0156         if (currentEvent != nullptr) {
0157           G4TrajectoryContainer* trajectoryContainer = currentEvent->GetTrajectoryContainer();
0158           if (!trajectoryContainer) {
0159             trajectoryContainer = new G4TrajectoryContainer;
0160             currentEvent->SetTrajectoryContainer(trajectoryContainer);
0161           }
0162           trajectoryContainer->insert(trajectory);
0163         }
0164         else {
0165           fTrajectories.push_back(trajectory);
0166         }
0167       }
0168     }
0169     else if ((!fStoreTrajectory) && trajectory) {
0170       delete trajectory;
0171       trajectory = nullptr;
0172     }
0173     delete trajectory_lock;
0174     trackingInfo->SetTrajectory_Lock(0);
0175   }
0176 }
0177 
0178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0179 
0180 void ITTrackingInteractivity::Finalize()
0181 {
0182   for (std::vector<G4VTrajectory*>::iterator it = fTrajectories.begin(); it != fTrajectories.end();
0183        it++)
0184   {
0185     G4VisManager::GetConcreteInstance()->Draw(**it);
0186   }
0187 }