Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/g3tog4/src/G3Division.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 /g3tog4/src/G3Division.cc (Version 11.3.0) and /g3tog4/src/G3Division.cc (Version 7.1)


  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 // ********************************************************************
 25 //                                                 22 //
 26 //                                                 23 //
                                                   >>  24 // $Id: G3Division.cc,v 1.16 2004/12/07 08:33:38 gcosmo Exp $
                                                   >>  25 // GEANT4 tag $Name: geant4-07-01 $
 27 //                                                 26 //
 28 // by I.Hrivnacova, V.Berejnoi 13.10.99            27 // by I.Hrivnacova, V.Berejnoi 13.10.99
 29                                                    28 
 30 #include <assert.h>                            << 
 31                                                << 
 32 #include "G3Division.hh"                           29 #include "G3Division.hh"
 33 #include "G3VolTableEntry.hh"                      30 #include "G3VolTableEntry.hh"
 34 #include "G3toG4MakeSolid.hh"                      31 #include "G3toG4MakeSolid.hh"
 35 #include "G4Para.hh"                               32 #include "G4Para.hh"
 36 #include "G3Pos.hh"                                33 #include "G3Pos.hh"
 37 #include "G4SystemOfUnits.hh"                  << 
 38 #include "G4LogicalVolume.hh"                      34 #include "G4LogicalVolume.hh"
 39 #include "G4VPhysicalVolume.hh"                    35 #include "G4VPhysicalVolume.hh"
 40 #include "G4PVPlacement.hh"                        36 #include "G4PVPlacement.hh"
 41 #include "G4PVReplica.hh"                          37 #include "G4PVReplica.hh"
 42 #ifndef G3G4_NO_REFLECTION                         38 #ifndef G3G4_NO_REFLECTION
 43 #include "G4ReflectionFactory.hh"                  39 #include "G4ReflectionFactory.hh"
 44 #endif                                             40 #endif
 45                                                    41 
 46 G3VolTableEntry* G4CreateVTE(G4String vname, G     42 G3VolTableEntry* G4CreateVTE(G4String vname, G4String shape, G4int nmed,
 47                                G4double Rpar[]     43                                G4double Rpar[], G4int npar);
 48                                                    44 
 49 G3Division::G3Division(G3DivType type, G3VolTa     45 G3Division::G3Division(G3DivType type, G3VolTableEntry* vte, 
 50                 G3VolTableEntry* mvte, G4int n     46                 G3VolTableEntry* mvte, G4int nofDivisions, 
 51     G4int iaxis, G4int nmed, G4double c0, G4do     47     G4int iaxis, G4int nmed, G4double c0, G4double step)
 52   : fType(type),                                   48   : fType(type),
 53     fVTE(vte),                                     49     fVTE(vte),
 54     fMVTE(mvte),                                   50     fMVTE(mvte),
 55     fNofDivisions(nofDivisions),                   51     fNofDivisions(nofDivisions),
 56     fIAxis(iaxis),                                 52     fIAxis(iaxis),
 57     fNmed(nmed),                                   53     fNmed(nmed),
 58     fC0(c0),                                       54     fC0(c0),
 59     fStep(step),                                   55     fStep(step),
 60     fLowRange(0.),                                 56     fLowRange(0.),
 61     fHighRange(0.),                                57     fHighRange(0.),
 62     fWidth(0.),                                    58     fWidth(0.),
 63     fOffset(0.),                                   59     fOffset(0.),
 64     fAxis(kXAxis)                                  60     fAxis(kXAxis)
 65 {                                                  61 {
 66   fVTE->SetHasNegPars(true);                       62   fVTE->SetHasNegPars(true);
 67 }                                                  63 }
 68                                                    64 
 69 G3Division::G3Division(G3VolTableEntry* vte, G     65 G3Division::G3Division(G3VolTableEntry* vte, G3VolTableEntry* mvte,
 70                        const G3Division& divis     66                        const G3Division& division)
 71   : fVTE(vte),                                     67   : fVTE(vte),
 72     fMVTE(mvte)                                    68     fMVTE(mvte)
 73 {                                                  69 {
 74   // only "input" parameters are copied from d     70   // only "input" parameters are copied from division
 75   fType = division.fType;                          71   fType = division.fType;
 76   fNofDivisions = division.fNofDivisions;          72   fNofDivisions = division.fNofDivisions;
 77   fIAxis = division.fIAxis;                        73   fIAxis = division.fIAxis;
 78   fNmed = division.fNmed;                          74   fNmed = division.fNmed;
 79   fC0 = division.fC0;                              75   fC0 = division.fC0;
 80   fStep = division.fStep;                          76   fStep = division.fStep;
 81                                                    77 
 82   // other parameters are set as in standard c     78   // other parameters are set as in standard constructor
 83   fLowRange = 0.;                                  79   fLowRange = 0.;
 84   fHighRange = 0.;                                 80   fHighRange = 0.;
 85   fWidth = 0.;                                     81   fWidth = 0.;
 86   fOffset = 0.;                                    82   fOffset = 0.;
 87   fAxis = kXAxis;                                  83   fAxis = kXAxis;
 88   fVTE->SetHasNegPars(true);                       84   fVTE->SetHasNegPars(true);
 89 }                                                  85 }
 90                                                    86 
 91 G3Division::~G3Division()                          87 G3Division::~G3Division()
 92 {}                                                 88 {}
 93                                                    89 
 94 // public methods                                  90 // public methods
 95                                                    91 
 96 void G3Division::UpdateVTE()                       92 void G3Division::UpdateVTE()
 97 {                                                  93 {
 98   if (fVTE->HasNegPars() && !(fMVTE->HasNegPar     94   if (fVTE->HasNegPars() && !(fMVTE->HasNegPars())) {
 99                                                    95 
100     // set nmed from mother                        96     // set nmed from mother 
101     if (fNmed == 0) fNmed = fMVTE->GetNmed();      97     if (fNmed == 0) fNmed = fMVTE->GetNmed();
102     fVTE->SetNmed(fNmed);                          98     fVTE->SetNmed(fNmed);
103                                                    99    
104     SetRangeAndAxis();                            100     SetRangeAndAxis();
105                                                   101     
106     // create envelope (if necessary)             102     // create envelope (if necessary)
107     // and solid                                  103     // and solid    
108     G3VolTableEntry* envVTE = 0;                  104     G3VolTableEntry* envVTE = 0;
109     if      (fType == kDvn)  envVTE = Dvn();      105     if      (fType == kDvn)  envVTE = Dvn(); 
110     else if (fType == kDvn2) envVTE = Dvn2();     106     else if (fType == kDvn2) envVTE = Dvn2(); 
111     else if (fType == kDvt)  envVTE = Dvt();      107     else if (fType == kDvt)  envVTE = Dvt(); 
112     else if (fType == kDvt2) envVTE = Dvt2();     108     else if (fType == kDvt2) envVTE = Dvt2();
113                                                   109     
114     if (envVTE) {                                 110     if (envVTE) {
115       // reset mother <-> daughter                111       // reset mother <-> daughter
116       fMVTE->ReplaceDaughter(fVTE, envVTE);       112       fMVTE->ReplaceDaughter(fVTE, envVTE);
117       fVTE->ReplaceMother(fMVTE, envVTE);         113       fVTE->ReplaceMother(fMVTE, envVTE);
118       envVTE->AddDaughter(fVTE);                  114       envVTE->AddDaughter(fVTE);
119       envVTE->AddMother(fMVTE);                   115       envVTE->AddMother(fMVTE);
120                                                   116 
121       // replace mother with envelope             117       // replace mother with envelope
122       fMVTE = envVTE;                             118       fMVTE = envVTE;
123     }                                             119     }
124   }                                               120   }  
125 }                                                 121 }
126                                                   122 
127 void G3Division::CreatePVReplica()                123 void G3Division::CreatePVReplica()
128 {                                                 124 {
129   G4String name = fVTE->GetName();                125   G4String name = fVTE->GetName();
130   G4LogicalVolume* lv =  fVTE->GetLV();           126   G4LogicalVolume* lv =  fVTE->GetLV();
131   G4LogicalVolume* mlv = fMVTE->GetLV();          127   G4LogicalVolume* mlv = fMVTE->GetLV();
132                                                   128   
133   G4String shape = fMVTE->GetShape();             129   G4String shape = fMVTE->GetShape();
134   if (shape == "PARA") {                          130   if (shape == "PARA") {
135     // The para volume cannot be replicated us    131     // The para volume cannot be replicated using G4PVReplica.
136     // (Replicating a volume along a cartesian    132     // (Replicating a volume along a cartesian axis means "slicing" it
137     // with slices -perpendicular- to that axi    133     // with slices -perpendicular- to that axis.)
138                                                   134     
139     // position the replicated elements           135     // position the replicated elements    
140     for (G4int i=0; i<fNofDivisions; i++) {       136     for (G4int i=0; i<fNofDivisions; i++) {
141        G4ThreeVector position = G4ThreeVector(    137        G4ThreeVector position = G4ThreeVector(); 
142        position[fIAxis-1] = fLowRange + fWidth    138        position[fIAxis-1] = fLowRange + fWidth/2. + i*fWidth;
143        if (position.y()!=0.)                      139        if (position.y()!=0.) 
144          position.setX(position.y()*((G4Para*)    140          position.setX(position.y()*((G4Para*)lv->GetSolid())->GetTanAlpha());
145                                                   141 
146        #ifndef G3G4_NO_REFLECTION                 142        #ifndef G3G4_NO_REFLECTION
147        G4ReflectionFactory::Instance()            143        G4ReflectionFactory::Instance()
148          ->Place(G4Translate3D(position), name    144          ->Place(G4Translate3D(position), name, lv, mlv, 0, i);
149                                                   145 
150        #else                                      146        #else  
151        new G4PVPlacement(0, position, lv, name    147        new G4PVPlacement(0, position, lv, name, mlv, 0, i);
152                                                   148 
153        #endif                                     149        #endif
154     }                                             150     }
155                                                   151     
156     // G4PVReplica cannot be created              152     // G4PVReplica cannot be created
157     return;                                       153     return;   
158   }                                               154   }     
159                                                   155   
160   #ifdef G3G4DEBUG                                156   #ifdef G3G4DEBUG
161     G4cout << "Create G4PVReplica name " << na    157     G4cout << "Create G4PVReplica name " << name << " logical volume name " 
162      << lv->GetName() << " mother logical volm    158      << lv->GetName() << " mother logical volme name "
163      << mlv->GetName() << " axis " << fAxis <<    159      << mlv->GetName() << " axis " << fAxis << " ndivisions " 
164      << fNofDivisions << " width " << fWidth <    160      << fNofDivisions << " width " << fWidth << " Offset "
165      << fOffset << G4endl;                        161      << fOffset << G4endl;
166   #endif                                          162   #endif
167                                                   163 
168   #ifndef G3G4_NO_REFLECTION                      164   #ifndef G3G4_NO_REFLECTION
169   G4ReflectionFactory::Instance()                 165   G4ReflectionFactory::Instance()
170     ->Replicate(name, lv, mlv, fAxis, fNofDivi    166     ->Replicate(name, lv, mlv, fAxis, fNofDivisions, fWidth, fOffset);
171                                                   167 
172   #else                                           168   #else    
173   new G4PVReplica(name, lv, mlv, fAxis, fNofDi    169   new G4PVReplica(name, lv, mlv, fAxis, fNofDivisions, fWidth, fOffset);
174                                                   170 
175   #endif                                          171   #endif
176 }                                                 172 }
177                                                   173 
178 // private methods                                174 // private methods
179                                                   175 
180 void G3Division::Exception(G4String where, G4S << 176 void G3Division::Exception(G4String where, G4String what) {
181 {                                              << 177   G4Exception("G3Division::" + where + " for " + what + " is not implemented");
182   G4String err_message = "G3Division::" + wher << 
183                        + what + " is not imple << 
184   G4Exception("G3Division::Exception()", "G3to << 
185               FatalException, err_message);    << 
186   return;                                      << 
187 }                                                 178 }  
188                                                   179 
189 void G3Division::SetRangeAndAxis()                180 void G3Division::SetRangeAndAxis()
190 // set fHighRange, fLowRange, fAxis               181 // set fHighRange, fLowRange, fAxis
191 {                                                 182 {
192     G4String shape = fMVTE->GetShape();           183     G4String shape = fMVTE->GetShape();
193     G4double *Rpar = fMVTE->GetRpar();            184     G4double *Rpar = fMVTE->GetRpar();
194                                                   185     
195     switch (fIAxis) {                             186     switch (fIAxis) {
196       case 1: fAxis = kXAxis;                     187       case 1: fAxis = kXAxis;
197               break;                              188               break;
198       case 2: fAxis = kYAxis;                     189       case 2: fAxis = kYAxis;
199               break;                              190               break;
200       case 3: fAxis = kZAxis;                     191       case 3: fAxis = kZAxis;
201               break;                              192               break;
202       default: G4Exception("G3Division::SetRan << 193       default: G4Exception("G3Division: wrong iaxis defenition");
203                             FatalException, "W << 
204     }                                             194     }
205                                                   195 
206     if ( shape == "BOX" ) {                       196     if ( shape == "BOX" ) {
207       fHighRange = Rpar[fIAxis-1]*cm;             197       fHighRange = Rpar[fIAxis-1]*cm;
208       fLowRange = -fHighRange;                    198       fLowRange = -fHighRange;
209     }                                             199     }
210     else if ( shape == "TRD1" ) {                 200     else if ( shape == "TRD1" ) {
211       if (fIAxis == 1){                           201       if (fIAxis == 1){
212         fHighRange = std::max(Rpar[0]*cm, Rpar    202         fHighRange = std::max(Rpar[0]*cm, Rpar[1]*cm);
213       }                                           203       }
214       else if( fIAxis == 2) {                     204       else if( fIAxis == 2) {
215        fHighRange = Rpar[2]*cm;                   205        fHighRange = Rpar[2]*cm;
216       }                                           206       }
217       else if( fIAxis == 3) {                     207       else if( fIAxis == 3) {
218        fHighRange = Rpar[3]*cm;                   208        fHighRange = Rpar[3]*cm;
219       }                                           209       }
220       fLowRange = - fHighRange;                   210       fLowRange = - fHighRange;
221     }                                             211     }
222     else if ( shape == "TRD2" ) {                 212     else if ( shape == "TRD2" ) {
223       if (fIAxis == 1){                           213       if (fIAxis == 1){
224         fHighRange = std::max(Rpar[0]*cm, Rpar    214         fHighRange = std::max(Rpar[0]*cm, Rpar[1]*cm);
225       }                                           215       }
226       else if( fIAxis == 2) {                     216       else if( fIAxis == 2) {
227         fHighRange = std::max(Rpar[2]*cm, Rpar    217         fHighRange = std::max(Rpar[2]*cm, Rpar[3]*cm);
228       }                                           218       }
229       else if( fIAxis == 3) {                     219       else if( fIAxis == 3) {
230        fHighRange = Rpar[4]*cm;                   220        fHighRange = Rpar[4]*cm;
231       }                                           221       }
232     }                                             222     }
233     else if ( shape == "TRAP" ) {                 223     else if ( shape == "TRAP" ) {
234       if ( fIAxis == 3 ) fHighRange = Rpar[0]*    224       if ( fIAxis == 3 ) fHighRange = Rpar[0]*cm;
235       else               fHighRange = 0.;         225       else               fHighRange = 0.;
236       fLowRange = -fHighRange;                    226       fLowRange = -fHighRange;
237     }                                             227     }
238     else if ( shape == "TUBE" ) {                 228     else if ( shape == "TUBE" ) {
239       if (fIAxis == 1){                           229       if (fIAxis == 1){
240         fHighRange = Rpar[1]*cm;                  230         fHighRange = Rpar[1]*cm;
241         fLowRange = Rpar[0]*cm;                   231         fLowRange = Rpar[0]*cm;
242         fAxis = kRho;                             232         fAxis = kRho;
243       }                                           233       }
244       else if( fIAxis == 2) {                     234       else if( fIAxis == 2) {
245         fHighRange = 360.*deg;                    235         fHighRange = 360.*deg;
246         fLowRange = 0.;                           236         fLowRange = 0.;
247         fAxis = kPhi;                             237         fAxis = kPhi;
248       }                                           238       }
249       else if( fIAxis == 3) {                     239       else if( fIAxis == 3) {
250        fHighRange = Rpar[2]*cm;                   240        fHighRange = Rpar[2]*cm;
251        fLowRange = -fHighRange;                   241        fLowRange = -fHighRange;
252       }                                           242       }
253     }                                             243     }
254     else if ( shape == "TUBS" ) {                 244     else if ( shape == "TUBS" ) {
255       if (fIAxis == 1){                           245       if (fIAxis == 1){
256         fHighRange = Rpar[1]*cm;                  246         fHighRange = Rpar[1]*cm;
257         fLowRange = Rpar[0]*cm;                   247         fLowRange = Rpar[0]*cm;
258         fAxis = kRho;                             248         fAxis = kRho;
259       }                                           249       }
260       else if( fIAxis == 2) {                     250       else if( fIAxis == 2) {
261                                                   251 
262        fLowRange = Rpar[3]*deg;                   252        fLowRange = Rpar[3]*deg;
263        fHighRange = Rpar[4]*deg - fLowRange;      253        fHighRange = Rpar[4]*deg - fLowRange;
264        if ( Rpar[4]*deg <= fLowRange )fHighRan    254        if ( Rpar[4]*deg <= fLowRange )fHighRange = fHighRange + 360.*deg;
265        fHighRange = fHighRange + fLowRange;       255        fHighRange = fHighRange + fLowRange;
266        fAxis = kPhi;                              256        fAxis = kPhi;
267       }                                           257       }
268       else if( fIAxis == 3) {                     258       else if( fIAxis == 3) {
269        fHighRange = Rpar[2]*cm;                   259        fHighRange = Rpar[2]*cm;
270        fLowRange = -fHighRange;                   260        fLowRange = -fHighRange;
271       }                                           261       }
272     }                                             262     }
273     else if ( shape == "CONE" ) {                 263     else if ( shape == "CONE" ) {
274       if (fIAxis == 1){                           264       if (fIAxis == 1){
275         fHighRange = std::max(Rpar[2]*cm,Rpar[    265         fHighRange = std::max(Rpar[2]*cm,Rpar[4]*cm);
276         fLowRange = std::max(Rpar[1]*cm,Rpar[3    266         fLowRange = std::max(Rpar[1]*cm,Rpar[3]*cm);
277         fAxis = kRho;                             267         fAxis = kRho;
278       }                                           268       }
279       else if( fIAxis == 2) {                     269       else if( fIAxis == 2) {
280                                                   270 
281        fLowRange = 0.;                            271        fLowRange = 0.;
282        fHighRange = 360.*deg;                     272        fHighRange = 360.*deg;
283        fAxis = kPhi;                              273        fAxis = kPhi;
284       }                                           274       }
285       else if( fIAxis == 3) {                     275       else if( fIAxis == 3) {
286        fHighRange = Rpar[0]*cm;                   276        fHighRange = Rpar[0]*cm;
287        fLowRange = -fHighRange;                   277        fLowRange = -fHighRange;
288       }                                           278       }
289     }                                             279     }
290     else if ( shape == "CONS" ) {                 280     else if ( shape == "CONS" ) {
291       if (fIAxis == 1){                           281       if (fIAxis == 1){
292         fHighRange = std::max(Rpar[2]*cm,Rpar[    282         fHighRange = std::max(Rpar[2]*cm,Rpar[4]*cm);
293         fLowRange = std::max(Rpar[1]*cm,Rpar[3    283         fLowRange = std::max(Rpar[1]*cm,Rpar[3]*cm);
294         fAxis = kRho;                             284         fAxis = kRho;
295       }                                           285       }
296       else if( fIAxis == 2) {                     286       else if( fIAxis == 2) {
297                                                   287 
298        fLowRange = Rpar[5]*deg;                   288        fLowRange = Rpar[5]*deg;
299        fHighRange = Rpar[6]*deg - fLowRange;      289        fHighRange = Rpar[6]*deg - fLowRange;
300        if ( Rpar[6]*deg <= fLowRange )fHighRan    290        if ( Rpar[6]*deg <= fLowRange )fHighRange = fHighRange + 360.*deg;
301        fHighRange = fHighRange + fLowRange;       291        fHighRange = fHighRange + fLowRange;
302        fAxis = kPhi;                              292        fAxis = kPhi;
303       }                                           293       }
304       else if( fIAxis == 3) {                     294       else if( fIAxis == 3) {
305        fHighRange = Rpar[2]*cm;                   295        fHighRange = Rpar[2]*cm;
306        fLowRange = -fHighRange;                   296        fLowRange = -fHighRange;
307       }                                           297       }
308     }                                             298     }
309     else if ( shape == "SPHE" ) {                 299     else if ( shape == "SPHE" ) {
310       if (fIAxis == 1){                           300       if (fIAxis == 1){
311         fHighRange = Rpar[1]*cm;                  301         fHighRange = Rpar[1]*cm;
312         fLowRange = Rpar[0]*cm;                   302         fLowRange = Rpar[0]*cm;
313         fAxis = kRho;                             303         fAxis = kRho;
314       }                                           304       }
315       else if( fIAxis == 2) {                     305       else if( fIAxis == 2) {
316        fLowRange = std::min(Rpar[2]*deg,Rpar[3    306        fLowRange = std::min(Rpar[2]*deg,Rpar[3]*deg);
317        fHighRange = std::max(Rpar[2]*deg,Rpar[    307        fHighRange = std::max(Rpar[2]*deg,Rpar[3]*deg);
318        fAxis = kPhi;                              308        fAxis = kPhi;
319       }                                           309       }
320       else if( fIAxis == 3) {                     310       else if( fIAxis == 3) {
321        fLowRange = std::min(Rpar[4]*deg,Rpar[5    311        fLowRange = std::min(Rpar[4]*deg,Rpar[5]*deg);
322        fHighRange = std::max(Rpar[4]*deg,Rpar[    312        fHighRange = std::max(Rpar[4]*deg,Rpar[5]*deg);
323        fAxis = kPhi; // ??????                    313        fAxis = kPhi; // ?????? 
324       }                                           314       }
325     }                                             315     }
326     else if ( shape == "PARA" ) {                 316     else if ( shape == "PARA" ) {
327       fHighRange = Rpar[fIAxis-1]*cm;             317       fHighRange = Rpar[fIAxis-1]*cm;
328       fLowRange = -fHighRange;                    318       fLowRange = -fHighRange;
329     }                                             319     }
330     else if ( shape == "PGON" ) {                 320     else if ( shape == "PGON" ) {
331         G4int i;                                  321         G4int i;
332         G4int nz = G4int(Rpar[3]);                322         G4int nz = G4int(Rpar[3]);
333                                                   323 
334         G4double pPhi1 = Rpar[0]*deg;             324         G4double pPhi1 = Rpar[0]*deg;
335         G4double dPhi  = Rpar[1]*deg;             325         G4double dPhi  = Rpar[1]*deg;
336                                                   326     
337         G4double *DzArray = new G4double[nz];     327         G4double *DzArray = new G4double[nz];
338         G4double *Rmax    = new G4double[nz];     328         G4double *Rmax    = new G4double[nz];
339         G4double *Rmin    = new G4double[nz];     329         G4double *Rmin    = new G4double[nz];
340         G4double rangehi[3], rangelo[3];          330         G4double rangehi[3], rangelo[3];
341         rangehi[0] = -kInfinity  ;                331         rangehi[0] = -kInfinity  ;
342         rangelo[0] =  kInfinity ;                 332         rangelo[0] =  kInfinity ;
343         rangehi[2] = -kInfinity ;                 333         rangehi[2] = -kInfinity ;
344         rangelo[2] =  kInfinity ;                 334         rangelo[2] =  kInfinity ;
345                                                   335 
346         for(i=0; i<nz; i++)                       336         for(i=0; i<nz; i++) 
347         {                                         337         {
348             G4int i4=3*i+4;                       338             G4int i4=3*i+4;
349             G4int i5=i4+1;                        339             G4int i5=i4+1;
350             G4int i6=i4+2;                        340             G4int i6=i4+2;
351                                                   341             
352             DzArray[i] = Rpar[i4]*cm;             342             DzArray[i] = Rpar[i4]*cm;
353             Rmin[i] = Rpar[i5]*cm;                343             Rmin[i] = Rpar[i5]*cm;
354             Rmax[i] = Rpar[i6]*cm;                344             Rmax[i] = Rpar[i6]*cm;
355             rangelo[0] = std::min(rangelo[0],     345             rangelo[0] = std::min(rangelo[0], Rmin[i]);
356             rangehi[0] = std::max(rangehi[0],     346             rangehi[0] = std::max(rangehi[0], Rmax[i]);
357             rangelo[2] = std::min(rangelo[2],     347             rangelo[2] = std::min(rangelo[2], DzArray[i]);
358             rangehi[2] = std::max(rangehi[2],     348             rangehi[2] = std::max(rangehi[2], DzArray[i]);
359         }                                         349         }
360         for (i=0;i<nz;i++){                       350         for (i=0;i<nz;i++){
361             assert(Rmin[i]>=0 && Rmax[i]>=Rmin    351             assert(Rmin[i]>=0 && Rmax[i]>=Rmin[i]);
362         }                                         352         }
363         rangehi[1] = pPhi1 + dPhi;                353         rangehi[1] = pPhi1 + dPhi;
364         rangelo[1] = pPhi1;                       354         rangelo[1] = pPhi1;
365         fHighRange = rangehi[fIAxis-1];           355         fHighRange = rangehi[fIAxis-1];
366         fLowRange = rangelo[fIAxis-1];            356         fLowRange = rangelo[fIAxis-1];
367         if      (fIAxis == 1)fAxis = kRho;        357         if      (fIAxis == 1)fAxis = kRho;
368         else if (fIAxis == 2)fAxis = kPhi;        358         else if (fIAxis == 2)fAxis = kPhi;
369         else if (fIAxis == 3)fAxis = kZAxis;      359         else if (fIAxis == 3)fAxis = kZAxis;
370                                                   360 
371         delete [] DzArray;                        361         delete [] DzArray;
372         delete [] Rmin;                           362         delete [] Rmin;
373         delete [] Rmax;                           363         delete [] Rmax;
374                                                   364 
375     }                                             365     }
376     else if ( shape == "PCON" ) {                 366     else if ( shape == "PCON" ) {
377                                                   367 
378         G4int i;                                  368         G4int i;
379         G4double pPhi1 = Rpar[0]*deg;             369         G4double pPhi1 = Rpar[0]*deg;
380         G4double dPhi  = Rpar[1]*deg;             370         G4double dPhi  = Rpar[1]*deg;    
381         G4int nz = G4int(Rpar[2]);                371         G4int nz = G4int(Rpar[2]);
382                                                   372     
383         G4double *DzArray = new G4double[nz];     373         G4double *DzArray = new G4double[nz];
384         G4double *Rmax    = new G4double[nz];     374         G4double *Rmax    = new G4double[nz];
385         G4double *Rmin    = new G4double[nz];     375         G4double *Rmin    = new G4double[nz];
386         G4double rangehi[3],rangelo[3];           376         G4double rangehi[3],rangelo[3];
387                                                   377 
388         rangehi[0] = -kInfinity  ;                378         rangehi[0] = -kInfinity  ;
389         rangelo[0] =  kInfinity ;                 379         rangelo[0] =  kInfinity ;
390         rangehi[2] = -kInfinity ;                 380         rangehi[2] = -kInfinity ;
391         rangelo[2] =  kInfinity ;                 381         rangelo[2] =  kInfinity ;
392                                                   382         
393         for(i=0; i<nz; i++){                      383         for(i=0; i<nz; i++){
394             G4int i4=3*i+3;                       384             G4int i4=3*i+3;
395             G4int i5=i4+1;                        385             G4int i5=i4+1;
396             G4int i6=i4+2;                        386             G4int i6=i4+2;
397                                                   387             
398             DzArray[i] = Rpar[i4]*cm;             388             DzArray[i] = Rpar[i4]*cm;
399             Rmin[i] = Rpar[i5]*cm;                389             Rmin[i] = Rpar[i5]*cm;
400             Rmax[i] = Rpar[i6]*cm;                390             Rmax[i] = Rpar[i6]*cm;
401             rangelo[0] = std::min(rangelo[0],     391             rangelo[0] = std::min(rangelo[0], Rmin[i]);
402             rangehi[0] = std::max(rangehi[0],     392             rangehi[0] = std::max(rangehi[0], Rmax[i]);
403             rangelo[2] = std::min(rangelo[2],     393             rangelo[2] = std::min(rangelo[2], DzArray[i]);
404             rangehi[2] = std::max(rangehi[2],     394             rangehi[2] = std::max(rangehi[2], DzArray[i]);
405         }                                         395         }
406         for (i=0;i<nz;i++){                       396         for (i=0;i<nz;i++){
407             assert(Rmin[i]>=0 && Rmax[i]>=Rmin    397             assert(Rmin[i]>=0 && Rmax[i]>=Rmin[i]);
408         }                                         398         }
409         rangehi[1] = pPhi1 + dPhi;                399         rangehi[1] = pPhi1 + dPhi;
410         rangelo[1] = pPhi1;                       400         rangelo[1] = pPhi1;
411         fHighRange = rangehi[fIAxis-1];           401         fHighRange = rangehi[fIAxis-1];
412         fLowRange = rangelo[fIAxis-1];            402         fLowRange = rangelo[fIAxis-1];
413         if      (fIAxis == 1)fAxis = kRho;        403         if      (fIAxis == 1)fAxis = kRho;
414         else if (fIAxis == 2)fAxis = kPhi;        404         else if (fIAxis == 2)fAxis = kPhi;
415         else if (fIAxis == 3)fAxis = kZAxis;      405         else if (fIAxis == 3)fAxis = kZAxis;
416                                                   406 
417                                                   407 
418         delete [] DzArray;                        408         delete [] DzArray;
419         delete [] Rmin;                           409         delete [] Rmin;
420         delete [] Rmax;                           410         delete [] Rmax;
421     }                                             411     }
422     else if ( shape == "ELTU" ||  shape == "HY    412     else if ( shape == "ELTU" ||  shape == "HYPE" || shape == "GTRA" ||
423          shape == "CTUB") {                       413          shape == "CTUB") {
424        Exception("SetRangeAndAxis", shape);       414        Exception("SetRangeAndAxis", shape);
425     }                                             415     }
426     else {                                        416     else {
427        Exception("SetRangeAndAxis", "Unknown s    417        Exception("SetRangeAndAxis", "Unknown shape" + shape);
428     }                                             418     }  
429                                                   419 
430     // verbose                                    420     // verbose
431     #ifdef G3G4DEBUG                              421     #ifdef G3G4DEBUG
432       G4cout << "Shape " << shape << " SetRang    422       G4cout << "Shape " << shape << " SetRangeAndAxis: " 
433        << fLowRange << " " << fHighRange << "     423        << fLowRange << " " << fHighRange << " " << fAxis << G4endl;
434     #endif                                        424     #endif
435 }                                                 425 }
436                                                   426 
437 G3VolTableEntry* G3Division::CreateEnvelope(G4    427 G3VolTableEntry* G3Division::CreateEnvelope(G4String shape, G4double hi, 
438                                G4double lo, G4    428                                G4double lo, G4double par[], G4int npar)
439 // create new VTE with G3Pos corresponding to     429 // create new VTE with G3Pos corresponding to the
440 // envelope of divided volume                     430 // envelope of divided volume
441 {                                                 431 {
442     // verbose                                    432     // verbose
443     // G4cout << "  G3Division::CreateEnvelope    433     // G4cout << "  G3Division::CreateEnvelope " << "fIAaxis= " << fIAxis
444     //        << " hi= " << hi                    434     //        << " hi= " << hi
445     //        << " lo= " << lo                    435     //        << " lo= " << lo
446     //        << G4endl;                          436     //        << G4endl;
447                                                   437 
448     G4double *Rpar = new G4double[npar+2];        438     G4double *Rpar = new G4double[npar+2];
449     for (G4int i=0; i<npar; ++i){ Rpar[i] = pa    439     for (G4int i=0; i<npar; ++i){ Rpar[i] = par[i];}
450     G4double pos[3] = {0.,0.,0.};                 440     G4double pos[3] = {0.,0.,0.};
451                                                   441   
452     if ( shape == "BOX" ) {                       442     if ( shape == "BOX" ) {
453       Rpar[fIAxis-1] = (hi - lo)/2./cm;           443       Rpar[fIAxis-1] = (hi - lo)/2./cm;
454       pos [fIAxis-1] = (hi + lo)/2.;              444       pos [fIAxis-1] = (hi + lo)/2.;
455     }                                             445     }
456     else if ( shape == "TRD1" ) {                 446     else if ( shape == "TRD1" ) {
457       if ( fIAxis == 1 || fIAxis == 2  ) {        447       if ( fIAxis == 1 || fIAxis == 2  ) {
458         Exception("CreateEnvelope","TRD1-x,y")    448         Exception("CreateEnvelope","TRD1-x,y");
459       }                                           449       }
460       else if ( fIAxis == 3 ) {                   450       else if ( fIAxis == 3 ) {
461   // x = x1 + (c-z1)(x2 -x1)/(z2-z1)              451   // x = x1 + (c-z1)(x2 -x1)/(z2-z1)
462   G4double tn, x1, z1;                            452   G4double tn, x1, z1;
463         tn = (Rpar[1] - Rpar[0])/(2.* Rpar[3])    453         tn = (Rpar[1] - Rpar[0])/(2.* Rpar[3]); 
464         x1 = Rpar[0]; z1 = -Rpar[3];              454         x1 = Rpar[0]; z1 = -Rpar[3];
465         Rpar[0] = x1 + tn * (lo/cm - z1);         455         Rpar[0] = x1 + tn * (lo/cm - z1);
466         Rpar[1] = x1 + tn * (hi/cm - z1);         456         Rpar[1] = x1 + tn * (hi/cm - z1);
467         Rpar[3] = (hi - lo)/2./cm;                457         Rpar[3] = (hi - lo)/2./cm;
468         pos[2]  = (hi + lo)/2.;                   458         pos[2]  = (hi + lo)/2.;
469       }                                           459       }
470     }                                             460     }
471     else if ( shape == "TRD2" ) {                 461     else if ( shape == "TRD2" ) {
472       if ( fIAxis == 1 || fIAxis == 2) {          462       if ( fIAxis == 1 || fIAxis == 2) {
473         Exception("CreateEnvelope","TRD2-x,y")    463         Exception("CreateEnvelope","TRD2-x,y");
474       }                                           464       }
475       else if ( fIAxis == 3 ) {                   465       else if ( fIAxis == 3 ) {
476   // x = x1 + (c-z1)(x2 -x1)/(z2-z1)              466   // x = x1 + (c-z1)(x2 -x1)/(z2-z1)
477   // y = y1 + (c-z1)(y2 -y1)/(z2-z1)              467   // y = y1 + (c-z1)(y2 -y1)/(z2-z1)
478   G4double tn1, tn2, x1, y1, z1;                  468   G4double tn1, tn2, x1, y1, z1;
479         tn1 = (Rpar[1] - Rpar[0])/(2.* Rpar[4]    469         tn1 = (Rpar[1] - Rpar[0])/(2.* Rpar[4]); 
480         tn2 = (Rpar[3] - Rpar[2])/(2.* Rpar[4]    470         tn2 = (Rpar[3] - Rpar[2])/(2.* Rpar[4]); 
481         x1 = Rpar[0]; y1 = Rpar[2]; z1 = -Rpar    471         x1 = Rpar[0]; y1 = Rpar[2]; z1 = -Rpar[3];
482         Rpar[0] = x1 + tn1 * (lo/cm - z1);        472         Rpar[0] = x1 + tn1 * (lo/cm - z1);
483         Rpar[1] = x1 + tn1 * (hi/cm - z1);        473         Rpar[1] = x1 + tn1 * (hi/cm - z1);
484         Rpar[2] = y1 + tn2 * (lo/cm - z1);        474         Rpar[2] = y1 + tn2 * (lo/cm - z1);
485         Rpar[3] = y1 + tn2 * (hi/cm - z1);        475         Rpar[3] = y1 + tn2 * (hi/cm - z1);
486         Rpar[4] = (hi - lo)/2./cm;                476         Rpar[4] = (hi - lo)/2./cm;
487         pos[2]  = (hi + lo)/2.;                   477         pos[2]  = (hi + lo)/2.;
488       }                                           478       }
489     }                                             479     }
490     else if ( shape == "TRAP" ) {                 480     else if ( shape == "TRAP" ) {
491       Exception("CreateEnvelope","TRAP-x,y,z")    481       Exception("CreateEnvelope","TRAP-x,y,z");
492     }                                             482     }
493     else if ( shape == "TUBE" ) {                 483     else if ( shape == "TUBE" ) {
494       if ( fIAxis == 1 ) {                        484       if ( fIAxis == 1 ) {
495         Rpar[0] = lo/cm;                          485         Rpar[0] = lo/cm;
496         Rpar[1] = hi/cm;                          486         Rpar[1] = hi/cm;
497       }                                           487       }
498       else if ( fIAxis == 2 ) {                   488       else if ( fIAxis == 2 ) {
499         Rpar[3] = lo/deg;                         489         Rpar[3] = lo/deg;
500         Rpar[4] = hi/deg;                         490         Rpar[4] = hi/deg;
501         npar = npar + 2;                          491         npar = npar + 2;
502         shape = "TUBS";                           492         shape = "TUBS";
503       }                                           493       }
504       else if ( fIAxis == 3 ) {                   494       else if ( fIAxis == 3 ) {
505         Rpar[2] = (hi - lo)/2./cm;                495         Rpar[2] = (hi - lo)/2./cm;
506         pos [2] = (hi + lo)/2.;                   496         pos [2] = (hi + lo)/2.;
507       }                                           497       }
508     }                                             498     }
509     else if ( shape == "TUBS" ) {                 499     else if ( shape == "TUBS" ) {
510       if ( fIAxis == 1 ) {                        500       if ( fIAxis == 1 ) {
511         Rpar[0] = lo/cm;                          501         Rpar[0] = lo/cm;
512         Rpar[1] = hi/cm;                          502         Rpar[1] = hi/cm;
513       }                                           503       }
514       else if ( fIAxis == 2 ) {                   504       else if ( fIAxis == 2 ) {
515         Rpar[3] = lo/deg;                         505         Rpar[3] = lo/deg;
516         Rpar[4] = hi/deg;                         506         Rpar[4] = hi/deg;
517       }                                           507       }
518       else if ( fIAxis == 3 ) {                   508       else if ( fIAxis == 3 ) {
519         Rpar[2] = (hi - lo)/2./cm;                509         Rpar[2] = (hi - lo)/2./cm;
520         pos [2] = (hi + lo)/2.;                   510         pos [2] = (hi + lo)/2.;
521       }                                           511       }
522     }                                             512     }
523     else if ( shape == "CONE" ) {                 513     else if ( shape == "CONE" ) {
524       if ( fIAxis == 1) {                         514       if ( fIAxis == 1) {
525         Exception("CreateEnvelope","CONE-x,z")    515         Exception("CreateEnvelope","CONE-x,z");
526       }                                           516       }
527       else if ( fIAxis == 2 ) {                   517       else if ( fIAxis == 2 ) {
528         Rpar[5] = lo/deg;                         518         Rpar[5] = lo/deg;
529         Rpar[6] = hi/deg;                         519         Rpar[6] = hi/deg;
530         npar = npar + 2;                          520         npar = npar + 2;
531         shape = "CONS";                           521         shape = "CONS";
532       }                                           522       }
533       else if ( fIAxis == 3 ) {                   523       else if ( fIAxis == 3 ) {
534         G4double tn1, tn2, rmin, rmax, z1;        524         G4double tn1, tn2, rmin, rmax, z1;
535         tn1 = (Rpar[3] - Rpar[1])/(2.* Rpar[0]    525         tn1 = (Rpar[3] - Rpar[1])/(2.* Rpar[0]); 
536         tn2 = (Rpar[4] - Rpar[2])/(2.* Rpar[0]    526         tn2 = (Rpar[4] - Rpar[2])/(2.* Rpar[0]); 
537         rmin = Rpar[1]; rmax = Rpar[2]; z1 = -    527         rmin = Rpar[1]; rmax = Rpar[2]; z1 = -Rpar[0];
538         Rpar[1] = rmin + tn1 * (lo/cm - z1);      528         Rpar[1] = rmin + tn1 * (lo/cm - z1);
539         Rpar[3] = rmin + tn1 * (hi/cm - z1);      529         Rpar[3] = rmin + tn1 * (hi/cm - z1);
540         Rpar[2] = rmax + tn2 * (lo/cm - z1);      530         Rpar[2] = rmax + tn2 * (lo/cm - z1);
541         Rpar[4] = rmax + tn2 * (hi/cm - z1);      531         Rpar[4] = rmax + tn2 * (hi/cm - z1);
542         Rpar[0] = (hi - lo)/2./cm;                532         Rpar[0] = (hi - lo)/2./cm;
543         pos[2]  = (hi + lo)/2.;                   533         pos[2]  = (hi + lo)/2.;
544       }                                           534       }
545     }                                             535     }
546     else if ( shape == "CONS" ) {                 536     else if ( shape == "CONS" ) {
547       if ( fIAxis == 1 ) {                        537       if ( fIAxis == 1 ) {
548         Exception("CreateEnvelope","CONS-x");     538         Exception("CreateEnvelope","CONS-x");
549       }                                           539       }
550       else if ( fIAxis == 2 ) {                   540       else if ( fIAxis == 2 ) {
551         Rpar[5] = lo/deg;                         541         Rpar[5] = lo/deg;
552         Rpar[6] = hi/deg;                         542         Rpar[6] = hi/deg;
553       }                                           543       }
554       else if ( fIAxis == 3 ) {                   544       else if ( fIAxis == 3 ) {
555         G4double tn1, tn2, rmin, rmax, z1;        545         G4double tn1, tn2, rmin, rmax, z1;
556         tn1 = (Rpar[3] - Rpar[1])/(2.* Rpar[0]    546         tn1 = (Rpar[3] - Rpar[1])/(2.* Rpar[0]); 
557         tn2 = (Rpar[4] - Rpar[2])/(2.* Rpar[0]    547         tn2 = (Rpar[4] - Rpar[2])/(2.* Rpar[0]); 
558         rmin = Rpar[1]; rmax = Rpar[2]; z1 = -    548         rmin = Rpar[1]; rmax = Rpar[2]; z1 = -Rpar[0];
559         Rpar[1] = rmin + tn1 * (lo/cm - z1);      549         Rpar[1] = rmin + tn1 * (lo/cm - z1);
560         Rpar[3] = rmin + tn1 * (hi/cm - z1);      550         Rpar[3] = rmin + tn1 * (hi/cm - z1);
561         Rpar[2] = rmax + tn2 * (lo/cm - z1);      551         Rpar[2] = rmax + tn2 * (lo/cm - z1);
562         Rpar[4] = rmax + tn2 * (hi/cm - z1);      552         Rpar[4] = rmax + tn2 * (hi/cm - z1);
563         Rpar[0] = (hi - lo)/2./cm;                553         Rpar[0] = (hi - lo)/2./cm;
564         pos[2]  = (hi + lo)/2.;                   554         pos[2]  = (hi + lo)/2.;
565       }                                           555       }
566     }                                             556     }
567     else if ( shape == "SPHE" ) {                 557     else if ( shape == "SPHE" ) {
568       Exception("CreateEnvelope","SPHE-x,y,z")    558       Exception("CreateEnvelope","SPHE-x,y,z");                
569     }                                             559     }
570     else if ( shape == "PARA" ) {                 560     else if ( shape == "PARA" ) {
571       Exception("CreateEnvelope","PARA-x,y,z")    561       Exception("CreateEnvelope","PARA-x,y,z");
572     }                                             562     }
573     else if ( shape == "PGON" ) {                 563     else if ( shape == "PGON" ) {
574       if ( fIAxis == 2) {                         564       if ( fIAxis == 2) {
575   Rpar[0] = lo/deg;                               565   Rpar[0] = lo/deg;
576   Rpar[1] = hi/deg;                               566   Rpar[1] = hi/deg;
577   // rotm = ???                                   567   // rotm = ???
578       }                                           568       }
579       else {                                      569       else {
580         Exception("CreateEnvelope","PGON-x,z")    570         Exception("CreateEnvelope","PGON-x,z");
581       }                                           571       }
582     }                                             572     }
583     else if ( shape == "PCON" ) {                 573     else if ( shape == "PCON" ) {
584       if ( fIAxis == 2) {                         574       if ( fIAxis == 2) {
585   Rpar[0] = lo/deg;                               575   Rpar[0] = lo/deg;
586   Rpar[1] = hi/deg;                               576   Rpar[1] = hi/deg;
587   // rotm = ???                                   577   // rotm = ???
588       }                                           578       }
589       else {                                      579       else {
590         Exception("CreateEnvelope","PCON-x,z")    580         Exception("CreateEnvelope","PCON-x,z");
591       }                                           581       }
592     }                                             582     }
593     else {                                        583     else {
594        Exception("CreateEnvelope", "Unknown sh    584        Exception("CreateEnvelope", "Unknown shape" + shape);
595     }                                             585     }  
596                                                   586 
597     // create new VTE corresponding to envelop    587     // create new VTE corresponding to envelope
598     G4String envName = fVTE->GetName() + "_ENV    588     G4String envName = fVTE->GetName() + "_ENV"; 
599     G3VolTableEntry* envVTE                       589     G3VolTableEntry* envVTE 
600       = G4CreateVTE(envName, shape, fNmed, Rpa    590       = G4CreateVTE(envName, shape, fNmed, Rpar, npar);
601                                                   591 
602     // create a G3Pos object and add it to env    592     // create a G3Pos object and add it to envVTE
603     G4String motherName = fMVTE->GetMasterClon    593     G4String motherName = fMVTE->GetMasterClone()->GetName();
604     G4ThreeVector* offset = new G4ThreeVector(    594     G4ThreeVector* offset = new G4ThreeVector(pos[0],pos[1],pos[2]);    
605     G4String only = "ONLY";                       595     G4String only = "ONLY";
606     G3Pos* aG3Pos = new G3Pos(motherName, 1, o    596     G3Pos* aG3Pos = new G3Pos(motherName, 1, offset, 0, only);              
607     envVTE->AddG3Pos(aG3Pos);                     597     envVTE->AddG3Pos(aG3Pos);
608                                                   598 
609     delete [] Rpar;                               599     delete [] Rpar; 
610                                                   600 
611     return envVTE;                                601     return envVTE;
612 }                                                 602 }
613                                                   603 
614 void G3Division::CreateSolid(G4String shape, G    604 void G3Division::CreateSolid(G4String shape, G4double par[], G4int npar)
615 // create the solid corresponding to divided v    605 // create the solid corresponding to divided volume
616 // and set the fOffset for replica                606 // and set the fOffset for replica
617 {                                                 607 {
618     G4double *Rpar = new G4double[npar+2];        608     G4double *Rpar = new G4double[npar+2];
619     for (G4int i=0; i<npar; ++i){ Rpar[i] = pa    609     for (G4int i=0; i<npar; ++i){ Rpar[i] = par[i];}
620                                                   610 
621     // verbose                                    611     // verbose
622     // G4cout << "G3Division::CreateSolid volu    612     // G4cout << "G3Division::CreateSolid volume before: " 
623     //        << fVTE->GetName() << " " << sha    613     //        << fVTE->GetName() << " " << shape << G4endl;    
624     // G4cout << " npar,Rpar: " << npar;          614     // G4cout << " npar,Rpar: " << npar;
625     // for (G4int ii = 0; ii < npar; ++ii) G4c    615     // for (G4int ii = 0; ii < npar; ++ii) G4cout << " " << Rpar[ii];
626     // G4cout << G4endl;                          616     // G4cout << G4endl;
627                                                   617   
628     if ( shape == "BOX" ) {                       618     if ( shape == "BOX" ) {
629       if      ( fIAxis == 1 ) Rpar[0] = fWidth    619       if      ( fIAxis == 1 ) Rpar[0] = fWidth/2./cm;
630       else if ( fIAxis == 2 ) Rpar[1] = fWidth    620       else if ( fIAxis == 2 ) Rpar[1] = fWidth/2./cm; 
631       else if ( fIAxis == 3 ) Rpar[2] = fWidth    621       else if ( fIAxis == 3 ) Rpar[2] = fWidth/2./cm; 
632     }                                             622     }
633     else if ( shape == "TRD1" ) {                 623     else if ( shape == "TRD1" ) {
634       if ( fIAxis == 1 || fIAxis == 2 ) {         624       if ( fIAxis == 1 || fIAxis == 2 ) {
635         Exception("CreateSolid", "TRD1-x,y");     625         Exception("CreateSolid", "TRD1-x,y");
636       }                                           626       }
637       else if ( fIAxis == 3 ) {                   627       else if ( fIAxis == 3 ) {
638          Rpar[3] = fWidth/2./cm;                  628          Rpar[3] = fWidth/2./cm; 
639       }                                           629       }
640     }                                             630     }
641     else if ( shape == "TRD2" ) {                 631     else if ( shape == "TRD2" ) {
642       if ( fIAxis == 1 || fIAxis == 2 ) {         632       if ( fIAxis == 1 || fIAxis == 2 ) {
643         Exception("CreateSolid", "TRD2-x,y");     633         Exception("CreateSolid", "TRD2-x,y");
644       }                                           634       }
645       else if ( fIAxis == 3 ) {                   635       else if ( fIAxis == 3 ) {
646          Rpar[4] =  fWidth/2./cm;                 636          Rpar[4] =  fWidth/2./cm; 
647       }                                           637       }
648     }                                             638     }
649     else if ( shape == "TRAP" ) {                 639     else if ( shape == "TRAP" ) {
650       if ( fIAxis == 1 || fIAxis == 2) {          640       if ( fIAxis == 1 || fIAxis == 2) {
651         Exception("CreateSolid", "TRAP-x,y");     641         Exception("CreateSolid", "TRAP-x,y");
652       }                                           642       }
653       else if ( fIAxis == 3 ) {                   643       else if ( fIAxis == 3 ) {
654          Rpar[0] =  fWidth/2./cm;                 644          Rpar[0] =  fWidth/2./cm; 
655       }                                           645       }
656     }                                             646     }
657     else if ( shape == "TUBE" ) {                 647     else if ( shape == "TUBE" ) {
658       if ( fIAxis == 1 ) {                        648       if ( fIAxis == 1 ) {
659          Rpar[1] = Rpar[0] + fWidth/cm;           649          Rpar[1] = Rpar[0] + fWidth/cm;
660          fOffset = Rpar[0]*cm;                    650          fOffset = Rpar[0]*cm;
661       }                                           651       }
662       else if ( fIAxis == 2 ) {                   652       else if ( fIAxis == 2 ) {
663          Rpar[3] = 0.;                            653          Rpar[3] = 0.; 
664          Rpar[4] = fWidth/deg;                    654          Rpar[4] = fWidth/deg; 
665          shape = "TUBS";                          655          shape = "TUBS";
666          npar = npar + 2;                         656          npar = npar + 2;
667       }                                           657       }
668       else if ( fIAxis == 3 ) {                   658       else if ( fIAxis == 3 ) {
669          Rpar[2] = fWidth/2./cm;                  659          Rpar[2] = fWidth/2./cm; 
670       }                                           660       }
671     }                                             661     }
672     else if ( shape == "TUBS" ) {                 662     else if ( shape == "TUBS" ) {
673       if ( fIAxis == 1 ) {                        663       if ( fIAxis == 1 ) {
674         Rpar[1] = Rpar[0] + fWidth/cm;            664         Rpar[1] = Rpar[0] + fWidth/cm;
675         fOffset = Rpar[0]*cm;                     665         fOffset = Rpar[0]*cm;
676       }                                           666       }
677       else if ( fIAxis == 2 ) {                   667       else if ( fIAxis == 2 ) {
678          fOffset = Rpar[3]*deg;                   668          fOffset = Rpar[3]*deg; 
679          Rpar[3] = 0.;                            669          Rpar[3] = 0.;
680          Rpar[4] =  fWidth/deg;                   670          Rpar[4] =  fWidth/deg;
681       }                                           671       }
682       else if ( fIAxis == 3 ) {                   672       else if ( fIAxis == 3 ) {
683          Rpar[2] = fWidth/2./cm;                  673          Rpar[2] = fWidth/2./cm; 
684       }                                           674       }
685     }                                             675     }
686     else if ( shape == "CONE" ) {                 676     else if ( shape == "CONE" ) {
687       if ( fIAxis == 1 ) {                        677       if ( fIAxis == 1 ) {
688         Exception("CreateSolid", "CONE-x");       678         Exception("CreateSolid", "CONE-x"); 
689       }                                           679       }
690       else if ( fIAxis == 2 ) {                   680       else if ( fIAxis == 2 ) {
691          Rpar[5] = 0.;                            681          Rpar[5] = 0.;
692          Rpar[6] = fWidth/deg;                    682          Rpar[6] = fWidth/deg;
693          shape = "CONS";                          683          shape = "CONS";
694          npar = npar + 2;                         684          npar = npar + 2;
695       }                                           685       }
696       else if ( fIAxis == 3 ) {                   686       else if ( fIAxis == 3 ) {
697          Rpar[0] = fWidth/2./cm;                  687          Rpar[0] = fWidth/2./cm; 
698       }                                           688       }
699     }                                             689     }
700     else if ( shape == "CONS" ) {                 690     else if ( shape == "CONS" ) {
701       if ( fIAxis == 1 ) {                        691       if ( fIAxis == 1 ) {
702         Exception("CreateSolid", "CONS-x");       692         Exception("CreateSolid", "CONS-x"); 
703       }                                           693       }
704       else if ( fIAxis == 2 ) {                   694       else if ( fIAxis == 2 ) {
705          fOffset = Rpar[5]*deg;                   695          fOffset = Rpar[5]*deg;
706          Rpar[5] = 0.;                            696          Rpar[5] = 0.;
707          Rpar[6] = fWidth/deg;                    697          Rpar[6] = fWidth/deg;
708       }                                           698       }
709       else if ( fIAxis == 3 ) {                   699       else if ( fIAxis == 3 ) {
710          Rpar[0] = fWidth/2./cm;                  700          Rpar[0] = fWidth/2./cm; 
711       }                                           701       }
712     }                                             702     }
713     else if (shape == "PARA") {                   703     else if (shape == "PARA") {
714       if      ( fIAxis == 1 ) {                   704       if      ( fIAxis == 1 ) {
715          Rpar[0] = fWidth/2./cm;                  705          Rpar[0] = fWidth/2./cm;
716       }                                           706       }  
717       else if ( Rpar[4] == 0. && Rpar[5] == 0.    707       else if ( Rpar[4] == 0. && Rpar[5] == 0. ) {
718          // only special case for axis 2,3 is     708          // only special case for axis 2,3 is supported
719         if ( fIAxis == 2 ) {                      709         if ( fIAxis == 2 ) {
720           Rpar[1] = fWidth/2./cm;                 710           Rpar[1] = fWidth/2./cm;
721   }                                               711   }  
722     else if ( fIAxis == 3) {                      712     else if ( fIAxis == 3) {
723           Rpar[2] = fWidth/2./cm;                 713           Rpar[2] = fWidth/2./cm;
724   }                                               714   }
725       }                                           715       }   
726       else                                        716       else    
727          Exception("CreateSolid", shape);         717          Exception("CreateSolid", shape);
728     }                                             718     }  
729     else if (shape == "SPHE") {                   719     else if (shape == "SPHE") {
730       Exception("CreateSolid", shape);            720       Exception("CreateSolid", shape);
731     }                                             721     }
732     else if ( shape == "PGON" ) {                 722     else if ( shape == "PGON" ) {
733       if ( fIAxis == 2 ) {                        723       if ( fIAxis == 2 ) {
734          fOffset = Rpar[0]*deg;                   724          fOffset = Rpar[0]*deg;
735          Rpar[0] = 0.;                            725          Rpar[0] = 0.;
736          Rpar[1] = fWidth/deg;                    726          Rpar[1] = fWidth/deg;
737          Rpar[2] = 1.;                            727          Rpar[2] = 1.;
738       }                                           728       }
739       else                                        729       else
740        Exception("CreateSolid", shape);           730        Exception("CreateSolid", shape);
741     }                                             731     }
742     else if ( shape == "PCON" ) {                 732     else if ( shape == "PCON" ) {
743       if ( fIAxis == 2 ) {                        733       if ( fIAxis == 2 ) {
744          fOffset = Rpar[0]*deg;                   734          fOffset = Rpar[0]*deg;
745          Rpar[0] = 0.;                            735          Rpar[0] = 0.;
746          Rpar[1] = fWidth/deg;                    736          Rpar[1] = fWidth/deg;
747       }                                           737       }
748       else {                                      738       else {
749         Exception("CreateSolid", shape);          739         Exception("CreateSolid", shape);
750       }                                           740       } 
751     }                                             741     }
752     else {                                        742     else {
753        Exception("CreateSolid", "Unknown shape    743        Exception("CreateSolid", "Unknown shape" + shape);
754     }                                             744     }  
755                                                   745 
756     // create solid and set it to fVTE            746     // create solid and set it to fVTE
757     G4bool hasNegPars;                            747     G4bool hasNegPars;
758     G4bool deferred;                              748     G4bool deferred;   
759     G4bool okAxis[3];                             749     G4bool okAxis[3];
760     G4VSolid* solid                               750     G4VSolid* solid
761     = G3toG4MakeSolid(fVTE->GetName(), shape,     751     = G3toG4MakeSolid(fVTE->GetName(), shape, Rpar, npar, hasNegPars, deferred, okAxis);  
762                                                   752 
763     if (hasNegPars) {                             753     if (hasNegPars) {
764        G4String err_message = "CreateSolid VTE << 754        G4String name = fVTE->GetName();
765                             + " has negative p << 755        G4Exception("CreateSolid VTE " + name + " has negative parameters.");
766        G4Exception("G3Division::CreateSolid()" << 
767                    FatalException, err_message << 
768        return;                                 << 
769     }                                             756     }   
770                                                   757     
771     // update vte                                 758     // update vte
772     fVTE->SetSolid(solid);                        759     fVTE->SetSolid(solid);
773     fVTE->SetNRpar(npar, Rpar);                   760     fVTE->SetNRpar(npar, Rpar); 
774     fVTE->SetHasNegPars(hasNegPars);              761     fVTE->SetHasNegPars(hasNegPars);
775                                                   762 
776     // verbose                                    763     // verbose
777     // G4cout << "G3Division::CreateSolid volu    764     // G4cout << "G3Division::CreateSolid volume after: " 
778     //        << fVTE->GetName() << " " << sha    765     //        << fVTE->GetName() << " " << shape << G4endl;    
779     // G4cout << " npar,Rpar: " << npar;          766     // G4cout << " npar,Rpar: " << npar;
780     // for (G4int iii = 0; iii < npar; ++iii)     767     // for (G4int iii = 0; iii < npar; ++iii) G4cout << " " << Rpar[iii];
781     // G4cout << G4endl;                          768     // G4cout << G4endl;
782     delete [] Rpar;                            << 
783 }                                                 769 }
784                                                   770 
785                                                   771 
786 G3VolTableEntry* G3Division::Dvn()                772 G3VolTableEntry* G3Division::Dvn()
787 {                                                 773 {   
788   // no envelope need to be created               774   // no envelope need to be created 
789                                                   775 
790   // get parameters from mother                   776   // get parameters from mother
791   G4String shape = fMVTE->GetShape();             777   G4String shape = fMVTE->GetShape(); 
792   G4double* Rpar = fMVTE->GetRpar();              778   G4double* Rpar = fMVTE->GetRpar();
793   G4int     npar = fMVTE->GetNpar();              779   G4int     npar = fMVTE->GetNpar();
794                                                   780 
795   // set width for replica and create solid       781   // set width for replica and create solid
796   fWidth = (fHighRange - fLowRange)/fNofDivisi    782   fWidth = (fHighRange - fLowRange)/fNofDivisions;
797   CreateSolid(shape, Rpar, npar);                 783   CreateSolid(shape, Rpar, npar);
798                                                   784 
799   return 0;                                       785   return 0;       
800 }                                                 786 }
801                                                   787 
802 G3VolTableEntry* G3Division::Dvn2()               788 G3VolTableEntry* G3Division::Dvn2()
803 {                                                 789 {
804   // to be defined as const of this class         790   // to be defined as const of this class
805   G4double Rmin = 0.0001*cm;                      791   G4double Rmin = 0.0001*cm;
806                                                   792 
807   G4String shape = fMVTE->GetShape();             793   G4String shape = fMVTE->GetShape();
808   G4double* Rpar = fMVTE->GetRpar();              794   G4double* Rpar = fMVTE->GetRpar();
809   G4int     npar = fMVTE->GetNpar();              795   G4int     npar = fMVTE->GetNpar();
810                                                   796 
811   G4double c0 = fC0;                              797   G4double c0 = fC0;
812   if (fAxis == kPhi)  c0 = c0*deg;                798   if (fAxis == kPhi)  c0 = c0*deg;
813   else                c0 = c0*cm;                 799   else                c0 = c0*cm;
814                                                   800           
815   // create envelope (if needed)                  801   // create envelope (if needed)
816   G3VolTableEntry* envVTE = 0;                    802   G3VolTableEntry* envVTE = 0;
817   if( std::abs(c0 - fLowRange) > Rmin) {          803   if( std::abs(c0 - fLowRange) > Rmin) {
818     envVTE = CreateEnvelope(shape, fHighRange,    804     envVTE = CreateEnvelope(shape, fHighRange, c0, Rpar, npar);
819     Rpar = envVTE->GetRpar();                     805     Rpar = envVTE->GetRpar();
820     npar = envVTE->GetNpar();                     806     npar = envVTE->GetNpar();
821   }                                               807   }  
822                                                   808 
823   // set width for replica and create solid       809   // set width for replica and create solid
824   fWidth = (fHighRange - c0)/fNofDivisions;       810   fWidth = (fHighRange - c0)/fNofDivisions;
825   CreateSolid(shape, Rpar, npar);                 811   CreateSolid(shape, Rpar, npar);
826                                                   812 
827   return envVTE;                                  813   return envVTE;
828 }                                                 814 }
829                                                   815 
830 G3VolTableEntry* G3Division::Dvt()                816 G3VolTableEntry* G3Division::Dvt()
831 {                                                 817 {
832   // to be defined as const of this class         818   // to be defined as const of this class
833   G4double Rmin = 0.0001*cm;                      819   G4double Rmin = 0.0001*cm;
834                                                   820 
835   // get parameters from mother                   821   // get parameters from mother
836   G4String shape = fMVTE->GetShape();             822   G4String shape = fMVTE->GetShape();
837   G4double* Rpar = fMVTE->GetRpar();              823   G4double* Rpar = fMVTE->GetRpar();
838   G4int     npar = fMVTE->GetNpar();              824   G4int     npar = fMVTE->GetNpar();
839                                                   825 
840   // calculate the number of divisions            826   // calculate the number of divisions    
841   G4int ndvmx = fNofDivisions;                    827   G4int ndvmx = fNofDivisions;
842   G4double step = fStep;                          828   G4double step = fStep;
843                                                   829   
844   if (fAxis == kPhi)  step = step*deg;            830   if (fAxis == kPhi)  step = step*deg;
845   else                step = step*cm;             831   else                step = step*cm;
846                                                   832 
847   G4int ndiv = G4int((fHighRange - fLowRange +    833   G4int ndiv = G4int((fHighRange - fLowRange + Rmin)/step);
848   // to be added warning                          834   // to be added warning
849   if (ndvmx > 255) ndvmx = 255;                   835   if (ndvmx > 255) ndvmx = 255;
850   if (ndiv > ndvmx && ndvmx > 0 ) ndiv = ndvmx    836   if (ndiv > ndvmx && ndvmx > 0 ) ndiv = ndvmx;
851                                                   837 
852   // create envVTE (if needed)                    838   // create envVTE (if needed)
853   G3VolTableEntry* envVTE = 0;                    839   G3VolTableEntry* envVTE = 0;
854   G4double delta = std::abs((fHighRange - fLow    840   G4double delta = std::abs((fHighRange - fLowRange) - ndiv*step);
855   if (delta > Rmin) {                             841   if (delta > Rmin) {
856     envVTE                                        842     envVTE 
857        = CreateEnvelope(shape, fHighRange-delt    843        = CreateEnvelope(shape, fHighRange-delta/2., fLowRange+delta/2., 
858                         Rpar, npar);              844                         Rpar, npar);
859     Rpar = envVTE->GetRpar();                     845     Rpar = envVTE->GetRpar();
860     npar = envVTE->GetNpar();                     846     npar = envVTE->GetNpar();
861   }                                               847   }
862                                                   848 
863   // set width for replica and create solid       849   // set width for replica and create solid
864   fWidth = step;                                  850   fWidth = step;
865   fNofDivisions = ndiv;                           851   fNofDivisions = ndiv;
866   CreateSolid(shape, Rpar, npar);                 852   CreateSolid(shape, Rpar, npar);
867                                                   853 
868   return envVTE;                                  854   return envVTE;
869 }                                                 855 }
870                                                   856 
871 G3VolTableEntry* G3Division::Dvt2()               857 G3VolTableEntry* G3Division::Dvt2()
872 {                                                 858 {
873   // to be defined as const of this class         859   // to be defined as const of this class
874   G4double Rmin = 0.0001*cm;                      860   G4double Rmin = 0.0001*cm;
875                                                   861 
876   // get parameters from mother                   862   // get parameters from mother
877   G4String shape = fMVTE->GetShape();             863   G4String shape = fMVTE->GetShape();
878   G4double* Rpar = fMVTE->GetRpar();              864   G4double* Rpar = fMVTE->GetRpar();
879   G4int     npar = fMVTE->GetNpar();              865   G4int     npar = fMVTE->GetNpar();
880                                                   866 
881   // calculate the number of divisions            867   // calculate the number of divisions   
882   G4int ndvmx = fNofDivisions;                    868   G4int ndvmx = fNofDivisions;
883   G4double step = fStep;                          869   G4double step = fStep;
884   G4double c0 = fC0;                              870   G4double c0 = fC0;
885                                                   871 
886   if(fAxis == kPhi){                              872   if(fAxis == kPhi){
887     step = step*deg;                              873     step = step*deg;
888     c0 = c0*deg;                                  874     c0 = c0*deg;
889   }                                               875   } 
890   else {                                          876   else {
891     step = step*cm;                               877     step = step*cm;
892     c0 = c0*cm;                                   878     c0 = c0*cm;
893   }                                               879   }  
894                                                   880 
895   G4int ndiv = G4int((fHighRange - c0 + Rmin)/    881   G4int ndiv = G4int((fHighRange - c0 + Rmin)/step);
896   // to be added warning                          882   // to be added warning
897   if (ndvmx > 255) ndvmx = 255;                   883   if (ndvmx > 255) ndvmx = 255;
898   if (ndiv > ndvmx && ndvmx > 0 ) ndiv = ndvmx    884   if (ndiv > ndvmx && ndvmx > 0 ) ndiv = ndvmx;
899                                                   885 
900   // create envelope (if needed)                  886   // create envelope (if needed)
901   G3VolTableEntry* envVTE = 0;                    887   G3VolTableEntry* envVTE = 0;
902   G4double delta = std::abs((fHighRange - c0)     888   G4double delta = std::abs((fHighRange - c0) - ndiv*step);
903   if (std::abs(c0 - fLowRange) > Rmin) {          889   if (std::abs(c0 - fLowRange) > Rmin) {
904     envVTE                                        890     envVTE 
905       = CreateEnvelope(shape, fHighRange-delta    891       = CreateEnvelope(shape, fHighRange-delta/2., c0+delta/2., Rpar, npar);
906     Rpar = envVTE->GetRpar();                     892     Rpar = envVTE->GetRpar();
907     npar = envVTE->GetNpar();                     893     npar = envVTE->GetNpar();
908   }                                               894   }
909                                                   895 
910   // set with for replica and create solid        896   // set with for replica and create solid
911   fWidth = step;                                  897   fWidth = step;
912   fNofDivisions = ndiv;                           898   fNofDivisions = ndiv;
913   CreateSolid(shape, Rpar, npar);                 899   CreateSolid(shape, Rpar, npar);
914                                                   900 
915   return envVTE;                                  901   return envVTE;   
916 }                                                 902 }
917                                                   903