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] [ 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 /geometry/volumes/src/G4PVParameterised.cc (Version 11.3.0) and /geometry/volumes/src/G4PVParameterised.cc (Version 11.0.p1)


  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 // class G4PVParameterised implementation          26 // class G4PVParameterised implementation
 27 //                                                 27 //
 28 // 29.07.95, P.Kent - first non-stub version       28 // 29.07.95, P.Kent - first non-stub version
 29 // -------------------------------------------     29 // ----------------------------------------------------------------------
 30                                                    30 
 31 #include "G4PVParameterised.hh"                    31 #include "G4PVParameterised.hh"
 32 #include "G4VPVParameterisation.hh"                32 #include "G4VPVParameterisation.hh"
 33 #include "G4AffineTransform.hh"                    33 #include "G4AffineTransform.hh"
 34 #include "G4UnitsTable.hh"                         34 #include "G4UnitsTable.hh"
 35 #include "G4VSolid.hh"                             35 #include "G4VSolid.hh"
 36 #include "G4LogicalVolume.hh"                      36 #include "G4LogicalVolume.hh"
 37                                                    37 
 38 // -------------------------------------------     38 // ----------------------------------------------------------------------
 39 // Constructor                                     39 // Constructor
 40 //                                                 40 //
 41 G4PVParameterised::G4PVParameterised( const G4     41 G4PVParameterised::G4PVParameterised( const G4String& pName,
 42                                             G4     42                                             G4LogicalVolume* pLogical,
 43                                             G4     43                                             G4VPhysicalVolume* pMotherPhysical,
 44                                       const EA     44                                       const EAxis pAxis,
 45                                       const G4     45                                       const G4int nReplicas,
 46                                             G4     46                                             G4VPVParameterisation* pParam,
 47                                             G4     47                                             G4bool pSurfChk )
 48 : G4PVReplica(pName, nReplicas, pAxis, pLogica     48 : G4PVReplica(pName, nReplicas, pAxis, pLogical,
 49               pMotherPhysical != nullptr ? pMo <<  49               pMotherPhysical ? pMotherPhysical->GetLogicalVolume() : nullptr ),
 50     fparam(pParam)                                 50     fparam(pParam)
 51 {                                                  51 {
 52   G4LogicalVolume* motherLogical= pMotherPhysi <<  52   G4LogicalVolume* motherLogical= pMotherPhysical ?
 53       pMotherPhysical->GetLogicalVolume() : nu     53       pMotherPhysical->GetLogicalVolume() : nullptr;
 54                                                    54 
 55   SetMotherLogical( motherLogical );               55   SetMotherLogical( motherLogical );
 56   if( motherLogical != nullptr )               <<  56   if( motherLogical )
 57   {                                                57   {
 58     // Registration moved here to ensure that      58     // Registration moved here to ensure that the volume is recognised as Parameterised     
 59     motherLogical->AddDaughter(this);              59     motherLogical->AddDaughter(this);
 60   }                                                60   }
 61                                                    61 
 62 #ifdef G4VERBOSE                                   62 #ifdef G4VERBOSE  
 63   if ((pMotherPhysical != nullptr) && (pMother     63   if ((pMotherPhysical != nullptr) && (pMotherPhysical->IsParameterised()))
 64   {                                                64   {
 65     std::ostringstream message, hint;              65     std::ostringstream message, hint;
 66     message << "A parameterised volume is bein     66     message << "A parameterised volume is being placed" << G4endl
 67             << "inside another parameterised v     67             << "inside another parameterised volume !";
 68     hint << "To make sure that no overlaps are     68     hint << "To make sure that no overlaps are generated," << G4endl
 69          << "you should verify the mother repl     69          << "you should verify the mother replicated shapes" << G4endl
 70          << "are of the same type and dimensio     70          << "are of the same type and dimensions." << G4endl
 71          << "   Mother physical volume: " << p     71          << "   Mother physical volume: " << pMotherPhysical->GetName() << G4endl
 72          << "   Parameterised volume: " << pNa     72          << "   Parameterised volume: " << pName << G4endl
 73          << "  (To switch this warning off, co     73          << "  (To switch this warning off, compile with G4_NO_VERBOSE)";
 74     G4Exception("G4PVParameterised::G4PVParame     74     G4Exception("G4PVParameterised::G4PVParameterised()", "GeomVol1002",
 75                 JustWarning, message, G4String     75                 JustWarning, message, G4String(hint.str()));
 76   }                                                76   }
 77 #endif                                             77 #endif
 78   if (pSurfChk) { CheckOverlaps(); }               78   if (pSurfChk) { CheckOverlaps(); }
 79 }                                                  79 }
 80                                                    80 
 81 // -------------------------------------------     81 // ----------------------------------------------------------------------
 82 // Constructor                                     82 // Constructor
 83 //                                                 83 //
 84 G4PVParameterised::G4PVParameterised( const G4     84 G4PVParameterised::G4PVParameterised( const G4String& pName,
 85                                             G4     85                                             G4LogicalVolume* pLogical,
 86                                             G4     86                                             G4LogicalVolume* pMotherLogical,
 87                                       const EA     87                                       const EAxis pAxis,
 88                                       const G4     88                                       const G4int nReplicas,
 89                                             G4     89                                             G4VPVParameterisation* pParam,
 90                                             G4     90                                             G4bool pSurfChk )
 91   : G4PVReplica(pName, nReplicas, pAxis, pLogi     91   : G4PVReplica(pName, nReplicas, pAxis, pLogical, pMotherLogical ),
 92     fparam(pParam)                                 92     fparam(pParam)
 93 {                                                  93 {
 94   SetMotherLogical( pMotherLogical );              94   SetMotherLogical( pMotherLogical );
 95   if( pMotherLogical != nullptr )              <<  95   if( pMotherLogical )
 96   {                                                96   {
 97     // Registration moved here to ensure that      97     // Registration moved here to ensure that the volume is recognised as Parameterised
 98     pMotherLogical->AddDaughter(this);             98     pMotherLogical->AddDaughter(this);
 99   }                                                99   }
100   if (pSurfChk) { CheckOverlaps(); }              100   if (pSurfChk) { CheckOverlaps(); }
101 }                                                 101 }
102                                                   102 
103 // -------------------------------------------    103 // ----------------------------------------------------------------------
104 // Fake default constructor - sets only member    104 // Fake default constructor - sets only member data and allocates memory
105 //                            for usage restri    105 //                            for usage restricted to object persistency.
106 //                                                106 //
107 G4PVParameterised::G4PVParameterised( __void__    107 G4PVParameterised::G4PVParameterised( __void__& a )
108   : G4PVReplica(a)                                108   : G4PVReplica(a)
109 {                                                 109 {
110 }                                                 110 }
111                                                   111 
112 // -------------------------------------------    112 // ----------------------------------------------------------------------
113 // Destructor                                     113 // Destructor
114 //                                                114 //
115 G4PVParameterised::~G4PVParameterised() = defa << 115 G4PVParameterised::~G4PVParameterised()
                                                   >> 116 {
                                                   >> 117 }
116                                                   118 
117 // -------------------------------------------    119 // ----------------------------------------------------------------------
118 // GetParameterisation                            120 // GetParameterisation
119 //                                                121 //
120 G4VPVParameterisation* G4PVParameterised::GetP    122 G4VPVParameterisation* G4PVParameterised::GetParameterisation() const
121 {                                                 123 {
122   return fparam;                                  124   return fparam;
123 }                                                 125 }
124                                                   126 
125 // -------------------------------------------    127 // ----------------------------------------------------------------------
126 // IsParameterised                                128 // IsParameterised
127 //                                                129 //
128 G4bool G4PVParameterised::IsParameterised() co    130 G4bool G4PVParameterised::IsParameterised() const
129 {                                                 131 {
130   return true;                                    132   return true;
131 }                                                 133 }
132                                                   134 
133 // -------------------------------------------    135 // ----------------------------------------------------------------------
134 // VolumeType                                     136 // VolumeType
135 //                                                137 //
136 EVolume G4PVParameterised::VolumeType() const     138 EVolume G4PVParameterised::VolumeType() const 
137 {                                                 139 {
138   return kParameterised;                          140   return kParameterised;
139 }                                                 141 }
140                                                   142 
141 // -------------------------------------------    143 // ----------------------------------------------------------------------
142 // GetReplicationData                             144 // GetReplicationData
143 //                                                145 //
144 void G4PVParameterised::GetReplicationData( EA    146 void G4PVParameterised::GetReplicationData( EAxis& axis,
145                                             G4    147                                             G4int& nReplicas,
146                                             G4    148                                             G4double& width,
147                                             G4    149                                             G4double& offset,
148                                             G4    150                                             G4bool& consuming) const
149 {                                                 151 {
150   axis = faxis;                                   152   axis = faxis;
151   nReplicas = fnReplicas;                         153   nReplicas = fnReplicas;
152   width = fwidth;                                 154   width = fwidth;
153   offset = foffset;                               155   offset = foffset;
154   consuming = false;                              156   consuming = false;
155 }                                                 157 }
156                                                   158 
157 // -------------------------------------------    159 // ----------------------------------------------------------------------
158 // SetRegularStructureId                          160 // SetRegularStructureId
159 //                                                161 //
160 void  G4PVParameterised::SetRegularStructureId    162 void  G4PVParameterised::SetRegularStructureId( G4int code )
161 {                                                 163 {
162   G4PVReplica::SetRegularStructureId( code );     164   G4PVReplica::SetRegularStructureId( code );
163   // To undertake additional preparation, a de    165   // To undertake additional preparation, a derived volume must
164   // redefine this method, while calling also     166   // redefine this method, while calling also the above method
165 }                                                 167 }
166                                                   168 
167                                                   169 
168 // -------------------------------------------    170 // ----------------------------------------------------------------------
169 // CheckOverlaps                                  171 // CheckOverlaps
170 //                                                172 //
171 G4bool                                            173 G4bool
172 G4PVParameterised::CheckOverlaps(G4int res, G4    174 G4PVParameterised::CheckOverlaps(G4int res, G4double tol,
173                                  G4bool verbos    175                                  G4bool verbose, G4int maxErr)
174 {                                                 176 {
175   if (res<=0) { return false; }                   177   if (res<=0) { return false; }
176                                                   178 
177   G4int trials = 0;                               179   G4int trials = 0;
178   G4bool retval = false;                          180   G4bool retval = false;
179   G4VSolid *solidA = nullptr, *solidB = nullpt    181   G4VSolid *solidA = nullptr, *solidB = nullptr;
180   G4LogicalVolume* motherLog = GetMotherLogica    182   G4LogicalVolume* motherLog = GetMotherLogical();
181   G4VSolid *motherSolid = motherLog->GetSolid(    183   G4VSolid *motherSolid = motherLog->GetSolid();
182   std::vector<G4ThreeVector> points;              184   std::vector<G4ThreeVector> points;
183                                                   185 
184   if (verbose)                                    186   if (verbose)
185   {                                               187   {
186     G4cout << "Checking overlaps for parameter    188     G4cout << "Checking overlaps for parameterised volume "
187            << GetName() << " ... ";               189            << GetName() << " ... ";
188   }                                               190   }
189                                                   191 
190   for (auto i=0; i<GetMultiplicity(); ++i)        192   for (auto i=0; i<GetMultiplicity(); ++i)
191   {                                               193   {
192     solidA = fparam->ComputeSolid(i, this);       194     solidA = fparam->ComputeSolid(i, this);
193     solidA->ComputeDimensions(fparam, i, this)    195     solidA->ComputeDimensions(fparam, i, this);
194     fparam->ComputeTransformation(i, this);       196     fparam->ComputeTransformation(i, this);
195                                                   197 
196     // Create the transformation from daughter    198     // Create the transformation from daughter to mother
197     //                                            199     //
198     G4AffineTransform Tm( GetRotation(), GetTr    200     G4AffineTransform Tm( GetRotation(), GetTranslation() );
199                                                   201 
200     // Generate random points on surface accor    202     // Generate random points on surface according to the given resolution,
201     // transform them to the mother's coordina    203     // transform them to the mother's coordinate system and if no overlaps
202     // with the mother volume, cache them in a    204     // with the mother volume, cache them in a vector for later use with
203     // the daughters                              205     // the daughters
204     //                                            206     //
205     for (auto n=0; n<res; ++n)                    207     for (auto n=0; n<res; ++n)
206     {                                             208     {
207       G4ThreeVector mp = Tm.TransformPoint(sol    209       G4ThreeVector mp = Tm.TransformPoint(solidA->GetPointOnSurface());
208                                                   210 
209       // Checking overlaps with the mother vol    211       // Checking overlaps with the mother volume
210       //                                          212       //
211       if (motherSolid->Inside(mp)==kOutside)      213       if (motherSolid->Inside(mp)==kOutside)
212       {                                           214       {
213         G4double distin = motherSolid->Distanc    215         G4double distin = motherSolid->DistanceToIn(mp);
214         if (distin > tol)                         216         if (distin > tol)
215         {                                         217         {
216           ++trials; retval = true;                218           ++trials; retval = true;
217           std::ostringstream message;             219           std::ostringstream message;
218           message << "Overlap with mother volu    220           message << "Overlap with mother volume !" << G4endl
219                   << "         Overlap is dete    221                   << "         Overlap is detected for volume "
220                   << GetName() << ", parameter    222                   << GetName() << ", parameterised instance: " << i << G4endl
221                   << "          with its mothe    223                   << "          with its mother volume "
222                   << motherLog->GetName() << G    224                   << motherLog->GetName() << G4endl
223                   << "          at mother loca    225                   << "          at mother local point " << mp << ", "
224                   << "overlapping by at least:    226                   << "overlapping by at least: "
225                   << G4BestUnit(distin, "Lengt    227                   << G4BestUnit(distin, "Length");
226           if (trials>=maxErr)                     228           if (trials>=maxErr)
227           {                                       229           {
228             message << G4endl                     230             message << G4endl
229                     << "NOTE: Reached maximum     231                     << "NOTE: Reached maximum fixed number -" << maxErr
230                     << "- of overlaps reports     232                     << "- of overlaps reports for this volume !";
231           }                                       233           }
232           G4Exception("G4PVParameterised::Chec    234           G4Exception("G4PVParameterised::CheckOverlaps()",
233                       "GeomVol1002", JustWarni    235                       "GeomVol1002", JustWarning, message);
234           if (trials>=maxErr)  { return true;     236           if (trials>=maxErr)  { return true; }
235         }                                         237         }
236       }                                           238       }
237       points.push_back(mp);                       239       points.push_back(mp);
238     }                                             240     }
239                                                   241 
240     // Checking overlaps with each other param    242     // Checking overlaps with each other parameterised instance
241     //                                            243     //
242     for (auto j=i+1; j<GetMultiplicity(); ++j)    244     for (auto j=i+1; j<GetMultiplicity(); ++j)
243     {                                             245     {
244       solidB = fparam->ComputeSolid(j,this);      246       solidB = fparam->ComputeSolid(j,this);
245       solidB->ComputeDimensions(fparam, j, thi    247       solidB->ComputeDimensions(fparam, j, this);
246       fparam->ComputeTransformation(j, this);     248       fparam->ComputeTransformation(j, this);
247                                                   249 
248       // Create the transformation for daughte    250       // Create the transformation for daughter volume
249       //                                          251       //
250       G4AffineTransform Td( GetRotation(), Get    252       G4AffineTransform Td( GetRotation(), GetTranslation() );
251                                                   253 
252       for (const auto & point : points)        << 254       for (auto pos=points.cbegin(); pos!=points.cend(); ++pos)
253       {                                           255       {
254         // Transform each point according to d    256         // Transform each point according to daughter's frame
255         //                                        257         //
256         G4ThreeVector md = Td.InverseTransform << 258         G4ThreeVector md = Td.InverseTransformPoint(*pos);
257                                                   259 
258         if (solidB->Inside(md)==kInside)          260         if (solidB->Inside(md)==kInside)
259         {                                         261         {
260           G4double distout = solidB->DistanceT    262           G4double distout = solidB->DistanceToOut(md);
261           if (distout > tol)                      263           if (distout > tol)
262           {                                       264           {
263             ++trials; retval = true;              265             ++trials; retval = true;
264             std::ostringstream message;           266             std::ostringstream message;
265             message << "Overlap within paramet    267             message << "Overlap within parameterised volumes !" << G4endl
266                     << "          Overlap is d    268                     << "          Overlap is detected for volume "
267                     << GetName() << ", paramet    269                     << GetName() << ", parameterised instance: " << i << G4endl
268                     << "          with paramet    270                     << "          with parameterised volume instance: " << j
269                     << G4endl                     271                     << G4endl
270                     << "          at local poi    272                     << "          at local point " << md << ", "
271                     << "overlapping by at leas    273                     << "overlapping by at least: "
272                     << G4BestUnit(distout, "Le    274                     << G4BestUnit(distout, "Length")
273                     << ", related to volume in    275                     << ", related to volume instance: " << j << ".";
274             if (trials>=maxErr)                   276             if (trials>=maxErr)
275             {                                     277             {
276               message << G4endl                   278               message << G4endl
277                       << "NOTE: Reached maximu    279                       << "NOTE: Reached maximum fixed number -" << maxErr
278                       << "- of overlaps report    280                       << "- of overlaps reports for this volume !";
279             }                                     281             }
280             G4Exception("G4PVParameterised::Ch    282             G4Exception("G4PVParameterised::CheckOverlaps()",
281                         "GeomVol1002", JustWar    283                         "GeomVol1002", JustWarning, message);
282             if (trials>=maxErr)  { return true    284             if (trials>=maxErr)  { return true; }
283           }                                       285           }
284         }                                         286         }
285       }                                           287       }
286     }                                             288     }
287   }                                               289   }
288   if (verbose)                                    290   if (verbose)
289   {                                               291   {
290     G4cout << "OK! " << G4endl;                   292     G4cout << "OK! " << G4endl;
291   }                                               293   }
292                                                   294 
293   return retval;                                  295   return retval;
294 }                                                 296 }
295                                                   297