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

00001 #include "BDSBeamPipeFactoryBase.hh"
00002 #include "BDSBeamPipeFactoryLHC.hh"
00003 #include "BDSBeamPipe.hh"
00004 
00005 #include "BDSDebug.hh"
00006 #include "BDSExecOptions.hh"
00007 #include "BDSGlobalConstants.hh"
00008 #include "BDSSDManager.hh"
00009 
00010 #include "globals.hh"                      // geant4 globals / types
00011 #include "G4Box.hh"
00012 #include "G4CutTubs.hh"
00013 #include "G4IntersectionSolid.hh"
00014 #include "G4LogicalVolume.hh"
00015 #include "G4Material.hh"
00016 #include "G4SubtractionSolid.hh"
00017 #include "G4ThreeVector.hh"
00018 #include "G4Tubs.hh"
00019 #include "G4VSolid.hh"
00020 
00021 #include <cmath>
00022 #include <utility>                         // for std::pair
00023 
00024 
00025 BDSBeamPipeFactoryLHC* BDSBeamPipeFactoryLHC::_instance = 0;
00026 
00027 BDSBeamPipeFactoryLHC* BDSBeamPipeFactoryLHC::Instance()
00028 {
00029   if (_instance == 0)
00030     {_instance = new BDSBeamPipeFactoryLHC();}
00031   return _instance;
00032 }
00033 
00034 BDSBeamPipeFactoryLHC::BDSBeamPipeFactoryLHC():BDSBeamPipeFactoryBase()
00035 {
00036 }
00037 
00038 BDSBeamPipeFactoryLHC::~BDSBeamPipeFactoryLHC()
00039 {
00040   _instance = 0;
00041 }
00042 
00043 BDSBeamPipe* BDSBeamPipeFactoryLHC::CreateBeamPipe(G4String    nameIn,              // name
00044                                                    G4double    lengthIn,            // length [mm]
00045                                                    G4double    aper1In,             // rect half width
00046                                                    G4double    aper2In,             // rect half height
00047                                                    G4double    aper3In,             // radius of circle
00048                                                    G4double    /*aper4In*/,         // aperture parameter 4
00049                                                    G4Material* vacuumMaterialIn,    // vacuum material
00050                                                    G4double    beamPipeThicknessIn, // beampipe thickness [mm]
00051                                                    G4Material* beamPipeMaterialIn)  // beampipe material
00052 {
00053 #ifdef BDSDEBUG
00054   G4cout << __METHOD_NAME__ << G4endl;
00055 #endif
00056    // clean up after last usage
00057   CleanUp();
00058   
00059   // test input parameters - set global options as default if not specified
00060   TestInputParameters(vacuumMaterialIn,beamPipeThicknessIn,beamPipeMaterialIn,aper1In,aper2In,aper3In);
00061 
00062   // build the solids
00063   //vacuum cylindrical solid (circular cross-section)
00064   G4VSolid* vacCylSolid = new G4Tubs(nameIn + "_vacuum_cylinder", // name
00065                                      0,                           // inner radius
00066                                      aper3In,                     // outer radius
00067                                      lengthIn*0.5-2*lengthSafety, // half length
00068                                      0,                           // rotation start angle
00069                                      CLHEP::twopi);               // rotation finish angle
00070   //vacuum box solid (rectangular cross-section)
00071   G4VSolid* vacRectSolid = new G4Box(nameIn + "_vacuum_box", // name
00072                                      aper1In,                // x half width
00073                                      aper2In,                // y half width
00074                                      lengthIn); // z full width (long for unambiguous intersection)
00075   //intersection of both of these gives the desired shape
00076   vacuumSolid = new G4IntersectionSolid(nameIn + "_vacuum_solid", // name
00077                                         vacCylSolid,              // solid 1
00078                                         vacRectSolid);            // solid 2
00079 
00080   //beampipe cylindrical solid (circular cross-section)
00081   //beampipe inner edge for subtraction (actually just like vacuum + lengthSafety)x
00082   G4VSolid* bpInnerCylSolid = new G4Tubs(nameIn + "_pipe_inner_cylinder", // name
00083                                          0,                               // inner radius
00084                                          aper3In + lengthSafety,          // outer radius
00085                                          1.5*lengthIn,   // length big for unambiguous subtraction (but < outerlength)
00086                                          0,                               // rotation start angle
00087                                          CLHEP::twopi);                   // rotation finish angle
00088   //beampipe inner edge box solid (rectangular cross-section)
00089   G4VSolid* bpInnerRectSolid = new G4Box(nameIn + "_pipe_inner_box", // name
00090                                          aper1In + lengthSafety,     // x half width
00091                                          aper2In + lengthSafety,     // y half width
00092                                          1.7*lengthIn); // z long for unambiguous intersection
00093   //beampipe inner intersection - 1.5*length long which is > half length for unambiguous subtraction later
00094   G4VSolid* bpInnerSolid = new G4IntersectionSolid(nameIn + "_pipe_inner_solid", // name
00095                                                    bpInnerCylSolid,              // solid 1
00096                                                    bpInnerRectSolid);            // solid 2
00097 
00098   //beampipe outer edge for subtraction (actually just like vacuum + lengthSafety)x
00099   G4VSolid* bpOuterCylSolid = new G4Tubs(nameIn + "_pipe_inner_cylinder", // name
00100                                          0,                               // inner radius (0 for unambiguous subtraction)
00101                                          aper3In + beamPipeThicknessIn,   // outer radius
00102                                          (lengthIn*0.5)-2*lengthSafety,   // half length
00103                                          0,                               // rotation start angle
00104                                          CLHEP::twopi);                   // rotation finish angle
00105   //beampipe outer edge box solid (rectangular cross-section)
00106   G4VSolid* bpOuterRectSolid = new G4Box(nameIn + "_pipe_inner_box",    // name
00107                                          aper1In + beamPipeThicknessIn, // x half width
00108                                          aper2In + beamPipeThicknessIn, // y half width
00109                                          lengthIn); // z full width (long for unambiguous intersection)
00110   G4VSolid* bpOuterSolid = new G4IntersectionSolid(nameIn + "_pipe_inner_solid", // name
00111                                                    bpOuterCylSolid,              // solid 1
00112                                                    bpOuterRectSolid);            // solid 2
00113   
00114 
00115   beamPipeSolid = new G4SubtractionSolid(nameIn + "_pipe_solid",  // name
00116                                          bpOuterSolid,            // this
00117                                          bpInnerSolid);           // minus this
00118   
00119   //container cylindrical solid (circular cross-section)
00120   G4VSolid* contCylSolid = new G4Tubs(nameIn + "_vacuum_cylinder", // name
00121                                      0,                           // inner radius
00122                                      aper3In + beamPipeThicknessIn + lengthSafety, // outer radius
00123                                      lengthIn*0.5, // half length
00124                                      0,                           // rotation start angle
00125                                      CLHEP::twopi);               // rotation finish angle
00126   //vacuum box solid (rectangular cross-section)
00127   G4VSolid* contRectSolid = new G4Box(nameIn + "_vacuum_box", // name
00128                                      aper1In + beamPipeThicknessIn + lengthSafety, // x half width
00129                                      aper2In + beamPipeThicknessIn + lengthSafety, // y half width
00130                                      lengthIn); // z full width (long for unambiguous intersection)
00131   //intersection of both of these gives the desired shape
00132   containerSolid = new G4IntersectionSolid(nameIn + "_vacuum_solid", // name
00133                                            contCylSolid,              // solid 1
00134                                            contRectSolid);            // solid 2
00135 
00136   G4double width  = aper3In + beamPipeThicknessIn + lengthSafety;
00137   G4double height = aper2In + beamPipeThicknessIn + lengthSafety;
00138 
00139   CreateContainerSubtractionSolid(nameIn, lengthIn, beamPipeThicknessIn, aper1In, aper2In, aper3In);
00140   
00141   return CommonFinalConstruction(nameIn, vacuumMaterialIn, beamPipeMaterialIn, lengthIn, width, height);
00142 }
00143 
00144 BDSBeamPipe* BDSBeamPipeFactoryLHC::CreateBeamPipeAngledInOut(G4String    nameIn,              // name
00145                                                               G4double    lengthIn,            // length [mm]
00146                                                               G4double    angleInIn,           // the normal angle of the input face
00147                                                               G4double    angleOutIn,          // the normal angle of the input face
00148                                                               G4double    aper1In,             // aperture parameter 1
00149                                                               G4double    aper2In,             // aperture parameter 2
00150                                                               G4double    aper3In,             // aperture parameter 3
00151                                                               G4double    /*aper4In */,        // aperture parameter 4
00152                                                               G4Material* vacuumMaterialIn,    // vacuum material
00153                                                               G4double    beamPipeThicknessIn, // beampipe thickness [mm]
00154                                                               G4Material* beamPipeMaterialIn)  // beampipe material
00155 {
00156 #ifdef BDSDEBUG
00157   G4cout << __METHOD_NAME__ << G4endl;
00158 #endif
00159    // clean up after last usage
00160   CleanUp();
00161   
00162    // test input parameters - set global options as default if not specified
00163   TestInputParameters(vacuumMaterialIn,beamPipeThicknessIn,beamPipeMaterialIn,aper1In,aper2In,aper3In);
00164 
00165   std::pair<G4ThreeVector,G4ThreeVector> faces = CalculateFaces(angleInIn, angleOutIn);
00166   G4ThreeVector inputface  = faces.first;
00167   G4ThreeVector outputface = faces.second;
00168 
00169   G4double width  = aper3In + beamPipeThicknessIn + lengthSafety;
00170   G4double height = aper2In + beamPipeThicknessIn + lengthSafety;
00171   
00172   CreateGeneralAngledSolids(nameIn, lengthIn, aper1In, aper2In, aper3In, beamPipeThicknessIn, inputface, outputface);
00173   CreateContainerSubtractionSolid(nameIn, lengthIn, beamPipeThicknessIn, aper1In, aper2In, aper3In);
00174   
00175   return CommonFinalConstruction(nameIn, vacuumMaterialIn, beamPipeMaterialIn, lengthIn, width, height);
00176 }
00177 
00179 
00181 void BDSBeamPipeFactoryLHC::TestInputParameters(G4Material*&  vacuumMaterialIn,     // reference to a pointer
00182                                                 G4double&     beamPipeThicknessIn,
00183                                                 G4Material*&  beamPipeMaterialIn,
00184                                                 G4double&     aper1In,
00185                                                 G4double&     aper2In,
00186                                                 G4double&     aper3In)
00187 {
00188   BDSBeamPipeFactoryBase::TestInputParameters(vacuumMaterialIn,beamPipeThicknessIn,beamPipeMaterialIn);
00189 
00190   if (aper1In < 1e-10)
00191     {aper1In = BDSGlobalConstants::Instance()->GetBeamPipeRadius();}
00192 
00193   if (aper2In < 1e-10)
00194     {aper2In = BDSGlobalConstants::Instance()->GetAper2();}
00195 
00196   if (aper3In < 1e-10)
00197     {aper3In = BDSGlobalConstants::Instance()->GetAper3();}
00198 }
00199 
00202 BDSBeamPipe* BDSBeamPipeFactoryLHC::CommonFinalConstruction(G4String    nameIn,
00203                                                             G4Material* vacuumMaterialIn,
00204                                                             G4Material* beamPipeMaterialIn,
00205                                                             G4double    lengthIn,
00206                                                             G4double    containerWidthIn,
00207                                                             G4double    containerHeightIn)
00208 {
00209 #ifdef BDSDEBUG
00210   G4cout << __METHOD_NAME__ << G4endl;
00211 #endif
00212 
00213   BDSBeamPipeFactoryBase::CommonConstruction(nameIn,
00214                                              vacuumMaterialIn,
00215                                              beamPipeMaterialIn,
00216                                              lengthIn);
00217   
00218   // record extents
00219   std::pair<double,double> extX = std::make_pair(-containerWidthIn,containerWidthIn);
00220   std::pair<double,double> extY = std::make_pair(-containerHeightIn,containerHeightIn);
00221   std::pair<double,double> extZ = std::make_pair(-lengthIn*0.5,lengthIn*0.5);
00222 
00223   // build the BDSBeamPipe instance and return it
00224   return BuildBeamPipeAndRegisterVolumes(extX,extY,extZ,containerWidthIn);
00225 }
00226 
00227 
00230 void BDSBeamPipeFactoryLHC::CreateGeneralAngledSolids(G4String      nameIn,
00231                                                       G4double      lengthIn,
00232                                                       G4double      aper1In,
00233                                                       G4double      aper2In,
00234                                                       G4double      aper3In,
00235                                                       G4double      beamPipeThicknessIn,
00236                                                       G4ThreeVector inputfaceIn,
00237                                                       G4ThreeVector outputfaceIn)
00238 {
00239   // build the solids
00240   //vacuum cylindrical solid (circular cross-section)
00241   G4VSolid* vacCylSolid = new G4CutTubs(nameIn + "_vacuum_cylinder", // name
00242                                         0,                           // inner radius
00243                                         aper3In,                     // outer radius
00244                                         lengthIn*0.5-2*lengthSafety, // half length
00245                                         0,                           // rotation start angle
00246                                         CLHEP::twopi,                // rotation finish angle
00247                                         inputfaceIn,                 // input face normal
00248                                         outputfaceIn);               // output face normal
00249   //vacuum box solid (rectangular cross-section)
00250   G4VSolid* vacRectSolid = new G4Box(nameIn + "_vacuum_box", // name
00251                                      aper1In,                // x half width
00252                                      aper2In,                // y half width
00253                                      lengthIn); // z full width (long for unambiguous intersection)
00254   //intersection of both of these gives the desired shape
00255   vacuumSolid = new G4IntersectionSolid(nameIn + "_vacuum_solid", // name
00256                                         vacCylSolid,              // solid 1
00257                                         vacRectSolid);            // solid 2
00258 
00259   //beampipe cylindrical solid (circular cross-section)
00260   //beampipe inner edge for subtraction (actually just like vacuum + lengthSafety)x
00261   G4VSolid* bpInnerCylSolid = new G4CutTubs(nameIn + "_pipe_inner_cylinder", // name
00262                                             0,                               // inner radius
00263                                             aper3In + lengthSafety,          // outer radius
00264                                             1.5*lengthIn,   // length big for unambiguous subtraction (but < outerlength)
00265                                             0,                               // rotation start angle
00266                                             CLHEP::twopi,                    // rotation finish angle
00267                                             inputfaceIn,                     // input face normal
00268                                             outputfaceIn);                   // output face normal
00269   
00270   //beampipe inner edge box solid (rectangular cross-section)
00271   G4VSolid* bpInnerRectSolid = new G4Box(nameIn + "_pipe_inner_box", // name
00272                                          aper1In + lengthSafety,     // x half width
00273                                          aper2In + lengthSafety,     // y half width
00274                                          1.7*lengthIn); // z long for unambiguous intersection
00275   //beampipe inner intersection - 1.5*length long which is > half length for unambiguous subtraction later
00276   G4VSolid* bpInnerSolid = new G4IntersectionSolid(nameIn + "_pipe_inner_solid", // name
00277                                                    bpInnerCylSolid,              // solid 1
00278                                                    bpInnerRectSolid);            // solid 2
00279 
00280   //beampipe outer edge for subtraction (actually just like vacuum + lengthSafety)x
00281   G4VSolid* bpOuterCylSolid = new G4CutTubs(nameIn + "_pipe_inner_cylinder", // name
00282                                             0,                               // inner radius (0 for unambiguous subtraction)
00283                                             aper3In + beamPipeThicknessIn,   // outer radius
00284                                             (lengthIn*0.5)-2*lengthSafety,   // half length
00285                                             0,                               // rotation start angle
00286                                             CLHEP::twopi,                    // rotation finish angle
00287                                             inputfaceIn,                     // input face normal
00288                                             outputfaceIn);                   // output face normal
00289   
00290   //beampipe outer edge box solid (rectangular cross-section)
00291   G4VSolid* bpOuterRectSolid = new G4Box(nameIn + "_pipe_inner_box",    // name
00292                                          aper1In + beamPipeThicknessIn, // x half width
00293                                          aper2In + beamPipeThicknessIn, // y half width
00294                                          lengthIn); // z full width (long for unambiguous intersection)
00295   G4VSolid* bpOuterSolid = new G4IntersectionSolid(nameIn + "_pipe_inner_solid", // name
00296                                                    bpOuterCylSolid,              // solid 1
00297                                                    bpOuterRectSolid);            // solid 2
00298   
00299 
00300   beamPipeSolid = new G4SubtractionSolid(nameIn + "_pipe_solid",  // name
00301                                          bpOuterSolid,            // this
00302                                          bpInnerSolid);           // minus this
00303   
00304   //container cylindrical solid (circular cross-section)
00305   G4VSolid* contCylSolid = new G4CutTubs(nameIn + "_vacuum_cylinder", // name
00306                                          0,                           // inner radius
00307                                          aper3In + beamPipeThicknessIn + lengthSafety, // outer radius
00308                                          lengthIn*0.5, // half length
00309                                          0,                           // rotation start angle
00310                                          CLHEP::twopi,                // rotation finish angle
00311                                          inputfaceIn,                 // input face normal
00312                                          outputfaceIn);               // output face normal
00313   
00314   //vacuum box solid (rectangular cross-section)
00315   G4VSolid* contRectSolid = new G4Box(nameIn + "_vacuum_box", // name
00316                                       aper1In + beamPipeThicknessIn + lengthSafety, // x half width
00317                                       aper2In + beamPipeThicknessIn + lengthSafety, // y half width
00318                                       lengthIn); // z full width (long for unambiguous intersection)
00319   //intersection of both of these gives the desired shape
00320   containerSolid = new G4IntersectionSolid(nameIn + "_vacuum_solid", // name
00321                                            contCylSolid,              // solid 1
00322                                            contRectSolid);            // solid 2
00323 }
00324 
00325 void BDSBeamPipeFactoryLHC::CreateContainerSubtractionSolid(G4String& nameIn,
00326                                                             G4double& lengthIn,
00327                                                             G4double& beamPipeThicknessIn,
00328                                                             G4double& aper1In,
00329                                                             G4double& aper2In,
00330                                                             G4double& aper3In)
00331 {
00332   //container cylindrical solid (circular cross-section)
00333   G4VSolid* contSubCylSolid = new G4Tubs(nameIn + "_subtraction_cylinder", // name
00334                                          0,                                // inner radius
00335                                          aper3In + beamPipeThicknessIn + lengthSafety, // outer radius
00336                                          2*lengthIn,                       // long length for unambiguous subtraction
00337                                          0,                                // rotation start angle
00338                                          CLHEP::twopi);                    // rotation finish angle
00339   //vacuum box solid (rectangular cross-section)
00340   G4VSolid* contSubRectSolid = new G4Box(nameIn + "_subtraction_box",                  // name
00341                                          aper1In + beamPipeThicknessIn + lengthSafety, // x half width
00342                                          aper2In + beamPipeThicknessIn + lengthSafety, // y half width
00343                                          1.7*lengthIn); // z full width (long for unambiguous intersection)
00344   //intersection of both of these gives the desired shape
00345   containerSubtractionSolid = new G4IntersectionSolid(nameIn + "_subtraction_solid", // name
00346                                                       contSubCylSolid,               // solid 1
00347                                                       contSubRectSolid);             // solid 2
00348 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7