00001 #include "BDSGlobalConstants.hh"
00002 #include "BDSElement.hh"
00003 #include "G4Box.hh"
00004 #include "G4Tubs.hh"
00005 #include "G4Cons.hh"
00006 #include "G4Torus.hh"
00007 #include "G4Trd.hh"
00008 #include "G4Trap.hh"
00009 #include "G4VisAttributes.hh"
00010 #include "G4LogicalVolume.hh"
00011 #include "G4VPhysicalVolume.hh"
00012 #include "G4PVPlacement.hh"
00013 #include "G4UserLimits.hh"
00014
00015 #include "BDSAcceleratorComponent.hh"
00016 #include "ggmad.hh"
00017
00018 using namespace std;
00019
00020 extern BDSMaterials* theMaterials;
00021
00022
00023
00024 GGmadDriver::GGmadDriver(G4String file)
00025 {
00026 G4cout<<"reading file "<<file<<G4endl;
00027 inputf.open(file);
00028 if(!inputf.good()) {G4cerr<<"ggmad driver: error opening input file "<<file<<G4endl; exit(1);}
00029 }
00030
00031 void GGmadDriver::Construct(G4LogicalVolume *marker)
00032 {
00033
00034 G4String token;
00035 G4String token1;
00036
00037 G4double x0=0, y0=0, z0=0, x=0, y=0, z=0;
00038 G4double rmin, rmax,rmin2, rmax2, phi0, dphi;
00039 G4double x1=0, x2=0, y1=0, y2=0;
00040 G4double phi=0, theta=0, psi=0;
00041 G4String material;
00042
00043 G4Material *theMaterial = theMaterials->GetMaterial("Vacuum");
00044
00045 G4Box *aBox;
00046 G4Tubs *aTubs;
00047 G4Cons *aCons;
00048
00049 G4Trd *aTrd;
00050
00051 G4LogicalVolume *lvol;
00052 G4VPhysicalVolume* PhysiComp;
00053
00054 G4VisAttributes *visAttr = new G4VisAttributes(true, G4Colour(0.2,0.2,0.2));
00055 visAttr->SetForceSolid(true);
00056
00057
00058 G4int count = 0;
00059
00060 while (inputf.good())
00061 {
00062 token = getWord();
00063
00064 if(token=="Box") {
00065 if(getWord() == "{")
00066 {
00067
00068 while(token = getWord())
00069 {
00070 if (token == "}") break;
00071
00072 getParameter(x0,"x0",token);
00073 getParameter(y0,"y0",token);
00074 getParameter(z0,"z0",token);
00075 getParameter(x,"x",token);
00076 getParameter(y,"y",token);
00077 getParameter(z,"z",token);
00078 getParameter(phi,"phi",token);
00079 getParameter(theta,"theta",token);
00080 getParameter(psi,"psi",token);
00081 getParameter(material,"material",token);
00082 }
00083
00084
00085
00086 theMaterial = theMaterials->GetMaterial(material);
00087
00088
00089 G4cout<<"creating box : "<<x0<<" "<<y0<<" "<<z0<<endl;
00090
00091
00092 aBox = new G4Box("aBox" + G4String(count),
00093 x,
00094 y,
00095 z );
00096
00097 lvol = new G4LogicalVolume(aBox,
00098 theMaterial,
00099 "_bmp_logical");
00100
00101
00102
00103
00104 G4RotationMatrix *rot = new G4RotationMatrix;
00105 rot->rotateX(2*pi*phi/360.);
00106 rot->rotateY(2*pi*theta/360.);
00107 rot->rotateZ(2*pi*psi/360.);
00108
00109 PhysiComp =
00110 new G4PVPlacement(
00111 rot,
00112 G4ThreeVector(x0,y0,z0),
00113 lvol,
00114 "vol_"+G4String(count),
00115 marker,
00116 false,
00117 0);
00118
00119 count++;
00120
00121 } else error();
00122
00123 }
00124
00125 if(token=="Tubs") {
00126 if(getWord() == "{")
00127 {
00128
00129 while(token = getWord())
00130 {
00131 if (token == "}") break;
00132
00133 getParameter(x0,"x0",token);
00134 getParameter(y0,"y0",token);
00135 getParameter(z0,"z0",token);
00136 getParameter(rmin,"rmin",token);
00137 getParameter(rmax,"rmax",token);
00138 getParameter(z,"z",token);
00139 getParameter(phi0,"phi0",token);
00140 getParameter(dphi,"dphi",token);
00141 getParameter(phi,"phi",token);
00142 getParameter(theta,"theta",token);
00143 getParameter(psi,"psi",token);
00144 getParameter(material,"material",token);
00145 }
00146
00147
00148
00149 theMaterial = theMaterials->GetMaterial(material);
00150
00151
00152 G4cout<<"creating tubs : "<<x0<<" "<<y0<<" "<<z0<<endl;
00153
00154
00155 phi0 = 0;
00156 dphi = 360;
00157
00158 aTubs = new G4Tubs("aTubs" + G4String(count),
00159 rmin,
00160 rmax,
00161 z,
00162 phi0,
00163 2 * pi * dphi / 360 );
00164
00165 lvol = new G4LogicalVolume(aTubs,
00166 theMaterial,
00167 "_bmp_logical");
00168
00169
00170
00171
00172 G4RotationMatrix *rot = new G4RotationMatrix;
00173 rot->rotateX(2*pi*phi/360.);
00174 rot->rotateY(2*pi*theta/360.);
00175 rot->rotateZ(2*pi*psi/360.);
00176
00177
00178 PhysiComp =
00179 new G4PVPlacement(
00180 rot,
00181 G4ThreeVector(x0,y0,z0),
00182 lvol,
00183 "vol_"+G4String(count),
00184 marker,
00185 false,
00186 0);
00187
00188 count++;
00189
00190 } else error();
00191 }
00192
00193 if(token=="Cons") {
00194 if(getWord() == "{")
00195 {
00196
00197 while(token = getWord())
00198 {
00199 if (token == "}") break;
00200
00201 getParameter(x0,"x0",token);
00202 getParameter(y0,"y0",token);
00203 getParameter(z0,"z0",token);
00204 getParameter(rmin,"rmin1",token);
00205 getParameter(rmax,"rmax1",token);
00206 getParameter(rmin2,"rmin2",token);
00207 getParameter(rmax2,"rmax2",token);
00208 getParameter(z,"z",token);
00209 getParameter(phi0,"phi0",token);
00210 getParameter(dphi,"dphi",token);
00211 getParameter(phi,"phi",token);
00212 getParameter(theta,"theta",token);
00213 getParameter(psi,"psi",token);
00214 getParameter(material,"material",token);
00215 }
00216
00217
00218
00219 theMaterial = theMaterials->GetMaterial(material);
00220
00221
00222 G4cout<<"creating cons : "<<x0<<" "<<y0<<" "<<z0<<endl;
00223 G4cout<<"rotation : "<<phi<<" "<<theta<<" "<<psi<<endl;
00224
00225
00226 phi0 = 0;
00227 dphi = 360;
00228
00229 aCons = new G4Cons("aCons" + G4String(count),
00230 rmin,
00231 rmax,
00232 rmin2,
00233 rmax2,
00234 z,
00235 phi0,
00236 2 * pi * dphi / 360 );
00237
00238 lvol = new G4LogicalVolume(aCons,
00239 theMaterial,
00240 "_bmp_logical");
00241
00242 lvol->SetVisAttributes( visAttr );
00243
00244
00245
00246
00247 G4RotationMatrix *rot = new G4RotationMatrix;
00248 rot->rotateX(2*pi*phi/360.);
00249 rot->rotateY(2*pi*theta/360.);
00250 rot->rotateZ(2*pi*psi/360.);
00251
00252 PhysiComp =
00253 new G4PVPlacement(
00254 rot,
00255 G4ThreeVector(x0,y0,z0),
00256 lvol,
00257 "vol_"+G4String(count),
00258 marker,
00259 false,
00260 0);
00261
00262 count++;
00263
00264 } else error();
00265 }
00266 if(token=="Trd") {
00267 if(getWord() == "{")
00268 {
00269
00270 while(token = getWord())
00271 {
00272 if (token == "}") break;
00273
00274 getParameter(x0,"x0",token);
00275 getParameter(y0,"y0",token);
00276 getParameter(z0,"z0",token);
00277 getParameter(x1,"x1",token);
00278 getParameter(x2,"x2",token);
00279 getParameter(y1,"y1",token);
00280 getParameter(y2,"y2",token);
00281 getParameter(z,"z",token);
00282 getParameter(phi,"phi",token);
00283 getParameter(theta,"theta",token);
00284 getParameter(psi,"psi",token);
00285 getParameter(material,"material",token);
00286 }
00287
00288
00289
00290 theMaterial = theMaterials->GetMaterial(material);
00291
00292
00293 G4cout<<"creating trd : "<<x0<<" "<<y0<<" "<<z0<<
00294 z<<" "<<y<<" "<<x1<<" "<<x2<<endl;
00295
00296
00297 aTrd = new G4Trd("aTrd" + G4String(count),
00298 x1,x2,
00299 y1,y2,
00300 z);
00301
00302 lvol = new G4LogicalVolume(aTrd,
00303 theMaterial,
00304 "_bmp_logical");
00305
00306
00307
00308 G4RotationMatrix *rot = new G4RotationMatrix;
00309 rot->rotateX(2*pi*phi/360.);
00310 rot->rotateY(2*pi*theta/360.);
00311 rot->rotateZ(2*pi*psi/360.);
00312
00313
00314 PhysiComp =
00315 new G4PVPlacement(
00316 rot,
00317 G4ThreeVector(x0,y0,z0),
00318 lvol,
00319 "vol_"+G4String(count),
00320 marker,
00321 false,
00322 0);
00323
00324 count++;
00325
00326 } else error();
00327 }
00328 }
00329
00330
00331 return;
00332 }
00333
00334
00335 G4String GGmadDriver::getWord()
00336 {
00337
00338 G4String str="";
00339 char c = 'a';
00340
00341 while (inputf.good())
00342 {
00343 c = inputf.get();
00344
00345
00346 if(c=='=') return G4String(c);
00347
00348
00349 if( (c != ' ' ) && (c != '\t' )&& (c != ',' ) && (c != '\n' )) break;
00350 }
00351
00352 while (inputf.good())
00353 {
00354 str += c;
00355 c = inputf.get();
00356 if( (c == ' ' ) || (c == '\t' )|| (c == ',' )|| (c == '\n' )|| (c == '=' ) )
00357 {
00358 inputf.putback(c);
00359 break;
00360 }
00361 }
00362
00363 return str;
00364
00365 }
00366
00367 void GGmadDriver::getParameter(G4double& x, G4String name, G4String lastToken)
00368 {
00369 G4String token;
00370
00371 if(lastToken == name)
00372 {
00373 token = getWord();
00374 if(token == "=")
00375 {
00376 token = getWord();
00377 x = strtod(token.c_str(),NULL);
00378 }
00379 }
00380 }
00381
00382 void GGmadDriver::getParameter(G4String& lval, G4String name, G4String lastToken)
00383 {
00384 G4String token;
00385
00386 if(lastToken == name)
00387 {
00388 token = getWord();
00389 if(token == "=")
00390 {
00391 token = getWord();
00392 lval = token;
00393 }
00394 }
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453