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


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