Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

MJGeometryDetectorConstruction.cc

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------//
00002 //bb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nu//
00003 //                                                                           //
00004 //                         MAJORANA Simulation                               //
00005 //                                                                           //
00006 //      This code implementation is the intellectual property of the         //
00007 //      MAJORANA Collaboration. It is based on Geant4, an intellectual       //
00008 //      property of the RD44 GEANT4 collaboration.                           //
00009 //                                                                           //
00010 //                        *********************                              //
00011 //                                                                           //
00012 //    Neither the authors of this software system, nor their employing       //
00013 //    institutes, nor the agencies providing financial support for this      //
00014 //    work  make  any representation or  warranty, express or implied,       //
00015 //    regarding this software system or assume any liability for its use.    //
00016 //    By copying, distributing or modifying the Program (or any work based   //
00017 //    on on the Program) you indicate your acceptance of this statement,     //
00018 //    and all its terms.                                                     //
00019 //                                                                           //
00020 //bb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nubb0nu//
00021 //---------------------------------------------------------------------------//
00022 //                                                          
00023 // $Id: MJGeometryDetectorConstruction.cc,v 1.5 2004/11/26 09:53:18 pandola Exp $ 
00024 //      
00025 // CLASS IMPLEMENTATION:  MJGeometryDetectorConstruction.cc
00026 //
00027 //---------------------------------------------------------------------------//
00033 // 
00034 //---------------------------------------------------------------------------//
00059 //---------------------------------------------------------------------------//
00060 //
00061 
00062 #include <vector>
00063 
00064 //  GEANT4 headers
00065 #include "globals.hh"
00066 #include "G4Box.hh"
00067 #include "G4LogicalVolume.hh"
00068 #include "G4Material.hh"
00069 #include "G4VPhysicalVolume.hh"
00070 #include "G4PVPlacement.hh"
00071 #include "G4RunManager.hh"
00072 
00073 //  MJ headers
00074 #include "geometry/MJGeometryCloverDetector.hh"
00075 #include "geometry/MJGeometryDetectorMessenger.hh"
00076 #include "geometry/MJGeometryDetector.hh"
00077 #include "geometry/MJGeometryCloverInNaIBarrel.hh"
00078 #include "geometry/MJGeometrySolidBlock.hh"
00079 #include "database/MJDatabase.hh"
00080 #include "database/MJDatabaseMaterial.hh"
00081 #include "materials/MJMaterial.hh"
00082 #include "materials/MJGerdaLocalMaterialTable.hh"
00083 #include "io/MJLogger.hh"
00084 
00085 //  Detector headers (also fall under the title "MJ headers")
00086 #include "geometry/MJGeometryDetectorConstruction.hh"
00087 #include "gerdageometry/MaGeGeometryGerda.hh"
00088 #include "gerdageometry/MaGeGeometryGerdaHole.hh"
00089 #include "gerdageometry/MaGeGeometryGerdaCrystal.hh"
00090 #include "gerdageometry/MaGeGeometryGerdaCrystalHole.hh"
00091 
00092 
00093 //Luciano
00094 #include "G4MaterialTable.hh"
00095 
00096 using namespace std;
00097 
00098 //---------------------------------------------------------------------------//
00099 
00100 MJGeometryDetectorConstruction::MJGeometryDetectorConstruction():
00101   fMJMaterials(0), fNumberOfMaterials(0), theDetector(0),
00102   fUseDatabase(true)
00103 {
00104         detectorMessenger = new MJGeometryDetectorMessenger(this);
00105         localTable = new  MJGerdaLocalMaterialTable;
00106 }
00107 
00108 //---------------------------------------------------------------------------//
00109 
00110 MJGeometryDetectorConstruction::~MJGeometryDetectorConstruction() 
00111 {
00112   while(fNumberOfMaterials > 0)
00113     delete fMJMaterials[--fNumberOfMaterials];
00114   delete []fMJMaterials;
00115   delete detectorMessenger;
00116   delete theDetector;
00117   delete localTable;
00118 }
00119 
00120 //---------------------------------------------------------------------------//
00121 
00122 G4VPhysicalVolume *MJGeometryDetectorConstruction::Construct() 
00123 {
00124   if (fUseDatabase) 
00125     {
00126       BuildAllMaterialsInDatabase();
00127     }
00128   else 
00129     {
00130       localTable->CreateMaterials();
00131     }
00132   return ConstructDetector();
00133 }
00134 
00135 //---------------------------------------------------------------------------//
00136 
00137 G4VPhysicalVolume *MJGeometryDetectorConstruction::ConstructDetector() 
00138 {       
00139   // RH: Construct Detector here, *after* materials are defined.
00140   theDetector->ConstructDetector();
00141 
00142         //  Create the physical world
00143         solidWorld = new G4Box( "solidWorld", 10*m, 10*m, 10*m );
00144         logicWorld = new G4LogicalVolume( solidWorld, G4Material::GetMaterial("Air"), "World" );
00145         physiWorld = new G4PVPlacement( 0, G4ThreeVector(), "World", logicWorld, 0, false, 0 );
00146         
00147         //the name of the Detector is "Detector" by default
00148         theDetectorPhysical = new G4PVPlacement( 0, G4ThreeVector(),theDetector->GetDetectorName(), 
00149                                                  theDetector->GetDetectorLogical(), 
00150                                                  physiWorld, false, 0 );
00151         
00152         //  Always return the physical world
00153         return physiWorld;
00154 }
00155 
00156 //---------------------------------------------------------------------------//
00157 
00158 void MJGeometryDetectorConstruction::BuildAllMaterialsInDatabase() 
00159 {
00160   vector<string> materialNames = MJDatabase::GetMaterialNames();
00161   vector<string>::iterator namesIterator = materialNames.begin();
00162   fNumberOfMaterials = materialNames.size();
00163   if(MJLogger::GetSeverity() == MJLogger::debugging) {
00164     MJLog(trace) << "Building materials from database: " << endlog;
00165     while(namesIterator != materialNames.end()) {
00166       G4cout << *namesIterator << G4endl;
00167       namesIterator++;
00168     }      
00169   }
00170   namesIterator = materialNames.begin();
00171   fMJMaterials = new MJMaterial*[fNumberOfMaterials];
00172   if(!fMJMaterials) {
00173     MJLog(error) << "Could not allocate memory for materials!" << endlog;
00174     MJLog(fatal) << endlog;
00175   }
00176   G4int i;
00177   for(i = 0; i < fNumberOfMaterials; i++) { 
00178     // Horrible hack for now. G4 does not like Hg196. To be fixed...
00179     // RH. 7/15/2004 
00180     if(*namesIterator != "Mercury") {
00181       MJLog(debugging) << "Building material : " << *namesIterator << endlog;
00182       fMJMaterials[i] = new MJMaterial((*namesIterator).c_str(), true);
00183     }
00184     namesIterator++;
00185   }
00186   MJLog(routine) << "Built all materials in database : " 
00187                  << fNumberOfMaterials << " materials built." << endlog;
00188 }
00189 
00190 //---------------------------------------------------------------------------//
00191 
00192 void MJGeometryDetectorConstruction::SetDetector( G4String detectorType ) 
00193 {
00194   if(!theDetector) {
00195         if( detectorType == "clover" )
00196           theDetector = new MJGeometryCloverDetector( "LANL1" );
00197         else if (detectorType == "cloverinNaIbarrel")
00198           theDetector = new MJGeometryCloverInNaIBarrel("0000");
00199         else if (detectorType == "solidBlock")
00200           theDetector = new MJGeometrySolidBlock();
00201         else if (detectorType == "GerdaArray")
00202           theDetector = new MaGeGeometryGerda();
00203         else if (detectorType == "GerdaCrystal")
00204           theDetector = new MaGeGeometryGerdaCrystal();
00205         else if (detectorType == "GerdaCrystalHole")
00206           theDetector = new MaGeGeometryGerdaCrystalHole();
00207         else if (detectorType == "GerdaArrayHole")
00208           theDetector = new MaGeGeometryGerdaHole();
00209         else
00210                 G4cout << "Couldn't find detector of type \"" << detectorType 
00211                        << "\"!" << G4endl;
00212 
00213         MJLog(routine) << "Using the " << detectorType << " detector."<<endlog;
00214   } else {
00215     MJLog(error) << "Error: Detector already defined." << endlog;
00216   }
00217 }
00218 
00219 //---------------------------------------------------------------------------//
00220 

Generated on Mon Nov 29 16:58:51 2004 for Majorana Simulation by  doxygen 1.3.9.1