Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:16:00

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