/scratch0/jsnuveri/BDSIM/BDSIMgit/bdsim/src/ggmad.cc

00001 #include "BDSGlobalConstants.hh" 
00002 #include "BDSDebug.hh"
00003 #include "ggmad.hh"
00004 
00005 #include "BDSMaterials.hh"
00006 
00007 #include "G4Box.hh"
00008 #include "G4Cons.hh"
00009 #include "G4LogicalVolume.hh"
00010 #include "G4PVPlacement.hh"
00011 #include "G4Trd.hh"
00012 #include "G4Tubs.hh"
00013 #include "G4VisAttributes.hh"
00014 #include "G4VPhysicalVolume.hh"
00015 
00016 
00017 GGmadDriver::GGmadDriver(G4String file)
00018 {
00019   G4cout << __METHOD_NAME__ << "> reading file : " << file << G4endl;
00020   inputf.open(file);
00021   if(!inputf.good()) {G4cerr<<"ggmad driver: error opening input file "<<file<<G4endl; exit(1);}
00022 }
00023 
00024 void GGmadDriver::Construct(G4LogicalVolume *marker)
00025 {
00026   
00027   G4String token;
00028   G4String token1;
00029 
00030   G4double x0=0, y0=0, z0=0, x=0, y=0, z=0; // box parameters
00031   G4double rmin=0, rmax=0, rmin2=0, rmax2=0, phi0=0, dphi=0; // cylindrical parameters
00032   G4double x1=0, x2=0, y1=0, y2=0;
00033   G4double phi=0, theta=0, psi=0; // Euler angles - for rotation of components
00034   G4String material;
00035 
00036   G4Material *theMaterial;
00037   G4LogicalVolume *lvol;
00038 
00039   G4VisAttributes *visAttr = new G4VisAttributes(true, G4Colour(0.2,0.2,0.2));
00040   visAttr->SetForceSolid(true);
00041 
00042   G4int count = 0;
00043 
00044   while (inputf.good())
00045     {
00046       token = getWord();
00047  
00048       if(token=="Box") {
00049         if(getWord() == "{")
00050           {
00051             
00052             while((token = getWord()))
00053               {
00054                 if (token == "}") break;
00055                 
00056                 getParameter(x0,"x0",token); // origin
00057                 getParameter(y0,"y0",token);
00058                 getParameter(z0,"z0",token);
00059                 getParameter(x,"x",token); //half lengths
00060                 getParameter(y,"y",token);
00061                 getParameter(z,"z",token);
00062                 getParameter(phi,"phi",token);
00063                 getParameter(theta,"theta",token);
00064                 getParameter(psi,"psi",token);
00065                 getParameter(material,"material",token);
00066               }
00067 
00068             //create Box
00069 
00070             theMaterial = BDSMaterials::Instance()->GetMaterial(material);
00071             
00072           
00073             G4cout<<"creating box : "<<x0<<"  "<<y0<<" "<<z0<<G4endl;
00074 
00075 
00076             G4Box* aBox = new G4Box("aBox" + G4String(count),
00077                                     x,   // half x
00078                                     y, // half y
00079                                     z ); // half z
00080             
00081             lvol = new G4LogicalVolume(aBox,
00082                         theMaterial,
00083                         "_bmp_logical");
00084 
00085 
00086             // place into mother volume
00087 
00088             G4RotationMatrix *rot = new G4RotationMatrix;
00089             rot->rotateX(CLHEP::twopi*phi/360.);
00090             rot->rotateY(CLHEP::twopi*theta/360.);
00091             rot->rotateZ(CLHEP::twopi*psi/360.);
00092 
00093             // G4VPhysicalVolume* PhysiComp =
00094             new G4PVPlacement(
00095               rot,                     // rotation
00096               G4ThreeVector(x0,y0,z0), // at (x0,y0,z0)
00097               lvol,                    // its logical volume
00098               "vol_"+G4String(count),  // its name
00099               marker,                  // its mother  volume
00100               false,                   // no boolean operation
00101               0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00102             count++;
00103 
00104           } else error();
00105         
00106       }// G4Box
00107 
00108       if(token=="Tubs") {
00109         if(getWord() == "{")
00110           {
00111             
00112             while((token = getWord()))
00113               {
00114                 if (token == "}") break;
00115                 
00116                 getParameter(x0,"x0",token); // origin
00117                 getParameter(y0,"y0",token);
00118                 getParameter(z0,"z0",token);
00119                 getParameter(rmin,"rmin",token); //half lengths
00120                 getParameter(rmax,"rmax",token);
00121                 getParameter(z,"z",token);
00122                 getParameter(phi0,"phi0",token);
00123                 getParameter(dphi,"dphi",token);
00124                 getParameter(phi,"phi",token);
00125                 getParameter(theta,"theta",token);
00126                 getParameter(psi,"psi",token);
00127                 getParameter(material,"material",token);
00128               }
00129             
00130             //create Box
00131             
00132             theMaterial = BDSMaterials::Instance()->GetMaterial(material);
00133             
00134             
00135             G4cout<<"creating tubs : "<<x0<<"  "<<y0<<" "<<z0<<G4endl;
00136             
00137             // default - tube
00138             phi0 = 0;
00139             dphi = 360; // degrees
00140             
00141             G4Tubs* aTubs = new G4Tubs("aTubs" + G4String(count),
00142                                        rmin,   // inner R
00143                                        rmax, // outer R
00144                                        z, //z
00145                                        phi0,//phi 0 
00146                                        CLHEP::twopi * dphi / 360  ); //delta phi
00147             
00148             lvol = new G4LogicalVolume(aTubs,
00149                                        theMaterial,
00150                                        "_bmp_logical");
00151             
00152             
00153             // place into mother volume
00154             
00155             G4RotationMatrix *rot = new G4RotationMatrix;
00156             rot->rotateX(CLHEP::twopi*phi/360.);
00157             rot->rotateY(CLHEP::twopi*theta/360.);
00158             rot->rotateZ(CLHEP::twopi*psi/360.);
00159 
00160             // G4VPhysicalVolume* PhysiComp =
00161             new G4PVPlacement(
00162                               rot,                           // rotation
00163                               G4ThreeVector(x0,y0,z0),     // at (0,0,0)
00164                               lvol,  // its logical volume
00165                               "vol_"+G4String(count),        // its name
00166                               marker,     // its mother  volume
00167                               false,                 // no boolean operation
00168                               0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00169             
00170             count++;
00171             
00172           } else error();
00173       }
00174 
00175       if(token=="Cons") {
00176         if(getWord() == "{")
00177           {
00178             
00179             while((token = getWord()))
00180               {
00181                 if (token == "}") break;
00182                 
00183                 getParameter(x0,"x0",token); // origin
00184                 getParameter(y0,"y0",token);
00185                 getParameter(z0,"z0",token);
00186                 getParameter(rmin,"rmin1",token); //half lengths
00187                 getParameter(rmax,"rmax1",token);
00188                 getParameter(rmin2,"rmin2",token); //half lengths
00189                 getParameter(rmax2,"rmax2",token);
00190                 getParameter(z,"z",token);
00191                 getParameter(phi0,"phi0",token);
00192                 getParameter(dphi,"dphi",token);
00193                 getParameter(phi,"phi",token);
00194                 getParameter(theta,"theta",token);
00195                 getParameter(psi,"psi",token);
00196                 getParameter(material,"material",token);
00197               }
00198             
00199             //create Box
00200             
00201             theMaterial = BDSMaterials::Instance()->GetMaterial(material);
00202             
00203             
00204             G4cout<<"creating cons : "<<x0<<"  "<<y0<<" "<<z0<<G4endl;
00205             G4cout<<"rotation : "<<phi<<"  "<<theta<<" "<<psi<<G4endl;
00206             
00207             // default - tube
00208             phi0 = 0;
00209             dphi = 360; // degrees
00210             
00211             G4Cons* aCons = new G4Cons("aCons" + G4String(count),
00212                                        rmin,   // inner R
00213                                        rmax,
00214                                        rmin2,
00215                                        rmax2,
00216                                        z, //z
00217                                        phi0,//phi 0 
00218                                        CLHEP::twopi * dphi / 360  ); //delta phi
00219             
00220             lvol = new G4LogicalVolume(aCons,
00221                                        theMaterial,
00222                                        "_bmp_logical");
00223 
00224             lvol->SetVisAttributes( visAttr );
00225             
00226             
00227             // place into mother volume
00228 
00229             G4RotationMatrix *rot = new G4RotationMatrix;
00230             rot->rotateX(CLHEP::twopi*phi/360.);
00231             rot->rotateY(CLHEP::twopi*theta/360.);
00232             rot->rotateZ(CLHEP::twopi*psi/360.);
00233 
00234             // G4VPhysicalVolume* PhysiComp =
00235             new G4PVPlacement(
00236                               rot,                           // rotation
00237                               G4ThreeVector(x0,y0,z0),     // at (0,0,0)
00238                               lvol,  // its logical volume
00239                               "vol_"+G4String(count),        // its name
00240                               marker,     // its mother  volume
00241                               false,                 // no boolean operation
00242                               0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00243             
00244             count++;
00245             
00246           } else error();
00247       }
00248       if(token=="Trd") {   // trapezoid
00249         if(getWord() == "{")
00250           {
00251             
00252             while((token = getWord()))
00253               {
00254                 if (token == "}") break;
00255                 
00256                 getParameter(x0,"x0",token); // origin
00257                 getParameter(y0,"y0",token);
00258                 getParameter(z0,"z0",token);
00259                 getParameter(x1,"x1",token); //half length at wider side
00260                 getParameter(x2,"x2",token); //half length at narrow side
00261                 getParameter(y1,"y1",token); //half lengths
00262                 getParameter(y2,"y2",token); //half lengths
00263                 getParameter(z,"z",token);
00264                 getParameter(phi,"phi",token);
00265                 getParameter(theta,"theta",token);
00266                 getParameter(psi,"psi",token);
00267                 getParameter(material,"material",token);
00268               }
00269             
00270             //create Box
00271             
00272             theMaterial = BDSMaterials::Instance()->GetMaterial(material);
00273             
00274             
00275             G4cout<<"creating trd : "<<x0<<"  "<<y0<<" "<<z0<<
00276                   z<<" "<<y<<" "<<x1<<" "<<x2<<G4endl;
00277             
00278             
00279             G4Trd* aTrd = new G4Trd("aTrd" + G4String(count),
00280                                     x1,x2,   // inner R
00281                                     y1,y2,
00282                                     z);
00283             
00284             lvol = new G4LogicalVolume(aTrd,
00285                                        theMaterial,
00286                                        "_bmp_logical");
00287 
00288             // place into mother volume
00289 
00290             G4RotationMatrix *rot = new G4RotationMatrix;
00291             rot->rotateX(CLHEP::twopi*phi/360.);
00292             rot->rotateY(CLHEP::twopi*theta/360.);
00293             rot->rotateZ(CLHEP::twopi*psi/360.);
00294             
00295             
00296             // G4VPhysicalVolume* PhysiComp =
00297             new G4PVPlacement(
00298                               rot,                           // rotation
00299                               G4ThreeVector(x0,y0,z0),     // at (0,0,0)
00300                               lvol,  // its logical volume
00301                               "vol_"+G4String(count),        // its name
00302                               marker,     // its mother  volume
00303                               false,                 // no boolean operation
00304                               0, BDSGlobalConstants::Instance()->GetCheckOverlaps());
00305             
00306             count++;
00307             
00308           } else error();
00309       }
00310     }
00311 
00312 
00313   return;
00314 }
00315 
00316 
00317 G4String GGmadDriver::getWord()
00318 {
00319 
00320   G4String str="";
00321   char c = 'a';
00322 
00323   while (inputf.good())     // loop while extraction from file is possible
00324   {
00325     inputf.get(c);       // get character from file
00326 
00327     // return char tokens 
00328     if(c=='=') return G4String(c);
00329 
00330     // skip whitespace
00331     if( (c != ' ' ) && (c != '\t' )&& (c != ',' ) && (c != '\n' )) break;
00332   }
00333 
00334   while (inputf.good())     // loop while extraction from file is possible
00335   {
00336     str += c;
00337     inputf.get(c);       // get character from file
00338     if( (c == ' ' ) || (c == '\t' )|| (c == ',' )|| (c == '\n' )|| (c == '=' ) ) 
00339       {
00340         inputf.putback(c);
00341         break;
00342       }
00343   }
00344 
00345   return str;
00346 
00347 }
00348 
00349 void GGmadDriver::getParameter(G4double& x, G4String name, G4String lastToken)
00350 {
00351   G4String token;
00352 
00353   if(lastToken == name)
00354     {
00355       token = getWord();
00356       if(token == "=")
00357         {
00358           token = getWord();
00359           x = strtod(token.c_str(),NULL);
00360         }
00361     }
00362 }
00363 
00364 void GGmadDriver::getParameter(G4String& lval, G4String name, G4String lastToken)
00365 {
00366   G4String token;
00367 
00368   if(lastToken == name)
00369     {
00370       token = getWord();
00371       if(token == "=")
00372         {
00373           token = getWord();
00374           lval = token;
00375         }
00376     }
00377 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7