src/BDSSampler.cc

00001 /* BDSIM code.    Version 1.0
00002    Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    Last modified 24.7.2002
00004    Copyright (c) 2002 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 
00006    Modified 22.03.05 by J.C.Carter, Royal Holloway, Univ. of London.
00007    Changed Samplers to account for plane and cylinder types (GABs code)
00008 */
00009 // gab:
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 //#include"MagFieldFunction.hh"
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   //G4int nSamplers=(*LogVolCount)[itsName];
00056   //BDSRoot->SetSamplerNumber(nSamplers);
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       //      itsOuterUserLimits =new G4UserLimits();
00081       //double stepFactor=5;
00082       //      itsOuterUserLimits->SetMaxAllowedStep(itsLength*stepFactor);
00083       //itsMarkerLogicalVolume->SetUserLimits(itsOuterUserLimits);
00084 #endif
00085      // Sensitive Detector:
00086 //SPM G4cout << "Sampler.cc Nsamplers " << bdsOutput->nSamplers << G4endl;
00087 #ifdef DEBUG
00088       G4cout << "BDSSampler.cc Nsamplers " << nSamplers << G4endl;
00089 #endif
00090 
00091 //SPM if(bdsOutput->nSamplers==0)
00092       if(nSamplers==0)
00093         {
00094           G4SDManager* SDMan = G4SDManager::GetSDMpointer();
00095           BDSSamplerSensDet=new BDSSamplerSD(itsName,"plane");
00096           SDMan->AddNewDetector(BDSSamplerSensDet);
00097 //SPM     itsMarkerLogicalVolume->SetSensitiveDetector(BDSSamplerSensDet);
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 }

Generated on 27 Aug 2013 for BDSIM by  doxygen 1.4.7