G4SteppingManager.cc

Go to the documentation of this file.
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: G4SteppingManager.cc 67009 2013-01-29 16:00:21Z gcosmo $
00028 //
00029 //---------------------------------------------------------------
00030 //
00031 // G4SteppingManager.cc
00032 //
00033 // Description:
00034 //   This class represents the manager who steers to move the give
00035 //   particle from the TrackingManger by one Step.
00036 //
00037 // Contact:
00038 //   Questions and comments to this code should be sent to
00039 //     Katsuya Amako  (e-mail: Katsuya.Amako@kek.jp)
00040 //     Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
00041 //
00042 //---------------------------------------------------------------
00043 
00044 #include "G4SteppingManager.hh"
00045 #include "G4SteppingVerbose.hh"
00046 #include "G4UImanager.hh"
00047 #include "G4ForceCondition.hh"
00048 #include "G4GPILSelection.hh"
00049 #include "G4SteppingControl.hh"
00050 #include "G4TransportationManager.hh"
00051 #include "G4UserLimits.hh"
00052 #include "G4VSensitiveDetector.hh"    // Include from 'hits/digi'
00053 #include "G4GeometryTolerance.hh"
00054 
00056 G4SteppingManager::G4SteppingManager()
00058   : fUserSteppingAction(0), verboseLevel(0)
00059 {
00060 
00061 // Construct simple 'has-a' related objects
00062    fStep = new G4Step();
00063    fSecondary = fStep->NewSecondaryVector();
00064    fPreStepPoint  = fStep->GetPreStepPoint();
00065    fPostStepPoint = fStep->GetPostStepPoint();
00066 #ifdef G4VERBOSE
00067    if(G4VSteppingVerbose::GetInstance()==0) {
00068      fVerbose =  new G4SteppingVerbose();
00069      G4VSteppingVerbose::SetInstance(fVerbose);
00070      fVerbose -> SetManager(this);
00071      KillVerbose = true;
00072    }
00073    else { 
00074       fVerbose = G4VSteppingVerbose::GetInstance();
00075       fVerbose -> SetManager(this);
00076       KillVerbose = false;
00077    }
00078 #endif
00079    SetNavigator(G4TransportationManager::GetTransportationManager()
00080                    ->GetNavigatorForTracking());
00081 
00082    fSelectedAtRestDoItVector
00083       = new G4SelectedAtRestDoItVector(SizeOfSelectedDoItVector,0);
00084    fSelectedAlongStepDoItVector
00085       = new G4SelectedAlongStepDoItVector(SizeOfSelectedDoItVector,0);
00086    fSelectedPostStepDoItVector
00087       = new G4SelectedPostStepDoItVector(SizeOfSelectedDoItVector,0);
00088 
00089    SetNavigator(G4TransportationManager::GetTransportationManager()
00090      ->GetNavigatorForTracking());
00091 
00092    physIntLength = DBL_MAX; 
00093    kCarTolerance = 0.5*G4GeometryTolerance::GetInstance()->GetSurfaceTolerance();
00094 }
00095 
00097 G4SteppingManager::~G4SteppingManager()
00099 {
00100 
00101 // Destruct simple 'has-a' objects
00102    fStep->DeleteSecondaryVector();
00104    delete fStep;
00105    delete fSelectedAtRestDoItVector;
00106    delete fSelectedAlongStepDoItVector;
00107    delete fSelectedPostStepDoItVector;
00108    if (fUserSteppingAction) delete fUserSteppingAction;
00109 #ifdef G4VERBOSE
00110    if(KillVerbose) delete fVerbose;
00111 #endif
00112 }
00113 
00114 
00116 G4StepStatus G4SteppingManager::Stepping()
00118 {
00119 
00120 //--------
00121 // Prelude
00122 //--------
00123 #ifdef G4VERBOSE
00124             // !!!!! Verbose
00125              if(verboseLevel>0) fVerbose->NewStep();
00126              else 
00127              if(verboseLevel==-1) { 
00128                  G4VSteppingVerbose::SetSilent(1);
00129              }
00130              else
00131                  G4VSteppingVerbose::SetSilent(0);
00132 #endif 
00133 
00134 // Store last PostStepPoint to PreStepPoint, and swap current and nex
00135 // volume information of G4Track. Reset total energy deposit in one Step. 
00136    fStep->CopyPostToPreStepPoint();
00137    fStep->ResetTotalEnergyDeposit();
00138 
00139 // Switch next touchable in track to current one
00140    fTrack->SetTouchableHandle(fTrack->GetNextTouchableHandle());
00141 
00142 // Reset the secondary particles
00143    fN2ndariesAtRestDoIt = 0;
00144    fN2ndariesAlongStepDoIt = 0;
00145    fN2ndariesPostStepDoIt = 0;
00146 
00147 //JA Set the volume before it is used (in DefineStepLength() for User Limit) 
00148    fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume();
00149 
00150 // Reset the step's auxiliary points vector pointer
00151    fStep->SetPointerToVectorOfAuxiliaryPoints(0);
00152 
00153 //-----------------
00154 // AtRest Processes
00155 //-----------------
00156 
00157    if( fTrack->GetTrackStatus() == fStopButAlive ){
00158      if( MAXofAtRestLoops>0 ){
00159         InvokeAtRestDoItProcs();
00160         fStepStatus = fAtRestDoItProc;
00161         fStep->GetPostStepPoint()->SetStepStatus( fStepStatus );
00162        
00163 #ifdef G4VERBOSE
00164             // !!!!! Verbose
00165              if(verboseLevel>0) fVerbose->AtRestDoItInvoked();
00166 #endif 
00167 
00168      }
00169      // Make sure the track is killed
00170      fTrack->SetTrackStatus( fStopAndKill );
00171    }
00172 
00173 //---------------------------------
00174 // AlongStep and PostStep Processes
00175 //---------------------------------
00176 
00177 
00178    else{
00179      // Find minimum Step length demanded by active disc./cont. processes
00180      DefinePhysicalStepLength();
00181 
00182      // Store the Step length (geometrical length) to G4Step and G4Track
00183      fStep->SetStepLength( PhysicalStep );
00184      fTrack->SetStepLength( PhysicalStep );
00185      G4double GeomStepLength = PhysicalStep;
00186 
00187      // Store StepStatus to PostStepPoint
00188      fStep->GetPostStepPoint()->SetStepStatus( fStepStatus );
00189 
00190      // Invoke AlongStepDoIt 
00191      InvokeAlongStepDoItProcs();
00192 
00193      // Update track by taking into account all changes by AlongStepDoIt
00194      fStep->UpdateTrack();
00195 
00196      // Update safety after invocation of all AlongStepDoIts
00197      endpointSafOrigin= fPostStepPoint->GetPosition();
00198 //     endpointSafety=  std::max( proposedSafety - GeomStepLength, 0.);
00199      endpointSafety=  std::max( proposedSafety - GeomStepLength, kCarTolerance);
00200 
00201      fStep->GetPostStepPoint()->SetSafety( endpointSafety );
00202 
00203 #ifdef G4VERBOSE
00204                          // !!!!! Verbose
00205            if(verboseLevel>0) fVerbose->AlongStepDoItAllDone();
00206 #endif
00207 
00208      // Invoke PostStepDoIt
00209      InvokePostStepDoItProcs();
00210 
00211 #ifdef G4VERBOSE
00212                  // !!!!! Verbose
00213      if(verboseLevel>0) fVerbose->PostStepDoItAllDone();
00214 #endif
00215    }
00216 
00217 //-------
00218 // Finale
00219 //-------
00220 
00221 // Update 'TrackLength' and remeber the Step length of the current Step
00222    fTrack->AddTrackLength(fStep->GetStepLength());
00223    fPreviousStepSize = fStep->GetStepLength();
00224    fStep->SetTrack(fTrack);
00225 #ifdef G4VERBOSE
00226                          // !!!!! Verbose
00227 
00228            if(verboseLevel>0) fVerbose->StepInfo();
00229 #endif
00230 // Send G4Step information to Hit/Dig if the volume is sensitive
00231    fCurrentVolume = fStep->GetPreStepPoint()->GetPhysicalVolume();
00232    StepControlFlag =  fStep->GetControlFlag();
00233    if( fCurrentVolume != 0 && StepControlFlag != AvoidHitInvocation) {
00234       fSensitive = fStep->GetPreStepPoint()->
00235                                    GetSensitiveDetector();
00236       if( fSensitive != 0 ) {
00237         fSensitive->Hit(fStep);
00238       }
00239    }
00240 
00241 // User intervention process.
00242    if( fUserSteppingAction != 0 ) {
00243       fUserSteppingAction->UserSteppingAction(fStep);
00244    }
00245    G4UserSteppingAction* regionalAction
00246     = fStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetRegion()
00247       ->GetRegionalSteppingAction();
00248    if( regionalAction ) regionalAction->UserSteppingAction(fStep);
00249 
00250 // Stepping process finish. Return the value of the StepStatus.
00251    return fStepStatus;
00252 
00253 }
00254 
00256 void G4SteppingManager::SetInitialStep(G4Track* valueTrack)
00258 {
00259 
00260 // Set up several local variables.
00261    PreStepPointIsGeom = false;
00262    FirstStep = true;
00263    fParticleChange = 0;
00264    fPreviousStepSize = 0.;
00265    fStepStatus = fUndefined;
00266 
00267    fTrack = valueTrack;
00268    Mass = fTrack->GetDynamicParticle()->GetMass();
00269 
00270    PhysicalStep = 0.;
00271    GeometricalStep = 0.;
00272    CorrectedStep = 0.;
00273    PreStepPointIsGeom = false;
00274    FirstStep = false;
00275    fStepStatus = fUndefined;
00276 
00277    TempInitVelocity = 0.;
00278    TempVelocity = 0.;
00279    sumEnergyChange = 0.;
00280 
00281 
00282 // If the primary track has 'Suspend' or 'PostponeToNextEvent' state,
00283 // set the track state to 'Alive'.
00284    if( (fTrack->GetTrackStatus()==fSuspend) ||
00285        (fTrack->GetTrackStatus()==fPostponeToNextEvent) ){ 
00286       fTrack->SetTrackStatus(fAlive);
00287    }
00288 
00289 // If the primary track has 'zero' kinetic energy, set the track
00290 // state to 'StopButAlive'.
00291    if(fTrack->GetKineticEnergy() <= 0.0){
00292       fTrack->SetTrackStatus( fStopButAlive );
00293    }
00294 
00295 
00296 // Set Touchable to track and a private attribute of G4SteppingManager
00297  
00298 
00299   if ( ! fTrack->GetTouchableHandle() ) {
00300      G4ThreeVector direction= fTrack->GetMomentumDirection();
00301      fNavigator->LocateGlobalPointAndSetup( fTrack->GetPosition(),
00302                                             &direction, false, false );
00303      fTouchableHandle = fNavigator->CreateTouchableHistory();
00304 
00305      fTrack->SetTouchableHandle( fTouchableHandle );
00306      fTrack->SetNextTouchableHandle( fTouchableHandle );
00307   }else{
00308      fTrack->SetNextTouchableHandle( fTouchableHandle = fTrack->GetTouchableHandle() );
00309      G4VPhysicalVolume* oldTopVolume= fTrack->GetTouchableHandle()->GetVolume();
00310      G4VPhysicalVolume* newTopVolume=
00311      fNavigator->ResetHierarchyAndLocate( fTrack->GetPosition(), 
00312         fTrack->GetMomentumDirection(),
00313         *((G4TouchableHistory*)fTrack->GetTouchableHandle()()) );
00314 //     if(newTopVolume != oldTopVolume ){
00315      if(newTopVolume != oldTopVolume || oldTopVolume->GetRegularStructureId() == 1 ) { 
00316         fTouchableHandle = fNavigator->CreateTouchableHistory();
00317         fTrack->SetTouchableHandle( fTouchableHandle );
00318         fTrack->SetNextTouchableHandle( fTouchableHandle );
00319      }
00320   }
00321 // Set vertex information of G4Track at here
00322    if ( fTrack->GetCurrentStepNumber() == 0 ) {
00323      fTrack->SetVertexPosition( fTrack->GetPosition() );
00324      fTrack->SetVertexMomentumDirection( fTrack->GetMomentumDirection() );
00325      fTrack->SetVertexKineticEnergy( fTrack->GetKineticEnergy() );
00326      fTrack->SetLogicalVolumeAtVertex( fTrack->GetVolume()->GetLogicalVolume() );
00327    }
00328 // Initial set up for attributes of 'G4SteppingManager'
00329    fCurrentVolume = fTouchableHandle->GetVolume();
00330 
00331 // If track is already outside the world boundary, kill it
00332    if( fCurrentVolume==0 ){
00333        // If the track is a primary, stop processing
00334        if(fTrack->GetParentID()==0)
00335        {
00336          G4cerr << "ERROR - G4SteppingManager::SetInitialStep()" << G4endl
00337                 << "        Primary particle starting at - "
00338                 << fTrack->GetPosition()
00339                 << " - is outside of the world volume." << G4endl;
00340          G4Exception("G4SteppingManager::SetInitialStep()", "Tracking0010",
00341                      FatalException, "Primary vertex outside of the world!");
00342        }
00343 
00344        fTrack->SetTrackStatus( fStopAndKill );
00345        G4cout << "WARNING - G4SteppingManager::SetInitialStep()" << G4endl
00346               << "          Initial track position is outside world! - "
00347               << fTrack->GetPosition() << G4endl;
00348    }
00349    else {
00350 // Initial set up for attribues of 'Step'
00351        fStep->InitializeStep( fTrack );
00352    }
00353 #ifdef G4VERBOSE
00354                          // !!!!! Verbose
00355    if(verboseLevel>0) fVerbose->TrackingStarted();
00356 #endif
00357 }
00358 

Generated on Mon May 27 17:49:54 2013 for Geant4 by  doxygen 1.4.7