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

MJMaterial.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: MJMaterial.cc,v 1.2 2004/11/09 13:42:39 xliu Exp $ 
00024 //      
00025 // CLASS IMPLEMENTATION:  MJMaterial.cc
00026 //
00027 //---------------------------------------------------------------------------//
00033 // 
00034 //---------------------------------------------------------------------------//
00047 //---------------------------------------------------------------------------//
00048 //
00049 
00050 #include "globals.hh"
00051 #include "G4ios.hh"
00052 #include "G4Material.hh"               
00053 #include "G4Element.hh"
00054   
00055 #include "database/MJDatabase.hh"
00056 #include "materials/MJMaterialElement.hh"
00057 #include "io/MJLogger.hh"
00058 
00059 //---------------------------------------------------------------------------//
00060 
00061 #include "materials/MJMaterial.hh"
00062 
00063 //---------------------------------------------------------------------------//
00064 
00065 MJMaterial::MJMaterial():
00066  fExists(false), fG4Material(0)
00067 {
00068   fMJElements.clear();
00069 }
00070 
00071 //---------------------------------------------------------------------------//
00072 
00073 MJMaterial::MJMaterial(G4String name, G4bool registerG4):
00074   fMaterialName(name), fG4Material(0)
00075 {
00076   fMJElements.clear();
00077   CreateFromDatabase();
00078   if(registerG4) RegisterWithG4();
00079 }
00080 
00081 //---------------------------------------------------------------------------//
00082 
00083 MJMaterial::~MJMaterial() {;}
00084 
00085 //---------------------------------------------------------------------------//
00086 
00087 void MJMaterial::CreateFromDatabase() 
00088 {
00089     // Get Material information from database
00090     MJDatabaseMaterial *theDBMaterial = MJDatabase::GetMaterial(fMaterialName);
00091     if(theDBMaterial) {
00092       fDensity = theDBMaterial->GetDensity() * g / cm3;
00093       fTemperature = theDBMaterial->GetTemperature() * kelvin;
00094       fPressure = theDBMaterial->GetPressure() * pascal;
00095       fNumComponents = theDBMaterial->GetNoComponents();
00096       fNumOfAtoms = theDBMaterial->GetNoAtoms();
00097       fComponents = theDBMaterial->GetComponents();
00098       fFracMass = theDBMaterial->GetFracMass(); // CAUTION ... UNDEFINED UNITS.
00099       fDefaultBKG = theDBMaterial->GetBackground();
00100       fMaterialComment = theDBMaterial->GetComment();
00101       fExists = true;
00102       MJLog(trace) << "Material "<<fMaterialName<<" created from database."
00103                    << endlog;
00104     } else {
00105       fExists = false;
00106       MJLog(fatal) << "Material "<<fMaterialName<<" not found in database."
00107                    << endlog;
00108     }
00109  }
00110 
00111 //---------------------------------------------------------------------------//
00112 
00113 void MJMaterial::RegisterWithG4()
00114 {
00115   // Note: This method can currently only build a material from elements, 
00116   // not other materials. 
00117   // This will be fixed in the next version.
00118   //
00119   if(fExists) {
00120     if((fG4Material = G4Material::GetMaterial(fMaterialName))) {
00121       MJLog(debugging)<<fMaterialName<<" already registered with G4."<<endlog;
00122     } else {
00123       // Register new materials with G4
00124       G4State state = kStateUndefined;
00125       fG4Material = new G4Material(fMaterialName, fDensity, fNumComponents,
00126                                    state, fTemperature, fPressure);
00127 
00128       // Setup loop to add elements.
00129       vector<string>::iterator  componentsIterator = fComponents.begin();
00130       vector<G4int>::iterator  NatomsIterator = fNumOfAtoms.begin();
00131       G4Element *g4ele;
00132       G4String componentName;
00133 
00134       // Define and add required elements
00135       while (componentsIterator != fComponents.end() && 
00136              NatomsIterator != fNumOfAtoms.end()) {
00137         componentName = *componentsIterator;
00138         if(!(g4ele = G4Element::GetElement(componentName))) {
00139           MJMaterialElement *mjElement =
00140             new MJMaterialElement(componentName, true);
00141           fMJElements.push_back(*mjElement);
00142           if(!(g4ele = G4Element::GetElement(componentName))) {
00143             MJLog(fatal) << "Could not register " << *componentName 
00144                          << " with G4." << endlog;
00145           }
00146         }
00147         fG4Material->AddElement(g4ele, *NatomsIterator);
00148         componentsIterator++; 
00149         NatomsIterator++;
00150       }
00151       MJLog(trace) << "Material " << fMaterialName << " created in G4 :"
00152       << "Density : " << fDensity << " " << fNumComponents << endlog;
00153     }
00154   } else {
00155     MJLog(error) << "Cannot register material " << fMaterialName << " with G4"
00156                  << " before defining it." << endlog;
00157   }
00158 }
00159 //---------------------------------------------------------------------------//
00160 //---------------------------------------------------------------------------//

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