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

MJMaterialElement.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: MJMaterialElement.cc,v 1.2 2004/11/09 13:42:39 xliu Exp $ 
00024 //      
00025 // CLASS IMPLEMENTATION:  MJMaterialElement.cc
00026 //
00027 //---------------------------------------------------------------------------//
00033 // 
00034 //---------------------------------------------------------------------------//
00045 //---------------------------------------------------------------------------//
00046 //
00047 
00048 #include <vector>
00049 
00050 #include "globals.hh"
00051 #include "G4Element.hh"
00052 #include "G4Isotope.hh"
00053 
00054 #include "database/MJDatabase.hh"
00055 #include "database/MJDatabaseElement.hh"
00056 #include "io/MJLogger.hh"
00057 #include "materials/MJMaterialIsotope.hh"
00058 
00059 //---------------------------------------------------------------------------//
00060 
00061 #include "materials/MJMaterialElement.hh"
00062 
00063 //---------------------------------------------------------------------------//
00064 
00065 MJMaterialElement::MJMaterialElement():
00066  fExists(false), fG4Element(0)
00067 {
00068   fMJIsotopes.clear();
00069 }
00070 
00071 //---------------------------------------------------------------------------//
00072 
00073 MJMaterialElement::MJMaterialElement(G4String name, G4bool registerG4):
00074   fName(name), fG4Element(0)
00075 {
00076   fMJIsotopes.clear();
00077   CreateFromDatabase();
00078   if(registerG4) RegisterWithG4();
00079 }
00080 
00081 //---------------------------------------------------------------------------//
00082 
00083 MJMaterialElement::MJMaterialElement(const MJMaterialElement & other)
00084 {
00085   fExists = other.fExists;
00086   fName = other.fName;
00087   fSymbol = other.fSymbol;
00088   fNoOfIsotopes = other.fNoOfIsotopes;
00089   fZ = other.fZ;
00090   fG4Element = other.fG4Element;
00091   fIsoName = other.fIsoName;
00092   fIsoSymb = other.fIsoSymb;
00093   fIsoAbundance = other.fIsoAbundance;
00094   fMJIsotopes = other.fMJIsotopes;
00095 }
00096 
00097 //---------------------------------------------------------------------------//
00098 
00099 MJMaterialElement::~MJMaterialElement()
00100 {;}
00101 
00102 //---------------------------------------------------------------------------//
00103 
00104 void MJMaterialElement::CreateFromDatabase()
00105 {
00106   MJDatabaseElement* theDBElement = MJDatabase::GetElement(fName);
00107   if(theDBElement) { 
00108     fName = theDBElement->GetName();
00109     fSymbol = theDBElement->GetSymbol();
00110     fNoOfIsotopes = theDBElement->GetNoOfIsotopes();
00111     fZ = theDBElement->GetZ();
00112     fIsoName = theDBElement->GetIsoNames();
00113     fIsoAbundance = theDBElement->GetIsoAbundance();
00114     fExists = true;
00115     MJLog(trace) << fName << " MJ element created from database." << endlog;
00116   } else {
00117     fExists = false;
00118     MJLog(error) << fName << " element not in database." << endlog;
00119   }
00120 }
00121 
00122 //---------------------------------------------------------------------------//
00123 
00124 void MJMaterialElement::RegisterWithG4()
00125 {
00126   if(fExists) {
00127     if((fG4Element = G4Element::GetElement(fName))) {
00128       MJLog(debugging)<<fName<<" element already registered with G4."<<endlog;
00129     } else {
00130       // Register new element with G4
00131       fG4Element = new G4Element(fName, fSymbol, fNoOfIsotopes);
00132 
00133       // Setup loop to add isotopes.
00134       G4Isotope *g4iso;
00135       vector<string>::iterator componentIterator = fIsoName.begin();
00136       vector<G4double>::iterator abundanceIterator = fIsoAbundance.begin();
00137 
00138       // Define and add required isotopes.
00139       while(componentIterator != fIsoName.end() && 
00140             abundanceIterator != fIsoAbundance.end()) {
00141         if(!(g4iso = G4Isotope::GetIsotope(*componentIterator))) {
00142           MJMaterialIsotope *mjiso = new 
00143             MJMaterialIsotope(*componentIterator, true);
00144           fMJIsotopes.push_back(*mjiso);
00145           if(!(g4iso = G4Isotope::GetIsotope(*componentIterator))){
00146             MJLog(error) << "Could not register " << *componentIterator 
00147                          <<" with G4."<<endlog;
00148             MJLog(fatal) << endlog;
00149           }
00150         } // if
00151         fG4Element->AddIsotope(g4iso, *abundanceIterator * 100.0 * perCent);
00152         componentIterator++;
00153         abundanceIterator++;
00154       } // while
00155       MJLog(trace) << "Element " << fName << " created in G4." << endlog;
00156     } // if
00157   } else {
00158     MJLog(error) << "Cannot register element " << fName << " with G4 before "
00159                  << "defining it." << endlog;
00160   }  
00161 }
00162 
00163 //---------------------------------------------------------------------------//
00164 //---------------------------------------------------------------------------//
00165  

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