From 2cf7c9177ce478857165f5835adb2d321471d779 Mon Sep 17 00:00:00 2001 From: Markus Frank <markus.frank@cern.ch> Date: Thu, 11 Dec 2014 19:55:23 +0000 Subject: [PATCH] Improve visualization --- DDDetectors/compact/SiD/SiD_Ecal.xml | 2 +- DDDetectors/compact/SiD/SiD_EcalEndcap.xml | 6 +- DDDetectors/compact/SiD/SiD_Tracker.xml | 2 +- .../src/PolyhedraEndcapCalorimeter2_geo.cpp | 83 +++++++++++-------- .../PolyhedraEndcapCalorimeter2_surfaces.cpp | 46 ++++++++++ DDDetectors/src/SiTrackerEndcap_surfaces.cpp | 2 +- 6 files changed, 101 insertions(+), 40 deletions(-) create mode 100644 DDDetectors/src/PolyhedraEndcapCalorimeter2_surfaces.cpp diff --git a/DDDetectors/compact/SiD/SiD_Ecal.xml b/DDDetectors/compact/SiD/SiD_Ecal.xml index 95bebae6f..0fca44873 100644 --- a/DDDetectors/compact/SiD/SiD_Ecal.xml +++ b/DDDetectors/compact/SiD/SiD_Ecal.xml @@ -31,7 +31,7 @@ <vis name="EcalSensitiveVis" alpha="1.0" r="0.7" g="0.3" b="0.0" showDaughters="false" visible="true"/> <vis name="EcalAbsorberVis" alpha="1.0" r="0.4" g="0.4" b="0.0" showDaughters="false" visible="true"/> - <vis name="EcalEndcapVis" alpha="1.0" r="0.77" g="0.74" b="0.86" showDaughters="false" visible="true"/> + <vis name="EcalEndcapVis" alpha="1.0" r="0.77" g="0.74" b="0.86" showDaughters="true" visible="true"/> </display> <!-- Definition of the readout segmentation/definition --> diff --git a/DDDetectors/compact/SiD/SiD_EcalEndcap.xml b/DDDetectors/compact/SiD/SiD_EcalEndcap.xml index 910d35bd6..362cf46fd 100644 --- a/DDDetectors/compact/SiD/SiD_EcalEndcap.xml +++ b/DDDetectors/compact/SiD/SiD_EcalEndcap.xml @@ -11,13 +11,13 @@ <comment>Electromagnetic Calorimeter Endcaps</comment> <dimensions numsides="(int) CaloSides" zmin="EcalEndcap_zmin" rmin="EcalEndcap_rmin" rmax="EcalEndcap_rmax" /> - <layer repeat="1"> + <layer repeat="1" vis="EcalLayerVis"> <slice material = "Silicon" thickness = "0.032*cm" sensitive="yes" limits="cal_limits" vis="EcalSensitiveVis"/> <slice material = "Copper" thickness = "0.005*cm" vis="EcalAbsorberVis"/> <slice material = "Kapton" thickness = "0.030*cm" vis="EcalAbsorberVis"/> <slice material = "Air" thickness = "0.033*cm" vis="InvisibleNoDaughters"/> </layer> - <layer repeat="20"> + <layer repeat="20" vis="EcalLayerVis"> <slice material = "TungstenDens24" thickness = "0.25*cm" /> <slice material = "Air" thickness = "0.025*cm" vis="InvisibleNoDaughters"/> <slice material = "Silicon" thickness = "0.032*cm" sensitive="yes" limits="cal_limits" vis="EcalSensitiveVis"/> @@ -25,7 +25,7 @@ <slice material = "Kapton" thickness = "0.030*cm" vis="EcalAbsorberVis"/> <slice material = "Air" thickness = "0.033*cm" vis="InvisibleNoDaughters"/> </layer> - <layer repeat="10"> + <layer repeat="10" vis="EcalLayerVis"> <slice material = "TungstenDens24" thickness = "0.5*cm" /> <slice material = "Air" thickness = "0.025*cm" vis="InvisibleNoDaughters"/> <slice material = "Silicon" thickness = "0.032*cm" sensitive="yes" limits="cal_limits" vis="EcalSensitiveVis"/> diff --git a/DDDetectors/compact/SiD/SiD_Tracker.xml b/DDDetectors/compact/SiD/SiD_Tracker.xml index 2ffaeaf6e..0d3113a29 100644 --- a/DDDetectors/compact/SiD/SiD_Tracker.xml +++ b/DDDetectors/compact/SiD/SiD_Tracker.xml @@ -43,8 +43,8 @@ </readouts> <!-- Includes for sensitives and support --> - <include ref="SiD_TrackerEndcap.xml"/> <include ref="SiD_TrackerBarrel.xml"/> + <include ref="SiD_TrackerEndcap.xml"/> <include ref="SiD_TrackerForward.xml"/> <include ref="SiD_TrackerSupport.xml"/> <!-- diff --git a/DDDetectors/src/PolyhedraEndcapCalorimeter2_geo.cpp b/DDDetectors/src/PolyhedraEndcapCalorimeter2_geo.cpp index d81deb668..5c60bcdf2 100644 --- a/DDDetectors/src/PolyhedraEndcapCalorimeter2_geo.cpp +++ b/DDDetectors/src/PolyhedraEndcapCalorimeter2_geo.cpp @@ -17,8 +17,8 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { xml_det_t x_det = e; xml_dim_t dim = x_det.dimensions(); int det_id = x_det.id(); - string det_name = x_det.nameStr(); bool reflect = x_det.reflect(true); + string det_name = x_det.nameStr(); Material air = lcdd.air(); int numsides = dim.numsides(); double rmin = dim.rmin(); @@ -26,13 +26,14 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { double zmin = dim.zmin(); Layering layering(x_det); double totalThickness = layering.totalThickness(); - Volume envelopeVol("envelope",PolyhedraRegular(numsides,rmin,rmax,totalThickness),air); - + Volume endcapVol("endcap",PolyhedraRegular(numsides,rmin,rmax,totalThickness),air); + DetElement endcap("endcap",det_id); + int l_num = 1; int layerType = 0; double layerZ = -totalThickness/2; - envelopeVol.setAttributes(lcdd,x_det.regionStr(),x_det.limitsStr(),x_det.visStr()); + endcapVol.setAttributes(lcdd,x_det.regionStr(),x_det.limitsStr(),x_det.visStr()); for(xml_coll_t c(x_det,_U(layer)); c; ++c) { xml_comp_t x_layer = c; @@ -40,7 +41,8 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { string l_name = _toString(layerType,"layer%d"); int l_repeat = x_layer.repeat(); Volume l_vol(l_name,PolyhedraRegular(numsides,rmin,rmax,l_thick),air); - + vector<PlacedVolume> sensitives; + int s_num = 1; double sliceZ = -l_thick/2; for(xml_coll_t s(x_layer,_U(slice)); s; ++s) { @@ -50,61 +52,74 @@ static Ref_t create_detector(LCDD& lcdd, xml_h e, SensitiveDetector sens) { Material s_mat = lcdd.material(x_slice.materialStr()); Volume s_vol(s_name,PolyhedraRegular(numsides,rmin,rmax,s_thick),s_mat); + s_vol.setVisAttributes(lcdd.visAttributes(x_slice.visStr())); + sliceZ += s_thick/2; + PlacedVolume s_phv = l_vol.placeVolume(s_vol,Position(0,0,sliceZ)); + s_phv.addPhysVolID("slice",s_num); if ( x_slice.isSensitive() ) { sens.setType("calorimeter"); s_vol.setSensitiveDetector(sens); + sensitives.push_back(s_phv); } - s_vol.setVisAttributes(lcdd.visAttributes(x_slice.visStr())); sliceZ += s_thick/2; - PlacedVolume s_phv = l_vol.placeVolume(s_vol,Position(0,0,sliceZ)); - s_phv.addPhysVolID("slice",s_num); s_num++; } l_vol.setVisAttributes(lcdd.visAttributes(x_layer.visStr())); - if ( l_repeat <= 0 ) throw std::runtime_error(det_name+"> Invalid repeat value"); + if ( l_repeat <= 0 ) throw std::runtime_error(x_det.nameStr()+"> Invalid repeat value"); for(int j=0; j<l_repeat; ++j) { - string phys_lay = det_name + _toString(l_num,"_layer%d"); + string phys_lay = _toString(l_num,"layer%d"); layerZ += l_thick/2; - PlacedVolume phys_vol = envelopeVol.placeVolume(l_vol,Position(0,0,layerZ)); - phys_vol.addPhysVolID("layer", l_num); + DetElement layer_elt(endcap, phys_lay, l_num); + PlacedVolume pv = endcapVol.placeVolume(l_vol,Position(0,0,layerZ)); + pv.addPhysVolID("layer", l_num); + layer_elt.setPlacement(pv); + for(size_t ic=0; ic<sensitives.size(); ++ic) { + PlacedVolume sens_pv = sensitives[ic]; + DetElement comp_elt(layer_elt,sens_pv.volume().name(),l_num); + comp_elt.setPlacement(sens_pv); + } layerZ += l_thick/2; ++l_num; } ++layerType; } - DetElement sdet(det_name,det_id); - Volume motherVol = lcdd.pickMotherVolume(sdet); + double z_pos = zmin+totalThickness/2; + PlacedVolume pv; // Reflect it. if ( reflect ) { - Assembly assembly(det_name); - PlacedVolume pv = motherVol.placeVolume(assembly); - pv.addPhysVolID("system", det_id); - sdet.setPlacement(pv); + Assembly assembly(det_name); + DetElement both_endcaps(det_name,det_id); + Volume motherVol = lcdd.pickMotherVolume(both_endcaps); + DetElement sdetA = endcap; + Ref_t(sdetA)->SetName((det_name+"_A").c_str()); + DetElement sdetB = endcap.clone(det_name+"_B",x_det.id()); - DetElement sdetA(sdet,det_name+"_A",x_det.id()); - pv = assembly.placeVolume(envelopeVol,Transform3D(RotationZYX(M_PI/numsides,0,0), - Position(0,0,zmin+totalThickness/2))); + pv = assembly.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,0,0), + Position(0,0,z_pos))); pv.addPhysVolID("barrel", 1); sdetA.setPlacement(pv); - DetElement sdetB = sdetA.clone(det_name+"_B",x_det.id()); - sdet.add(sdetB); - pv = assembly.placeVolume(envelopeVol,Transform3D(RotationZYX(M_PI/numsides,M_PI,0), - Position(0,0,-(zmin+totalThickness/2)))); + pv = assembly.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,M_PI,0), + Position(0,0,-z_pos))); pv.addPhysVolID("barrel", 2); sdetB.setPlacement(pv); - } - else { - PlacedVolume pv = motherVol.placeVolume(envelopeVol, - Transform3D(RotationZYX(M_PI/numsides,0,0), - Position(0,0,zmin+totalThickness/2))); + + pv = motherVol.placeVolume(assembly); pv.addPhysVolID("system", det_id); - pv.addPhysVolID("barrel", 1); - sdet.setPlacement(pv); + both_endcaps.setPlacement(pv); + both_endcaps.add(sdetA); + both_endcaps.add(sdetB); + return both_endcaps; } - - return sdet; + Volume motherVol = lcdd.pickMotherVolume(endcap); + pv = motherVol.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,0,0), + Position(0,0,z_pos))); + pv.addPhysVolID("system", det_id); + pv.addPhysVolID("barrel", 1); + endcap.setPlacement(pv); + Ref_t(endcap)->SetName(det_name.c_str()); + return endcap; } DECLARE_DETELEMENT(DD4hep_PolyhedraEndcapCalorimeter2,create_detector) diff --git a/DDDetectors/src/PolyhedraEndcapCalorimeter2_surfaces.cpp b/DDDetectors/src/PolyhedraEndcapCalorimeter2_surfaces.cpp new file mode 100644 index 000000000..9318d3a9d --- /dev/null +++ b/DDDetectors/src/PolyhedraEndcapCalorimeter2_surfaces.cpp @@ -0,0 +1,46 @@ +// $Id: $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Author : M.Frank +// +//==================================================================== +// Framework include files +#define DD4HEP_USE_SURFACEINSTALL_HELPER DD4hep_PolyhedraEndcapCalorimeterSurfacePlugin +#include "DD4hep/SurfaceInstaller.h" + +/// Install measurement surfaces +template <typename UserData> +void Installer<UserData>::install(DetElement component, PlacedVolume pv) { + Volume comp_vol = pv.volume(); + if ( comp_vol.isSensitive() ) { + Volume mod_vol = parentVolume(component); + DD4hep::Geometry::PolyhedraRegular comp_shape(comp_vol.solid()), mod_shape(mod_vol.solid()); + + if ( !comp_shape.isValid() || !mod_shape.isValid() ) { + invalidInstaller("Components and/or modules are not Trapezoid -- invalid shapes"); + } + else if ( !handleUsingCache(component,comp_vol) ) { + DetElement par = component.parent(); + const TGeoHMatrix& m = par.worldTransformation(); + double dz = m.GetTranslation()[2]; + const double* trans = placementTranslation(component); + double half_mod_thickness = (mod_shape->GetZ(1)-mod_shape->GetZ(0))/2.0; + double half_comp_thickness = (comp_shape->GetZ(1)-comp_shape->GetZ(0))/2.0; + double si_position = trans[2]+half_mod_thickness; + double outer_thickness = half_mod_thickness - si_position; + double inner_thickness = half_mod_thickness + si_position; + Vector3D u(1.,0.,0.), v(0.,1.,0.), n(0.,0.,1.), o(100.,100.,0.); + std::cout << " Module: " << mod_shape.toString() << std::endl; + std::cout << " Component: " << comp_shape.toString() << std::endl; + std::cout << "dz:" << dz << " Si-pos:" << si_position + << " Mod-thickness:" << half_mod_thickness + << " Comp-thickness:" << half_comp_thickness + << std::endl; + VolPlane surf(comp_vol,Type(Type::Sensitive,Type::Measurement1D), + inner_thickness, outer_thickness, u, v, n, o); + addSurface(component,surf); + } + } +} diff --git a/DDDetectors/src/SiTrackerEndcap_surfaces.cpp b/DDDetectors/src/SiTrackerEndcap_surfaces.cpp index 52fd3c271..b8025f088 100644 --- a/DDDetectors/src/SiTrackerEndcap_surfaces.cpp +++ b/DDDetectors/src/SiTrackerEndcap_surfaces.cpp @@ -13,7 +13,7 @@ /// Install measurement surfaces template <typename UserData> void Installer<UserData>::install(DetElement component, PlacedVolume pv) { - Volume comp_vol = pv.volume(); + Volume comp_vol = pv.volume(); if ( comp_vol.isSensitive() ) { Volume mod_vol = parentVolume(component); DD4hep::Geometry::Trapezoid comp_shape(comp_vol.solid()), mod_shape(mod_vol.solid()); -- GitLab