Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:11:41

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 G4ReplicaNavigation inline implementations
0027 //
0028 // Author: Paul Kent (CERN), August 1996
0029 // --------------------------------------------------------------------
0030 
0031 // ********************************************************************
0032 // VoxelLocate
0033 // ********************************************************************
0034 //
0035 inline
0036 G4int
0037 G4ReplicaNavigation::VoxelLocate( const G4SmartVoxelHeader* pHead,
0038                                   const G4ThreeVector& localPoint,
0039                                   const G4int blocked ) const
0040 {
0041   EAxis targetHeaderAxis;
0042   G4double coord = 0.;
0043   G4double targetHeaderMin, targetHeaderMax;
0044   G4double targetHeaderNodeWidth, targetNodePos;
0045   G4int targetHeaderNoSlices, targetNodeNo;
0046   
0047   targetHeaderAxis = pHead->GetAxis();
0048   targetHeaderNoSlices = G4int(pHead->GetNoSlices());
0049   targetHeaderMin = pHead->GetMinExtent();
0050   targetHeaderMax = pHead->GetMaxExtent();
0051   targetHeaderNodeWidth = ( targetHeaderMax-targetHeaderMin )
0052                           / targetHeaderNoSlices;
0053 
0054   switch (targetHeaderAxis)
0055   {
0056     case kXAxis:
0057       coord = localPoint.x();
0058       break;
0059     case kYAxis:
0060       coord = localPoint.y();
0061       break;
0062     case kZAxis:
0063       coord = localPoint.z();
0064       break;
0065     case kRho:
0066       coord = localPoint.perp();
0067       break;
0068     case kPhi:
0069       coord = localPoint.phi();
0070       if ( (coord<0) && (coord<targetHeaderMin) ) { coord += CLHEP::twopi; }
0071       break;
0072     case kRadial3D:
0073     default:
0074       break;
0075   }
0076   targetNodePos = (coord-targetHeaderMin)/targetHeaderNodeWidth;
0077   targetNodeNo = (G4int) targetNodePos;
0078 
0079   if ( targetNodeNo==blocked )
0080   {
0081     targetNodeNo = (targetNodePos-targetNodeNo<0.5)
0082                    ? targetNodeNo-1 : targetNodeNo+1;
0083       
0084     // Do not need to check range: If on outer edge of zeroth
0085     // voxel & it is blocked => should have exited mother
0086     // (or similar)       P.Kent
0087     // assert(targetNodeNo>=0&&targetNodeNo<targetHeaderNoSlices);
0088 
0089     if( (targetNodeNo<0) || (targetNodeNo>=targetHeaderNoSlices) )
0090     {
0091 
0092 #ifdef G4DEBUG_NAVIGATION
0093       std::ostringstream message; 
0094       message << "Voxel location failed:" << G4endl
0095               << " (targetNodeNo>=0&&targetNodeNo<targetHeaderNoSlices) "
0096               << G4endl
0097               << " - targetNodeNo= " << targetNodeNo << G4endl
0098               << " - Number of Slices =  " << targetHeaderNoSlices;
0099       G4Exception("G4ReplicaNavigation::VoxelLocate()",
0100                   "GeomNav1002", JustWarning, message);
0101 #endif
0102       // In the case of rotational symmetry and an extent over the
0103       // whole 360 degrees, the above is not true and you can go from
0104       // the last voxel to the zeroth and vice versa
0105       //                                        H.Boie, April 30, 2001  
0106       if ( (targetHeaderAxis==kPhi)
0107            && (targetHeaderMin==0) && (targetHeaderMax==CLHEP::twopi) )
0108       {
0109         if ( targetNodeNo<0 )
0110         { 
0111           targetNodeNo = targetHeaderNoSlices-1;
0112         }
0113         else if ( targetNodeNo>=targetHeaderNoSlices )
0114         {
0115           targetNodeNo = 0;
0116         }
0117       }
0118       else 
0119       {
0120         if( targetNodeNo<0 )
0121         {
0122           targetNodeNo = 0;
0123         }
0124         else if ( targetNodeNo>=targetHeaderNoSlices )
0125         {
0126           targetNodeNo = targetHeaderNoSlices-1;
0127         }
0128       }
0129     }
0130   }
0131   else
0132   {
0133     // Rounding protection
0134     //
0135     if ( targetNodeNo<0 )
0136     {
0137       targetNodeNo = 0;
0138     }
0139     else if ( targetNodeNo>=targetHeaderNoSlices )
0140     {
0141       targetNodeNo = targetHeaderNoSlices-1;
0142     }
0143   }
0144   return targetNodeNo;
0145 }
0146 
0147 // ********************************************************************
0148 // LevelLocate
0149 // ********************************************************************
0150 //
0151 inline
0152 G4bool
0153 G4ReplicaNavigation::LevelLocate( G4NavigationHistory& history,
0154                             const G4VPhysicalVolume* blockedVol,
0155                             const G4int              blockedNum,
0156                             const G4ThreeVector&,     // globalPoint
0157                             const G4ThreeVector*,     // globalDirection
0158                             const G4bool,             // pLocatedOnEdge
0159                                   G4ThreeVector& localPoint )
0160 {
0161   G4VPhysicalVolume *motherPhysical, *pPhysical;
0162   G4LogicalVolume *motherLogical;
0163   G4SmartVoxelHeader *motherVoxelHeader;
0164   G4int nodeNo;
0165 
0166   motherPhysical = history.GetTopVolume();
0167   motherLogical = motherPhysical->GetLogicalVolume();
0168   motherVoxelHeader = motherLogical->GetVoxelHeader();
0169   pPhysical = motherLogical->GetDaughter(0);
0170 
0171   if ( blockedVol==pPhysical )
0172   {
0173     nodeNo = VoxelLocate(motherVoxelHeader, localPoint, blockedNum);
0174   }
0175   else
0176   {
0177     nodeNo = VoxelLocate(motherVoxelHeader, localPoint);
0178   }
0179 
0180   ComputeTransformation(nodeNo, pPhysical, localPoint);
0181   history.NewLevel(pPhysical, kReplica, nodeNo);
0182   pPhysical->SetCopyNo(nodeNo); 
0183 
0184   return true;
0185 }
0186 
0187 // ********************************************************************
0188 // SetPhiTransformation
0189 // ********************************************************************
0190 //
0191 inline
0192 void
0193 G4ReplicaNavigation::SetPhiTransformation( const G4double ang,
0194                                                  G4VPhysicalVolume* pVol ) const
0195 {
0196   G4RotationMatrix rm;
0197   rm.rotateZ(ang);
0198   if ( pVol != nullptr )
0199   {
0200     *pVol->GetRotation() = rm;
0201   }
0202 }
0203 
0204 // ********************************************************************
0205 // GetVerboseLevel
0206 // ********************************************************************
0207 //
0208 inline
0209 G4int G4ReplicaNavigation::GetVerboseLevel() const
0210 {
0211   return fVerbose;
0212 }
0213 
0214 // ********************************************************************
0215 // SetVerboseLevel
0216 // ********************************************************************
0217 //
0218 inline
0219 void G4ReplicaNavigation::SetVerboseLevel(G4int level)
0220 {
0221   fVerbose = level;
0222 }
0223 
0224 // ********************************************************************
0225 // CheckMode
0226 // ********************************************************************
0227 //
0228 inline
0229 void G4ReplicaNavigation::CheckMode(G4bool mode)
0230 {
0231   fCheck = mode;
0232 }