File indexing completed on 2026-05-12 08:04:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/DetFactoryHelper.h>
0016 #include <DD4hep/DD4hepUnits.h>
0017 #include <DD4hep/PropertyTable.h>
0018 #include <DD4hep/Printout.h>
0019
0020
0021 #include <TGeoElement.h>
0022 #include <TGeoPhysicalConstants.h>
0023 #include <TGeant4PhysicalConstants.h>
0024 #include <TMath.h>
0025
0026 namespace units = dd4hep;
0027 using namespace dd4hep;
0028
0029 static Ref_t create_element(Detector& description, xml_h xml_det, SensitiveDetector ) {
0030 xml_det_t x_det = xml_det;
0031 std::string det_name = x_det.nameStr();
0032 Assembly assembly(det_name+"_assembly");
0033 DetElement det(det_name,x_det.typeStr(), x_det.id());
0034
0035 if ( x_det.hasChild(_U(box)) ) {
0036 xml_det_t xbox = x_det.child(_U(box));
0037 Volume box = Volume(det_name+"_box",
0038 Box(xbox.x(), xbox.y(), xbox.z()),
0039 description.material(xbox.attr<std::string>(_U(material))));
0040 PlacedVolume place = assembly.placeVolume(box);
0041 place.addPhysVolID("box",0);
0042 }
0043
0044 for(xml_coll_t k(x_det,_Unicode(test)); k; ++k) {
0045 xml_comp_t c = k;
0046 Material mat = description.material(c.nameStr());
0047 TGeoMaterial* material = mat->GetMaterial();
0048 printout(INFO,det_name,"+++ Material:%s [%p, %p] Z=%6.2f A=%6.2f D=%9.4f [g/cm3]",
0049 mat.name(), mat.ptr(), material, mat.Z(), mat.A(),
0050 material->GetDensity());
0051
0052 printout(INFO,det_name,"+++ Radiation Length:%9.4f [cm] Interaction length:%9.4f [cm] Mixture:%s",
0053 material->GetRadLen()/TGeant4Unit::mm*units::cm, material->GetIntLen()/TGeant4Unit::mm*units::cm,
0054
0055 yes_no(material->IsMixture()));
0056 printout(INFO,det_name,"+++ Elements:%d Index:%d",
0057 material->GetNelements(), material->GetIndex());
0058 for(Int_t i=0, n=material->GetNelements(); i<n; ++i) {
0059 TGeoElement* e = material->GetElement(i);
0060 Double_t a=0., z=0., w=0.;
0061 material->GetElementProp(a,z,w,i);
0062 printout(INFO,det_name,"+++ ELT[%02d]: %s Z=%3d N=%3d N_eff=%7.2f A=%6.2f Weight=%9.4f ",
0063 i, e->GetName(), e->Z(), e->N(), e->Neff(), e->A(), w);
0064 if ( material->IsMixture() ) {
0065 auto* mix = (TGeoMixture*)material;
0066 Int_t* nmix = mix->GetNmixt();
0067 Double_t* wmix = mix->GetWmixt();
0068 printout(INFO,det_name,"+++ Zmix:%7.3f Nmix:%3d Amix:%7.3f Wmix:%7.3f",
0069 mix->GetZmixt()[i],nmix ? nmix[i] : -1,
0070 mix->GetAmixt()[i],wmix ? wmix[i] : -1e0);
0071 }
0072 }
0073 if ( mat.numProperties() > 0 ) {
0074 printout(INFO,det_name,"+++ Properties: %d", material->GetNproperties());
0075 for(std::size_t i=0, n=mat.numProperties(); i<n; ++i) {
0076 PropertyTable matrix(mat.property(i));
0077 printout(INFO,det_name,"+++ \"%s\" [%s] rows:%d cols:%d",
0078 matrix.name(), matrix.title(), matrix.numRows(), matrix.numColumns());
0079 matrix->Print();
0080 }
0081 printout(INFO,det_name,"+++ Properties by NAME:");
0082 for(Int_t i=0, n=mat.numProperties(); i<n; ++i) {
0083 const auto* name = material->GetProperties().At(i)->GetName();
0084
0085 PropertyTable matrix(mat.property(name));
0086 printout(INFO,det_name,"+++ \"%s\" [%s,%s] cols: %d rows: %d", name,
0087 matrix.name(), matrix.title(), matrix.numColumns(), matrix.numRows());
0088 }
0089 }
0090 if ( mat.numConstProperties() > 0 ) {
0091 printout(INFO,det_name,"+++ CONST Properties: %d", material->GetNconstProperties());
0092 const TList& all = material->GetConstProperties();
0093 for(Int_t i=0, n=mat.numConstProperties(); i<n; ++i) {
0094 const TNamed* prop = (const TNamed*)all.At(i);
0095 double value = mat.constProperty(i);
0096 printout(INFO,det_name,"+++ \"%s\" [%s] value: %f",
0097 prop->GetName(), prop->GetTitle(), value);
0098 }
0099 printout(INFO,det_name,"+++ CONST Properties by NAME:");
0100 for(Int_t i=0, n=mat.numConstProperties(); i<n; ++i) {
0101 const char* name = ((const TNamed*)all.At(i))->GetName();
0102 double value = mat.constProperty(name);
0103 printout(INFO,det_name,"+++ \"%s\" value: %f", name, value);
0104 }
0105 }
0106 }
0107
0108 printout(INFO,det_name,"+++ Basic units:");
0109 printout(INFO,det_name,"+++ Length: mm: %12.3f Geant4: %8.3f mm dd4hep: %8.3f mm TGeo: %8.3g",
0110 units::mm, units::mm/TGeant4Unit::mm, units::mm/units::mm, units::mm/TGeoUnit::mm);
0111 printout(INFO,det_name,"+++ Time: s: %12.0g Geant4: %8.3f s dd4hep: %8.3f s TGeo: %8.3g",
0112 units::s , units::s /TGeant4Unit::s , units::s /units::s, units::s /TGeoUnit::s );
0113 printout(INFO,det_name,"+++ Energy: eV: %12.3g Geant4: %8.3f eV dd4hep: %8.3f eV TGeo: %8.3g",
0114 units::eV, units::eV/TGeant4Unit::eV, units::eV/units::eV, units::eV/TGeoUnit::eV);
0115 printout(INFO,det_name,"+++ Energy: MeV: %12.3f Geant4: %8.3f MeV dd4hep: %8.3f MeV TGeo: %8.3g",
0116 units::MeV, units::MeV/TGeant4Unit::MeV, units::MeV /units::MeV, units::MeV /TGeoUnit::MeV);
0117 printout(INFO,det_name,"+++ 1./Fine structure: %12.3f Geant4: %8.3f dd4hep: %8.3f TGeo: %8.3f",
0118 1./units::fine_structure_const, 1./TGeant4Unit::fine_structure_const,
0119 1./units::fine_structure_const, 1./TGeoUnit::fine_structure_const);
0120 printout(INFO,det_name,"+++ Universe density: %12.3g Geant4: %8.3g g/cm3 dd4hep: %8.3g g/cm3 TGeo: %8.3g",
0121 units::universe_mean_density,
0122 units::universe_mean_density/TGeant4Unit::g*TGeant4Unit::cm3,
0123 units::universe_mean_density/units::g*units::cm3,
0124 units::universe_mean_density/TGeoUnit::g*TGeoUnit::cm3);
0125 printout(INFO,det_name,"+++ STP_temperature: %12.3f Geant4: %8.3f K dd4hep: %8.3f K TGeo: %8.3f K",
0126 STP_temperature, STP_temperature/TGeant4Unit::kelvin,
0127 STP_temperature/units::kelvin, STP_temperature/TGeoUnit::kelvin);
0128 printout(INFO,det_name,"+++ STP_pressure: %12.0f Geant4: %8.3f hPa dd4hep: %8.3f hPa TGeo: %8.3f hPa",
0129 STP_pressure, STP_pressure/TGeant4Unit::pascal/1e2,
0130 STP_pressure/units::pascal/1e2,STP_pressure/TGeoUnit::pascal/1e2);
0131
0132 PlacedVolume pv = description.pickMotherVolume(det).placeVolume(assembly);
0133 pv.addPhysVolID("system",x_det.id());
0134 det.setPlacement(pv);
0135 return det;
0136 }
0137
0138 DECLARE_DETELEMENT(MaterialTester,create_element)
0139