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