src/BDSCollimator.cc

00001 /* BDSIM code.    Version beta
00002    Author: Grahame I. Agapov, Royal Holloway, Univ. of London.
00003 
00004 */
00005 #include "BDSGlobalConstants.hh" 
00006 #include "BDSCollimator.hh"
00007 #include "G4VisAttributes.hh"
00008 #include "G4LogicalVolume.hh"
00009 #include "G4VPhysicalVolume.hh"
00010 #include "G4PVPlacement.hh"               
00011 #include "G4SubtractionSolid.hh"
00012 #include "G4UserLimits.hh"
00013 #include "G4TransportationManager.hh"
00014 
00015 #include "G4SDManager.hh"
00016 #include "G4UserLimits.hh"
00017 #include "parser/gmad.h"
00018 #include <map>
00019 
00020 //============================================================
00021 typedef std::map<G4String,int> LogVolCountMap;
00022 extern LogVolCountMap* LogVolCount;
00023 
00024 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00025 extern LogVolMap* LogVol;
00026 
00027 //============================================================
00028 
00029 BDSCollimator::BDSCollimator (G4String aName,G4double aLength,G4double bpRad,
00030                               G4double xAper,G4double yAper, G4int type,
00031                               G4Material *CollimatorMaterial, G4double outR, 
00032                               std::list<G4double> blmLocZ, std::list<G4double> blmLocTheta,
00033                               G4String aTunnelMaterial):
00034   BDSAcceleratorComponent(aName,
00035                           aLength,bpRad,xAper,yAper,
00036                           SetVisAttributes(), blmLocZ, blmLocTheta, aTunnelMaterial),
00037   itsPhysiComp(NULL), itsPhysiComp2(NULL), itsSolidLogVol(NULL), itsTempSolidLogVol(NULL),
00038   itsInnerLogVol(NULL), itsInnerSolid(NULL), itsOuterSolid(NULL), itsSolid(NULL), itsSoilTube(NULL),
00039   itsTunnelTube(NULL),  itsInnerTunnelTube(NULL), itsInnerTunnelLogicalVolume(NULL),
00040   itsSoilTunnelLogicalVolume(NULL), itsTunnelUserLimits(NULL), itsSoilTunnelUserLimits(NULL),
00041   itsInnerTunnelUserLimits(NULL), itsVisAttributes(NULL), itsEqRhs(NULL),
00042   itsCollimatorMaterial(CollimatorMaterial), itsOuterR(outR)
00043 {
00044   if(type==_RCOL) itsType="rcol";
00045   if(type==_ECOL) itsType="ecol";
00046 
00047   if(itsOuterR==0) itsOuterR = BDSGlobalConstants::Instance()->GetComponentBoxSize()/2;
00048 
00049   if ( (*LogVolCount)[itsName]==0)
00050     {
00051   G4double xLength, yLength;
00052   xLength = yLength = std::max(itsOuterR,BDSGlobalConstants::Instance()->GetComponentBoxSize()/2);
00053 
00054   xLength = std::max(xLength, this->GetTunnelRadius()+2*std::abs(this->GetTunnelOffsetX()) + BDSGlobalConstants::Instance()->GetTunnelThickness()+BDSGlobalConstants::Instance()->GetTunnelSoilThickness() + 4*BDSGlobalConstants::Instance()->GetLengthSafety() );   
00055   yLength = std::max(yLength, this->GetTunnelRadius()+2*std::abs(BDSGlobalConstants::Instance()->GetTunnelOffsetY()) + BDSGlobalConstants::Instance()->GetTunnelThickness()+BDSGlobalConstants::Instance()->GetTunnelSoilThickness()+4*BDSGlobalConstants::Instance()->GetLengthSafety() );
00056 
00057   itsMarkerLogicalVolume=new G4LogicalVolume
00058     (new G4Box( itsName+"_marker_log",
00059                 xLength,
00060                 yLength,
00061                 (itsLength+BDSGlobalConstants::Instance()->GetLengthSafety())/2), //z half length 
00062      BDSMaterials::Instance()->GetMaterial("vacuum"),
00063      itsName+"_log");
00064 
00065       if(BDSGlobalConstants::Instance()->GetBuildTunnel()){
00066         BuildTunnel();
00067       }
00068       BuildInnerCollimator();
00069       BuildBLMs();
00070 
00071       itsSolidLogVol->SetVisAttributes(SetVisAttributes());
00072 
00073       // visual attributes
00074       G4VisAttributes* VisAtt1 =
00075         new G4VisAttributes(G4Colour(0., 0., 0.));
00076       VisAtt1->SetForceSolid(true);
00077       if (itsInnerLogVol) itsInnerLogVol->SetVisAttributes(VisAtt1);
00078 
00079       (*LogVolCount)[itsName]=1;
00080       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00081     }
00082   else
00083     {
00084       (*LogVolCount)[itsName]++;
00085       itsMarkerLogicalVolume=(*LogVol)[itsName];
00086     }  
00087 }
00088 
00089 void BDSCollimator::BuildBLMs(){
00090   itsBlmLocationR=itsOuterR*2;
00091   BDSAcceleratorComponent::BuildBLMs();
00092 }
00093 
00094 G4VisAttributes* BDSCollimator::SetVisAttributes()
00095 {
00096   itsVisAttributes=new G4VisAttributes(G4Colour(0.3,0.4,0.2));
00097   itsVisAttributes->SetForceSolid(true);
00098   return itsVisAttributes;
00099 }
00100 
00101 
00102 void BDSCollimator::BuildInnerCollimator()
00103 {
00104 
00105   // zero aperture --> no aperture
00106   if(itsXAper <= 0) itsXAper = DBL_MIN;//BDSGlobalConstants::Instance()->GetComponentBoxSize()/2;
00107   if(itsYAper <= 0) itsYAper = DBL_MIN;//BDSGlobalConstants::Instance()->GetComponentBoxSize()/2;
00108 
00109   if( (itsXAper>0) && (itsYAper>0) ){
00110     G4cout << "BDSCollimator: building aperture" << G4endl;
00111     if(itsType == "rcol")
00112       {
00113         itsInnerSolid=new G4Box(itsName+"_inner",
00114                                 itsXAper,
00115                                 itsYAper,
00116                                 itsLength/2);
00117       }
00118     
00119     if(itsType == "ecol")
00120       {
00121         itsInnerSolid=new G4EllipticalTube(itsName+"_inner",
00122                                            itsXAper,
00123                                            itsYAper,
00124                                            itsLength/2);
00125       }
00126   
00127     itsInnerLogVol=
00128       new G4LogicalVolume(itsInnerSolid,
00129                           BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->GetVacuumMaterial()),
00130                           itsName+"_inner_log");
00131 
00132 #ifndef NOUSERLIMITS
00133   itsInnerLogVol-> SetUserLimits(itsUserLimits);
00134 #endif
00135 
00136   }
00137   
00138   itsOuterSolid = new G4Box(itsName+"_outer_solid",
00139                             itsOuterR,
00140                             itsOuterR,
00141                             itsLength/2);
00142 
00143   G4ThreeVector nullThreeVector = G4ThreeVector(0,0,0);
00144   G4RotationMatrix *nullRotationMatrix = new G4RotationMatrix();  
00145 
00146   itsSolidLogVol=
00147     new G4LogicalVolume(itsOuterSolid,
00148                         itsCollimatorMaterial,
00149                         itsName+"_solid_log");
00150   
00151 #ifndef NOUSERLIMITS
00152   itsSolidLogVol-> SetUserLimits(itsUserLimits);
00153   itsMarkerLogicalVolume->SetUserLimits(itsUserLimits);
00154 #endif
00155   itsPhysiComp = 
00156     new G4PVPlacement(
00157                       nullRotationMatrix,   // no rotation
00158                       nullThreeVector,        // its position
00159                       itsSolidLogVol,    // its logical volume
00160                       itsName+"_solid_phys",         // its name
00161                       itsMarkerLogicalVolume, // its mother  volume
00162                       false,                 // no boolean operation
00163                       0, BDSGlobalConstants::Instance()->GetCheckOverlaps());                // copy number  
00164 
00165   if( (itsXAper>0) && (itsYAper>0) ){
00166     G4cout << "BDSCollimator: placing aperture" << G4endl;
00167     itsPhysiComp2 = 
00168       new G4PVPlacement(
00169                         nullRotationMatrix,  // no rotation
00170                         nullThreeVector,     // its position
00171                         itsInnerLogVol,      // its logical volume
00172                         itsName+"_inner_phys", // its name
00173                         itsSolidLogVol,      // its mother  volume
00174                         false,             // no boolean operation
00175                         0, BDSGlobalConstants::Instance()->GetCheckOverlaps());            // copy number 
00176     SetMultiplePhysicalVolumes(itsPhysiComp2);
00177   } 
00178   
00179   if(BDSGlobalConstants::Instance()->GetSensitiveComponents()){
00180     SetSensitiveVolume(itsSolidLogVol);
00181   }
00182   SetMultiplePhysicalVolumes(itsPhysiComp);
00183   G4cout << "BDSCollimator: finished building geometry" << G4endl;
00184 }
00185 
00186 
00187 BDSCollimator::~BDSCollimator()
00188 {
00189   delete itsVisAttributes;
00190 }

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7