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