Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:02

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