/scratch0/jsnuveri/BDSIM/BDSIMgit/bdsim/src/BDSGeometryComponent.cc

00001 #include "BDSGeometryComponent.hh"
00002 
00003 #include "BDSDebug.hh"
00004 
00005 #include "globals.hh"              // geant4 globals / types
00006 #include "G4VSolid.hh"
00007 #include "G4LogicalVolume.hh"
00008 #include <utility>                 // for std::pair
00009 #include <vector>
00010 
00011 BDSGeometryComponent::BDSGeometryComponent(G4VSolid*        containerSolidIn,
00012                                            G4LogicalVolume* containerLVIn):
00013   containerSolid(containerSolidIn),
00014   containerLogicalVolume(containerLVIn),
00015   placementOffset(G4ThreeVector(0,0,0))
00016 {
00017   SetExtentX(0,0); // initialise only - unphysical - should be set by child class
00018   SetExtentY(0,0);
00019   SetExtentZ(0,0);
00020 }
00021 
00022 BDSGeometryComponent::BDSGeometryComponent(G4VSolid*                    containerSolidIn,
00023                                            G4LogicalVolume*             containerLVIn,
00024                                            std::pair<G4double,G4double> extentXIn,
00025                                            std::pair<G4double,G4double> extentYIn,
00026                                            std::pair<G4double,G4double> extentZIn,
00027                                            G4ThreeVector                placementOffsetIn):
00028   containerSolid(containerSolidIn),
00029   containerLogicalVolume(containerLVIn),
00030   extentX(extentXIn),
00031   extentY(extentYIn),
00032   extentZ(extentZIn),
00033   placementOffset(placementOffsetIn)
00034 {;}
00035 
00036 BDSGeometryComponent::BDSGeometryComponent(BDSGeometryComponent& component):
00037   containerSolid(component.containerSolid),
00038   containerLogicalVolume(component.containerLogicalVolume),
00039   extentX(component.extentX),
00040   extentY(component.extentY),
00041   extentZ(component.extentZ),
00042   placementOffset(component.placementOffset)
00043 {;}
00044 
00045 BDSGeometryComponent::~BDSGeometryComponent()
00046 {
00047   delete containerSolid;
00048   delete containerLogicalVolume;
00049 }
00050 
00051 void BDSGeometryComponent::RegisterLogicalVolume(G4LogicalVolume* logicalVolume)
00052 {
00053   // only register it if it doesn't exist already
00054   // note search the vector each time something is added is quite computationally expensive
00055   // but will protect against resetting sensitivity and possibly seg faults by doulby registered
00056   // logical volumes.  Also, the number of volumes should be < 20 (at maximum) and is only done
00057   // once at construction time so not as bad as it could be.
00058   if (std::find(allLogicalVolumes.begin(), allLogicalVolumes.end(), logicalVolume) == allLogicalVolumes.end())
00059            {
00060              // not found so register it
00061              allLogicalVolumes.push_back(logicalVolume);
00062            }
00063 #ifdef BDSDEBUG
00064   else
00065     {
00066       // found - so don't register it
00067       G4cout << __METHOD_NAME__ << "warning - logical volume \""
00068              << logicalVolume->GetName()
00069              << "\" already in this geometry component \"";
00070       if (containerSolid)
00071         {G4cout << containerSolid->GetName();}
00072       else
00073         {G4cout << " INVALID CONTAINER ";}
00074       G4cout << "\"" << G4endl;
00075     }
00076 #endif
00077 }
00078 
00079 void BDSGeometryComponent::RegisterLogicalVolumes(std::vector<G4LogicalVolume*> logicalVolumes)
00080 {
00081   std::vector<G4LogicalVolume*>::iterator it = logicalVolumes.begin();
00082   for (; it != logicalVolumes.end(); ++it)
00083     {
00084       RegisterLogicalVolume(*it);
00085     }
00086 }
00087 
00088 void BDSGeometryComponent::RegisterSensitiveVolume(G4LogicalVolume* sensitiveVolume)
00089 {
00090   // only register it if it doesn't exist already
00091   // note search the vector each time something is added is quite computationally expensive
00092   // but will protect against resetting sensitivity and possibly seg faults by doulby registered
00093   // logical volumes.  Also, the number of volumes should be < 20 (at maximum) and is only done
00094   // once at construction time so not as bad as it could be.
00095   if (std::find(allSensitiveVolumes.begin(), allSensitiveVolumes.end(), sensitiveVolume) == allSensitiveVolumes.end())
00096            {
00097              // not found so register it
00098              allSensitiveVolumes.push_back(sensitiveVolume);
00099            }
00100   else
00101     {
00102       // found - so don't register it
00103 #ifdef BDSDEBUG
00104       G4cout << __METHOD_NAME__ << "warning - sensitive volume \""
00105              << sensitiveVolume->GetName()
00106              << "\" alreay in this geometry component \"";
00107       if (containerSolid)
00108         {G4cout << containerSolid->GetName();}
00109       else
00110         {G4cout << " INVALID CONTAINER ";}
00111       G4cout << "\"" << G4endl;
00112 #endif
00113     }
00114 }
00115 
00116 void BDSGeometryComponent::RegisterSensitiveVolumes(std::vector<G4LogicalVolume*> sensitiveVolumes)
00117 {
00118   std::vector<G4LogicalVolume*>::iterator it = sensitiveVolumes.begin();
00119   for (; it != sensitiveVolumes.end(); ++it)
00120     {
00121       RegisterSensitiveVolume(*it);
00122     }
00123 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7