9 #include "GeoModelKernel/GeoMaterial.h"
10 #include "GeoModelKernel/Units.h"
19 #include "GaudiKernel/IMessageSvc.h"
20 #include "GaudiKernel/ISvcLocator.h"
21 #include "GaudiKernel/MsgStream.h"
22 #include "GaudiKernel/SystemOfUnits.h"
52 if(
name.find(
"::",0) == std::string::npos) {
62 std::string
name = p_element->getName();
63 std::string symbol = p_element->getSymbol();
64 double a = p_element->getA();
65 double z = p_element->getZ();
67 std::cout <<
" ***** CheckElement(): Print the Element: " <<
name <<
"\n";
68 std::cout <<
" ***** The Element: name, symbol, A, Z \n" ;
76 std::string
name = p_element->getName();
77 std::string symbol = p_element->getSymbol();
78 double a = p_element->getA();
79 double z = p_element->getZ();
81 std::cout <<
" ***** PrintElement(): Print the Element: " <<
name <<
"\n";
82 std::cout <<
" ***** The Element: name, symbol, A, Z \n";
90 std::string
name = p_material->getName();
93 std::cout <<
" ***** PrintMaterial(): Print the Material: " <<
name <<
"\n";
94 std::cout <<
" ***** The Material: name, density \n" ;
95 std::cout <<
" ***** "<<
name <<
" "<<density <<
" " << std::endl;
102 std::string
name = p_material->getName();
105 std::cout <<
" ***** PrintFullMaterial(): Print the Material: " <<
name <<
"\n";
106 std::cout <<
" ***** The Material: name, density\n" ;
107 std::cout <<
" ***** "<<
name <<
" "<<density <<
" " << std::endl;
110 int element_number = p_material->getNumElements();
113 if ( element_number == 0){
114 std::cout <<
" ***** No Elements now in this printMaterial( ) " << std::endl;
118 element_number = p_material->getNumElements();
120 for(
int i =0;
i< element_number;
i ++)
122 const GeoElement* tmp_element = p_material->getElement(
i);
123 double element_fraction = p_material->getFraction(
i);
125 std::cout<<
" ***** ***** Number: " <<
i <<
" Fraction: " << element_fraction<< std::endl;
137 throw std::runtime_error(
"RDBMaterialManager failed to read Geometry DB");
145 SmartIF<IGeoModelSvc> iGeoModel{pSvcLocator->service(
"GeoModelSvc")};
148 SmartIF<IRDBAccessSvc> iAccessSvc{pSvcLocator->service(
"RDBAccessSvc")};
151 auto warn = [&](
const std::string &
msg){
152 if (
log.level()<=MSG::WARNING){
156 auto debug = [&](
const std::string &
msg){
163 return (loadDefaults and pRecordset->size() == 0);
166 if (loadDefaults)
debug(
"Will load material defaults if not present");
170 m_elements = iAccessSvc->getRecordsetPtr(
"Elements",keyAtlas.
tag(),keyAtlas.
node());
172 warn(
"Getting Elements with default tag");
173 m_elements = iAccessSvc->getRecordsetPtr(
"Elements",
"Materials-00",
"Materials");
177 warn(
"Getting StdMatComponents with default tag");
178 m_stdmatcomponents = iAccessSvc->getRecordsetPtr(
"StdMatComponents",
"Materials-00",
"Materials");
182 warn(
"Getting StdMaterials with default tag");
183 m_stdmaterials = iAccessSvc->getRecordsetPtr(
"StdMaterials",
"Materials-00",
"Materials");
190 warn(
"Getting PixMatComponents with default tag");
191 m_pixmatcomponents = iAccessSvc->getRecordsetPtr(
"PixMatComponents",
"PixMatComponents-00");
195 warn(
"Getting PixMaterials with default tag");
196 m_pixmaterials = iAccessSvc->getRecordsetPtr(
"PixMaterials",
"PixMaterials-00");
203 debug(
"Getting PixTBMatComponents with default tag" );
208 debug(
"Getting PixTBMaterials with default tag");
209 m_pixtbmaterials = iAccessSvc->getRecordsetPtr(
"PixMaterials",
"PixMaterials-00");
216 warn(
"Getting SCTMatComponents with default tag");
217 m_sctmatcomponents = iAccessSvc->getRecordsetPtr(
"SCTMatComponents",
"SCTMatComponents-00");
222 warn(
"Getting SCTMaterials with default tag");
223 m_sctmaterials = iAccessSvc->getRecordsetPtr(
"SCTMaterials",
"SCTMaterials-00");
230 warn(
"Getting TrtMatComponents with default tag");
231 m_trtmatcomponents = iAccessSvc->getRecordsetPtr(
"TrtMatComponents",
"TrtMatComponents-00");
235 warn(
"Getting TrtMaterials with default tag");
236 m_trtmaterials = iAccessSvc->getRecordsetPtr(
"TrtMaterials",
"TrtMaterials-00");
243 debug(
"Getting InDetMatComponents with default tag");
244 m_indetmatcomponents = iAccessSvc->getRecordsetPtr(
"InDetMatComponents",
"InDetMatComponents-00");
249 debug(
"Getting InDetMaterials with default tag");
250 m_indetmaterials = iAccessSvc->getRecordsetPtr(
"InDetMaterials",
"InDetMaterials-00");
257 warn(
"Getting LArMatComponents with default tag");
258 m_larmatcomponents = iAccessSvc->getRecordsetPtr(
"LArMatComponents",
"LArMatComponents-00");
262 warn(
"Getting LArMaterials with default tag");
263 m_larmaterials = iAccessSvc->getRecordsetPtr(
"LArMaterials",
"LArMaterials-00");
270 warn(
"Getting TileMatComponents with default tag" );
271 m_tilematcomponents = iAccessSvc->getRecordsetPtr(
"TileMatComponents",
"TileMatComponents-00");
275 warn(
"Getting TileMaterials with default tag");
276 m_tilematerials = iAccessSvc->getRecordsetPtr(
"TileMaterials",
"TileMaterials-00");
283 warn(
"Getting MUOMatComponents with default tag");
284 m_muomatcomponents = iAccessSvc->getRecordsetPtr(
"MUOMatComponents",
"MUOMatComponents-00");
288 warn(
"Getting MUOMaterials with default tag" );
289 m_muomaterials = iAccessSvc->getRecordsetPtr(
"MUOMaterials",
"MUOMaterials-00");
293 warn(
"Getting ShieldMatComponents with default tag");
298 warn(
"Getting ShieldMaterials with default tag");
299 m_shieldmaterials = iAccessSvc->getRecordsetPtr(
"ShieldMaterials",
"ShieldMaterials-00");
303 warn(
"Getting ToroMatComponents with default tag");
304 m_toromatcomponents = iAccessSvc->getRecordsetPtr(
"ToroMatComponents",
"ToroMatComponents-00");
308 warn(
"Getting ToroMaterials with default tag");
309 m_toromaterials = iAccessSvc->getRecordsetPtr(
"ToroMaterials",
"ToroMaterials-00");
311 return StatusCode::SUCCESS;
378 unsigned int ind{0}, com_ind{0};
380 std::string material_name;
381 std::string tmp_name;
383 double material_density{0.};
386 std::string component_name{};
387 double component_fraction{0.};
395 std::string matcomponents_table;
397 [[maybe_unused]]
static const bool specialMaterialsDone = [
this]() {
402 GeoMaterial* pmaterial;
404 const GeoElement* p_com_element;
415 if (pmaterial!=
nullptr)
418 if(
name.starts_with(
"std"))
423 data_id =
"STDMATERIALS_DATA_ID";
425 else if(
name.starts_with(
"trt"))
430 data_id =
"TRTMATERIALS_DATA_ID";
432 else if(
name.starts_with(
"LAr"))
437 data_id =
"LARMATERIALS_DATA_ID";
439 else if(
name.starts_with(
"muo"))
444 data_id =
"MUOMATERIALS_DATA_ID";
446 else if(
name.starts_with(
"pixtb"))
451 data_id =
"PIXELTBMATERIALS_DATA_ID";
453 else if(
name.starts_with(
"pix"))
458 data_id =
"PIXMATERIALS_DATA_ID";
460 else if(
name.starts_with(
"sct"))
465 data_id =
"SCTMATERIALS_DATA_ID";
467 else if(
name.starts_with(
"indet"))
472 data_id =
"INDETMATERIALS_DATA_ID";
474 else if(
name.starts_with(
"shield"))
479 data_id =
"SHIELDMATERIALS_DATA_ID";
481 else if(
name.starts_with(
"tile"))
486 data_id =
"TILEMATERIALS_DATA_ID";
488 else if(
name.starts_with(
"toro"))
493 data_id =
"TOROMATERIALS_DATA_ID";
497 for(
ind = 0;
ind < tmp_materials->size();
ind++)
502 if(
name == tmp_name){
504 material_id = rec->
getLong(data_id);
505 material_density = rec->
getDouble(
"DENSITY");
508 log <<
MSG::DEBUG <<
" ***** Material: name id density: " << material_name <<
" " << material_id <<
" "<< material_density <<
endmsg;
513 if (
ind == tmp_materials->size())
518 bool firstComponent =
true;
519 bool hasSubMaterial =
false;
520 bool calculateFraction =
false;
521 double totalFraction = 0.;
522 std::vector <const GeoElement*> elementComponents;
523 std::vector <double> elementFractions;
525 for( com_ind = 0; com_ind <tmp_matcomponents->size(); com_ind++)
527 const IRDBRecord* com_rec = (*tmp_matcomponents)[com_ind];
529 component_id = com_rec->
getLong(
"MATERIAL_ID");
530 if( component_id == material_id)
532 component_name = com_rec->
getString(
"COMPNAME");
533 component_fraction = com_rec->
getDouble(
"FRACTION");
537 firstComponent =
false;
538 if(component_fraction>=1.)
539 calculateFraction =
true;
546 if(calculateFraction)
548 totalFraction += component_fraction*p_com_element->getA();
549 elementComponents.push_back(p_com_element);
550 elementFractions.push_back(component_fraction);
553 pmaterial->add( p_com_element, component_fraction);
557 hasSubMaterial =
true;
558 const GeoMaterial* p_com_material =
getMaterial(component_name);
559 pmaterial->add(p_com_material, component_fraction);
565 if(calculateFraction && hasSubMaterial && elementComponents.size()>0)
566 std::cerr << material_name <<
" description should be changed. Please indicate the exact fraction for elements\n";
568 if(calculateFraction && !elementComponents.empty()) {
569 double inv_totalFraction = 1. / totalFraction;
570 for(
unsigned i=0;
i<elementComponents.size();
i++)
571 pmaterial->add(elementComponents[
i],elementFractions[
i]*elementComponents[
i]->getA() * inv_totalFraction);
586 std::string element_symbol;
587 std::string tmp_name;
592 GeoElement *pelement;
596 if (pelement !=
nullptr)
609 if(
name == tmp_name)
612 element_symbol = rec->
getString(
"SYMBOL");
636 std::string element_symbol;
641 GeoElement* pelement(0);
654 element_symbol = rec->
getString(
"SYMBOL");
677 std::string
key = std::string(material->getName());
680 log << MSG::WARNING <<
" Attempt to redefine material " <<
key <<
"!. The existing instance is kept. Please choose another name for new material" <<
endmsg;
704 o <<
"============Material Manager Element List========================\n";
711 for (
size_t i = 0;
i<
p.second->getNumElements();
i++) {
712 o <<
" ***** ***** "<<
int (
p.second->getFraction(
i)*100) <<
"% \t" <<
p.second->getElement(
i)->getName() << std::endl;
722 GeoElement* ethElement =
new GeoElement(
"Ether",
"ET",500.0,0.0);
724 GeoMaterial* ether =
new GeoMaterial(
"special::Ether",0.0);
725 ether->add(ethElement,1.);
728 GeoMaterial* hu =
new GeoMaterial(
"special::HyperUranium",0.0);
729 hu->add(ethElement,1.);