Back to home page

EIC code displayed by LXR

 
 

    


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 // * 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 // This example is provided by the Geant4-DNA collaboration
0030 // Any report or published results obtained using the Geant4-DNA software
0031 // shall cite the following Geant4-DNA collaboration publication:
0032 // Med. Phys. 37 (2010) 4692-4708
0033 // and papers
0034 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507
0035 // O. Belov et al. Physica Medica 32 (2016) 1510-1520
0036 // The Geant4-DNA web site is available at http://geant4-dna.org
0037 //
0038 // -------------------------------------------------------------------
0039 // November 2016
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   // In case you want to use same tracking/stepping action
0080   // for normal and IT stepping
0081   /*
0082     fpUserTrackingAction =
0083       trackingManager->GetUserTrackingAction();
0084     fpUserSteppingAction =
0085       G4EventManager::GetEventManager()->GetUserSteppingAction();
0086    */
0087   ////////////////////////////
0088 }
0089 
0090 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0115 
0116 void ITTrackingInteractivity::Initialize()
0117 {
0118   G4TrackingManager* trackingManager = G4EventManager::GetEventManager()->GetTrackingManager();
0119   fStoreTrajectory = trackingManager->GetStoreTrajectory();
0120   fVerboseLevel = trackingManager->GetVerboseLevel();
0121 }
0122 
0123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   // Pre tracking user intervention process.
0136   if (fpUserTrackingAction != 0) {
0137     fpUserTrackingAction->PreUserTrackingAction(track);
0138   }
0139   // #ifdef G4_STORE_TRAJECTORY
0140   G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
0141   G4Trajectory_Lock* trajectory_lock = trackingInfo->GetTrajectory_Lock();
0142 
0143   // Construct a trajectory if it is requested
0144   if (fStoreTrajectory && (!trajectory_lock)) {
0145     trajectory_lock = new G4Trajectory_Lock();
0146     trackingInfo->SetTrajectory_Lock(trajectory_lock);
0147     G4VTrajectory* trajectory = 0;
0148     // default trajectory concrete class object
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   // #endif
0164 }
0165 
0166 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0167 
0168 void ITTrackingInteractivity::AppendStep(G4Track* track, G4Step* step)
0169 {
0170   ////////////////////////////
0171   // If you want to use sensitive detector
0172   /*
0173     G4VPhysicalVolume* currentVolume =
0174     step->GetPreStepPoint()->GetPhysicalVolume();
0175     G4SteppingControl stepControlFlag =  step->GetControlFlag();
0176 
0177     if( currentVolume  != 0 && stepControlFlag != AvoidHitInvocation)
0178     {
0179         G4VSensitiveDetector* sensitive = step->GetPreStepPoint()->
0180                 GetSensitiveDetector();
0181         if( sensitive != 0 )
0182         {
0183             sensitive->Hit(fpStep);
0184         }
0185     }
0186    */
0187   ////////////////////////////
0188 
0189   if (fpUserSteppingAction) fpUserSteppingAction->UserSteppingAction(step);
0190 
0191   ////////////////////////////
0192   // If you want to use regional stepping action
0193   /*
0194     G4UserSteppingAction* regionalAction
0195             = fpStep->GetPreStepPoint()->GetPhysicalVolume()->
0196                   GetLogicalVolume()->GetRegion()->
0197                   GetRegionalSteppingAction();
0198     if( regionalAction ) regionalAction->UserSteppingAction(fpStep);
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0210 
0211 void ITTrackingInteractivity::EndTracking(G4Track* track)
0212 {
0213 #ifdef G4VERBOSE
0214   if (fVerboseLevel) {
0215     TrackBanner(track, "G4ITTrackingManager::EndTracking : ");
0216   }
0217 #endif
0218   // Post tracking user intervention process.
0219   if (fpUserTrackingAction != 0) {
0220     fpUserTrackingAction->PostUserTrackingAction(track);
0221   }
0222 
0223   // #ifdef G4_STORE_TRAJECTORY
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     // Destruct the trajectory if it was created
0254     else if ((!fStoreTrajectory) && trajectory) {
0255       delete trajectory;
0256       trajectory = 0;
0257     }
0258     delete trajectory_lock;
0259     trackingInfo->SetTrajectory_Lock(0);
0260   }
0261   // #endif
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 }