Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:15:58

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Aranya Giri
0003 
0004 // Start Date - 10/31/2022
0005 // Homogeneous PbWO4 (EM Calorimeter) Pair Spectrometer
0006 
0007 #include "DD4hep/DetFactoryHelper.h"
0008 #include <XML/Helper.h>
0009 #include <algorithm>
0010 #include <iostream>
0011 #include <tuple>
0012 
0013 using namespace std;
0014 using namespace dd4hep;
0015 
0016 // Definition of function to build the modules
0017 static tuple<Volume, Position> build_specHomoCAL_module(const Detector& description,
0018                                                         const xml::Component& mod_x,
0019                                                         SensitiveDetector& sens);
0020 
0021 // Driver Function
0022 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
0023   sens.setType("calorimeter");
0024 
0025   xml_det_t x_det  = e;
0026   xml_comp_t x_mod = x_det.child(_Unicode(module));
0027   string det_name  = x_det.nameStr();
0028   int det_ID       = x_det.id();
0029 
0030   // Create main detector element to be returned at the end
0031   DetElement det(det_name, det_ID);
0032 
0033   // Mother volume
0034   Volume motherVol = description.pickMotherVolume(det);
0035 
0036   // Detector assembly
0037   Assembly assembly(det_name);
0038   assembly.setVisAttributes(description.invisible());
0039 
0040   // Create Modules
0041 
0042   auto [modVol, modSize] = build_specHomoCAL_module(description, x_mod, sens);
0043   double detSizeXY       = getAttrOrDefault(x_det, _Unicode(sizeXY), 20);
0044   int nxy                = int(detSizeXY / modSize.x());
0045   double xypos0          = -nxy * modSize.x() / 2.0 + modSize.x() / 2.0;
0046 
0047   // Build detector components
0048   // loop over sectors
0049   for (xml_coll_t si(x_det, _Unicode(sector)); si; si++) { // sectors (top,bottom)
0050 
0051     xml_comp_t x_sector(si);
0052     int sector_id = x_sector.id();
0053     int mod_id    = 0;
0054 
0055     xml_comp_t x_pos = x_sector.position();
0056     xml_comp_t x_rot = x_sector.rotation();
0057 
0058     for (int ix = 0; ix < nxy; ix++) {
0059       for (int iy = 0; iy < nxy; iy++) {
0060 
0061         double mod_pos_x = x_pos.x() + xypos0 + ix * modSize.x();
0062         double mod_pos_y = x_pos.y() + xypos0 + iy * modSize.y();
0063         double mod_pos_z = x_pos.z() + 0.0 * cm;
0064 
0065         PlacedVolume modPV =
0066             assembly.placeVolume(modVol, Transform3D(RotationZYX(x_rot.x(), x_rot.y(), x_rot.z()),
0067                                                      Position(mod_pos_x, mod_pos_y, mod_pos_z)));
0068 
0069         modPV.addPhysVolID("sector", sector_id).addPhysVolID("module", mod_id);
0070         mod_id++;
0071       }
0072     }
0073 
0074   } // sectors
0075 
0076   // Place assembly into mother volume.  Assembly is centered at origin
0077   PlacedVolume detPV = motherVol.placeVolume(assembly, Position(0.0, 0.0, 0.0));
0078   detPV.addPhysVolID("system", det_ID);
0079 
0080   // Connect to system ID
0081   det.setPlacement(detPV);
0082 
0083   return det;
0084 } //Driver class close
0085 
0086 //--------------------------------------------------------------------
0087 //Function for building the module
0088 static tuple<Volume, Position> build_specHomoCAL_module(const Detector& description,
0089                                                         const xml::Component& mod_x,
0090                                                         SensitiveDetector& sens) {
0091 
0092   double sx         = mod_x.attr<double>(_Unicode(sizex));
0093   double sy         = mod_x.attr<double>(_Unicode(sizey));
0094   double sz         = mod_x.attr<double>(_Unicode(sizez));
0095   double frame_size = mod_x.attr<double>(_Unicode(frameSize));
0096 
0097   Box modShape((sx / 2.0 - frame_size), (sy / 2.0 - frame_size), sz / 2.0);
0098   auto modMat = description.material(mod_x.attr<std::string>(_Unicode(material)));
0099   Volume modVol("module_vol", modShape, modMat);
0100 
0101   if (mod_x.hasAttr(_Unicode(vis))) {
0102     modVol.setVisAttributes(description.visAttributes(mod_x.attr<std::string>(_Unicode(vis))));
0103   }
0104 
0105   modVol.setSensitiveDetector(sens);
0106   return make_tuple(modVol, Position{sx, sy, sz});
0107 }
0108 
0109 DECLARE_DETELEMENT(LumiSpecHomoCAL, create_detector) //(det_type, driver func)