File indexing completed on 2025-01-18 09:14:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "JSON/Helper.h"
0016 #include "DD4hep/Printout.h"
0017 #include "DD4hep/Detector.h"
0018
0019 #include <iostream>
0020 #include <map>
0021
0022 using namespace std;
0023 using namespace dd4hep;
0024 using namespace dd4hep::detail;
0025
0026 namespace {
0027
0028 struct MyDetExtension {
0029 int idD, Ni, Nj;
0030 double posDX, posDY, posDZ;
0031 double dimDX, dimDY, dimDZ;
0032 double pixelX, pixelY, pixelZ;
0033 DetElement detector;
0034
0035 MyDetExtension(DetElement e) : idD(0), Ni(0), Nj(0),
0036 posDX(0.0), posDY(0.0), posDZ(0.0),
0037 dimDX(0.0), dimDY(0.0), dimDZ(0.0),
0038 pixelX(0.0), pixelY(0.0), pixelZ(0.0), detector(e) {}
0039 MyDetExtension(const MyDetExtension& e, DetElement d)
0040 : idD(e.idD), Ni(e.Ni), Nj(e.Nj),
0041 posDX(e.posDX), posDY(e.posDY), posDZ(e.posDZ),
0042 dimDX(e.dimDX), dimDY(e.dimDY), dimDZ(e.dimDZ),
0043 pixelX(e.pixelX), pixelY(e.pixelY), pixelZ(e.pixelZ),
0044 detector(d)
0045 {
0046 }
0047 };
0048 }
0049 typedef MyDetExtension DetectorExtension;
0050
0051 static Ref_t create_detector(Detector &description, json_h e, SensitiveDetector sens) {
0052 json_det_t x_det = e;
0053 string det_name = x_det.nameStr();
0054 Assembly assembly (det_name);
0055 int detectors_id = x_det.id();
0056
0057 DetElement sdet(det_name,x_det.id());
0058 DetectorExtension* ext = new MyDetExtension(sdet);
0059 sdet.addExtension<MyDetExtension>(ext);
0060 ext->idD= detectors_id;
0061
0062 json_comp_t det_po = x_det.child(_U(position));
0063
0064 double det_y = det_po.y();
0065 double det_x = det_po.x();
0066 double det_z = det_po.z();
0067 ext->posDY = det_y;
0068 ext->posDX = det_x;
0069 ext->posDZ = det_z;
0070
0071 json_comp_t det_dim = x_det.child(_U(dimensions));
0072 double dim_x = det_dim.x();
0073 double dim_y = det_dim.y();
0074 double dim_z = det_dim.z();
0075
0076 Material mat = description.material("Silicon");
0077
0078 Volume motherVol = description.pickMotherVolume(sdet);
0079
0080 PlacedVolume pv;
0081 json_comp_t dtc_mod = x_det.child(_U(module));
0082 double pixelX = dtc_mod.x();
0083 double pixelY = dtc_mod.y();
0084 double pixelZ = dtc_mod.z();
0085
0086 int Ni = dim_x/pixelX;
0087 int Nj = dim_y/pixelY;
0088
0089 ext->dimDX = dim_x;
0090 ext->dimDY = dim_y;
0091 ext->dimDZ = dim_z;
0092 ext->pixelX = pixelX;
0093 ext->pixelY = pixelY;
0094 ext->pixelZ = pixelZ;
0095 ext->Ni= Ni;
0096 ext->Nj= Nj;
0097
0098
0099 Volume m_volume(det_name, Box(dim_x, dim_y, dim_z), mat);
0100 m_volume.setVisAttributes(description.visAttributes(x_det.visStr()));
0101 pv = motherVol.placeVolume(m_volume,Transform3D(Position(det_x,det_y,det_z)));
0102
0103 json_comp_t dtctr = x_det;
0104 if ( dtctr.isSensitive() ) {
0105 sens.setType("tracker");
0106 pv.addPhysVolID("system",detectors_id);
0107 m_volume.setSensitiveDetector(sens);
0108 }
0109 sdet.setPlacement(pv);
0110
0111 description.constant<double>("world_side");
0112 return sdet;
0113 }
0114
0115 DECLARE_JSON_DETELEMENT(MiniTelPixel_json,create_detector)