src/BDSSamplerCylinder.cc

00001 /* BDSIM code.    Version 1.0
00002    Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    Last modified 5.3.2005
00004    Copyright (c) 2005 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 */
00006 #include "BDSGlobalConstants.hh" 
00007 #include "BDSSamplerCylinder.hh"
00008 #include "G4Box.hh"
00009 #include "G4Tubs.hh"
00010 #include "G4VisAttributes.hh"
00011 #include "G4LogicalVolume.hh"
00012 #include "G4VPhysicalVolume.hh"
00013 #include "G4PVPlacement.hh"               
00014 #include "G4UserLimits.hh"
00015 
00016 #include <map>
00017 
00018 #include "BDSSamplerSD.hh"
00019 #include "G4SDManager.hh"
00020 
00021 
00022 typedef std::map<G4String,int> LogVolCountMap;
00023 extern LogVolCountMap* LogVolCount;
00024 
00025 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00026 extern LogVolMap* LogVol;
00027 
00028 
00029 
00030 //============================================================
00031 
00032 int BDSSamplerCylinder::nSamplers = 0;
00033 
00034 int BDSSamplerCylinder::GetNSamplers() { return nSamplers; }
00035 
00036 void BDSSamplerCylinder::AddExternalSampler() { nSamplers++; }
00037 
00038 BDSSamplerCylinder::
00039 BDSSamplerCylinder (G4String aName,G4double aLength,G4double aRadius):
00040   BDSAcceleratorComponent(
00041                          aName,
00042                          aLength,0,0,0,
00043                          SetVisAttributes()),
00044   itsRadius(aRadius),itsVisAttributes(NULL)
00045 {
00046   nThisSampler = nSamplers + 1;
00047   SetName("CSampler_"+BDSGlobalConstants::Instance()->StringFromInt(nThisSampler)+"_"+itsName);
00048   SetType("csampler");
00049   SamplerCylinderLogicalVolume();
00050   nSamplers++;
00051   //G4int nSamplers=(*LogVolCount)[itsName];
00052   //BDSRoot->SetSampCylinderNumber(nSamplers);
00053 }
00054 
00055 
00056 void BDSSamplerCylinder::SamplerCylinderLogicalVolume()
00057 {
00058   if(!(*LogVolCount)[itsName])
00059     {
00060 
00061       itsMarkerLogicalVolume=
00062         new G4LogicalVolume(new G4Tubs(itsName+"_body",
00063                                        itsRadius-1.e-6*m,
00064                                        itsRadius,
00065                                        itsLength/2,
00066                                        0,twopi*radian),
00067                             BDSMaterials::Instance()->GetMaterial(BDSGlobalConstants::Instance()->GetVacuumMaterial()),
00068                             itsName);
00069       
00070       (*LogVolCount)[itsName]=1;
00071       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00072 #ifndef NOUSERLIMITS
00073       itsOuterUserLimits =new G4UserLimits();
00074       itsOuterUserLimits->SetMaxAllowedStep(BDSGlobalConstants::Instance()->GetSamplerDiameter()/2.0);
00075       itsMarkerLogicalVolume->SetUserLimits(itsOuterUserLimits);
00076 #endif
00077       // Sensitive Detector:
00078       G4SDManager* SDMan = G4SDManager::GetSDMpointer();
00079       BDSSamplerSD* SensDet=new BDSSamplerSD(itsName,"cylinder");
00080        
00081       SDMan->AddNewDetector(SensDet);
00082       itsMarkerLogicalVolume->SetSensitiveDetector(SensDet);
00083     }
00084   else
00085     {
00086       (*LogVolCount)[itsName]++;
00087       itsMarkerLogicalVolume=(*LogVol)[itsName];
00088     }
00089 }
00090 
00091 G4VisAttributes* BDSSamplerCylinder::SetVisAttributes()
00092 {
00093   itsVisAttributes=new G4VisAttributes(G4Colour(1,0,1));
00094   return itsVisAttributes;
00095 }
00096 
00097 BDSSamplerCylinder::~BDSSamplerCylinder()
00098 {
00099   delete itsVisAttributes;
00100   --nSamplers;
00101 }

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7