00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "BDSGlobalConstants.hh"
00011 #include "BDSSampler.hh"
00012 #include "G4Box.hh"
00013 #include "G4Tubs.hh"
00014 #include "G4VisAttributes.hh"
00015 #include "G4LogicalVolume.hh"
00016 #include "G4VPhysicalVolume.hh"
00017 #include "G4PVPlacement.hh"
00018 #include "G4UserLimits.hh"
00019 #include "BDSOutput.hh"
00020 #include "BDSSamplerSD.hh"
00021 #include "G4SDManager.hh"
00022
00023
00024 #include <map>
00025
00026 typedef std::map<G4String,int> LogVolCountMap;
00027 extern LogVolCountMap* LogVolCount;
00028
00029 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00030 extern LogVolMap* LogVol;
00031
00032 extern BDSSamplerSD* BDSSamplerSensDet;
00033
00034 extern BDSOutput* bdsOutput;
00035
00036
00037 int BDSSampler::nSamplers = 0;
00038
00039 int BDSSampler::GetNSamplers() { return nSamplers; }
00040
00041 void BDSSampler::AddExternalSampler() { nSamplers++; }
00042
00043 BDSSampler::BDSSampler (G4String aName,G4double aLength):
00044 BDSAcceleratorComponent(
00045 aName,
00046 aLength,0,0,0,
00047 SetVisAttributes()),
00048 itsVisAttributes(NULL)
00049 {
00050 nThisSampler= nSamplers + 1;
00051 SetName("Sampler_"+BDSGlobalConstants::Instance()->StringFromInt(nThisSampler)+"_"+itsName);
00052 SetType("sampler");
00053 SamplerLogicalVolume();
00054 nSamplers++;
00055
00056
00057
00058
00059 }
00060
00061
00062 void BDSSampler::SamplerLogicalVolume()
00063 {
00064 if(!(*LogVolCount)[itsName])
00065 {
00066
00067
00068 itsMarkerLogicalVolume=
00069 new G4LogicalVolume(
00070 new G4Box(itsName+"_solid",
00071 BDSGlobalConstants::Instance()->GetSamplerDiameter()/2,
00072 BDSGlobalConstants::Instance()->GetSamplerDiameter()/2,
00073 itsLength/2.0),
00074 BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->GetVacuumMaterial()),
00075 itsName);
00076
00077 (*LogVolCount)[itsName]=1;
00078 (*LogVol)[itsName]=itsMarkerLogicalVolume;
00079 #ifndef NOUSERLIMITS
00080
00081
00082
00083
00084 #endif
00085
00086
00087 #ifdef DEBUG
00088 G4cout << "BDSSampler.cc Nsamplers " << nSamplers << G4endl;
00089 #endif
00090
00091
00092 if(nSamplers==0)
00093 {
00094 G4SDManager* SDMan = G4SDManager::GetSDMpointer();
00095 BDSSamplerSensDet=new BDSSamplerSD(itsName,"plane");
00096 SDMan->AddNewDetector(BDSSamplerSensDet);
00097
00098 }
00099 itsMarkerLogicalVolume->SetSensitiveDetector(BDSSamplerSensDet);
00100 }
00101 else
00102 {
00103 (*LogVolCount)[itsName]++;
00104 itsMarkerLogicalVolume=(*LogVol)[itsName];
00105 itsMarkerLogicalVolume->SetSensitiveDetector(BDSSamplerSensDet);
00106 }
00107 }
00108
00109 G4VisAttributes* BDSSampler::SetVisAttributes()
00110 {
00111 itsVisAttributes=new G4VisAttributes(G4Colour(1,1,1));
00112 return itsVisAttributes;
00113 }
00114
00115 BDSSampler::~BDSSampler()
00116 {
00117 delete itsVisAttributes;
00118 --nSamplers;
00119 }