G4FastTrack.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$
00028 //
00029 //---------------------------------------------------------------
00030 //
00031 //  G4FastTrack.cc
00032 //
00033 //  Description:
00034 //    Keeps the current track information and special features
00035 //    for Parameterised Simulation Models.
00036 //
00037 //  History:
00038 //    Oct 97: Verderi && MoraDeFreitas - First Implementation.
00039 //
00040 //---------------------------------------------------------------
00041 
00042 #include "G4ios.hh"
00043 #include "G4FastTrack.hh"
00044 #include "G4TransportationManager.hh"
00045 #include "G4TouchableHistoryHandle.hh"
00046 
00047 // -----------
00048 // Constructor
00049 // -----------
00050 //
00051 G4FastTrack::G4FastTrack(G4Envelope *anEnvelope,
00052                          G4bool IsUnique) :
00053   fAffineTransformationDefined(false),   fEnvelope(anEnvelope),
00054   fIsUnique(IsUnique), fEnvelopeLogicalVolume(0), fEnvelopePhysicalVolume(0),
00055   fEnvelopeSolid(0)
00056 {}
00057 
00058 // -----------
00059 // Destructor:
00060 // -----------
00061 G4FastTrack::~G4FastTrack()
00062 {}
00063 
00064 //------------------------------------------------------------
00065 // The parameterised simulation manager uses the SetCurrentTrack
00066 // method to setup the current G4FastTrack object 
00067 //------------------------------------------------------------
00068 void G4FastTrack::SetCurrentTrack(const G4Track& track,
00069                                   const G4Navigator* theNavigator) 
00070 {
00071 
00072   // -- Register track pointer (used everywhere):
00073   fTrack = &track;
00074 
00075   //-----------------------------------------------------
00076   // First time the track enters the volume or if the
00077   // Logical Volume was placed n-Times in the geometry :
00078   // 
00079   // Records the Rotation+Translation for the Envelope !
00080   // When the particle is inside or on the boundary, the 
00081   // NavigationHistory IS UP TO DATE.
00082   //------------------------------------------------------
00083   if (!fAffineTransformationDefined || !fIsUnique) FRecordsAffineTransformation(theNavigator);
00084   
00085   //-------------------------------------------
00086   // Records local position/momentum/direction
00087   // of the Track.
00088   // They are accessible to the user through a
00089   // set of Get functions and should be useful
00090   // to decide to trigger or not.
00091   //-------------------------------------------
00092   // -- local position:
00093   fLocalTrackPosition = fAffineTransformation.TransformPoint(fTrack->GetPosition());
00094   // -- local momentum:
00095   fLocalTrackMomentum = fAffineTransformation.TransformAxis(fTrack->GetMomentum());
00096   // -- local direction:
00097   fLocalTrackDirection = fLocalTrackMomentum.unit();
00098   // -- local polarization:
00099   fLocalTrackPolarization = fAffineTransformation.TransformAxis(fTrack->GetPolarization());
00100 }
00101 
00102 //------------------------------------
00103 //
00104 // 3D transformation of the envelope
00105 // This is Done only one time.
00106 //
00107 //------------------------------------
00108 void 
00109 G4FastTrack::FRecordsAffineTransformation(const G4Navigator* theNavigator)
00110 {
00111 
00112   //--------------------------------------------------------
00113   // Get the touchable history which represents the current
00114   // volume hierachy the particle is in.
00115   // Note that TouchableHistory allocated by the Navigator
00116   // must be deleted by G4FastTrack.
00117   //--------------------------------------------------------
00118   const G4Navigator* NavigatorToUse;
00119   if(theNavigator != 0 ) NavigatorToUse = theNavigator;
00120   else                   NavigatorToUse = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
00121   
00122   G4TouchableHistoryHandle history = NavigatorToUse->CreateTouchableHistoryHandle();
00123   
00124   //-----------------------------------------------------
00125   // Run accross the hierarchy to find the physical volume
00126   // associated with the envelope
00127   //-----------------------------------------------------
00128   G4int depth = history->GetHistory()->GetDepth();
00129   G4int idepth, Done = 0;
00130   for (idepth = 0; idepth <= depth; idepth++)
00131   {
00132     G4VPhysicalVolume* currPV = history->GetHistory()->GetVolume(idepth);
00133     G4LogicalVolume* currLV   = currPV->GetLogicalVolume();
00134     if ( (currLV->GetRegion() == fEnvelope) && (currLV->IsRootRegion()) )
00135     {
00136       fEnvelopePhysicalVolume = currPV;
00137       fEnvelopeLogicalVolume  = currLV;
00138       fEnvelopeSolid          = currLV->GetSolid();
00139       Done = 1;
00140       break;
00141     }
00142   }
00143   //---------------------------------------------
00144   //-- Verification: should be removed in future:
00145   //---------------------------------------------
00146   if ( !Done )
00147     {
00148       G4ExceptionDescription ed;
00149       ed << "Can't find transformation for `" << fEnvelopePhysicalVolume->GetName() << "'" << G4endl;
00150       G4Exception("G4FastTrack::FRecordsAffineTransformation()",
00151                   "FastSim011",
00152                   JustWarning, ed);
00153     }
00154   else
00155     {
00156       //-------------------------------------------------------
00157       // Records the transformation and inverse transformation:
00158       //-------------------------------------------------------
00159       fAffineTransformation = history->GetHistory()->GetTransform(idepth);
00160       fInverseAffineTransformation = fAffineTransformation.Inverse();
00161       
00162       fAffineTransformationDefined = true;
00163     }
00164 }

Generated on Mon May 27 17:48:15 2013 for Geant4 by  doxygen 1.4.7