File indexing completed on 2026-03-28 07:50:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
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
0074
0075
0076
0077
0078
0079
0080
0081
0082 }
0083
0084
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
0109
0110 void ITTrackingInteractivity::Initialize()
0111 {
0112 G4TrackingManager* trackingManager = G4EventManager::GetEventManager()->GetTrackingManager();
0113 fStoreTrajectory = trackingManager->GetStoreTrajectory();
0114 fVerboseLevel = trackingManager->GetVerboseLevel();
0115 }
0116
0117
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
0130 if (fpUserTrackingAction != 0) {
0131 fpUserTrackingAction->PreUserTrackingAction(track);
0132 }
0133
0134 G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0135 G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0136
0137
0138 if (fStoreTrajectory && (!trajectory_lock)) {
0139 trajectory_lock = new G4Trajectory_Lock();
0140 trackingInfo->SetTrajectory_Lock(trajectory_lock);
0141 G4VTrajectory* trajectory = 0;
0142
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
0158 }
0159
0160
0161
0162 void ITTrackingInteractivity::AppendStep(G4Track* track, G4Step* step)
0163 {
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183 if (fpUserSteppingAction) fpUserSteppingAction->UserSteppingAction(step);
0184
0185
0186
0187
0188
0189
0190
0191
0192
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
0204
0205 void ITTrackingInteractivity::EndTracking(G4Track* track)
0206 {
0207 #ifdef G4VERBOSE
0208 if (fVerboseLevel) {
0209 TrackBanner(track, "G4ITTrackingManager::EndTracking : ");
0210 }
0211 #endif
0212
0213 if (fpUserTrackingAction != 0) {
0214 fpUserTrackingAction->PostUserTrackingAction(track);
0215 }
0216
0217
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
0248 else if ((!fStoreTrajectory) && trajectory) {
0249 delete trajectory;
0250 trajectory = 0;
0251 }
0252 delete trajectory_lock;
0253 trackingInfo->SetTrajectory_Lock(0);
0254 }
0255
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 }