|
| 1 | +# ========================================================================== |
| 2 | +# AIDA Detector description implementation |
| 3 | +# -------------------------------------------------------------------------- |
| 4 | +# Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) |
| 5 | +# All rights reserved. |
| 6 | +# |
| 7 | +# For the licensing terms see $DD4hepINSTALL/LICENSE. |
| 8 | +# For the list of contributors see $DD4hepINSTALL/doc/CREDITS. |
| 9 | +# |
| 10 | +# ========================================================================== |
| 11 | +# |
| 12 | +# IronCylinder_python_geo.py — Python port of IronCylinder_geo.cpp. |
| 13 | +# |
| 14 | +# Demonstrates the DD4hep_PythonDetector factory: |
| 15 | +# - Reads detector dimensions from the compact XML. |
| 16 | +# - Builds an iron tube sensitive calorimeter volume. |
| 17 | +# - Places it inside the world volume. |
| 18 | +# |
| 19 | +# ========================================================================== |
| 20 | + |
| 21 | +from dd4hep_geo_plugin import Assembly, DetElement, Tube, Volume, TMath, xml_det_t |
| 22 | + |
| 23 | + |
| 24 | +def create_detector(description, xml_h, sens): |
| 25 | + """Build an iron cylindrical calorimeter. |
| 26 | +
|
| 27 | + Parameters |
| 28 | + ---------- |
| 29 | + description : dd4hep.Detector |
| 30 | + The top-level detector description object. |
| 31 | + xml_h : dd4hep.xml.Handle_t |
| 32 | + Handle to the ``<detector>`` XML element. |
| 33 | + sens : dd4hep.SensitiveDetector |
| 34 | + Sensitive detector assigned to this sub-detector. |
| 35 | +
|
| 36 | + Returns |
| 37 | + ------- |
| 38 | + dd4hep.DetElement |
| 39 | + The fully placed detector element. |
| 40 | + """ |
| 41 | + x_det = xml_det_t(xml_h) |
| 42 | + name = x_det.nameStr() |
| 43 | + |
| 44 | + d_det = DetElement(name, x_det.id()) |
| 45 | + |
| 46 | + # Read dimensions from the compact XML. |
| 47 | + x_dim = x_det.dimensions() |
| 48 | + inner_r = x_dim.rmin() |
| 49 | + outer_r = x_dim.rmax() |
| 50 | + z_half = x_dim.z() / 2.0 |
| 51 | + |
| 52 | + # Envelope assembly volume. |
| 53 | + calo_vol = Assembly(name + "_envelope") |
| 54 | + calo_vol.setAttributes(description, |
| 55 | + x_det.regionStr(), |
| 56 | + x_det.limitsStr(), |
| 57 | + x_det.visStr()) |
| 58 | + |
| 59 | + # Sensitive iron tube. |
| 60 | + tub = Tube(inner_r, outer_r, z_half, 0.0, TMath.TwoPi()) |
| 61 | + tub_vol = Volume(name + "_tube", tub, |
| 62 | + description.material("Iron")) |
| 63 | + calo_vol.placeVolume(tub_vol).addPhysVolID("module", 1) |
| 64 | + |
| 65 | + sens.setType("calorimeter") |
| 66 | + tub_vol.setSensitiveDetector(sens) |
| 67 | + d_det.setAttributes(description, tub_vol, |
| 68 | + x_det.regionStr(), |
| 69 | + x_det.limitsStr(), |
| 70 | + x_det.visStr()) |
| 71 | + |
| 72 | + # Place the envelope inside the world / mother volume. |
| 73 | + mother = description.pickMotherVolume(d_det) |
| 74 | + calo_plv = mother.placeVolume(calo_vol) |
| 75 | + calo_plv.addPhysVolID("system", x_det.id()) |
| 76 | + calo_plv.addPhysVolID("barrel", 0) |
| 77 | + d_det.setPlacement(calo_plv) |
| 78 | + |
| 79 | + return d_det |
0 commit comments