/home/cern/BDSIM_new/src/ggmad.cc

00001 #include "BDSGlobalConstants.hh" // must be first in include list
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 //void GetMaterial(G4Material*& theMaterial, G4String material);
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; // box parameters
00038   G4double rmin, rmax,rmin2, rmax2, phi0, dphi; // cylindrical parameters
00039   G4double x1=0, x2=0, y1=0, y2=0;
00040   G4double phi=0, theta=0, psi=0; // Euler angles - for rotation of components
00041   G4String material;
00042 
00043   G4Material *theMaterial = theMaterials->GetMaterial("Vacuum");
00044 
00045   G4Box *aBox;
00046   G4Tubs *aTubs;
00047   G4Cons *aCons;
00048   //G4Trap *aTrap;
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); // origin
00073                 getParameter(y0,"y0",token);
00074                 getParameter(z0,"z0",token);
00075                 getParameter(x,"x",token); //half lengthes
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             //create Box
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,   // half x
00094                              y, // half y
00095                              z ); // half z
00096             
00097             lvol = new G4LogicalVolume(aBox,
00098                         theMaterial,
00099                         "_bmp_logical");
00100 
00101 
00102             // place into mother volume
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,                           // rotation
00112                       G4ThreeVector(x0,y0,z0),                       // at (x0,y0,z0)
00113                       lvol,  // its logical volume
00114                       "vol_"+G4String(count),        // its name
00115                       marker,     // its mother  volume
00116                       false,                 // no boolean operation
00117                       0);                  
00118 
00119             count++;
00120 
00121           } else error();
00122         
00123       }// G4Box
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); // origin
00134                 getParameter(y0,"y0",token);
00135                 getParameter(z0,"z0",token);
00136                 getParameter(rmin,"rmin",token); //half lengthes
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             //create Box
00148             
00149             theMaterial = theMaterials->GetMaterial(material);
00150             
00151             
00152             G4cout<<"creating tubs : "<<x0<<"  "<<y0<<" "<<z0<<endl;
00153             
00154             // default - tube
00155             phi0 = 0;
00156             dphi = 360; // degrees
00157             
00158             aTubs = new G4Tubs("aTubs" + G4String(count),
00159                                rmin,   // inner R
00160                                rmax, // outer R
00161                                z, //z
00162                                phi0,//phi 0 
00163                                2 * pi * dphi / 360  ); //delta phi
00164             
00165             lvol = new G4LogicalVolume(aTubs,
00166                                        theMaterial,
00167                                        "_bmp_logical");
00168             
00169             
00170             // place into mother volume
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,                         // rotation
00181                                 G4ThreeVector(x0,y0,z0),     // at (0,0,0)
00182                                 lvol,  // its logical volume
00183                                 "vol_"+G4String(count),      // its name
00184                                 marker,     // its mother  volume
00185                                 false,               // no boolean operation
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); // origin
00202                 getParameter(y0,"y0",token);
00203                 getParameter(z0,"z0",token);
00204                 getParameter(rmin,"rmin1",token); //half lengthes
00205                 getParameter(rmax,"rmax1",token);
00206                 getParameter(rmin2,"rmin2",token); //half lengthes
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             //create Box
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             // default - tube
00226             phi0 = 0;
00227             dphi = 360; // degrees
00228             
00229             aCons = new G4Cons("aCons" + G4String(count),
00230                                rmin,   // inner R
00231                                rmax,
00232                                rmin2,
00233                                rmax2,
00234                                z, //z
00235                                phi0,//phi 0 
00236                                2 * pi * dphi / 360  ); //delta phi
00237             
00238             lvol = new G4LogicalVolume(aCons,
00239                                        theMaterial,
00240                                        "_bmp_logical");
00241 
00242             lvol->SetVisAttributes( visAttr );
00243             
00244             
00245             // place into mother volume
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,                         // rotation
00255                                 G4ThreeVector(x0,y0,z0),     // at (0,0,0)
00256                                 lvol,  // its logical volume
00257                                 "vol_"+G4String(count),      // its name
00258                                 marker,     // its mother  volume
00259                                 false,               // no boolean operation
00260                                 0);                
00261             
00262             count++;
00263             
00264           } else error();
00265       }
00266       if(token=="Trd") {   // trapezoid
00267         if(getWord() == "{")
00268           {
00269             
00270             while(token = getWord())
00271               {
00272                 if (token == "}") break;
00273                 
00274                 getParameter(x0,"x0",token); // origin
00275                 getParameter(y0,"y0",token);
00276                 getParameter(z0,"z0",token);
00277                 getParameter(x1,"x1",token); //half length at wider side
00278                 getParameter(x2,"x2",token); // half length at narrow side
00279                 getParameter(y1,"y1",token); //half lengthes
00280                 getParameter(y2,"y2",token); //half lengthes
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             //create Box
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,   // inner R
00299                              y1,y2,
00300                              z);
00301             
00302             lvol = new G4LogicalVolume(aTrd,
00303                                        theMaterial,
00304                                        "_bmp_logical");
00305 
00306             // place into mother volume
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,                         // rotation
00317                                 G4ThreeVector(x0,y0,z0),     // at (0,0,0)
00318                                 lvol,  // its logical volume
00319                                 "vol_"+G4String(count),      // its name
00320                                 marker,     // its mother  volume
00321                                 false,               // no boolean operation
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())     // loop while extraction from file is possible
00342   {
00343     c = inputf.get();       // get character from file
00344 
00345     // return char tokens 
00346     if(c=='=') return G4String(c);
00347 
00348     // skip whitespace
00349     if( (c != ' ' ) && (c != '\t' )&& (c != ',' ) && (c != '\n' )) break;
00350   }
00351 
00352   while (inputf.good())     // loop while extraction from file is possible
00353   {
00354     str += c;
00355     c = inputf.get();       // get character from file
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 void GetMaterial(G4Material *&theMaterial, G4String material)
00399 {
00400   if(material=="\"Al\"" || material=="Al") 
00401     { 
00402       theMaterial = theMaterials->LCAluminium;
00403       return;
00404     }
00405   
00406   if(material=="\"W\"" || material=="W") 
00407     { 
00408       theMaterial = theMaterials->LCTungsten;
00409       return;
00410     }
00411   if(material=="\"Iron\""|| material=="Iron") 
00412     { 
00413       theMaterial = theMaterials->LCIron;
00414       return;
00415     }
00416   if(material=="\"Copper\"" || material=="Copper") 
00417     { 
00418       theMaterial = theMaterials->LCCopper;
00419       return;
00420     }
00421   
00422   if(material=="\"Ti\"" || material=="Ti") 
00423     { 
00424       theMaterial = theMaterials->LCTitanium;
00425       return;
00426     }
00427   if(material=="\"Graphite\"" || material=="Graphite") 
00428     { 
00429       theMaterial = theMaterials->LCGraphite;
00430       return;
00431     }
00432 
00433   if(material=="\"Lead\"" || material=="Lead")
00434     {
00435       theMaterial = theMaterials->LCLead;
00436       return;
00437     }
00438 
00439   if(material=="\"Concrete\"" || material=="Concrete")
00440     {
00441       theMaterial = theMaterials->LCConcrete;
00442       return;
00443     }
00444   if(material=="\"Soil\"" || material=="Soil")
00445     {
00446       theMaterial = theMaterials->LCSoil;
00447       return;
00448     }
00449 
00450 
00451   theMaterial = theMaterials->LCVacuum; // default is vacuum
00452 }
00453 */

Generated on Wed Mar 5 17:25:23 2008 for BDSIM by  doxygen 1.5.3