File indexing completed on 2025-02-23 09:22:04
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
0039
0040
0041
0042
0043 #include "ITTrackingInteractivity.hh"
0044
0045 #include "G4Event.hh"
0046 #include "G4EventManager.hh"
0047 #include "G4IT.hh"
0048 #include "G4RichTrajectory.hh"
0049 #include "G4SmoothTrajectory.hh"
0050 #include "G4TrackingInformation.hh"
0051 #include "G4Trajectory.hh"
0052 #include "G4UserSteppingAction.hh"
0053 #include "G4UserTrackingAction.hh"
0054 #include "G4VSteppingVerbose.hh"
0055 #include "G4VTrajectory.hh"
0056 #include "G4VisManager.hh"
0057
0058 class G4Trajectory_Lock
0059 {
0060 friend class ITTrackingInteractivity;
0061
0062 G4Trajectory_Lock() : fpTrajectory(0) { ; }
0063
0064 ~G4Trajectory_Lock() { ; }
0065
0066 G4VTrajectory* fpTrajectory;
0067 };
0068
0069 ITTrackingInteractivity::ITTrackingInteractivity()
0070 {
0071 fStoreTrajectory = 0;
0072 fVerboseLevel = 0;
0073
0074 fpUserTrackingAction = 0;
0075 fpUserSteppingAction = 0;
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087 }
0088
0089
0090
0091 ITTrackingInteractivity::~ITTrackingInteractivity()
0092 {
0093 G4EventManager* eventManager = G4EventManager::GetEventManager();
0094
0095 if (eventManager) {
0096 G4UserTrackingAction* std_trackAct = eventManager->GetUserTrackingAction();
0097 if (fpUserTrackingAction != std_trackAct && fpUserTrackingAction) delete fpUserTrackingAction;
0098
0099 G4UserSteppingAction* std_stepAct = eventManager->GetUserSteppingAction();
0100 if (fpUserSteppingAction != std_stepAct && fpUserSteppingAction) delete fpUserSteppingAction;
0101 }
0102 else {
0103 if (fpUserSteppingAction) {
0104 delete fpUserSteppingAction;
0105 }
0106
0107 if (fpUserTrackingAction) {
0108 delete fpUserTrackingAction;
0109 }
0110 }
0111 }
0112
0113
0114
0115 void ITTrackingInteractivity::Initialize()
0116 {
0117 G4TrackingManager* trackingManager = G4EventManager::GetEventManager()->GetTrackingManager();
0118 fStoreTrajectory = trackingManager->GetStoreTrajectory();
0119 fVerboseLevel = trackingManager->GetVerboseLevel();
0120 }
0121
0122
0123
0124 void ITTrackingInteractivity::StartTracking(G4Track* track)
0125 {
0126 #ifdef G4VERBOSE
0127 if (fVerboseLevel) {
0128 TrackBanner(track, "G4ITTrackingManager::StartTracking : ");
0129 }
0130 #endif
0131
0132 if (fVerboseLevel > 0 && (G4VSteppingVerbose::GetSilent() != 1)) TrackBanner(track);
0133
0134
0135 if (fpUserTrackingAction != 0) {
0136 fpUserTrackingAction->PreUserTrackingAction(track);
0137 }
0138
0139 G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0140 G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0141
0142
0143 if (fStoreTrajectory && (!trajectory_lock)) {
0144 trajectory_lock = new G4Trajectory_Lock();
0145 trackingInfo->SetTrajectory_Lock(trajectory_lock);
0146 G4VTrajectory* trajectory = 0;
0147
0148 switch (fStoreTrajectory) {
0149 default:
0150 case 1:
0151 trajectory = new G4Trajectory(track);
0152 break;
0153 case 2:
0154 trajectory = new G4SmoothTrajectory(track);
0155 break;
0156 case 3:
0157 trajectory = new G4RichTrajectory(track);
0158 break;
0159 }
0160 trajectory_lock->fpTrajectory = trajectory;
0161 }
0162
0163 }
0164
0165
0166
0167 void ITTrackingInteractivity::AppendStep(G4Track* track, G4Step* step)
0168 {
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 if (fpUserSteppingAction) fpUserSteppingAction->UserSteppingAction(step);
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 if (fStoreTrajectory) {
0202 G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0203 G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0204 trajectory_lock->fpTrajectory->AppendStep(step);
0205 }
0206 }
0207
0208
0209
0210 void ITTrackingInteractivity::EndTracking(G4Track* track)
0211 {
0212 #ifdef G4VERBOSE
0213 if (fVerboseLevel) {
0214 TrackBanner(track, "G4ITTrackingManager::EndTracking : ");
0215 }
0216 #endif
0217
0218 if (fpUserTrackingAction != 0) {
0219 fpUserTrackingAction->PostUserTrackingAction(track);
0220 }
0221
0222
0223 G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0224 G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0225
0226 if (trajectory_lock) {
0227 G4VTrajectory*& trajectory = trajectory_lock->fpTrajectory;
0228
0229 if (fStoreTrajectory && trajectory) {
0230 #ifdef G4VERBOSE
0231 if (fVerboseLevel > 10) trajectory->ShowTrajectory();
0232 #endif
0233 G4TrackStatus istop = track->GetTrackStatus();
0234
0235 if (trajectory && (istop != fStopButAlive) && (istop != fSuspend)) {
0236 G4Event* currentEvent = G4EventManager::GetEventManager()->GetNonconstCurrentEvent();
0237
0238 if (currentEvent) {
0239 G4TrajectoryContainer* trajectoryContainer = currentEvent->GetTrajectoryContainer();
0240
0241 if (!trajectoryContainer) {
0242 trajectoryContainer = new G4TrajectoryContainer;
0243 currentEvent->SetTrajectoryContainer(trajectoryContainer);
0244 }
0245 trajectoryContainer->insert(trajectory);
0246 }
0247 else {
0248 fTrajectories.push_back(trajectory);
0249 }
0250 }
0251 }
0252
0253 else if ((!fStoreTrajectory) && trajectory) {
0254 delete trajectory;
0255 trajectory = 0;
0256 }
0257 delete trajectory_lock;
0258 trackingInfo->SetTrajectory_Lock(0);
0259 }
0260
0261 }
0262
0263 void ITTrackingInteractivity::Finalize()
0264 {
0265 for (std::vector<G4VTrajectory*>::iterator it = fTrajectories.begin(); it != fTrajectories.end();
0266 it++)
0267 {
0268 G4VisManager::GetConcreteInstance()->Draw(**it);
0269 }
0270 }