/home/cern/BDSIM_new/src/BDSMuSpoiler.cc

00001 /* BDSIM code.    Version 1.0
00002    Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    Last modified 12.12.2004
00004    Copyright (c) 2004 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 */
00006 #include "BDSGlobalConstants.hh" // must be first in include list
00007 #include "BDSMuSpoiler.hh"
00008 #include "G4VisAttributes.hh"
00009 #include "G4LogicalVolume.hh"
00010 #include "G4VPhysicalVolume.hh"
00011 #include "G4PVPlacement.hh"               
00012 #include "G4UserLimits.hh"
00013 #include "G4TransportationManager.hh"
00014 #include "G4SDManager.hh"
00015 #include "G4UserLimits.hh"
00016 
00017 
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 //extern G4double BDS_Threshold_Energy;
00027 extern BDSMaterials* theMaterials;
00028 //============================================================
00029 
00030 BDSMuSpoiler::BDSMuSpoiler (G4String& aName,G4double aLength,G4double bpRad,
00031                             G4double rOuter,G4double aBField):
00032   BDSAcceleratorComponent(aName,
00033                          aLength,bpRad,bpRad,bpRad,
00034                          SetVisAttributes()),
00035   itsInnerRadius(bpRad),
00036   itsOuterRadius(rOuter),
00037   itsBField(aBField)
00038 
00039 {
00040   
00041   if ( (*LogVolCount)[itsName]==0)
00042     {
00043       itsMarkerLogicalVolume=
00044         new G4LogicalVolume(
00045                             new G4Box(itsName,
00046                                       itsOuterRadius,
00047                                       itsOuterRadius,
00048                                       itsLength/2),
00049                             theMaterials->GetMaterial("Vacuum"),
00050                             itsName);
00051 
00052   // now protect the fields inside the marker volume by giving the
00053   // marker a null magnetic field (otherwise G4VPlacement can
00054   // over-ride the already-created fields, by calling 
00055   // G4LogicalVolume::AddDaughter, which calls 
00056   // pDaughterLogical->SetFieldManager(fFieldManager, true) - the
00057   // latter 'true' over-writes all the other fields
00058       itsMarkerLogicalVolume->
00059         SetFieldManager(BDSGlobals->GetZeroFieldManager(),false);
00060         
00061       BuildMuSpoiler();
00062 
00063       (*LogVolCount)[itsName]=1;
00064       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00065     }
00066   else
00067     {
00068       (*LogVolCount)[itsName]++;
00069       itsMarkerLogicalVolume=(*LogVol)[itsName];
00070     }  
00071 }
00072 
00073 
00074 void BDSMuSpoiler::BuildMuSpoiler()
00075 {
00076   itsSolidLogVol=
00077     new G4LogicalVolume(new G4Tubs(itsName+"_solid",
00078                                    itsInnerRadius,
00079                                    itsOuterRadius,
00080                                    itsLength/2,
00081                                    0,twopi*radian),
00082                         theMaterials->GetMaterial("Iron"),
00083                         itsName+"_solid");
00084 
00085   itsInnerLogVol=
00086     new G4LogicalVolume(new G4Tubs(itsName+"_inner",
00087                                    0.,
00088                                    itsInnerRadius,
00089                                    itsLength/2,
00090                                    0,twopi*radian),
00091                         theMaterials->GetMaterial("Vacuum"),
00092                         itsName+"_inner");
00093 
00094   G4UserLimits* AbsUserLimits =
00095     new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,
00096                      BDSGlobals->GetThresholdCutCharged());
00097 
00098   AbsUserLimits->SetMaxAllowedStep(itsLength);
00099   itsInnerLogVol->SetUserLimits(AbsUserLimits);
00100 
00101   itsSolidLogVol->
00102     SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,
00103                                        BDSGlobals->GetThresholdCutCharged()));
00104 
00105   if(itsBField)
00106     {
00107       itsMagField=new BDSMuSpoilerMagField(itsBField);
00108       itsFieldMgr=new G4FieldManager(itsMagField);
00109       itsSolidLogVol->SetFieldManager(itsFieldMgr,false);
00110     }
00111   
00112   itsPhysiComp2 = 
00113     new G4PVPlacement(
00114                       0,                   // no rotation
00115                       0,                   // its position
00116                       itsInnerLogVol,      // its logical volume
00117                       itsName+"_combined", // its name
00118                       itsSolidLogVol,      // its mother  volume
00119                       false,               // no boolean operation
00120                       0);                  // copy number 
00121 
00122   SetSensitiveVolume(itsSolidLogVol);
00123 
00124   itsPhysiComp = 
00125     new G4PVPlacement(
00126                       0,                     // no rotation
00127                       0,                     // its position
00128                       itsSolidLogVol,    // its logical volume
00129                       itsName+"_solid",      // its name
00130                       itsMarkerLogicalVolume, // its mother  volume
00131                       false,                 // no boolean operation
00132                       0);                    // copy number   
00133 
00134 }
00135 
00136 
00137 
00138 
00139 G4VisAttributes* BDSMuSpoiler::SetVisAttributes()
00140 {
00141   itsVisAttributes=new G4VisAttributes(G4Colour(0.0,0.5,0.5));
00142   return itsVisAttributes;
00143 }
00144 
00145 
00146 BDSMuSpoiler::~BDSMuSpoiler()
00147 {
00148   if(itsVisAttributes) delete itsVisAttributes;
00149   if(itsUserLimits) delete itsUserLimits;
00150 
00151   if(itsMarkerLogicalVolume)delete itsMarkerLogicalVolume;
00152   if(itsSolidLogVol)delete itsSolidLogVol;
00153   if(itsInnerLogVol)delete itsInnerLogVol;
00154 
00155   if(itsPhysiComp) delete itsPhysiComp;
00156   if(itsPhysiComp2) delete itsPhysiComp2;
00157 
00158   if(itsMagField) delete itsMagField;
00159   if(itsFieldMgr) delete itsFieldMgr;
00160 
00161 }

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