Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/tracking/src/G4AdjointCrossSurfChecker.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /tracking/src/G4AdjointCrossSurfChecker.cc (Version 11.3.0) and /tracking/src/G4AdjointCrossSurfChecker.cc (Version 11.0.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4AdjointCrossSurfChecker class implementat     26 // G4AdjointCrossSurfChecker class implementation
 27 //                                                 27 //
 28 // Author: L. Desorgher, SpaceIT GmbH              28 // Author: L. Desorgher, SpaceIT GmbH
 29 // Contract: ESA contract 21435/08/NL/AT           29 // Contract: ESA contract 21435/08/NL/AT
 30 // Customer: ESA/ESTEC                             30 // Customer: ESA/ESTEC
 31 // -------------------------------------------     31 // --------------------------------------------------------------------
 32                                                    32 
 33 #include "G4AdjointCrossSurfChecker.hh"            33 #include "G4AdjointCrossSurfChecker.hh"
 34                                                << 
 35 #include "G4AffineTransform.hh"                << 
 36 #include "G4PhysicalConstants.hh"                  34 #include "G4PhysicalConstants.hh"
 37 #include "G4PhysicalVolumeStore.hh"            <<  35 #include "G4SystemOfUnits.hh"
 38 #include "G4Step.hh"                               36 #include "G4Step.hh"
 39 #include "G4StepPoint.hh"                          37 #include "G4StepPoint.hh"
 40 #include "G4SystemOfUnits.hh"                  <<  38 #include "G4PhysicalVolumeStore.hh" 
 41 #include "G4VSolid.hh"                             39 #include "G4VSolid.hh"
                                                   >>  40 #include "G4AffineTransform.hh"
                                                   >>  41 
                                                   >>  42 //////////////////////////////////////////////////////////////////////////////
                                                   >>  43 // 
                                                   >>  44 G4ThreadLocal G4AdjointCrossSurfChecker*
                                                   >>  45               G4AdjointCrossSurfChecker::instance = nullptr;
 42                                                    46 
 43 //////////////////////////////////////////////     47 //////////////////////////////////////////////////////////////////////////////
 44 //                                                 48 //
 45 G4ThreadLocal G4AdjointCrossSurfChecker* G4Adj <<  49 G4AdjointCrossSurfChecker::G4AdjointCrossSurfChecker()
                                                   >>  50 {
                                                   >>  51 }
 46                                                    52 
 47 //////////////////////////////////////////////     53 //////////////////////////////////////////////////////////////////////////////
 48 //                                                 54 //
 49 G4AdjointCrossSurfChecker::~G4AdjointCrossSurf <<  55 G4AdjointCrossSurfChecker::~G4AdjointCrossSurfChecker()
                                                   >>  56 {
                                                   >>  57   delete instance;
                                                   >>  58 }
 50                                                    59 
 51 //////////////////////////////////////////////     60 //////////////////////////////////////////////////////////////////////////////
 52 //                                                 61 //
 53 G4AdjointCrossSurfChecker* G4AdjointCrossSurfC     62 G4AdjointCrossSurfChecker* G4AdjointCrossSurfChecker::GetInstance()
 54 {                                                  63 {
 55   if (instance == nullptr) instance = new G4Ad     64   if (instance == nullptr) instance = new G4AdjointCrossSurfChecker();
 56   return instance;                                 65   return instance;
 57 }                                              <<  66 }  
 58                                                    67 
 59 //////////////////////////////////////////////     68 //////////////////////////////////////////////////////////////////////////////
 60 //                                                 69 //
 61 G4bool G4AdjointCrossSurfChecker::CrossingASph <<  70 G4bool G4AdjointCrossSurfChecker::
 62   G4ThreeVector sphere_center, G4ThreeVector&  <<  71 CrossingASphere(const G4Step* aStep, G4double sphere_radius,
                                                   >>  72                 G4ThreeVector sphere_center, G4ThreeVector& crossing_pos,
                                                   >>  73                 G4double& cos_th , G4bool& GoingIn)
 63 {                                                  74 {
 64   G4ThreeVector pos1 = aStep->GetPreStepPoint(     75   G4ThreeVector pos1 = aStep->GetPreStepPoint()->GetPosition() - sphere_center;
 65   G4ThreeVector pos2 = aStep->GetPostStepPoint     76   G4ThreeVector pos2 = aStep->GetPostStepPoint()->GetPosition() - sphere_center;
 66   G4double r1 = pos1.mag();                        77   G4double r1 = pos1.mag();
 67   G4double r2 = pos2.mag();                        78   G4double r2 = pos2.mag();
 68   G4bool did_cross = false;                    <<  79   G4bool did_cross = false; 
 69                                                <<  80   
 70   if (r1 <= sphere_radius && r2 > sphere_radiu <<  81   if (r1<=sphere_radius && r2>sphere_radius)
                                                   >>  82   {
 71     did_cross = true;                              83     did_cross = true;
 72     GoingIn = false;                               84     GoingIn = false;
 73   }                                            <<  85   } 
 74   else if (r2 <= sphere_radius && r1 > sphere_ <<  86   else if (r2<=sphere_radius && r1>sphere_radius)
                                                   >>  87   {
 75     did_cross = true;                              88     did_cross = true;
 76     GoingIn = true;                                89     GoingIn = true;
 77   }                                                90   }
 78                                                    91 
 79   if (did_cross) {                             <<  92   if (did_cross)
 80     G4ThreeVector dr = pos2 - pos1;            <<  93   { 
 81     G4double r12 = r1 * r1;                    <<  94     G4ThreeVector dr = pos2-pos1;
                                                   >>  95     G4double r12 = r1*r1;
 82     G4double rdr = dr.mag();                       96     G4double rdr = dr.mag();
 83     G4double a, b, c, d;                       <<  97     G4double a,b,c,d;
 84     a = rdr * rdr;                             <<  98     a = rdr*rdr;
 85     b = 2. * pos1.dot(dr);                     <<  99     b = 2.*pos1.dot(dr);
 86     c = r12 - sphere_radius * sphere_radius;   << 100     c = r12-sphere_radius*sphere_radius;
 87     d = std::sqrt(b * b - 4. * a * c);         << 101     d = std::sqrt(b*b-4.*a*c);
 88     G4double l = (-b + d) / 2. / a;            << 102     G4double l = (-b+d)/2./a;
 89     if (l > 1.) l = (-b - d) / 2. / a;         << 103     if (l > 1.) l=(-b-d)/2./a;
 90     crossing_pos = pos1 + l * dr;              << 104     crossing_pos = pos1+l*dr;
 91     cos_th = std::abs(dr.cosTheta(crossing_pos    105     cos_th = std::abs(dr.cosTheta(crossing_pos));
 92   }                                               106   }
 93   return did_cross;                               107   return did_cross;
 94 }                                                 108 }
 95                                                   109 
 96 //////////////////////////////////////////////    110 //////////////////////////////////////////////////////////////////////////////
 97 //                                                111 //
 98 G4bool G4AdjointCrossSurfChecker::GoingInOrOut << 112 G4bool G4AdjointCrossSurfChecker::
 99   const G4String& volume_name, G4double&, G4bo << 113 GoingInOrOutOfaVolume(const G4Step* aStep, const G4String& volume_name,
                                                   >> 114                       G4double&, G4bool& GoingIn) // from external surface
100 {                                                 115 {
101   G4bool step_at_boundary = (aStep->GetPostSte << 116   G4bool step_at_boundary =
                                                   >> 117          (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary);
102   G4bool did_cross = false;                       118   G4bool did_cross = false;
103   if (step_at_boundary) {                      << 119   if (step_at_boundary)
104     const G4VTouchable* postStepTouchable = aS << 120   {
105     const G4VTouchable* preStepTouchable = aSt << 121     const G4VTouchable* postStepTouchable =
106     if ((preStepTouchable != nullptr) && (post << 122                         aStep->GetPostStepPoint()->GetTouchable();
107         (postStepTouchable->GetVolume() != nul << 123     const G4VTouchable* preStepTouchable =
                                                   >> 124                         aStep->GetPreStepPoint()->GetTouchable();
                                                   >> 125     if (preStepTouchable && postStepTouchable
                                                   >> 126       && postStepTouchable->GetVolume() && preStepTouchable->GetVolume())
108     {                                             127     {
109       G4String post_vol_name = postStepTouchab    128       G4String post_vol_name = postStepTouchable->GetVolume()->GetName();
110       G4String pre_vol_name = preStepTouchable    129       G4String pre_vol_name = preStepTouchable->GetVolume()->GetName();
111                                                   130 
112       if (post_vol_name == volume_name) {      << 131       if (post_vol_name == volume_name )
                                                   >> 132       {
113         GoingIn = true;                           133         GoingIn = true;
114         did_cross = true;                         134         did_cross = true;
115       }                                           135       }
116       else if (pre_vol_name == volume_name) {  << 136       else if (pre_vol_name == volume_name)
                                                   >> 137       {
117         GoingIn = false;                          138         GoingIn = false;
118         did_cross = true;                         139         did_cross = true;
119       }                                           140       }
120     }                                          << 141     } 
121   }                                               142   }
122   return did_cross;  // still need to compute     143   return did_cross;  // still need to compute the cosine of the direction
123 }                                                 144 }
124                                                   145 
125 //////////////////////////////////////////////    146 /////////////////////////////////////////////////////////////////////////////
126 //                                                147 //
127 G4bool G4AdjointCrossSurfChecker::GoingInOrOut << 148 G4bool G4AdjointCrossSurfChecker::
128   const G4String& volume_name, const G4String& << 149 GoingInOrOutOfaVolumeByExtSurface(const G4Step* aStep,
129   G4bool& GoingIn)  // from external surf.     << 150                                   const G4String& volume_name,
                                                   >> 151                                   const G4String& mother_logical_vol_name,
                                                   >> 152                                         G4double&,
                                                   >> 153                                         G4bool& GoingIn) // from external surf.
130 {                                                 154 {
131   G4bool step_at_boundary = (aStep->GetPostSte << 155   G4bool step_at_boundary =
                                                   >> 156     (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary);
132   G4bool did_cross = false;                       157   G4bool did_cross = false;
133   if (step_at_boundary) {                      << 158   if (step_at_boundary)
134     const G4VTouchable* postStepTouchable = aS << 159   {
135     const G4VTouchable* preStepTouchable = aSt << 160     const G4VTouchable* postStepTouchable =
136     const G4VPhysicalVolume* postVol =         << 161             aStep->GetPostStepPoint()->GetTouchable();
137       (postStepTouchable != nullptr) ? postSte << 162     const G4VTouchable* preStepTouchable =
138     const G4VPhysicalVolume* preVol =          << 163             aStep->GetPreStepPoint()->GetTouchable();
139       (preStepTouchable != nullptr) ? preStepT << 164     const G4VPhysicalVolume* postVol = (postStepTouchable != nullptr)
140     if (preStepTouchable != nullptr && postSte << 165                                     ? postStepTouchable->GetVolume() : nullptr;
141         preVol != nullptr)                     << 166     const G4VPhysicalVolume* preVol = (preStepTouchable != nullptr)
                                                   >> 167                                     ? preStepTouchable->GetVolume() : nullptr;
                                                   >> 168     if (preStepTouchable != nullptr && postStepTouchable != nullptr
                                                   >> 169      && postVol != nullptr && preVol != nullptr)
142     {                                             170     {
143       G4String post_vol_name = postVol->GetNam    171       G4String post_vol_name = postVol->GetName();
144       G4String post_log_vol_name = postVol->Ge    172       G4String post_log_vol_name = postVol->GetLogicalVolume()->GetName();
145       G4String pre_vol_name = preVol->GetName(    173       G4String pre_vol_name = preVol->GetName();
146       G4String pre_log_vol_name = preVol->GetL    174       G4String pre_log_vol_name = preVol->GetLogicalVolume()->GetName();
147       if (post_vol_name == volume_name && pre_ << 175       if (post_vol_name == volume_name
                                                   >> 176        && pre_log_vol_name == mother_logical_vol_name)
                                                   >> 177       {
148         GoingIn = true;                           178         GoingIn = true;
149         did_cross = true;                         179         did_cross = true;
150       }                                           180       }
151       else if (pre_vol_name == volume_name &&  << 181       else if (pre_vol_name == volume_name
                                                   >> 182             && post_log_vol_name ==  mother_logical_vol_name )
                                                   >> 183       {
152         GoingIn = false;                          184         GoingIn = false;
153         did_cross = true;                         185         did_cross = true;
154       }                                           186       }
155     }                                          << 187     } 
156   }                                               188   }
157   return did_cross;  // still need to compute  << 189   return did_cross; // still need to compute the cosine of the direction
158 }                                                 190 }
159                                                   191 
160 //////////////////////////////////////////////    192 //////////////////////////////////////////////////////////////////////////////
161 //                                                193 //
162 G4bool G4AdjointCrossSurfChecker::CrossingAGiv << 194 G4bool G4AdjointCrossSurfChecker::
163   const G4String& surface_name, G4ThreeVector& << 195 CrossingAGivenRegisteredSurface(const G4Step* aStep,
164   G4bool& GoingIn)                             << 196                                 const G4String& surface_name,
                                                   >> 197                                       G4ThreeVector& crossing_pos,
                                                   >> 198                                       G4double& cos_to_surface, G4bool& GoingIn)
165 {                                                 199 {
166   G4int ind = FindRegisteredSurface(surface_na    200   G4int ind = FindRegisteredSurface(surface_name);
167   G4bool did_cross = false;                       201   G4bool did_cross = false;
168   if (ind >= 0) {                              << 202   if (ind >=0)
169     did_cross = CrossingAGivenRegisteredSurfac << 203   {
                                                   >> 204     did_cross = CrossingAGivenRegisteredSurface(aStep, ind, crossing_pos,
                                                   >> 205                                                 cos_to_surface, GoingIn);
170   }                                               206   }
171   return did_cross;                               207   return did_cross;
172 }                                                 208 }
173                                                   209 
174 //////////////////////////////////////////////    210 //////////////////////////////////////////////////////////////////////////////
175 //                                                211 //
176 G4bool G4AdjointCrossSurfChecker::CrossingAGiv << 212 G4bool G4AdjointCrossSurfChecker::
177   G4ThreeVector& crossing_pos, G4double& cos_t << 213 CrossingAGivenRegisteredSurface(const G4Step* aStep, G4int ind,
                                                   >> 214                                       G4ThreeVector& crossing_pos,
                                                   >> 215                                       G4double& cos_to_surface, G4bool& GoingIn)
178 {                                                 216 {
179   G4String surf_type = ListOfSurfaceType[ind];    217   G4String surf_type = ListOfSurfaceType[ind];
180   G4double radius = ListOfSphereRadius[ind];      218   G4double radius = ListOfSphereRadius[ind];
181   G4ThreeVector center = ListOfSphereCenter[in    219   G4ThreeVector center = ListOfSphereCenter[ind];
182   G4String vol1 = ListOfVol1Name[ind];            220   G4String vol1 = ListOfVol1Name[ind];
183   G4String vol2 = ListOfVol2Name[ind];            221   G4String vol2 = ListOfVol2Name[ind];
184                                                   222 
185   G4bool did_cross = false;                       223   G4bool did_cross = false;
186   if (surf_type == "Sphere") {                 << 224   if (surf_type == "Sphere")
187     did_cross = CrossingASphere(aStep, radius, << 225   {
188   }                                            << 226     did_cross = CrossingASphere(aStep, radius, center,crossing_pos,
189   else if (surf_type == "ExternalSurfaceOfAVol << 227                                 cos_to_surface, GoingIn);
190     did_cross = GoingInOrOutOfaVolumeByExtSurf << 228   }
191     crossing_pos = aStep->GetPostStepPoint()-> << 229   else if (surf_type == "ExternalSurfaceOfAVolume")
192   }                                            << 230   {
193   else if (surf_type == "BoundaryBetweenTwoVol << 231     did_cross = GoingInOrOutOfaVolumeByExtSurface(aStep, vol1, vol2,
194     did_cross = CrossingAnInterfaceBetweenTwoV << 232                                                   cos_to_surface, GoingIn);
195       aStep, vol1, vol2, crossing_pos, cos_to_ << 233     crossing_pos= aStep->GetPostStepPoint()->GetPosition();
                                                   >> 234   }
                                                   >> 235   else if (surf_type == "BoundaryBetweenTwoVolumes")
                                                   >> 236   {
                                                   >> 237     did_cross = CrossingAnInterfaceBetweenTwoVolumes(aStep, vol1, vol2,
                                                   >> 238                                                      crossing_pos,
                                                   >> 239                                                      cos_to_surface, GoingIn);
196   }                                               240   }
197   return did_cross;                               241   return did_cross;
198 }                                                 242 }
199                                                   243 
200 //////////////////////////////////////////////    244 //////////////////////////////////////////////////////////////////////////////
201 //                                                245 //
202 G4bool G4AdjointCrossSurfChecker::CrossingOneO << 246 G4bool G4AdjointCrossSurfChecker::
203   G4String& surface_name, G4ThreeVector& cross << 247 CrossingOneOfTheRegisteredSurface(const G4Step* aStep, G4String& surface_name,
204 {                                              << 248                                         G4ThreeVector& crossing_pos,
205   for (std::size_t i = 0; i < ListOfSurfaceNam << 249                                         G4double& cos_to_surface,
206     if (CrossingAGivenRegisteredSurface(aStep, << 250                                         G4bool& GoingIn)
                                                   >> 251 {
                                                   >> 252   for (std::size_t i=0; i<ListOfSurfaceName.size(); ++i)
                                                   >> 253   {
                                                   >> 254     if (CrossingAGivenRegisteredSurface(aStep, G4int(i), crossing_pos,
                                                   >> 255                                         cos_to_surface, GoingIn))
                                                   >> 256     {
207       surface_name = ListOfSurfaceName[i];        257       surface_name = ListOfSurfaceName[i];
208       return true;                                258       return true;
209     }                                             259     }
210   }                                               260   }
211   return false;                                   261   return false;
212 }                                                 262 }
213                                                   263 
214 //////////////////////////////////////////////    264 //////////////////////////////////////////////////////////////////////////////
215 //                                                265 //
216 G4bool G4AdjointCrossSurfChecker::CrossingAnIn << 266 G4bool G4AdjointCrossSurfChecker::
217   const G4String& vol1_name, const G4String& v << 267 CrossingAnInterfaceBetweenTwoVolumes(const G4Step* aStep,
                                                   >> 268                                      const G4String& vol1_name,
                                                   >> 269                                      const G4String& vol2_name,
                                                   >> 270                                            G4ThreeVector&, G4double&,
                                                   >> 271                                            G4bool& GoingIn)
218 {                                                 272 {
219   G4bool step_at_boundary = (aStep->GetPostSte << 273   G4bool step_at_boundary =
                                                   >> 274     (aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary);
220   G4bool did_cross = false;                       275   G4bool did_cross = false;
221   if (step_at_boundary) {                      << 276   if (step_at_boundary)
222     const G4VTouchable* postStepTouchable = aS << 277   {
223     const G4VTouchable* preStepTouchable = aSt << 278     const G4VTouchable* postStepTouchable =
224     if ((preStepTouchable != nullptr) && (post << 279                         aStep->GetPostStepPoint()->GetTouchable();
                                                   >> 280     const G4VTouchable* preStepTouchable =
                                                   >> 281                         aStep->GetPreStepPoint()->GetTouchable();
                                                   >> 282     if (preStepTouchable && postStepTouchable)
                                                   >> 283     {
225       G4String post_vol_name = postStepTouchab    284       G4String post_vol_name = postStepTouchable->GetVolume()->GetName();
226       if (post_vol_name.empty()) {             << 285       if (post_vol_name == "")
227         post_vol_name = postStepTouchable->Get << 286       {
                                                   >> 287         post_vol_name = postStepTouchable->GetVolume()->GetLogicalVolume()
                                                   >> 288                       ->GetName();
228       }                                           289       }
229       G4String pre_vol_name = preStepTouchable    290       G4String pre_vol_name = preStepTouchable->GetVolume()->GetName();
230       if (pre_vol_name.empty()) {              << 291       if (pre_vol_name == "")
231         pre_vol_name = preStepTouchable->GetVo << 292       {
                                                   >> 293         pre_vol_name = preStepTouchable->GetVolume()->GetLogicalVolume()
                                                   >> 294                      ->GetName();
232       }                                           295       }
233       if (pre_vol_name == vol1_name && post_vo << 296       if (pre_vol_name == vol1_name && post_vol_name == vol2_name)
234         GoingIn = true;                        << 297       {
235         did_cross = true;                      << 298         GoingIn=true;
                                                   >> 299         did_cross=true;
236       }                                           300       }
237       else if (pre_vol_name == vol2_name && po << 301       else if (pre_vol_name == vol2_name && post_vol_name == vol1_name)
238         GoingIn = false;                       << 302       {
239         did_cross = true;                      << 303         GoingIn=false;
                                                   >> 304         did_cross=true;
240       }                                           305       }
241     }                                          << 306     } 
242   }                                               307   }
243   return did_cross;  // still need to compute  << 308   return did_cross; // still need to compute the cosine of the direction
244 }                                                 309 }
245                                                   310 
246 //////////////////////////////////////////////    311 //////////////////////////////////////////////////////////////////////////////
247 //                                             << 312 //   
248 G4bool G4AdjointCrossSurfChecker::AddaSpherica << 313 G4bool G4AdjointCrossSurfChecker::
249   const G4String& SurfaceName, G4double radius << 314 AddaSphericalSurface(const G4String& SurfaceName, G4double radius,
                                                   >> 315                            G4ThreeVector pos, G4double& Area)
250 {                                                 316 {
251   G4int ind = FindRegisteredSurface(SurfaceNam    317   G4int ind = FindRegisteredSurface(SurfaceName);
252   Area = 4. * pi * radius * radius;            << 318   Area = 4.*pi*radius*radius;
253   if (ind >= 0) {                              << 319   if (ind>=0)
                                                   >> 320   {
254     ListOfSurfaceType[ind] = "Sphere";            321     ListOfSurfaceType[ind] = "Sphere";
255     ListOfSphereRadius[ind] = radius;             322     ListOfSphereRadius[ind] = radius;
256     ListOfSphereCenter[ind] = pos;                323     ListOfSphereCenter[ind] = pos;
257     ListOfVol1Name[ind] = "";                     324     ListOfVol1Name[ind] = "";
258     ListOfVol2Name[ind] = "";                     325     ListOfVol2Name[ind] = "";
259     AreaOfSurface[ind] = Area;                    326     AreaOfSurface[ind] = Area;
260   }                                               327   }
261   else {                                       << 328   else
                                                   >> 329   {
262     ListOfSurfaceName.push_back(SurfaceName);     330     ListOfSurfaceName.push_back(SurfaceName);
263     ListOfSurfaceType.emplace_back("Sphere");  << 331     ListOfSurfaceType.push_back("Sphere");
264     ListOfSphereRadius.push_back(radius);         332     ListOfSphereRadius.push_back(radius);
265     ListOfSphereCenter.push_back(pos);            333     ListOfSphereCenter.push_back(pos);
266     ListOfVol1Name.emplace_back("");           << 334     ListOfVol1Name.push_back("");
267     ListOfVol2Name.emplace_back("");           << 335     ListOfVol2Name.push_back("");
268     AreaOfSurface.push_back(Area);                336     AreaOfSurface.push_back(Area);
269   }                                            << 337   } 
270   return true;                                    338   return true;
271 }                                                 339 }
272                                                   340 
273 //////////////////////////////////////////////    341 //////////////////////////////////////////////////////////////////////////////
274 //                                             << 342 //   
275 G4bool G4AdjointCrossSurfChecker::AddaSpherica << 343 G4bool G4AdjointCrossSurfChecker::
276   const G4String& SurfaceName, G4double radius << 344 AddaSphericalSurfaceWithCenterAtTheCenterOfAVolume(const G4String& SurfaceName,
277   G4double& area)                              << 345                                                          G4double radius,
278 {                                              << 346                                                    const G4String& volume_name,
                                                   >> 347                                                          G4ThreeVector& center,
                                                   >> 348                                                          G4double& area)
                                                   >> 349 { 
279   G4VPhysicalVolume* thePhysicalVolume = nullp    350   G4VPhysicalVolume* thePhysicalVolume = nullptr;
280   G4PhysicalVolumeStore* thePhysVolStore = G4P    351   G4PhysicalVolumeStore* thePhysVolStore = G4PhysicalVolumeStore::GetInstance();
281   thePhysicalVolume = thePhysVolStore->GetVolu    352   thePhysicalVolume = thePhysVolStore->GetVolume(volume_name);
282   if (thePhysicalVolume != nullptr) {          << 353   if (thePhysicalVolume != nullptr)
                                                   >> 354   {
283     G4VPhysicalVolume* daughter = thePhysicalV    355     G4VPhysicalVolume* daughter = thePhysicalVolume;
284     G4LogicalVolume* mother = thePhysicalVolum    356     G4LogicalVolume* mother = thePhysicalVolume->GetMotherLogical();
285     G4AffineTransform theTransformationFromPhy    357     G4AffineTransform theTransformationFromPhysVolToWorld = G4AffineTransform();
286     while (mother != nullptr) {                << 358     while (mother != nullptr)
                                                   >> 359     {
287       theTransformationFromPhysVolToWorld *=      360       theTransformationFromPhysVolToWorld *=
288         G4AffineTransform(daughter->GetFrameRo << 361          G4AffineTransform(daughter->GetFrameRotation(),
289       for (std::size_t i = 0; i < thePhysVolSt << 362                            daughter->GetObjectTranslation());
290         if ((*thePhysVolStore)[i]->GetLogicalV << 363       for ( std::size_t i=0; i<thePhysVolStore->size(); ++i)
                                                   >> 364       {
                                                   >> 365         if ((*thePhysVolStore)[i]->GetLogicalVolume() == mother)
                                                   >> 366         {
291           daughter = (*thePhysVolStore)[i];       367           daughter = (*thePhysVolStore)[i];
292           mother = daughter->GetMotherLogical( << 368           mother =daughter->GetMotherLogical();
293           break;                                  369           break;
294         }                                         370         }
295       }                                           371       }
296     }                                             372     }
297     center = theTransformationFromPhysVolToWor    373     center = theTransformationFromPhysVolToWorld.NetTranslation();
298     G4cout << "Center of the spherical surface << 374     G4cout << "Center of the spherical surface is at the position: "
299            << G4endl;                          << 375            << center/cm << " cm" << G4endl;
300   }                                               376   }
301   else {                                       << 377   else
                                                   >> 378   {
302     return false;                                 379     return false;
303   }                                               380   }
304   return AddaSphericalSurface(SurfaceName, rad    381   return AddaSphericalSurface(SurfaceName, radius, center, area);
305 }                                                 382 }
306                                                   383 
307 //////////////////////////////////////////////    384 //////////////////////////////////////////////////////////////////////////////
308 //                                                385 //
309 G4bool G4AdjointCrossSurfChecker::AddanExtSurf << 386 G4bool G4AdjointCrossSurfChecker::
310   const G4String& SurfaceName, const G4String& << 387 AddanExtSurfaceOfAvolume(const G4String& SurfaceName,
                                                   >> 388                          const G4String& volume_name, G4double& Area)
311 {                                                 389 {
312   G4int ind = FindRegisteredSurface(SurfaceNam    390   G4int ind = FindRegisteredSurface(SurfaceName);
313                                                   391 
314   G4VPhysicalVolume* thePhysicalVolume = nullp    392   G4VPhysicalVolume* thePhysicalVolume = nullptr;
315   G4PhysicalVolumeStore* thePhysVolStore = G4P    393   G4PhysicalVolumeStore* thePhysVolStore = G4PhysicalVolumeStore::GetInstance();
316   thePhysicalVolume = thePhysVolStore->GetVolu    394   thePhysicalVolume = thePhysVolStore->GetVolume(volume_name);
317   if (thePhysicalVolume == nullptr) {          << 395   if (thePhysicalVolume == nullptr)
                                                   >> 396   {
318     return false;                                 397     return false;
319   }                                               398   }
320   Area = thePhysicalVolume->GetLogicalVolume()    399   Area = thePhysicalVolume->GetLogicalVolume()->GetSolid()->GetSurfaceArea();
321   G4String mother_vol_name = "";               << 400   G4String mother_vol_name = ""; 
322   G4LogicalVolume* theMother = thePhysicalVolu    401   G4LogicalVolume* theMother = thePhysicalVolume->GetMotherLogical();
323                                                << 402  
324   if (theMother != nullptr) mother_vol_name =  << 403   if (theMother != nullptr) mother_vol_name= theMother->GetName();
325   if (ind >= 0) {                              << 404   if (ind>=0)
                                                   >> 405   {
326     ListOfSurfaceType[ind] = "ExternalSurfaceO    406     ListOfSurfaceType[ind] = "ExternalSurfaceOfAVolume";
327     ListOfSphereRadius[ind] = 0.;                 407     ListOfSphereRadius[ind] = 0.;
328     ListOfSphereCenter[ind] = G4ThreeVector(0. << 408     ListOfSphereCenter[ind] = G4ThreeVector(0.,0.,0.);
329     ListOfVol1Name[ind] = volume_name;            409     ListOfVol1Name[ind] = volume_name;
330     ListOfVol2Name[ind] = std::move(mother_vol << 410     ListOfVol2Name[ind] = mother_vol_name;
331     AreaOfSurface[ind] = Area;                    411     AreaOfSurface[ind] = Area;
332   }                                               412   }
333   else {                                       << 413   else
                                                   >> 414   {
334     ListOfSurfaceName.push_back(SurfaceName);     415     ListOfSurfaceName.push_back(SurfaceName);
335     ListOfSurfaceType.emplace_back("ExternalSu << 416     ListOfSurfaceType.push_back("ExternalSurfaceOfAVolume");
336     ListOfSphereRadius.push_back(0.);             417     ListOfSphereRadius.push_back(0.);
337     ListOfSphereCenter.emplace_back(0., 0., 0. << 418     ListOfSphereCenter.push_back(G4ThreeVector(0.,0.,0.));
338     ListOfVol1Name.push_back(volume_name);        419     ListOfVol1Name.push_back(volume_name);
339     ListOfVol2Name.push_back(std::move(mother_ << 420     ListOfVol2Name.push_back(mother_vol_name);
340     AreaOfSurface.push_back(Area);                421     AreaOfSurface.push_back(Area);
341   }                                               422   }
342   return true;                                    423   return true;
343 }                                                 424 }
344                                                   425 
345 //////////////////////////////////////////////    426 //////////////////////////////////////////////////////////////////////////////
346 //                                                427 //
347 G4bool G4AdjointCrossSurfChecker::AddanInterfa << 428 G4bool G4AdjointCrossSurfChecker::
348   const G4String& volume_name1, const G4String << 429 AddanInterfaceBetweenTwoVolumes(const G4String& SurfaceName,
                                                   >> 430                                 const G4String& volume_name1,
                                                   >> 431                                 const G4String& volume_name2, G4double& Area)
349 {                                                 432 {
350   G4int ind = FindRegisteredSurface(SurfaceNam    433   G4int ind = FindRegisteredSurface(SurfaceName);
351   Area = -1.;  // the way to compute the surfa << 434   Area = -1.; // the way to compute the surface is not known yet
352   if (ind >= 0) {                              << 435   if (ind>=0)
                                                   >> 436   {
353     ListOfSurfaceType[ind] = "BoundaryBetweenT    437     ListOfSurfaceType[ind] = "BoundaryBetweenTwoVolumes";
354     ListOfSphereRadius[ind] = 0.;                 438     ListOfSphereRadius[ind] = 0.;
355     ListOfSphereCenter[ind] = G4ThreeVector(0. << 439     ListOfSphereCenter[ind] = G4ThreeVector(0.,0.,0.);
356     ListOfVol1Name[ind] = volume_name1;           440     ListOfVol1Name[ind] = volume_name1;
357     ListOfVol2Name[ind] = volume_name2;           441     ListOfVol2Name[ind] = volume_name2;
358     AreaOfSurface[ind] = Area;                    442     AreaOfSurface[ind] = Area;
359   }                                               443   }
360   else {                                       << 444   else
                                                   >> 445   {
361     ListOfSurfaceName.push_back(SurfaceName);     446     ListOfSurfaceName.push_back(SurfaceName);
362     ListOfSurfaceType.emplace_back("BoundaryBe << 447     ListOfSurfaceType.push_back("BoundaryBetweenTwoVolumes");
363     ListOfSphereRadius.push_back(0.);             448     ListOfSphereRadius.push_back(0.);
364     ListOfSphereCenter.emplace_back(0., 0., 0. << 449     ListOfSphereCenter.push_back(G4ThreeVector(0.,0.,0.));
365     ListOfVol1Name.push_back(volume_name1);       450     ListOfVol1Name.push_back(volume_name1);
366     ListOfVol2Name.push_back(volume_name2);       451     ListOfVol2Name.push_back(volume_name2);
367     AreaOfSurface.push_back(Area);                452     AreaOfSurface.push_back(Area);
368   }                                               453   }
369   return true;                                    454   return true;
370 }                                                 455 }
371                                                   456 
372 //////////////////////////////////////////////    457 //////////////////////////////////////////////////////////////////////////////
373 //                                                458 //
374 void G4AdjointCrossSurfChecker::ClearListOfSel    459 void G4AdjointCrossSurfChecker::ClearListOfSelectedSurface()
375 {                                                 460 {
376   ListOfSurfaceName.clear();                      461   ListOfSurfaceName.clear();
377   ListOfSurfaceType.clear();                      462   ListOfSurfaceType.clear();
378   ListOfSphereRadius.clear();                     463   ListOfSphereRadius.clear();
379   ListOfSphereCenter.clear();                     464   ListOfSphereCenter.clear();
380   ListOfVol1Name.clear();                         465   ListOfVol1Name.clear();
381   ListOfVol2Name.clear();                         466   ListOfVol2Name.clear();
382 }                                                 467 }
383                                                   468 
384 //////////////////////////////////////////////    469 //////////////////////////////////////////////////////////////////////////////
385 //                                                470 //
386 G4int G4AdjointCrossSurfChecker::FindRegistere    471 G4int G4AdjointCrossSurfChecker::FindRegisteredSurface(const G4String& name)
387 {                                                 472 {
388   for (std::size_t i = 0; i < ListOfSurfaceNam << 473   for (std::size_t i=0; i<ListOfSurfaceName.size(); ++i)
389     if (name == ListOfSurfaceName[i]) return G << 474   {
                                                   >> 475     if (name == ListOfSurfaceName[i])  return G4int(i);
390   }                                               476   }
391   return -1;                                      477   return -1;
392 }                                                 478 }
393                                                   479