Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:22:28

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 // Class G4VoxelNavigation inline methods implementation
0027 //
0028 // Author: Paul Kent (CERN), August 1996
0029 // --------------------------------------------------------------------
0030 
0031 // ********************************************************************
0032 // VoxelLocate
0033 // ********************************************************************
0034 //
0035 inline
0036 G4SmartVoxelNode*
0037 G4VoxelNavigation::VoxelLocate( G4SmartVoxelHeader* pHead,
0038                                 const G4ThreeVector& localPoint )
0039 {
0040   G4SmartVoxelHeader* targetVoxelHeader = pHead;
0041   G4SmartVoxelNode* targetVoxelNode = nullptr;
0042   G4SmartVoxelProxy* sampleProxy;
0043   EAxis targetHeaderAxis;
0044   G4double targetHeaderMin, targetHeaderNodeWidth;
0045   G4int targetHeaderNoSlices, targetNodeNo;
0046 
0047   fVoxelDepth = 0;
0048 
0049   while ( targetVoxelNode == nullptr )
0050   {
0051     targetHeaderAxis = targetVoxelHeader->GetAxis();
0052     targetHeaderNoSlices = G4int(targetVoxelHeader->GetNoSlices());
0053     targetHeaderMin = targetVoxelHeader->GetMinExtent();
0054     targetHeaderNodeWidth = (targetVoxelHeader->GetMaxExtent()-targetHeaderMin)
0055                           / targetHeaderNoSlices;
0056     targetNodeNo = G4int( (localPoint(targetHeaderAxis)-targetHeaderMin)
0057                           / targetHeaderNodeWidth);
0058     // Rounding protection
0059     //
0060     if ( targetNodeNo<0 )
0061     {
0062       targetNodeNo = 0;
0063     }
0064     else if ( targetNodeNo>=targetHeaderNoSlices )
0065     {
0066       targetNodeNo = targetHeaderNoSlices-1;
0067     }
0068     // Stack info for stepping
0069     //
0070     fVoxelAxisStack[fVoxelDepth] = targetHeaderAxis;
0071     fVoxelNoSlicesStack[fVoxelDepth] = targetHeaderNoSlices;
0072     fVoxelSliceWidthStack[fVoxelDepth] = targetHeaderNodeWidth;
0073     fVoxelNodeNoStack[fVoxelDepth] = targetNodeNo;
0074     fVoxelHeaderStack[fVoxelDepth] = targetVoxelHeader;
0075     sampleProxy = targetVoxelHeader->GetSlice(targetNodeNo);
0076 
0077     if ( sampleProxy->IsNode() )
0078     {
0079       targetVoxelNode = sampleProxy->GetNode();
0080     }
0081     else
0082     {
0083       targetVoxelHeader = sampleProxy->GetHeader();
0084       ++fVoxelDepth;
0085     }
0086   }
0087   fVoxelNode = targetVoxelNode;
0088   return targetVoxelNode;
0089 }
0090 
0091 // ********************************************************************
0092 // LevelLocate
0093 // ********************************************************************
0094 //
0095 inline
0096 G4bool
0097 G4VoxelNavigation::LevelLocate( G4NavigationHistory& history,
0098                           const G4VPhysicalVolume* blockedVol,
0099                           const G4int,
0100                           const G4ThreeVector& globalPoint,
0101                           const G4ThreeVector* globalDirection,
0102                           const G4bool pLocatedOnEdge, 
0103                                 G4ThreeVector& localPoint )
0104 {
0105   G4SmartVoxelHeader *targetVoxelHeader;
0106   G4SmartVoxelNode *targetVoxelNode;
0107   G4VPhysicalVolume *targetPhysical, *samplePhysical;
0108   G4LogicalVolume *targetLogical;
0109   G4VSolid *sampleSolid;
0110   G4ThreeVector samplePoint;
0111   G4int targetNoDaughters;
0112   
0113   targetPhysical = history.GetTopVolume();
0114   targetLogical = targetPhysical->GetLogicalVolume();
0115   targetVoxelHeader = targetLogical->GetVoxelHeader();
0116 
0117   // Find the voxel containing the point
0118   //
0119   targetVoxelNode = VoxelLocate(targetVoxelHeader,localPoint);
0120 
0121   targetNoDaughters = G4int(targetVoxelNode->GetNoContained());
0122   if ( targetNoDaughters==0 ) { return false; }
0123 
0124   //
0125   // Search daughters in volume
0126   //
0127 
0128   for ( auto sampleNo=targetNoDaughters-1; sampleNo>=0; sampleNo-- )
0129   {
0130     samplePhysical = targetLogical->
0131                      GetDaughter(targetVoxelNode->GetVolume(sampleNo));
0132     if ( samplePhysical!=blockedVol )
0133     {
0134       // Setup history
0135       //
0136       history.NewLevel(samplePhysical, kNormal, samplePhysical->GetCopyNo());
0137       sampleSolid = samplePhysical->GetLogicalVolume()->GetSolid();
0138       samplePoint = history.GetTopTransform().TransformPoint(globalPoint);
0139 
0140       if( G4AuxiliaryNavServices::CheckPointOnSurface(sampleSolid,
0141                                                       samplePoint,
0142                                                       globalDirection, 
0143                                                       history.GetTopTransform(),
0144                                                       pLocatedOnEdge) )
0145       {
0146         // Enter this daughter
0147         //
0148         localPoint = samplePoint;
0149         return true;
0150       }
0151       history.BackLevel();
0152     }
0153   }
0154   return false;
0155 }
0156 
0157 // ********************************************************************
0158 // GetVerboseLevel
0159 // ********************************************************************
0160 //
0161 inline
0162 G4int G4VoxelNavigation::GetVerboseLevel() const
0163 {
0164   return fLogger->GetVerboseLevel();
0165 }
0166 
0167 // ********************************************************************
0168 // EnableBestSafety
0169 // ********************************************************************
0170 //
0171 inline
0172 void  G4VoxelNavigation::EnableBestSafety(G4bool flag)
0173 {
0174   fBestSafety = flag;
0175 }