Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-23 08:26:57

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Shima Shimizu, Jihee Kim, Wouter Deconinck
0003 
0004 #include "DD4hep/DetFactoryHelper.h"
0005 #include "DD4hep/OpticalSurfaces.h"
0006 #include "DD4hep/Printout.h"
0007 #include "DDRec/DetectorData.h"
0008 #include "DDRec/Surface.h"
0009 #include <XML/Helper.h>
0010 #include <XML/Utilities.h>
0011 #include <algorithm>
0012 #include <iostream>
0013 #include <math.h>
0014 #include <tuple>
0015 //////////////////////////////////////////////////
0016 // Far Forward Ion Zero Degree Calorimeter - Ecal
0017 // Reference from ATHENA ScFiCalorimeter_geo.cpp
0018 //////////////////////////////////////////////////
0019 
0020 using namespace std;
0021 using namespace dd4hep;
0022 
0023 // main
0024 static Ref_t create_detector(Detector& desc, xml_h handle, SensitiveDetector sens) {
0025   xml::DetElement detElem = handle;
0026   std::string detName     = detElem.nameStr();
0027   int detID               = detElem.id();
0028   DetElement det(detName, detID);
0029   sens.setType("calorimeter");
0030   auto dim      = detElem.dimensions();
0031   auto xwidth   = dim.x();
0032   auto ywidth   = dim.y();
0033   auto length   = dim.z();
0034   xml_dim_t pos = detElem.position();
0035   xml_dim_t rot = detElem.rotation();
0036 
0037   // apply any detector type flags set in XML
0038   dd4hep::xml::setDetectorTypeFlag(detElem, det);
0039 
0040   // envelope
0041   Box envShape(xwidth * 0.5, ywidth * 0.5, length * 0.5);
0042   Volume env(detName + "_envelope", envShape, desc.material("Air"));
0043   env.setVisAttributes(desc.visAttributes(detElem.visStr()));
0044 
0045   int layerid   = 0;
0046   double zpos_0 = -length / 2.;
0047 
0048   for (xml_coll_t li(detElem, _Unicode(layer)); li; ++li) {
0049 
0050     xml_comp_t x_lyr = li;
0051     auto nlyr        = x_lyr.attr<int>(_Unicode(nlayer));
0052     auto gap_z       = x_lyr.attr<double>(_Unicode(gapspace));
0053 
0054     map<int, string> v_sl_name;
0055     map<string, Volume> slices;
0056     map<string, double> sl_thickness;
0057 
0058     int nsl = 0;
0059     xml_coll_t ci(x_lyr, _Unicode(slice));
0060     for (ci.reset(); ci; ++ci) {
0061       xml_comp_t x_sl = ci;
0062       Material sl_mat = desc.material(x_sl.materialStr());
0063       string sl_name  = x_sl.nameStr();
0064       double sl_z     = x_sl.thickness();
0065 
0066       Box sl_Shape(xwidth / 2., ywidth / 2., sl_z / 2.);
0067       Volume sl_Vol("slice_vol", sl_Shape, sl_mat);
0068       sl_Vol.setVisAttributes(desc.visAttributes(x_sl.visStr()));
0069       if (x_sl.isSensitive())
0070         sl_Vol.setSensitiveDetector(sens);
0071 
0072       nsl++;
0073       v_sl_name[nsl]        = sl_name;
0074       slices[sl_name]       = sl_Vol;
0075       sl_thickness[sl_name] = sl_z;
0076     }
0077 
0078     for (int ilyr = 0; ilyr < nlyr; ilyr++) {
0079       layerid++;
0080       for (int isl = 0; isl < nsl; isl++) {
0081         string sl_name = v_sl_name[isl + 1];
0082 
0083         double zpos = zpos_0 + sl_thickness[sl_name] / 2.;
0084         Position sl_pos(0, 0, zpos);
0085         PlacedVolume pv = env.placeVolume(slices[sl_name], sl_pos);
0086         if (slices[sl_name].isSensitive())
0087           pv.addPhysVolID(sl_name, layerid);
0088 
0089         zpos_0 += sl_thickness[sl_name];
0090       }
0091 
0092       zpos_0 += gap_z;
0093     }
0094   }
0095 
0096   // detector position and rotation
0097   Volume motherVol = desc.pickMotherVolume(det);
0098   Transform3D tr(RotationZYX(rot.z(), rot.y(), rot.x()), Position(pos.x(), pos.y(), pos.z()));
0099   PlacedVolume envPV = motherVol.placeVolume(env, tr);
0100   envPV.addPhysVolID("system", detID);
0101   det.setPlacement(envPV);
0102   return det;
0103 }
0104 
0105 DECLARE_DETELEMENT(ZDC_ImagingCal, create_detector)