Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-24 07:41:20

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