/home/cern/BDSIM_new/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" // must be first in include list
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 
00027 
00028 typedef std::map<G4String,int> LogVolCountMap;
00029 extern LogVolCountMap* LogVolCount;
00030 
00031 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00032 extern LogVolMap* LogVol;
00033 
00034 extern BDSSamplerSD* BDSSamplerSensDet;
00035 
00036 extern BDSOutput bdsOutput;
00037 extern BDSMaterials* theMaterials;
00038 //============================================================
00039 
00040 int BDSSampler::nSamplers = 0;
00041 
00042 const int BDSSampler::GetNSamplers() { return nSamplers; }
00043 
00044 void BDSSampler::AddExternalSampler() { nSamplers++; }
00045 
00046 BDSSampler::BDSSampler (G4String aName,G4double aLength):
00047   BDSAcceleratorComponent(
00048                          aName,
00049                          aLength,0,0,0,
00050                          SetVisAttributes())
00051 {
00052   nThisSampler= nSamplers + 1;
00053   SetName("Sampler_"+BDSGlobals->StringFromInt(nThisSampler)+"_"+itsName);
00054   SetType("sampler");
00055   SamplerLogicalVolume();
00056   nSamplers++;
00057   //G4int nSamplers=(*LogVolCount)[itsName];
00058   //BDSRoot->SetSamplerNumber(nSamplers);
00059 
00060  
00061 }
00062 
00063 
00064 void BDSSampler::SamplerLogicalVolume()
00065 {
00066   if(!(*LogVolCount)[itsName])
00067     {
00068 
00069       G4double SampTransSize;
00070       SampTransSize=2.*BDSGlobals->GetTunnelRadius();
00071 
00072       itsMarkerLogicalVolume=
00073         new G4LogicalVolume(
00074                             new G4Box(itsName+"_solid",
00075                                       SampTransSize,
00076                                       SampTransSize,
00077                                       itsLength/2.0),
00078                             theMaterials->GetMaterial("Vacuum"),
00079                             itsName);
00080 
00081       (*LogVolCount)[itsName]=1;
00082       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00083 
00084       itsOuterUserLimits =new G4UserLimits();
00085       itsOuterUserLimits->SetMaxAllowedStep(itsLength);
00086       itsMarkerLogicalVolume->SetUserLimits(itsOuterUserLimits);
00087 
00088      // Sensitive Detector:
00089 //SPM G4cout << "Sampler.cc Nsamplers " << bdsOutput.nSamplers << G4endl;
00090       G4cout << "Sampler.cc Nsamplers " << nSamplers << G4endl;
00091 
00092 //SPM if(bdsOutput.nSamplers==0)
00093       if(nSamplers==0)
00094         {
00095           G4SDManager* SDMan = G4SDManager::GetSDMpointer();
00096           BDSSamplerSensDet=new BDSSamplerSD(itsName,"plane");
00097           SDMan->AddNewDetector(BDSSamplerSensDet);
00098 //SPM     itsMarkerLogicalVolume->SetSensitiveDetector(BDSSamplerSensDet);
00099         }
00100       itsMarkerLogicalVolume->SetSensitiveDetector(BDSSamplerSensDet);
00101     }
00102   else
00103     {
00104       (*LogVolCount)[itsName]++;
00105       itsMarkerLogicalVolume=(*LogVol)[itsName];
00106       itsMarkerLogicalVolume->SetSensitiveDetector(BDSSamplerSensDet);
00107     }
00108 }
00109 
00110 G4VisAttributes* BDSSampler::SetVisAttributes()
00111 {
00112   itsVisAttributes=new G4VisAttributes(G4Colour(1,1,1));
00113   return itsVisAttributes;
00114 }
00115 
00116 BDSSampler::~BDSSampler()
00117 {
00118   if(itsVisAttributes) delete itsVisAttributes;
00119   if(itsUserLimits) delete itsUserLimits;
00120   --nSamplers;
00121 }

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