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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 8.0)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                    <<   3 // * DISCLAIMER                                                       *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th <<   5 // * The following disclaimer summarizes all the specific disclaimers *
  6 // * the Geant4 Collaboration.  It is provided <<   6 // * of contributors to this software. The specific disclaimers,which *
  7 // * conditions of the Geant4 Software License <<   7 // * govern, are listed with their locations in:                      *
  8 // * LICENSE and available at  http://cern.ch/ <<   8 // *   http://cern.ch/geant4/license                                  *
  9 // * include a list of copyright holders.      << 
 10 // *                                                9 // *                                                                  *
 11 // * Neither the authors of this software syst     10 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     11 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     12 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     13 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  <<  14 // * use.                                                             *
 16 // * for the full disclaimer and the limitatio << 
 17 // *                                               15 // *                                                                  *
 18 // * This  code  implementation is the result  <<  16 // * This  code  implementation is the  intellectual property  of the *
 19 // * technical work of the GEANT4 collaboratio <<  17 // * GEANT4 collaboration.                                            *
 20 // * By using,  copying,  modifying or  distri <<  18 // * By copying,  distributing  or modifying the Program (or any work *
 21 // * any work based  on the software)  you  ag <<  19 // * based  on  the Program)  you indicate  your  acceptance of  this *
 22 // * use  in  resulting  scientific  publicati <<  20 // * statement, and all its terms.                                    *
 23 // * acceptance of all terms of the Geant4 Sof << 
 24 // *******************************************     21 // ********************************************************************
                                                   >>  22 //
                                                   >>  23 //
                                                   >>  24 // $Id: G4PVParameterised.cc,v 1.5 2005/11/11 22:39:00 japost Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-08-00 $
                                                   >>  26 //
 25 //                                                 27 // 
 26 // class G4PVParameterised implementation      <<  28 // class G4PVParameterised
                                                   >>  29 //
                                                   >>  30 // Implementation
 27 //                                                 31 //
 28 // 29.07.95, P.Kent - first non-stub version   << 
 29 // -------------------------------------------     32 // ----------------------------------------------------------------------
 30                                                    33 
 31 #include "G4PVParameterised.hh"                    34 #include "G4PVParameterised.hh"
 32 #include "G4VPVParameterisation.hh"                35 #include "G4VPVParameterisation.hh"
 33 #include "G4AffineTransform.hh"                    36 #include "G4AffineTransform.hh"
 34 #include "G4UnitsTable.hh"                     << 
 35 #include "G4VSolid.hh"                             37 #include "G4VSolid.hh"
 36 #include "G4LogicalVolume.hh"                      38 #include "G4LogicalVolume.hh"
 37                                                    39 
 38 // -------------------------------------------     40 // ----------------------------------------------------------------------
 39 // Constructor                                     41 // Constructor
 40 //                                                 42 //
 41 G4PVParameterised::G4PVParameterised( const G4     43 G4PVParameterised::G4PVParameterised( const G4String& pName,
 42                                             G4     44                                             G4LogicalVolume* pLogical,
 43                                             G4 <<  45                                             G4VPhysicalVolume* pMother,
 44                                       const EA     46                                       const EAxis pAxis,
 45                                       const G4     47                                       const G4int nReplicas,
 46                                             G4 <<  48                                             G4VPVParameterisation *pParam,
 47                                             G4     49                                             G4bool pSurfChk )
 48 : G4PVReplica(pName, nReplicas, pAxis, pLogica <<  50   : G4PVReplica(pName, pLogical, pMother, pAxis, nReplicas, 0, 0),
 49               pMotherPhysical != nullptr ? pMo << 
 50     fparam(pParam)                                 51     fparam(pParam)
 51 {                                                  52 {
 52   G4LogicalVolume* motherLogical= pMotherPhysi << 
 53       pMotherPhysical->GetLogicalVolume() : nu << 
 54                                                << 
 55   SetMotherLogical( motherLogical );           << 
 56   if( motherLogical != nullptr )               << 
 57   {                                            << 
 58     // Registration moved here to ensure that  << 
 59     motherLogical->AddDaughter(this);          << 
 60   }                                            << 
 61                                                << 
 62 #ifdef G4VERBOSE                                   53 #ifdef G4VERBOSE  
 63   if ((pMotherPhysical != nullptr) && (pMother <<  54   if ((pMother) && (pMother->IsParameterised()))
 64   {                                                55   {
 65     std::ostringstream message, hint;          <<  56     G4cout << "WARNING - G4PVParameterised::G4PVParameterised()" << G4endl
 66     message << "A parameterised volume is bein <<  57            << "          A parameterised volume is being placed" << G4endl
 67             << "inside another parameterised v <<  58            << "          inside another parameterised volume !" << G4endl
 68     hint << "To make sure that no overlaps are <<  59            << "          To make sure that no overlaps are generated," << G4endl
 69          << "you should verify the mother repl <<  60            << "          you should verify the mother replicated shapes" << G4endl
 70          << "are of the same type and dimensio <<  61            << "          are of the same type and dimensions." << G4endl
 71          << "   Mother physical volume: " << p <<  62            << "             Mother physical volume: " << pMother->GetName() << G4endl
 72          << "   Parameterised volume: " << pNa <<  63            << "             Parameterised volume: " << pName << G4endl
 73          << "  (To switch this warning off, co <<  64            << "  (To switch this warning off, compile with G4_NO_VERBOSE)" << G4endl;
 74     G4Exception("G4PVParameterised::G4PVParame << 
 75                 JustWarning, message, G4String << 
 76   }                                                65   }
 77 #endif                                             66 #endif
 78   if (pSurfChk) { CheckOverlaps(); }               67   if (pSurfChk) { CheckOverlaps(); }
 79 }                                                  68 }
 80                                                    69 
 81 // -------------------------------------------     70 // ----------------------------------------------------------------------
 82 // Constructor                                     71 // Constructor
 83 //                                                 72 //
 84 G4PVParameterised::G4PVParameterised( const G4     73 G4PVParameterised::G4PVParameterised( const G4String& pName,
 85                                             G4     74                                             G4LogicalVolume* pLogical,
 86                                             G4     75                                             G4LogicalVolume* pMotherLogical,
 87                                       const EA     76                                       const EAxis pAxis,
 88                                       const G4     77                                       const G4int nReplicas,
 89                                             G4 <<  78                                             G4VPVParameterisation *pParam,
 90                                             G4     79                                             G4bool pSurfChk )
 91   : G4PVReplica(pName, nReplicas, pAxis, pLogi <<  80   : G4PVReplica(pName, pLogical, pMotherLogical, pAxis, nReplicas, 0, 0),
 92     fparam(pParam)                                 81     fparam(pParam)
 93 {                                                  82 {
 94   SetMotherLogical( pMotherLogical );          << 
 95   if( pMotherLogical != nullptr )              << 
 96   {                                            << 
 97     // Registration moved here to ensure that  << 
 98     pMotherLogical->AddDaughter(this);         << 
 99   }                                            << 
100   if (pSurfChk) { CheckOverlaps(); }               83   if (pSurfChk) { CheckOverlaps(); }
101 }                                                  84 }
102                                                    85 
103 // -------------------------------------------     86 // ----------------------------------------------------------------------
104 // Fake default constructor - sets only member     87 // Fake default constructor - sets only member data and allocates memory
105 //                            for usage restri     88 //                            for usage restricted to object persistency.
106 //                                                 89 //
107 G4PVParameterised::G4PVParameterised( __void__     90 G4PVParameterised::G4PVParameterised( __void__& a )
108   : G4PVReplica(a)                             <<  91   : G4PVReplica(a), fparam(0)
109 {                                                  92 {
110 }                                                  93 }
111                                                    94 
112 // -------------------------------------------     95 // ----------------------------------------------------------------------
113 // Destructor                                      96 // Destructor
114 //                                                 97 //
115 G4PVParameterised::~G4PVParameterised() = defa <<  98 G4PVParameterised::~G4PVParameterised()
                                                   >>  99 {
                                                   >> 100 }
116                                                   101 
117 // -------------------------------------------    102 // ----------------------------------------------------------------------
118 // GetParameterisation                            103 // GetParameterisation
119 //                                                104 //
120 G4VPVParameterisation* G4PVParameterised::GetP    105 G4VPVParameterisation* G4PVParameterised::GetParameterisation() const
121 {                                                 106 {
122   return fparam;                                  107   return fparam;
123 }                                                 108 }
124                                                   109 
125 // -------------------------------------------    110 // ----------------------------------------------------------------------
126 // IsParameterised                                111 // IsParameterised
127 //                                                112 //
128 G4bool G4PVParameterised::IsParameterised() co    113 G4bool G4PVParameterised::IsParameterised() const
129 {                                                 114 {
130   return true;                                    115   return true;
131 }                                                 116 }
132                                                   117 
133 // -------------------------------------------    118 // ----------------------------------------------------------------------
134 // VolumeType                                  << 
135 //                                             << 
136 EVolume G4PVParameterised::VolumeType() const  << 
137 {                                              << 
138   return kParameterised;                       << 
139 }                                              << 
140                                                << 
141 // ------------------------------------------- << 
142 // GetReplicationData                             119 // GetReplicationData
143 //                                                120 //
144 void G4PVParameterised::GetReplicationData( EA    121 void G4PVParameterised::GetReplicationData( EAxis& axis,
145                                             G4    122                                             G4int& nReplicas,
146                                             G4    123                                             G4double& width,
147                                             G4    124                                             G4double& offset,
148                                             G4    125                                             G4bool& consuming) const
149 {                                                 126 {
150   axis = faxis;                                   127   axis = faxis;
151   nReplicas = fnReplicas;                         128   nReplicas = fnReplicas;
152   width = fwidth;                                 129   width = fwidth;
153   offset = foffset;                               130   offset = foffset;
154   consuming = false;                              131   consuming = false;
155 }                                                 132 }
156                                                   133 
157 // -------------------------------------------    134 // ----------------------------------------------------------------------
158 // SetRegularStructureId                          135 // SetRegularStructureId
159 //                                                136 //
160 void  G4PVParameterised::SetRegularStructureId << 137 void  G4PVParameterised::SetRegularStructureId( G4int Code )
161 {                                                 138 {
162   G4PVReplica::SetRegularStructureId( code );  << 139   G4PVReplica::SetRegularStructureId( Code );
163   // To undertake additional preparation, a de    140   // To undertake additional preparation, a derived volume must
164   // redefine this method, while calling also  << 141   //   redefine this method, while calling also the above method.
165 }                                                 142 }
166                                                   143 
167                                                   144 
168 // -------------------------------------------    145 // ----------------------------------------------------------------------
169 // CheckOverlaps                                  146 // CheckOverlaps
170 //                                                147 //
171 G4bool                                         << 148 G4bool G4PVParameterised::CheckOverlaps(G4int res)
172 G4PVParameterised::CheckOverlaps(G4int res, G4 << 
173                                  G4bool verbos << 
174 {                                                 149 {
175   if (res<=0) { return false; }                   150   if (res<=0) { return false; }
176                                                   151 
177   G4int trials = 0;                            << 152   G4VSolid *solidA = 0, *solidB = 0;
178   G4bool retval = false;                       << 153   G4LogicalVolume *motherLog = GetMotherLogical();
179   G4VSolid *solidA = nullptr, *solidB = nullpt << 
180   G4LogicalVolume* motherLog = GetMotherLogica << 
181   G4VSolid *motherSolid = motherLog->GetSolid(    154   G4VSolid *motherSolid = motherLog->GetSolid();
182   std::vector<G4ThreeVector> points;              155   std::vector<G4ThreeVector> points;
183                                                   156 
184   if (verbose)                                 << 157   G4cout << "Checking overlaps for parameterised volume "
185   {                                            << 158          << GetName() << " ... ";
186     G4cout << "Checking overlaps for parameter << 
187            << GetName() << " ... ";            << 
188   }                                            << 
189                                                   159 
190   for (auto i=0; i<GetMultiplicity(); ++i)     << 160   for (G4int i=0; i<GetMultiplicity(); i++)
191   {                                               161   {
192     solidA = fparam->ComputeSolid(i, this);       162     solidA = fparam->ComputeSolid(i, this);
193     solidA->ComputeDimensions(fparam, i, this)    163     solidA->ComputeDimensions(fparam, i, this);
194     fparam->ComputeTransformation(i, this);       164     fparam->ComputeTransformation(i, this);
195                                                   165 
196     // Create the transformation from daughter    166     // Create the transformation from daughter to mother
197     //                                            167     //
198     G4AffineTransform Tm( GetRotation(), GetTr << 168     G4AffineTransform Tm( GetFrameRotation(), GetFrameTranslation() );
199                                                   169 
200     // Generate random points on surface accor    170     // Generate random points on surface according to the given resolution,
201     // transform them to the mother's coordina    171     // transform them to the mother's coordinate system and if no overlaps
202     // with the mother volume, cache them in a    172     // with the mother volume, cache them in a vector for later use with
203     // the daughters                              173     // the daughters
204     //                                            174     //
205     for (auto n=0; n<res; ++n)                 << 175     for (G4int n=0; n<res; n++)
206     {                                             176     {
207       G4ThreeVector mp = Tm.TransformPoint(sol    177       G4ThreeVector mp = Tm.TransformPoint(solidA->GetPointOnSurface());
208                                                   178 
209       // Checking overlaps with the mother vol    179       // Checking overlaps with the mother volume
210       //                                          180       //
211       if (motherSolid->Inside(mp)==kOutside)      181       if (motherSolid->Inside(mp)==kOutside)
212       {                                           182       {
213         G4double distin = motherSolid->Distanc << 183         G4cout << G4endl;
214         if (distin > tol)                      << 184         G4cout << "WARNING - G4PVParameterised::CheckOverlaps()" << G4endl
215         {                                      << 185                << "          Overlap is detected for volume "
216           ++trials; retval = true;             << 186                << GetName() << ", parameterised instance: " << i << G4endl
217           std::ostringstream message;          << 187                << "          with its mother volume "
218           message << "Overlap with mother volu << 188                << motherLog->GetName() << G4endl
219                   << "         Overlap is dete << 189                << "          at point " << mp << G4endl;
220                   << GetName() << ", parameter << 190         G4Exception("G4PVParameterised::CheckOverlaps()", "InvalidSetup",
221                   << "          with its mothe << 191                     JustWarning, "Overlap with mother volume !");
222                   << motherLog->GetName() << G << 192         return true;
223                   << "          at mother loca << 
224                   << "overlapping by at least: << 
225                   << G4BestUnit(distin, "Lengt << 
226           if (trials>=maxErr)                  << 
227           {                                    << 
228             message << G4endl                  << 
229                     << "NOTE: Reached maximum  << 
230                     << "- of overlaps reports  << 
231           }                                    << 
232           G4Exception("G4PVParameterised::Chec << 
233                       "GeomVol1002", JustWarni << 
234           if (trials>=maxErr)  { return true;  << 
235         }                                      << 
236       }                                           193       }
237       points.push_back(mp);                       194       points.push_back(mp);
238     }                                             195     }
239                                                   196 
240     // Checking overlaps with each other param    197     // Checking overlaps with each other parameterised instance
241     //                                            198     //
242     for (auto j=i+1; j<GetMultiplicity(); ++j) << 199     std::vector<G4ThreeVector>::iterator pos;
                                                   >> 200     for (G4int j=i+1; j<GetMultiplicity(); j++)
243     {                                             201     {
244       solidB = fparam->ComputeSolid(j,this);      202       solidB = fparam->ComputeSolid(j,this);
245       solidB->ComputeDimensions(fparam, j, thi    203       solidB->ComputeDimensions(fparam, j, this);
246       fparam->ComputeTransformation(j, this);     204       fparam->ComputeTransformation(j, this);
247                                                   205 
248       // Create the transformation for daughte    206       // Create the transformation for daughter volume
249       //                                          207       //
250       G4AffineTransform Td( GetRotation(), Get << 208       G4AffineTransform Td( GetFrameRotation(), GetFrameTranslation() );
251                                                   209 
252       for (const auto & point : points)        << 210       for (pos=points.begin(); pos!=points.end(); pos++)
253       {                                           211       {
254         // Transform each point according to d    212         // Transform each point according to daughter's frame
255         //                                        213         //
256         G4ThreeVector md = Td.InverseTransform << 214         G4ThreeVector md = Td.Invert().TransformPoint(*pos);
257                                                   215 
258         if (solidB->Inside(md)==kInside)          216         if (solidB->Inside(md)==kInside)
259         {                                         217         {
260           G4double distout = solidB->DistanceT << 218           G4cout << G4endl;
261           if (distout > tol)                   << 219           G4cout << "WARNING - G4PVParameterised::CheckOverlaps()" << G4endl
262           {                                    << 220                  << "          Overlap is detected for volume "
263             ++trials; retval = true;           << 221                  << GetName() << ", parameterised instance: " << i << G4endl
264             std::ostringstream message;        << 222                  << "          with parameterised volume instance: " << j
265             message << "Overlap within paramet << 223                  << G4endl
266                     << "          Overlap is d << 224                  << "          at point " << md << G4endl;
267                     << GetName() << ", paramet << 225           G4Exception("G4PVParameterised::CheckOverlaps()", "InvalidSetup",
268                     << "          with paramet << 226                       JustWarning, "Overlap within parameterised volumes !");
269                     << G4endl                  << 227           return true;
270                     << "          at local poi << 
271                     << "overlapping by at leas << 
272                     << G4BestUnit(distout, "Le << 
273                     << ", related to volume in << 
274             if (trials>=maxErr)                << 
275             {                                  << 
276               message << G4endl                << 
277                       << "NOTE: Reached maximu << 
278                       << "- of overlaps report << 
279             }                                  << 
280             G4Exception("G4PVParameterised::Ch << 
281                         "GeomVol1002", JustWar << 
282             if (trials>=maxErr)  { return true << 
283           }                                    << 
284         }                                         228         }
285       }                                           229       }
286     }                                             230     }
287   }                                               231   }
288   if (verbose)                                 << 232   G4cout << "OK! " << G4endl;
289   {                                            << 
290     G4cout << "OK! " << G4endl;                << 
291   }                                            << 
292                                                   233 
293   return retval;                               << 234   return false;
294 }                                                 235 }
295                                                   236