File indexing completed on 2025-02-23 09:21:48
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 #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
0073
0074
0075
0076
0077
0078
0079
0080
0081 }
0082
0083
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
0108
0109 void ITTrackingInteractivity::Initialize()
0110 {
0111 G4TrackingManager* trackingManager = G4EventManager::GetEventManager()->GetTrackingManager();
0112 fStoreTrajectory = trackingManager->GetStoreTrajectory();
0113 fVerboseLevel = trackingManager->GetVerboseLevel();
0114 }
0115
0116
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
0129 if (fpUserTrackingAction != 0) {
0130 fpUserTrackingAction->PreUserTrackingAction(track);
0131 }
0132
0133 G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0134 G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0135
0136
0137 if (fStoreTrajectory && (!trajectory_lock)) {
0138 trajectory_lock = new G4Trajectory_Lock();
0139 trackingInfo->SetTrajectory_Lock(trajectory_lock);
0140 G4VTrajectory* trajectory = 0;
0141
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
0157 }
0158
0159
0160
0161 void ITTrackingInteractivity::AppendStep(G4Track* track, G4Step* step)
0162 {
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182 if (fpUserSteppingAction) fpUserSteppingAction->UserSteppingAction(step);
0183
0184
0185
0186
0187
0188
0189
0190
0191
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
0203
0204 void ITTrackingInteractivity::EndTracking(G4Track* track)
0205 {
0206 #ifdef G4VERBOSE
0207 if (fVerboseLevel) {
0208 TrackBanner(track, "G4ITTrackingManager::EndTracking : ");
0209 }
0210 #endif
0211
0212 if (fpUserTrackingAction != 0) {
0213 fpUserTrackingAction->PostUserTrackingAction(track);
0214 }
0215
0216
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
0247 else if ((!fStoreTrajectory) && trajectory) {
0248 delete trajectory;
0249 trajectory = 0;
0250 }
0251 delete trajectory_lock;
0252 trackingInfo->SetTrajectory_Lock(0);
0253 }
0254
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 }