src/BDSAcceleratorComponent.cc

00001 //  
00002 //   BDSIM, (C) 2001-2006 
00003 //   
00004 //   version 0.3
00005 //  
00006 //
00007 //
00008 //
00009 //
00010 //   Generic accelerator component class
00011 //
00012 //
00013 //   History
00014 //
00015 //     24 Nov 2006 by Agapov,  v.0.3
00016 //     x  x   2002 by Blair
00017 //
00018 //
00019 
00020 
00021 #include <list>
00022 #include <sstream>
00023 #include <string>
00024 #include <cmath>
00025 
00026 #include "BDSGlobalConstants.hh" 
00027 
00028 #include "BDSAcceleratorComponent.hh"
00029 #include "BDSMaterials.hh"
00030 #include <string>
00031 #include "G4Box.hh"
00032 #include "G4Tubs.hh"
00033 #include "G4Cons.hh"
00034 #include "G4Torus.hh"
00035 #include "G4VisAttributes.hh"
00036 #include "G4LogicalVolume.hh"
00037 #include "G4VPhysicalVolume.hh"
00038 #include "G4PVPlacement.hh"
00039 #include "G4UserLimits.hh"
00040 #include "G4TransportationManager.hh"
00041 #include "G4SubtractionSolid.hh"
00042 #include "G4IntersectionSolid.hh"
00043 #include "G4UnionSolid.hh"
00044 #include "G4AssemblyVolume.hh"
00045 #include "G4Transform3D.hh"
00046 
00047 
00048 extern G4RotationMatrix* RotY90;
00049 extern G4RotationMatrix* RotYM90;
00050 extern G4RotationMatrix* RotX90;
00051 extern G4RotationMatrix* RotXM90;
00052 extern G4RotationMatrix* RotYM90X90;
00053 extern G4RotationMatrix* RotYM90XM90;
00054 
00055 BDSAcceleratorComponent::BDSAcceleratorComponent (
00056                         G4String& aName,G4double aLength, 
00057                         G4double aBpRadius,G4double aXAper,G4double aYAper, 
00058                         G4VisAttributes* aVisAtt,
00059                         G4String aTunnelMaterial,
00060                         G4String aMaterial,G4double angle,
00061                         G4double XOffset, G4double YOffset,G4double ZOffset, G4double tunnelRadius, G4double tunnelOffsetX,G4String aTunnelCavityMaterial, G4int aPrecisionRegion):
00062   itsName(aName),itsLength(aLength),itsBpRadius(aBpRadius),
00063   itsXAper(aXAper),itsYAper(aYAper),itsAngle(angle),
00064   itsMaterial(aMaterial),itsVisAttributes(aVisAtt),itsTunnelMaterial(aTunnelMaterial),
00065   itsXOffset(XOffset),itsYOffset(YOffset), itsZOffset(ZOffset), itsTunnelRadius(tunnelRadius), itsTunnelOffsetX(tunnelOffsetX),itsTunnelCavityMaterial(aTunnelCavityMaterial), itsPrecisionRegion(aPrecisionRegion)
00066 {
00067   ConstructorInit();
00068 }
00069 
00070 BDSAcceleratorComponent::BDSAcceleratorComponent (
00071                         G4String& aName,G4double aLength, 
00072                         G4double aBpRadius,G4double aXAper,G4double aYAper, 
00073                         G4VisAttributes* aVisAtt,
00074                         std::list<G4double> blmLocZ, std::list<G4double> blmLocTheta,
00075                         G4String aTunnelMaterial,
00076                         G4String aMaterial,G4double angle,
00077                         G4double XOffset, G4double YOffset,G4double ZOffset, G4double tunnelRadius, G4double tunnelOffsetX, G4String aTunnelCavityMaterial, G4int aPrecisionRegion):
00078   itsName(aName),itsLength(aLength),itsBpRadius(aBpRadius),
00079   itsXAper(aXAper),itsYAper(aYAper),itsAngle(angle),
00080   itsMaterial(aMaterial),itsVisAttributes(aVisAtt), itsBlmLocZ(blmLocZ), itsBlmLocTheta(blmLocTheta),
00081   itsTunnelMaterial(aTunnelMaterial),
00082   itsXOffset(XOffset),itsYOffset(YOffset), itsZOffset(ZOffset), itsTunnelRadius(tunnelRadius), itsTunnelOffsetX(tunnelOffsetX), itsTunnelCavityMaterial(aTunnelCavityMaterial), itsPrecisionRegion(aPrecisionRegion)
00083 {
00084   if (itsBlmLocZ.size() != itsBlmLocTheta.size()){
00085     G4cerr << "BDSAcceleratorComponent: error, lists blmLocZ and blmLocTheta are of unequal size" << G4endl;
00086     G4cerr << "blmLocZ.size() = " << blmLocZ.size() << G4endl;
00087     G4cerr << "blmLocTheta.size() = " << blmLocTheta.size() << G4endl;
00088     exit(1);
00089   }
00090   ConstructorInit();
00091 }
00092 
00093 inline void BDSAcceleratorComponent::ConstructorInit(){
00094   //  itsInnerBeampipeUserLimits =new G4UserLimits();
00095 #ifndef NOUSERLIMITS
00096   itsUserLimits = new G4UserLimits();
00097   itsUserLimits->SetMaxAllowedStep(itsLength);
00098   itsUserLimits->SetUserMaxTime(BDSGlobalConstants::Instance()->GetMaxTime());
00099   itsUserLimits->SetUserMinEkine(BDSGlobalConstants::Instance()->GetThresholdCutCharged());
00100 #endif
00101   itsPhi = 0;
00102   itsTheta = 0;
00103   itsPsi = 0;
00104   itsK1 = 0.0; itsK2 = 0.0; itsK3 = 0.0;
00105   itsTilt = 0;
00106   itsPhiAngleIn = 0.0;
00107   itsPhiAngleOut = 0.0;
00108   itsOuterR=0;
00109   itsMagScaleFactor = 1;
00110   itsBlmLocationR=0;
00111   if (itsTunnelRadius<=BDSGlobalConstants::Instance()->GetLengthSafety()){
00112     itsTunnelRadius=BDSGlobalConstants::Instance()->GetTunnelRadius();
00113   }
00114   CalculateLengths();
00115   itsOuterLogicalVolume=NULL;
00116   itsMarkerLogicalVolume=NULL;
00117   itsTunnelLogicalVolume=NULL;
00118   itsTunnelFloorLogicalVolume=NULL;
00119   itsRotation=NULL;
00120   itsOuterStepper=NULL;
00121   itsOuterUserLimits=NULL;
00122   itsMarkerUserLimits=NULL;
00123   itsInnerBeampipeUserLimits=NULL;
00124   itsInnerMostLogicalVolume=NULL;
00125   itsMarkerSolidVolume=NULL;
00126   itsTunnelSolid=NULL;
00127   itsSoilSolid=NULL;
00128   itsInnerTunnelSolid=NULL;
00129   itsTunnelCavity=NULL;
00130   itsLargerTunnelCavity=NULL;
00131   itsTunnelFloor=NULL;
00132   itsLargerInnerTunnelSolid=NULL;
00133   itsTunnelMinusCavity=NULL;
00134   itsTunnelSizedBlock=NULL;
00135   itsBLMLogicalVolume=NULL;
00136   itsBlmCaseLogicalVolume=NULL;
00137   itsSoilTunnelLogicalVolume=NULL;
00138   itsTunnelCavityLogicalVolume=NULL;
00139   itsTunnelMinusCavityLogicalVolume=NULL;
00140   itsTunnelPhysiInner=NULL;
00141   itsTunnelPhysiComp=NULL;
00142   itsTunnelFloorPhysiComp=NULL;
00143   itsTunnelPhysiCompSoil=NULL;
00144   itsTunnelUserLimits=NULL;
00145   itsSoilTunnelUserLimits=NULL;
00146   itsInnerTunnelUserLimits=NULL;
00147 
00148   nullRotationMatrix=NULL;
00149   tunnelRot=NULL;
00150   VisAtt=NULL;
00151   VisAtt1=NULL;
00152   VisAtt2=NULL;
00153   VisAtt3=NULL;
00154   VisAtt4=NULL;
00155   VisAtt5=NULL;
00156   itsBLMSolid=NULL;
00157   itsBlmOuterSolid=NULL;
00158   itsSPos = 0.0;
00159   itsCopyNumber = 0;
00160   itsBDSEnergyCounter=NULL;
00161   itsSensitiveVolume=NULL;  
00162 }
00163 
00164 BDSAcceleratorComponent::~BDSAcceleratorComponent ()
00165 {
00166   delete VisAtt;
00167   delete VisAtt1;
00168   delete VisAtt2;
00169   delete VisAtt3;
00170   delete VisAtt4;
00171   delete VisAtt5;
00172 }
00173 
00174 void BDSAcceleratorComponent::PrepareField(G4VPhysicalVolume*)
00175 {//do nothing by default
00176   return;
00177 }
00178 
00179 void BDSAcceleratorComponent::CalculateLengths(){
00180   itsXLength = itsYLength = std::max(itsOuterR,BDSGlobalConstants::Instance()->GetComponentBoxSize()/2);
00181   itsXLength = std::max(itsXLength, this->GetTunnelRadius()+2*std::abs(this->GetTunnelOffsetX()) + BDSGlobalConstants::Instance()->GetTunnelThickness()+BDSGlobalConstants::Instance()->GetTunnelSoilThickness() + 4*BDSGlobalConstants::Instance()->GetLengthSafety() );   
00182   itsYLength = std::max(itsYLength, this->GetTunnelRadius()+2*std::abs(BDSGlobalConstants::Instance()->GetTunnelOffsetY()) + BDSGlobalConstants::Instance()->GetTunnelThickness()+BDSGlobalConstants::Instance()->GetTunnelSoilThickness()+4*BDSGlobalConstants::Instance()->GetLengthSafety() );
00183   
00184 }
00185 
00186 void BDSAcceleratorComponent::SynchRescale(G4double)
00187 {
00188   return;
00189 }
00190 
00191 void BDSAcceleratorComponent::AlignComponent(G4ThreeVector& TargetPos,
00192                                              G4RotationMatrix *TargetRot, 
00193                                              G4RotationMatrix&,
00194                                              G4ThreeVector&,
00195                                              G4ThreeVector&,
00196                                              G4ThreeVector&,
00197                                              G4ThreeVector&,
00198                                              G4ThreeVector&)
00199 {//do nothing by default, except set rotation and position for BDSOutline
00200   itsRotation=TargetRot;
00201   itsPosition=TargetPos;
00202   return;
00203 }
00204 
00205 void BDSAcceleratorComponent::BuildTunnel()
00206 {
00207   //Make sure length is not zero
00208   if(itsLength <= BDSGlobalConstants::Instance()->GetLengthSafety()){
00209     G4cout << "BDSAcceleratorComponent::BuildTunnel() - WARNING - " << G4endl;
00210     G4cout << "Components length, " << itsLength << ", less than or equal to safety length, " << BDSGlobalConstants::Instance()->GetLengthSafety() << ". Not building tunnel." << G4endl;
00211     G4Exception("Error: length of component less than safety length", "-1", JustWarning, "");
00212     return;
00213   }
00214 
00215   std::string tunnelMaterialName;
00216   if(itsTunnelMaterial!=""){
00217     tunnelMaterialName=itsTunnelMaterial;
00218   } else {
00219     tunnelMaterialName =BDSGlobalConstants::Instance()->GetTunnelMaterialName();
00220   }
00221   G4Material *tunnelMaterial=BDSMaterials::Instance()->GetMaterial(tunnelMaterialName);
00222   
00223   std::string soilMaterialName =BDSGlobalConstants::Instance()->GetSoilMaterialName();
00224   G4Material *soilMaterial=BDSMaterials::Instance()->GetMaterial(soilMaterialName);
00225 
00226 
00227 #ifdef DEBUG
00228   G4cout << "Soil :"
00229          << " r= " << (itsTunnelRadius+BDSGlobalConstants::Instance()->GetTunnelThickness())/m + BDSGlobalConstants::Instance()->GetTunnelSoilThickness()/m<< " m"
00230          << " l= " << itsLength/m << " m"
00231          << " material = " << soilMaterialName << " m"
00232          << G4endl;
00233   G4cout << "Outer tunnel :"
00234          << " r= " << (itsTunnelRadius+BDSGlobalConstants::Instance()->GetTunnelThickness())/m << " m"
00235          << " l= " << itsLength/m << " m"
00236          << " material = " << tunnelMaterialName << " m"
00237          << G4endl;
00238   G4cout << "Inner tunnel :"
00239          << " r= " << itsTunnelRadius/m << " m"
00240          << " l= " << itsLength/m << " m"
00241          << G4endl;
00242 #endif
00243 
00244   tunnelRot=new G4RotationMatrix();
00245   G4ThreeVector tunnelTrans;
00246   G4ThreeVector floorOffsetThreeVector;
00247   G4double blockSize = 4*itsTunnelRadius;
00248   G4ThreeVector nullThreeVector = G4ThreeVector(0,0,0);
00249   nullRotationMatrix = new G4RotationMatrix();
00250 
00251 
00252   //  if ( itsAngle/itsLength < 1.25e-4 ){ //Build a straight tunnel using tubes
00253   if ( itsAngle==0 ){ //Build a straight tunnel using tubes
00254   itsTunnelSizedBlock = new G4Box(
00255                                   itsName+"_bnd_sized_block_solid", 
00256                                   blockSize,
00257                                   blockSize,
00258                                   (itsLength-BDSGlobalConstants::Instance()->GetLengthSafety())
00259                                   );
00260 
00261    itsTunnelSolid=new G4Tubs(itsName+"_tun_solid",
00262                              0,
00263                              itsTunnelRadius+BDSGlobalConstants::Instance()->GetTunnelThickness(),
00264                              (itsLength-BDSGlobalConstants::Instance()->GetLengthSafety())/2.0,
00265                              0,twopi*radian);
00266    
00267    itsSoilSolid=new G4Tubs(itsName+"_tun_soil_solid",
00268                            itsTunnelRadius+BDSGlobalConstants::Instance()->GetTunnelThickness()+BDSGlobalConstants::Instance()->GetLengthSafety(),
00269                            itsTunnelRadius+BDSGlobalConstants::Instance()->GetTunnelThickness()+BDSGlobalConstants::Instance()->GetLengthSafety()+BDSGlobalConstants::Instance()->GetTunnelSoilThickness(),     
00270                            (itsLength-BDSGlobalConstants::Instance()->GetLengthSafety())/2.0,
00271                            0,twopi*radian);
00272    
00273    itsInnerTunnelSolid=new G4Tubs(itsName+"_inner_tun_solid",
00274                                   0.,
00275                                   itsTunnelRadius,
00276                                   (itsLength-BDSGlobalConstants::Instance()->GetLengthSafety())/2,
00277                                   0,twopi*radian);
00278    
00279    itsLargerInnerTunnelSolid=new G4Tubs(itsName+"_inner_tun_solid",
00280                                         0.,
00281                                         itsTunnelRadius+BDSGlobalConstants::Instance()->GetLengthSafety(),
00282                                         (itsLength-BDSGlobalConstants::Instance()->GetLengthSafety()),
00283                                         0,twopi*radian);
00284    
00285    tunnelTrans.setX(itsTunnelOffsetX);
00286    tunnelTrans.setY(BDSGlobalConstants::Instance()->GetTunnelOffsetY());
00287    tunnelTrans.setZ(0);
00288 
00289    floorOffsetThreeVector = G4ThreeVector(0,-blockSize-BDSGlobalConstants::Instance()->GetTunnelFloorOffset(),0);
00290 
00291    
00292    itsTunnelCavity = new G4SubtractionSolid(
00293                                          itsName +"_tun_cavity_solid", 
00294                                          itsInnerTunnelSolid,
00295                                          itsTunnelSizedBlock,
00296                                          nullRotationMatrix,
00297                                          floorOffsetThreeVector
00298                                          );
00299 
00300    itsLargerTunnelCavity = new G4SubtractionSolid(
00301                                          itsName +"_tun_cavity_solid", 
00302                                          itsLargerInnerTunnelSolid,
00303                                          itsTunnelSizedBlock,
00304                                          nullRotationMatrix,
00305                                          floorOffsetThreeVector
00306                                          );
00307 
00308   } else {//Build a trapezoidal tunnel to follow the bends
00309 
00310     G4double pi_ov_2 = asin(1.);
00311     tunnelRot->rotateY(pi_ov_2);
00312 
00313     G4double xHalfLengthPlus, xHalfLengthMinus, tunHalfLen;
00314     xHalfLengthMinus = (itsLength/itsAngle)*sin(itsAngle/2)
00315       - fabs(cos(itsAngle/2)) * (itsTunnelRadius + BDSGlobalConstants::Instance()->GetTunnelThickness()) * tan(itsAngle/2)/2;
00316     
00317     xHalfLengthPlus = (itsLength/itsAngle)*sin(itsAngle/2)
00318       + fabs(cos(itsAngle/2)) * (itsTunnelRadius + BDSGlobalConstants::Instance()->GetTunnelThickness()) * tan(itsAngle/2)/2;
00319     
00320     tunHalfLen = std::max(xHalfLengthPlus,xHalfLengthMinus);
00321     tunnelTrans.setZ(0);
00322     tunnelTrans.setX(0);
00323     tunnelTrans.setY(BDSGlobalConstants::Instance()->GetTunnelOffsetY());
00324 
00325     
00326 
00327 #ifdef DEBUG
00328     G4cout << "Building a block" << G4endl;
00329 #endif
00330     itsTunnelSizedBlock = new G4Box(
00331                                     itsName+"_bnd_sized_block_solid", 
00332                                     blockSize,
00333                                     blockSize,
00334                                     tunHalfLen
00335                                     );
00336 
00337     
00338 #ifdef DEBUG
00339     G4cout << "Building a tunnel solid" << G4endl;
00340 #endif
00341 
00342     itsTunnelSolid = new G4IntersectionSolid(
00343                                              itsName+"_tun_solid",
00344                                              new G4Tubs(
00345                                                         itsName+"_temp_tun_solid",
00346                                                         0,
00347                                                         itsTunnelRadius+BDSGlobalConstants::Instance()->GetTunnelThickness(),
00348                                                         tunHalfLen,
00349                                                         0,twopi*radian),                            
00350                                              itsMarkerLogicalVolume->GetSolid(),
00351                                              RotYM90,
00352                                              nullThreeVector
00353                                              ); 
00354 #ifdef DEBUG
00355     G4cout << "Building a soil tunnel solid" << G4endl;
00356 #endif
00357     itsSoilSolid = new G4IntersectionSolid(
00358                                            itsName+"_soil_solid",
00359                                            new G4Tubs(
00360                                                       itsName+"_temp_soil_solid",
00361                                                       itsTunnelRadius+BDSGlobalConstants::Instance()->GetTunnelThickness()+BDSGlobalConstants::Instance()->GetLengthSafety(),
00362                                                       itsTunnelRadius+BDSGlobalConstants::Instance()->GetTunnelThickness()+BDSGlobalConstants::Instance()->GetLengthSafety()+BDSGlobalConstants::Instance()->GetTunnelSoilThickness(),
00363                                                       tunHalfLen,
00364                                                       0,twopi*radian),
00365                                            itsMarkerLogicalVolume->GetSolid(),
00366                                            RotYM90,
00367                                            nullThreeVector
00368                                            ); 
00369 #ifdef DEBUG   
00370     G4cout << "Building inner tunnel solid" << G4endl;
00371 #endif
00372     itsInnerTunnelSolid=new G4IntersectionSolid(
00373                                                 itsName+"_inner_tun_solid",
00374                                                 new G4Tubs(itsName+"_temp_inner_tun_solid",
00375                                                            0.,
00376                                                            itsTunnelRadius,
00377                                                            tunHalfLen,
00378                                                            0,twopi*radian),
00379                                                 itsMarkerLogicalVolume->GetSolid(),
00380                                                 RotYM90,
00381                                                 nullThreeVector
00382                                                 ); 
00383 #ifdef DEBUG
00384     G4cout << "Building larger inner tunnel solid" << G4endl;
00385 #endif
00386     itsLargerInnerTunnelSolid= new G4Tubs(itsName+"_temp_inner_tun_solid",
00387                                           0.,
00388                                           itsTunnelRadius+BDSGlobalConstants::Instance()->GetLengthSafety(),
00389                                           2*tunHalfLen,
00390                                           0,twopi*radian);
00391                                                        
00392     
00393     floorOffsetThreeVector = G4ThreeVector(0,-blockSize-BDSGlobalConstants::Instance()->GetTunnelFloorOffset(),0);
00394     
00395 #ifdef DEBUG
00396     G4cout << "Building tunnel cavity" << G4endl;
00397 #endif
00398     itsTunnelCavity = new G4SubtractionSolid(
00399                                          itsName +"_tun_cavity_solid", 
00400                                          itsInnerTunnelSolid,
00401                                          itsTunnelSizedBlock,
00402                                          nullRotationMatrix,
00403                                          floorOffsetThreeVector
00404                                          );
00405 #ifdef DEBUG
00406     G4cout << "Building larger tunnel cavity" << G4endl;
00407 #endif
00408    itsLargerTunnelCavity = new G4SubtractionSolid(
00409                                          itsName +"_tun_cavity_solid", 
00410                                          itsLargerInnerTunnelSolid,
00411                                          itsTunnelSizedBlock,
00412                                          nullRotationMatrix,
00413                                          floorOffsetThreeVector
00414                                          );
00415   }   //End of "else" statement relevant to bending tunnel
00416 
00417   
00418 #ifdef DEBUG
00419   G4cout << "Building tunnel minus cavity" << G4endl;
00420 #endif
00421   itsTunnelMinusCavity = new G4SubtractionSolid(
00422                                                 itsName+"_tun_floor_and_tun",
00423                                                 itsTunnelSolid,
00424                                                 itsLargerTunnelCavity
00425                                                 );
00426 #ifdef DEBUG
00427   G4cout << "Building tunnel minus cavity logical volume" << G4endl;
00428 #endif
00429 
00430   itsTunnelMinusCavityLogicalVolume=    
00431     new G4LogicalVolume(itsTunnelMinusCavity,
00432                         tunnelMaterial,
00433                         itsName+"_tun_flr_and_tun_log");
00434   
00435 #ifdef DEBUG
00436   G4cout << "Building soil tunnel logical volume" << G4endl;
00437 #endif
00438   itsSoilTunnelLogicalVolume=   
00439     new G4LogicalVolume(itsSoilSolid,
00440                         soilMaterial,
00441                         itsName+"_tun_soil_log");
00442 #ifdef DEBUG
00443   G4cout << "Building tunnel logical volume" << G4endl;
00444 #endif
00445   itsTunnelLogicalVolume=       
00446     new G4LogicalVolume(itsTunnelSolid,
00447                         tunnelMaterial,
00448                         itsName+"_tun_log");
00449 #ifdef DEBUG
00450   G4cout << "Building tunnel cavity logical volume" << G4endl;
00451 #endif
00452 
00453   std::string tunnelCavityMaterialName;
00454   if(itsTunnelCavityMaterial!=""){
00455     tunnelCavityMaterialName=itsTunnelCavityMaterial;
00456   } else {
00457     tunnelCavityMaterialName =BDSGlobalConstants::Instance()->GetTunnelCavityMaterialName();
00458   }
00459 
00460   itsTunnelCavityLogicalVolume= 
00461     new G4LogicalVolume(itsLargerTunnelCavity,
00462                         BDSMaterials::Instance()->GetMaterial(tunnelCavityMaterialName),
00463                         itsName+"_tun_cav_log");
00464 #ifdef DEBUG
00465   G4cout << "Placing tunnel minus cavity" << G4endl;
00466 #endif
00467   itsTunnelPhysiComp = new G4PVPlacement(
00468                                          tunnelRot,                  // no rotation
00469                                          tunnelTrans,                        // at (0,0,0)
00470                                          itsTunnelMinusCavityLogicalVolume,  // its logical volume
00471                                          itsName+"_tun_phys",        // its name
00472                                          itsMarkerLogicalVolume,    // its mother  volume
00473                                          true,               // no boolean operation
00474                                          0, BDSGlobalConstants::Instance()->GetCheckOverlaps());                             // copy number
00475   
00476   
00477   SetMultiplePhysicalVolumes(itsTunnelPhysiComp);
00478 
00479 #ifdef DEBUG
00480   G4cout << "Placing soil around tunnel" << G4endl;
00481 #endif
00482   itsTunnelPhysiCompSoil = new G4PVPlacement(
00483                                              tunnelRot,              // no rotation
00484                                              tunnelTrans,                            // at (0,0,0)
00485                                              itsSoilTunnelLogicalVolume,  // its logical volume
00486                                              itsName+"_tun_phys_soil",       // its name
00487                                              itsMarkerLogicalVolume,    // its mother  volume
00488                                              true,                   // no boolean operation
00489                                              0, BDSGlobalConstants::Instance()->GetCheckOverlaps());                         // copy number
00490   
00491   SetMultiplePhysicalVolumes(itsTunnelPhysiCompSoil);
00492   /*
00493     itsTunnelPhysiInner = new G4PVPlacement(
00494     tunnelRot,
00495     tunnelTrans,                        // at (0,0,0)
00496     itsTunnelCavityLogicalVolume,  // its logical volume
00497     itsName+"_inner_tun_phys",// its name
00498     itsMarkerLogicalVolume,   // its mother  volume
00499     false,                      // no boolean operation
00500     0, BDSGlobalConstants::Instance()->GetCheckOverlaps());                     // copy number
00501   */
00502   
00503 #ifndef NOUSERLIMITS
00504   itsTunnelUserLimits = new G4UserLimits("tunnel cuts");
00505   itsSoilTunnelUserLimits = new G4UserLimits("tunnel soil cuts");
00506   itsInnerTunnelUserLimits = new G4UserLimits("inner tunnel cuts");
00507   G4double tcut = BDSGlobalConstants::Instance()->GetThresholdCutCharged();
00508   if(tcut>0){
00509     itsTunnelUserLimits->SetUserMinEkine(tcut);
00510     itsSoilTunnelUserLimits->SetUserMinEkine(tcut);
00511     itsInnerTunnelUserLimits->SetUserMinEkine(tcut);
00512   }
00513   
00514   itsTunnelUserLimits->SetUserMaxTime(BDSGlobalConstants::Instance()->GetMaxTime());
00515   itsSoilTunnelUserLimits->SetUserMaxTime(BDSGlobalConstants::Instance()->GetMaxTime());
00516   itsInnerTunnelUserLimits->SetUserMaxTime(BDSGlobalConstants::Instance()->GetMaxTime());
00517 
00518   itsTunnelUserLimits->SetMaxAllowedStep(itsLength);
00519   itsSoilTunnelUserLimits->SetMaxAllowedStep(itsLength);
00520   itsInnerTunnelUserLimits->SetMaxAllowedStep(itsLength);
00521   
00522   itsTunnelMinusCavityLogicalVolume->SetUserLimits(itsTunnelUserLimits);
00523   itsSoilTunnelLogicalVolume->SetUserLimits(itsSoilTunnelUserLimits);
00524   itsTunnelCavityLogicalVolume->SetUserLimits(itsInnerTunnelUserLimits);
00525 #endif
00526   
00527 #ifdef DEBUG
00528   G4cout << "Setting vis attributes" << G4endl;
00529 #endif
00530   //
00531     // set visualization attributes
00532     //
00533   VisAtt = new G4VisAttributes(G4Colour(0.0, 1.0, 0.0));
00534   VisAtt->SetVisibility(false);
00535   VisAtt->SetForceSolid(true);  
00536   
00537   itsSoilTunnelLogicalVolume->SetVisAttributes(VisAtt);
00538   VisAtt1 = new G4VisAttributes(G4Colour(0.4, 0.4, 0.4));
00539   VisAtt1->SetVisibility(BDSGlobalConstants::Instance()->GetShowTunnel());
00540   VisAtt1->SetForceSolid(true);
00541   VisAtt2 = new G4VisAttributes(G4Colour(0.0, 0.5, 0.5));
00542   VisAtt2->SetVisibility(false);
00543   VisAtt2->SetForceSolid(true);
00544   VisAtt3 = new G4VisAttributes(G4Colour(0.4, 0.4, 0.4));
00545   VisAtt3->SetVisibility(false);
00546   VisAtt3->SetForceSolid(true);
00547   itsTunnelMinusCavityLogicalVolume->SetVisAttributes(VisAtt1);
00548   itsMarkerLogicalVolume->SetVisAttributes(VisAtt);
00549   itsTunnelCavityLogicalVolume->SetVisAttributes(VisAtt2);
00550   
00551 }
00552 
00553 void BDSAcceleratorComponent::BuildBLMs()
00554 {
00555  if(itsBlmLocZ.size() > 0){
00556 
00557    //declare materials
00558    G4Material *blmMaterial;
00559    blmMaterial = BDSMaterials::Instance()->GetMaterial("nitrogen");
00560    G4Material *caseMaterial;
00561    caseMaterial = BDSMaterials::Instance()->GetMaterial("nitrogen");
00562    
00563    /*
00564      blmCaseMaterial = BDSMaterials::Instance()->GetMaterial("cement");
00565    */
00566 
00567    //declare Matrices & doubles
00568    G4RotationMatrix blmRot = G4RotationMatrix();
00569    G4ThreeVector blmTrans;
00570    //    G4double blmXRot;
00571    G4double blmYTrans;
00572    G4double blmXTrans;
00573    G4double blmCaseThickness;
00574    
00575    G4AssemblyVolume* assemblyBlms= new G4AssemblyVolume();
00576    G4Transform3D blmTr3d;
00577    
00578    //declare vis attributes
00579    VisAtt4 = new G4VisAttributes(G4Colour(0.5, 0.5, 0.0));
00580    VisAtt4->SetVisibility(true);
00581    VisAtt4->SetForceSolid(true);
00582    VisAtt5 = new G4VisAttributes(G4Colour(0.5, 0.0, 0.5));
00583    VisAtt5->SetVisibility(true);
00584    VisAtt5->SetForceSolid(true);
00585 
00586    //set case thickness
00587    blmCaseThickness = 1e-20*m;
00588 
00589    itsBlmLocationR = itsBlmLocationR + BDSGlobalConstants::Instance()->GetBlmRad() + BDSGlobalConstants::Instance()->GetLengthSafety() +itsBpRadius + blmCaseThickness;
00590    
00591 #ifdef DEBUG
00592    G4cout << "BDSAcceleratorComponent::BuildBLMs() itsBlmLocationRadius = " << itsBlmLocationR/mm << " mm" << G4endl;
00593 #endif
00594    
00595    G4double localLength;
00596    
00597    //Make sure BLM length can never exceed component length
00598 #ifdef DEBUG
00599    G4cout << "BLM length = " << BDSGlobalConstants::Instance()->GetBlmLength()/m << " m" << G4endl;
00600    G4cout << "BLM radius = " << BDSGlobalConstants::Instance()->GetBlmRad()/m << " m" << G4endl;
00601    G4cout << "Component length = " << itsLength/m << " m" << G4endl;
00602 #endif
00603    if(BDSGlobalConstants::Instance()->GetBlmLength()>=(itsLength-BDSGlobalConstants::Instance()->GetLengthSafety())){
00604      G4cout << itsName << "Warning: BLM longer than element. Setting BLM length to element length." << G4endl;
00605      localLength = itsLength-BDSGlobalConstants::Instance()->GetLengthSafety();
00606    } else {
00607      localLength=BDSGlobalConstants::Instance()->GetBlmLength();
00608    }
00609    
00610    G4int i = 0;
00611    std::list<double>::iterator zit;
00612    std::list<double>::iterator thetait;
00613    for (zit=itsBlmLocZ.begin(), thetait=itsBlmLocTheta.begin(); zit!=itsBlmLocZ.end(); zit++, thetait++){
00614 #ifdef DEBUG
00615      G4cout << "Building BLM " << i << G4endl; 
00616 #endif
00617      G4double indexInt = (G4double)i;
00618      std::string index;
00619      std::stringstream out;
00620      out << indexInt;
00621      index = out.str();
00622      
00623      blmYTrans=itsBlmLocationR*cos(*thetait);
00624      blmXTrans=-1*itsBlmLocationR*sin(*thetait);
00625      blmTrans.setZ(*zit*1000);
00626      blmTrans.setY(blmYTrans);
00627      blmTrans.setX(blmXTrans);
00628      
00629 #ifdef DEBUG
00630      if((*zit*1000) < 0){
00631        G4cout << "itsLength is: " << itsLength << G4endl;
00632        G4cout << "z position defined is: " << (*zit*1000) << G4endl;
00633      }
00634 #endif
00635      
00636      itsBLMSolid = new G4Tubs(itsName + "_BLM_sol_" + index,
00637                                       0,
00638                                       BDSGlobalConstants::Instance()->GetBlmRad(),
00639                                       localLength/2, 0, twopi*radian);
00640      
00641      
00642      itsBlmOuterSolid = new G4Tubs(itsName + "_Blm_outCase_sol_" + index, 
00643                                            0,
00644                                            BDSGlobalConstants::Instance()->GetBlmRad() + blmCaseThickness,
00645                                            localLength/2 + blmCaseThickness, 0, twopi*radian);
00646      
00647      G4SubtractionSolid *itsBlmCaseSolid = new G4SubtractionSolid(itsName + "_blm_case_subsolid_" + index,
00648                                                                   itsBlmOuterSolid,
00649                                                                   itsBLMSolid);       
00650        
00651        itsBLMLogicalVolume = new G4LogicalVolume(itsBLMSolid,
00652                                                  blmMaterial,
00653                                                  itsName + "_blm_logvol_" + index);
00654        
00655        //Set BLM gas as sensitive if option is chosen
00656        if(BDSGlobalConstants::Instance()->GetSensitiveBLMs()){
00657          SetMultipleSensitiveVolumes(itsBLMLogicalVolume);
00658        }
00659 
00660        itsBlmCaseLogicalVolume = new G4LogicalVolume(itsBlmCaseSolid,
00661                                                      caseMaterial,
00662                                                      itsName + "_blm_case_logvol_" + index);
00663        
00664        itsBlmCaseLogicalVolume->SetVisAttributes(VisAtt2);
00665        itsBLMLogicalVolume->SetVisAttributes(VisAtt1);
00666          
00667        blmTr3d=G4Transform3D(blmRot,blmTrans);
00668      
00669        assemblyBlms->AddPlacedVolume(itsBLMLogicalVolume,blmTr3d);
00670        assemblyBlms->AddPlacedVolume(itsBlmCaseLogicalVolume,blmTr3d);
00671    }  
00672    if (itsType=="sbend" || itsType=="rbend"){
00673      blmRot.setTheta(twopi/4.0);
00674      blmRot.setPsi(-twopi/4.0);
00675      blmRot.setPhi(twopi/4.0);
00676    } else {
00677      blmRot.setTheta(0.0);
00678      blmRot.setPsi(0.0);
00679      blmRot.setPhi(0.0);
00680    }
00681    blmTrans.setX(0.0);
00682    blmTrans.setY(0.0);
00683    blmTrans.setZ(0.0);
00684    blmTr3d=G4Transform3D(blmRot,blmTrans);
00685    assemblyBlms->MakeImprint(itsMarkerLogicalVolume,blmTr3d);
00686  }
00687 }
00688 
00689 //This Method is for investigating the Anomalous signal at LHc junction IP8
00690 
00691 void BDSAcceleratorComponent::BuildGate()
00692 {
00693   //Declare variables, matrices and constants to use
00694   G4RotationMatrix *gateRot = new G4RotationMatrix();
00695   G4ThreeVector gateTrans;
00696   G4ThreeVector floorOffsetThreeVector;
00697   G4Material *gateMaterial;
00698 
00699   //Set basic variables
00700   G4double gateX = 0.05*m;
00701   G4double gateY = 1.0*m;
00702   G4double gateZ = 0.63*0.99*m;//1.5*m;
00703   G4double gateXOffset = 3*m;
00704   G4double gateYOffset = -BDSGlobalConstants::Instance()->GetTunnelFloorOffset()/2 + gateY/2;
00705   G4double gateZOffset = -4.095*m; //Shifted along z 4.095m from centre of dipole
00706   gateMaterial = BDSMaterials::Instance()->GetMaterial("iron");
00707   
00708   //Set position and rotation of gate
00709   gateTrans.setX(gateZOffset);
00710   gateTrans.setY(gateYOffset);
00711   gateTrans.setZ(gateXOffset);
00712 
00713   G4Box* itsGateSolid = new G4Box(itsName + "_gate_Solid",
00714                               gateZ,
00715                               gateY,
00716                               gateX
00717                               );
00718   G4LogicalVolume* itsGateLogicalVolume = new G4LogicalVolume(itsGateSolid,
00719                                                           gateMaterial,
00720                                                           itsName + "_gate_Log_Vol");
00721 
00722   G4PVPlacement*  itsGatePhysi = new G4PVPlacement(gateRot,
00723                                                   gateTrans,
00724                                                   itsGateLogicalVolume,
00725                                                   itsName + "_gate_physi",
00726                                                   itsMarkerLogicalVolume,
00727                                                   false,
00728                                                    0,
00729                                                    BDSGlobalConstants::Instance()->GetCheckOverlaps());
00730   SetMultiplePhysicalVolumes(itsGatePhysi);
00731   
00732   G4VisAttributes* VisAtt = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0));
00733   VisAtt->SetVisibility(true);
00734   VisAtt->SetForceSolid(true);
00735   itsGateLogicalVolume->SetVisAttributes(VisAtt);
00736   }
00737 
00738 //  LocalWords:  itsTunnelUserLimits

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7