Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:50:27

0001 // ./G4Orb_Test.sh 
0002 
0003 #include <iostream>
0004 #include <iomanip>
0005 #include <sstream>
0006 #include <vector>
0007 #include <string>
0008 #include <cassert>
0009 
0010 #include "G4ThreeVector.hh"
0011 #include "G4Orb.hh"
0012 #include "sgeomdefs.h"
0013 #include "ssolid.h"
0014 
0015 
0016 std::string Label( const char* soname, char p_l, char d_l, const char* meth )
0017 {
0018     std::stringstream ss ;    
0019     ss << soname << "." << meth << "(" << p_l << ", " << d_l << ") " ; 
0020     std::string str = ss.str(); 
0021     return str ; 
0022 }
0023 
0024 std::string Format(double v, int w=10)
0025 {
0026     std::stringstream ss ;    
0027     if( v == kInfinity ) 
0028     { 
0029         ss << std::setw(w) << "kInfinity" ; 
0030     }
0031     else
0032     {
0033         ss << std::setw(w) << std::fixed << std::setprecision(4) << v ; 
0034     }
0035     std::string str = ss.str(); 
0036     return str ; 
0037 }
0038 
0039 std::string Format(const G4ThreeVector* v)
0040 {
0041     std::stringstream ss ;    
0042     ss << *v ; 
0043     std::string str = ss.str(); 
0044     return str ; 
0045 }
0046 
0047 int main()
0048 {
0049     G4Orb solid("Orb", 100.) ; 
0050 
0051     std::cout << solid << std::endl ;  
0052 
0053     G4String soname_ = solid.GetName() ; 
0054     const char* soname = soname_.c_str(); 
0055 
0056     G4ThreeVector A(0.,0., 200.); 
0057     G4ThreeVector B(0.,0., 150.); 
0058     G4ThreeVector C(0.,0., 100.); 
0059     G4ThreeVector D(0.,0.,  50.); 
0060     G4ThreeVector E(0.,0.,   0.); 
0061     G4ThreeVector F(0.,0., -50.); 
0062     G4ThreeVector G(0.,0.,-100.); 
0063     G4ThreeVector H(0.,0.,-150.); 
0064     G4ThreeVector I(0.,0.,-200.); 
0065 
0066     G4ThreeVector Z(0.,0.,1.); 
0067   
0068     std::vector<G4ThreeVector*> PP = {&A, &B, &C, &D, &E, &F, &G, &H, &I } ; 
0069     std::vector<char> PP_L         = {'A','B','C','D','E','F','G','H','I'}; 
0070 
0071     std::vector<G4ThreeVector*> DD = {&Z, &Z, &Z, &Z, &Z, &Z, &Z, &Z, &Z } ; 
0072     std::vector<char> DD_L         = {'Z','Z','Z','Z','Z','Z','Z','Z','Z' }; 
0073 
0074     for(int i=0 ; i < int(PP.size()) ; i++)
0075     {
0076         G4ThreeVector* p = PP[i] ;  
0077         G4ThreeVector* d = DD[i] ; 
0078         const char p_l = PP_L[i] ; 
0079         const char d_l = DD_L[i] ; 
0080 
0081         EInside in ; 
0082         G4double dis = ssolid::Distance_(&solid, *p, *d, in );   
0083         G4double d2o = solid.DistanceToOut( *p, *d ) ; 
0084         G4double d2i = solid.DistanceToIn(  *p, *d ) ; 
0085 
0086         std::cout 
0087              << p_l << " "
0088              << std::setw(10) << Format(p)
0089              << std::setw(30) << Label( soname, p_l, d_l, "DistanceToOut")  
0090              << " : " << Format(d2o)
0091              << " | "
0092              << std::setw(30) << Label( soname, p_l, d_l, "DistanceToIn")  
0093              << " : "
0094              << " : " << Format(d2i)
0095              << std::setw(30) << Label( soname, p_l, d_l, "Distance_")  
0096              << " : " << Format(dis)
0097              << " " << sgeomdefs::EInside_(in) 
0098              << std::endl
0099              ;
0100     }
0101 
0102     return 0 ; 
0103 }
0104 
0105 
0106 /**
0107 
0108 
0109                         200 A                                                +                                        +
0110                                                                              0                                       kInfinity
0111                                                                         
0112                         150 B                                            +                                        +
0113                                                                          0                                       kInfinity
0114                            
0115                +------- 100-C-----------+    +   +   +   +   +   +   +   +   +   +                            +
0116                |            |           |                            0                                       kInfinity
0117                |            |           |  
0118                |         50 D           |                        +                                        +  
0119                |            |           |                       50                                        0
0120                |            |           |  
0121                +----------0-E-----------+                    +                                        +
0122                |            |           |                   100                                       0 
0123                |            |           |                                                            
0124                |        -50 F           |                +                                        +
0125                |            |           |               150                                       0 
0126                |            |           |  
0127                +------ -100 G-----------+             +                           +   +   +   +   +   +   +   +   +   +   +
0128                                                      200                                      0
0129 
0130                        -150 H                     +                                       +
0131                                                  250                                     50
0132                       
0133                        -200 I                 +                                       +
0134                                              300                                     100
0135 
0136                                                        DistanceToOut( A->I, Z )                  DistanceToIn( A->I, Z)
0137 
0138 
0139 DistanceToOut
0140    distance to "far" side (HMM how about booleans with holes?)
0141 
0142 DistanceToIn
0143    distance to "near" side, 0 whilst inside, kInfinity at-or-beyond farside    
0144  
0145 Distance
0146    distance to closest side  
0147 
0148 
0149 -----------------------------------------------------------
0150     *** Dump for solid - Orb ***
0151     ===================================================
0152  Solid type: G4Orb
0153  Parameters: 
0154     outer radius: 100 mm 
0155 -----------------------------------------------------------
0156 
0157 A  (0,0,200)      Orb.DistanceToOut(A, Z)  :     0.0000 |        Orb.DistanceToIn(A, Z)  :  :  kInfinity          Orb.Distance_(A, Z)  :  kInfinity kOutside
0158 B  (0,0,150)      Orb.DistanceToOut(B, Z)  :     0.0000 |        Orb.DistanceToIn(B, Z)  :  :  kInfinity          Orb.Distance_(B, Z)  :  kInfinity kOutside
0159 C  (0,0,100)      Orb.DistanceToOut(C, Z)  :     0.0000 |        Orb.DistanceToIn(C, Z)  :  :  kInfinity          Orb.Distance_(C, Z)  :     0.0000 kSurface
0160 D   (0,0,50)      Orb.DistanceToOut(D, Z)  :    50.0000 |        Orb.DistanceToIn(D, Z)  :  :     0.0000          Orb.Distance_(D, Z)  :    50.0000 kInside
0161 E    (0,0,0)      Orb.DistanceToOut(E, Z)  :   100.0000 |        Orb.DistanceToIn(E, Z)  :  :     0.0000          Orb.Distance_(E, Z)  :   100.0000 kInside
0162 F  (0,0,-50)      Orb.DistanceToOut(F, Z)  :   150.0000 |        Orb.DistanceToIn(F, Z)  :  :     0.0000          Orb.Distance_(F, Z)  :   150.0000 kInside
0163 G (0,0,-100)      Orb.DistanceToOut(G, Z)  :   200.0000 |        Orb.DistanceToIn(G, Z)  :  :     0.0000          Orb.Distance_(G, Z)  :   200.0000 kSurface
0164 H (0,0,-150)      Orb.DistanceToOut(H, Z)  :   250.0000 |        Orb.DistanceToIn(H, Z)  :  :    50.0000          Orb.Distance_(H, Z)  :    50.0000 kOutside
0165 I (0,0,-200)      Orb.DistanceToOut(I, Z)  :   300.0000 |        Orb.DistanceToIn(I, Z)  :  :   100.0000          Orb.Distance_(I, Z)  :   100.0000 kOutside
0166 
0167 **/
0168 
0169