00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id: G4TrackingManager.cc 67009 2013-01-29 16:00:21Z gcosmo $ 00028 // 00029 //--------------------------------------------------------------- 00030 // 00031 // G4TrackingManager.cc 00032 // 00033 // Contact: 00034 // Questions and comments to this code should be sent to 00035 // Katsuya Amako (e-mail: Katsuya.Amako@kek.jp) 00036 // Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp) 00037 // 00038 //--------------------------------------------------------------- 00039 00040 #include "G4TrackingManager.hh" 00041 #include "G4Trajectory.hh" 00042 #include "G4SmoothTrajectory.hh" 00043 #include "G4RichTrajectory.hh" 00044 #include "G4ios.hh" 00045 class G4VSteppingVerbose; 00046 00048 G4TrackingManager::G4TrackingManager() 00050 : fpUserTrackingAction(0), fpTrajectory(0), 00051 StoreTrajectory(0), verboseLevel(0), EventIsAborted(false) 00052 { 00053 fpSteppingManager = new G4SteppingManager(); 00054 messenger = new G4TrackingMessenger(this); 00055 } 00056 00058 G4TrackingManager::~G4TrackingManager() 00060 { 00061 delete messenger; 00062 delete fpSteppingManager; 00063 if (fpUserTrackingAction) delete fpUserTrackingAction; 00064 } 00065 00067 void G4TrackingManager::ProcessOneTrack(G4Track* apValueG4Track) 00069 { 00070 00071 // Receiving a G4Track from the EventManager, this funciton has the 00072 // responsibility to trace the track till it stops. 00073 fpTrack = apValueG4Track; 00074 EventIsAborted = false; 00075 00076 // Clear 2ndary particle vector 00077 // GimmeSecondaries()->clearAndDestroy(); 00078 // std::vector<G4Track*>::iterator itr; 00079 size_t itr; 00080 // for(itr=GimmeSecondaries()->begin();itr=GimmeSecondaries()->end();itr++){ 00081 for(itr=0;itr<GimmeSecondaries()->size();itr++){ 00082 delete (*GimmeSecondaries())[itr]; 00083 } 00084 GimmeSecondaries()->clear(); 00085 00086 if(verboseLevel>0 && (G4VSteppingVerbose::GetSilent()!=1) ) TrackBanner(); 00087 00088 // Give SteppingManger the pointer to the track which will be tracked 00089 fpSteppingManager->SetInitialStep(fpTrack); 00090 00091 // Pre tracking user intervention process. 00092 fpTrajectory = 0; 00093 if( fpUserTrackingAction != 0 ) { 00094 fpUserTrackingAction->PreUserTrackingAction(fpTrack); 00095 } 00096 #ifdef G4_STORE_TRAJECTORY 00097 // Construct a trajectory if it is requested 00098 if(StoreTrajectory&&(!fpTrajectory)) { 00099 // default trajectory concrete class object 00100 switch (StoreTrajectory) { 00101 default: 00102 case 1: fpTrajectory = new G4Trajectory(fpTrack); break; 00103 case 2: fpTrajectory = new G4SmoothTrajectory(fpTrack); break; 00104 case 3: fpTrajectory = new G4RichTrajectory(fpTrack); break; 00105 } 00106 } 00107 #endif 00108 00109 // Give SteppingManger the maxmimum number of processes 00110 fpSteppingManager->GetProcessNumber(); 00111 00112 // Give track the pointer to the Step 00113 fpTrack->SetStep(fpSteppingManager->GetStep()); 00114 00115 // Inform beginning of tracking to physics processes 00116 fpTrack->GetDefinition()->GetProcessManager()->StartTracking(fpTrack); 00117 00118 // Track the particle Step-by-Step while it is alive 00119 // G4StepStatus stepStatus; 00120 00121 while( (fpTrack->GetTrackStatus() == fAlive) || 00122 (fpTrack->GetTrackStatus() == fStopButAlive) ){ 00123 00124 fpTrack->IncrementCurrentStepNumber(); 00125 fpSteppingManager->Stepping(); 00126 #ifdef G4_STORE_TRAJECTORY 00127 if(StoreTrajectory) fpTrajectory-> 00128 AppendStep(fpSteppingManager->GetStep()); 00129 #endif 00130 if(EventIsAborted) { 00131 fpTrack->SetTrackStatus( fKillTrackAndSecondaries ); 00132 } 00133 } 00134 // Inform end of tracking to physics processes 00135 fpTrack->GetDefinition()->GetProcessManager()->EndTracking(); 00136 00137 // Post tracking user intervention process. 00138 if( fpUserTrackingAction != 0 ) { 00139 fpUserTrackingAction->PostUserTrackingAction(fpTrack); 00140 } 00141 00142 // Destruct the trajectory if it was created 00143 #ifdef G4VERBOSE 00144 if(StoreTrajectory&&verboseLevel>10) fpTrajectory->ShowTrajectory(); 00145 #endif 00146 if( (!StoreTrajectory)&&fpTrajectory ) { 00147 delete fpTrajectory; 00148 fpTrajectory = 0; 00149 } 00150 } 00151 00152 void G4TrackingManager::SetTrajectory(G4VTrajectory* aTrajectory) 00153 { 00154 #ifndef G4_STORE_TRAJECTORY 00155 G4Exception("G4TrackingManager::SetTrajectory()", 00156 "Tracking0015", FatalException, 00157 "Invoked without G4_STORE_TRAJECTORY option set!"); 00158 #endif 00159 fpTrajectory = aTrajectory; 00160 } 00161 00163 void G4TrackingManager::EventAborted() 00165 { 00166 fpTrack->SetTrackStatus( fKillTrackAndSecondaries ); 00167 EventIsAborted = true; 00168 } 00169 00170 00171 void G4TrackingManager::TrackBanner() 00172 { 00173 G4cout << G4endl; 00174 G4cout << "*******************************************************" 00175 << "**************************************************" 00176 << G4endl; 00177 G4cout << "* G4Track Information: " 00178 << " Particle = " << fpTrack->GetDefinition()->GetParticleName() 00179 << "," 00180 << " Track ID = " << fpTrack->GetTrackID() 00181 << "," 00182 << " Parent ID = " << fpTrack->GetParentID() 00183 << G4endl; 00184 G4cout << "*******************************************************" 00185 << "**************************************************" 00186 << G4endl; 00187 G4cout << G4endl; 00188 } 00189 00190 00191 00192 00193 00194 00195