34#include "TGeoElement.h"
35#include "TGeoManager.h"
36#include "TGeoMaterial.h"
41const double RootGM::MaterialFactory::fgkTolerance = 1e-09;
45 :
VGM::IMaterialFactory(),
46 BaseVGM::VMaterialFactory(
"Root_GM_Material_Factory")
50 if (!gGeoManager)
new TGeoManager(
"VGM Root geometry",
"VGM Root geometry");
55 :
VGM::IMaterialFactory(rhs),
BaseVGM::VMaterialFactory(rhs)
77VGM::IElement* RootGM::MaterialFactory::GetElement(
double z,
double a)
const
81 for (
unsigned i = 0; i < Elements().size(); i++) {
84 if (std::abs(z - element->
Z()) < fgkTolerance &&
85 std::abs(a - element->
A()) < fgkTolerance)
94 const std::string& name)
const
98 for (
unsigned i = 0; i < Elements().size(); i++) {
101 if (name == element->
Name())
return element;
108VGM::IIsotope* RootGM::MaterialFactory::GetIsotope(
double z,
double n)
const
112 for (
unsigned i = 0; i < Isotopes().size(); i++) {
115 if (z == isotope->
Z() && n == isotope->
N())
return isotope;
122bool RootGM::MaterialFactory::CompareIsotopes(
const TGeoElement* tgeoElement,
130 if (Int_t(isotopes.size()) != tgeoElement->GetNisotopes())
return false;
132 for (
int i = 0; i < tgeoElement->GetNisotopes(); ++i) {
134 const TGeoIsotope* tgeoIsotope = tgeoElement->GetIsotope(i);
135 double tgeoRelAbundance = tgeoElement->GetRelativeAbundance(i);
138 for (
unsigned j = 0; j < isotopes.size(); ++j) {
140 if (std::abs(vgmIsotope->
Z() - tgeoIsotope->GetZ()) < fgkTolerance &&
141 std::abs(vgmIsotope->
N() - tgeoIsotope->GetN()) < fgkTolerance &&
142 std::abs(vgmIsotope->
A() - tgeoIsotope->GetA()) < fgkTolerance &&
143 std::abs(relAbundances[j] - tgeoRelAbundance) < fgkTolerance) {
148 if (!match)
return false;
156void RootGM::MaterialFactory::ImportIsotopes(TGeoElement* element)
160 int nofIsotopes = element->GetNisotopes();
161 if (nofIsotopes == 0)
return;
163 for (Int_t i = 0; i < nofIsotopes; i++) {
165 TGeoIsotope* tgeoIsotope = element->GetIsotope(i);
173 std::cout <<
"Importing isotope: ";
174 if (Debug() > 1) std::cout << tgeoIsotope;
175 std::cout << std::endl;
177 tgeoIsotope->Print();
187void RootGM::MaterialFactory::ImportElements(
188 TGeoMaterial* material, std::vector<VGM::IElement*>& elements)
195 if (material->IsMixture())
196 nofElements = ((TGeoMixture*)material)->GetNelements();
198 for (Int_t i = 0; i < nofElements; i++) {
200 double z = material->GetZ();
201 double a = material->GetA();
202 if (material->IsMixture()) {
203 z = ((TGeoMixture*)material)->GetZmixt()[i];
204 a = ((TGeoMixture*)material)->GetAmixt()[i];
211 if (vgmElement && (std::abs(vgmElement->
Z() - z) >= fgkTolerance ||
212 std::abs(vgmElement->
A() - a) >= fgkTolerance)) {
219 TGeoElement* tgeoElement = material->GetElement(i);
220 std::string name = tgeoElement->GetTitle();
221 std::string symbol = tgeoElement->GetName();
223 bool isElementObject = std::abs(tgeoElement->Z() - z) < fgkTolerance &&
224 std::abs(tgeoElement->A() - a) < fgkTolerance;
227 if (isElementObject) {
228 ImportIsotopes(tgeoElement);
230 from =
"from element object";
236 from =
"from material";
241 std::cout <<
"Importing element: ";
242 if (Debug() > 1) std::cout << vgmElement <<
" ";
243 std::cout << from << std::endl;
245 tgeoElement->Print();
250 elements.push_back(vgmElement);
255void RootGM::MaterialFactory::ImportMaterial(TGeoMaterial* material)
261 std::cout <<
"Importing material: ";
262 if (Debug() > 1) std::cout << material;
263 std::cout << std::endl;
270 std::vector<VGM::IElement*> elements;
271 ImportElements(material, elements);
279void RootGM::MaterialFactory::ImportMedium(TGeoMedium* medium)
285 std::cout <<
"Importing medium: ";
286 if (Debug() > 1) std::cout << medium;
287 std::cout << std::endl;
303 const std::string& name,
int z,
int n,
double a)
307 TGeoIsotope* tgeoIsotope =
308 TGeoElement::GetElementTable()->FindIsotope(name.data());
311 if (tgeoIsotope && (std::abs(tgeoIsotope->GetZ() - z) >= fgkTolerance ||
312 std::abs(tgeoIsotope->GetN() - n) >= fgkTolerance ||
313 std::abs(tgeoIsotope->GetA() - a) >= fgkTolerance)) {
323 IsotopeStore().push_back(vgmIsotope);
331 const std::string& name,
const std::string& symbol,
double z,
double a)
336 TGeoElement* tgeoElement =
337 TGeoElement::GetElementTable()->FindElement(name.data());
340 if (tgeoElement && (std::abs(tgeoElement->Z() - z) >= fgkTolerance ||
341 std::abs(tgeoElement->A() - a) >= fgkTolerance)) {
350 ElementStore().push_back(vgmElement);
355 ElementStore().push_back(vgmElement);
370 TGeoElement* tgeoElement =
372 if (tgeoElement && CompareIsotopes(tgeoElement, isotopes, relAbundances)) {
378 vgmElement =
new RootGM::Element(name, symbol, isotopes, relAbundances);
379 ElementStore().push_back(vgmElement);
390 TGeoElementTable* elementTable = gGeoManager->GetElementTable();
391 TGeoElement* geoElement = elementTable->GetElement(z);
393 std::cerr <<
"No element with z=" << z <<
" defined." << std::endl;
399 if (vgmElement)
return vgmElement;
403 ElementStore().push_back(vgmElement);
410 double density,
VGM::IElement* element,
double radlen,
double intlen)
417 MaterialStore().push_back(vgmMaterial);
423 double density,
VGM::IElement* element,
double radlen,
double intlen,
429 name, density, element, radlen, intlen, state, temperature, pressure);
431 MaterialStore().push_back(vgmMaterial);
445 MaterialStore().push_back(vgmMaterial);
453 double temperature,
double pressure)
458 name, density, elements, fractions, state, temperature, pressure);
460 MaterialStore().push_back(vgmMaterial);
474 MaterialStore().push_back(vgmMaterial);
482 double temperature,
double pressure)
487 name, density, elements, atomCounts, state, temperature, pressure);
489 MaterialStore().push_back(vgmMaterial);
495 int mediumId,
VGM::IMaterial* material,
int nofParameters,
double* parameters)
500 new RootGM::Medium(name, mediumId, material, nofParameters, parameters);
502 MediumStore().push_back(vgmMedium);
512 TList* materials = gGeoManager->GetListOfMaterials();
513 TIter next(materials);
514 while (TObject* obj = next()) {
515 TGeoMaterial* material = (TGeoMaterial*)obj;
516 ImportMaterial(material);
519 TList* media = gGeoManager->GetListOfMedia();
521 while (TObject* obj = next2()) {
522 TGeoMedium* medium = (TGeoMedium*)obj;
523 ImportMedium(medium);
TGeoElement * GetElement(VGM::IElement *iElement) const
static ElementMap * Instance()
VGM implementation for Root element which is not represented via TGeoElement object in Root geometry.
VGM implementation for Root element using TGeoElement object.
TGeoIsotope * GetIsotope(VGM::IIsotope *iIsotope) const
static IsotopeMap * Instance()
VGM implementation for Root isotope.
VGM material factory for Root.
virtual VGM::IMaterial * CreateMaterial(const std::string &name, double density, VGM::IElement *element, double radlen, double intlen)
Create a material.
virtual VGM::IElement * CreateElement(const std::string &name, const std::string &symbol, double z, double a)
Create a chemical element.
virtual bool Import()
Import native materials.
virtual VGM::IIsotope * CreateIsotope(const std::string &name, int z, int n, double a=0.)
Create a chemical isotope.
virtual ~MaterialFactory()
virtual VGM::IMedium * CreateMedium(const std::string &name, int mediumId, VGM::IMaterial *material, int nofParameters, double *parameters)
Create a tracking medium.
static MaterialMap * Instance()
VGM implementation for Root material.
VGM implementation for Root medium.
The VGM interface to elements.
virtual double Z() const =0
Return the effective atomic number.
virtual std::string Name() const =0
Return the name of this element.
virtual double A() const =0
Return the effective effective mass of a mole in g/mole.
The VGM interface to elements.
virtual int N() const =0
Return the effective number of nucleons.
virtual double A() const =0
Return the effective effective mass of a mole in g/mole.
virtual int Z() const =0
Return the effective atomic number.
The VGM interface to materials.
The VGM interface to tracking medium.
void DebugInfo()
Debug printing.
std::vector< IMaterial * > MaterialStore
std::vector< double > RelAbundanceVector
std::vector< int > AtomCountVector
std::vector< double > MassFractionVector
std::vector< IElement * > ElementVector
std::vector< IMedium * > MediumStore
std::vector< IIsotope * > IsotopeStore
std::vector< IIsotope * > IsotopeVector
std::vector< IElement * > ElementStore