Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:57

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 //
0014 // Specialized generic detector constructor
0015 // 
0016 //==========================================================================
0017 #include "DD4hep/DetFactoryHelper.h"
0018 #include "DD4hep/Printout.h"
0019 #include "XML/Layering.h"
0020 
0021 using namespace std;
0022 using namespace dd4hep;
0023 using namespace dd4hep::detail;
0024 
0025 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens)  {
0026   xml_det_t  x_det     = e;
0027   xml_dim_t  dim       = x_det.dimensions();
0028   Material   air       = description.air();
0029   string     det_name  = x_det.nameStr();
0030   bool       reflect   = x_det.reflect();
0031   double     zmin      = dim.inner_z();
0032   double     rmin      = dim.inner_r();
0033   double     rmax      = dim.outer_r();
0034   double     totWidth  = Layering(x_det).totalThickness();
0035   double     z         = zmin;
0036   Tube       envelope   (rmin,rmax,totWidth/2);
0037   Volume     envelopeVol(det_name+"_envelope",envelope,air);
0038   int        layer_num = 1;
0039   PlacedVolume pv;
0040 
0041   // Set attributes of slice
0042   for(xml_coll_t c(x_det,_U(layer)); c; ++c)  {
0043     xml_comp_t x_layer = c;
0044     double layerWidth = 0;
0045     for(xml_coll_t l(x_layer,_U(slice)); l; ++l)
0046       layerWidth += xml_comp_t(l).thickness();
0047     for(int i=0, im=0, repeat=x_layer.repeat(); i<repeat; ++i)  {
0048       double     zlayer = z;
0049       string     layer_name = det_name + _toString(layer_num,"_layer%d");
0050       Volume     layer_vol(layer_name,Tube(rmin,rmax,layerWidth),air);
0051 
0052       for(xml_coll_t l(x_layer,_U(slice)); l; ++l, ++im)  {
0053         xml_comp_t x_slice = l;
0054         double     w = x_slice.thickness();
0055         string     slice_name = layer_name + _toString(m+1,"slice%d");
0056         Material   slice_mat  = description.material(x_slice.materialStr());
0057         Volume     slice_vol (slice_name,Tube(rmin,rmax,w),slice_mat);
0058 
0059         if ( x_slice.isSensitive() )  {
0060           sens.setType("calorimeter");
0061           slice_vol.setSensitiveDetector(sens);
0062         }
0063         slice_vol.setAttributes(description,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
0064         pv = layer_vol.placeVolume(slice_vol,Position(0,0,z-zlayer-layerWidth/2+w/2));
0065         pv.addPhysVolID("slice",m+1);
0066         z += w;
0067       }
0068       layer_vol.setVisAttributes(description,x_layer.visStr());
0069 
0070       Position layer_pos(0,0,zlayer-zmin-totWidth/2+layerWidth/2);
0071       pv = envelopeVol.placeVolume(layer_vol,layer_pos);
0072       pv.addPhysVolID("layer",layer_num);
0073       printout(DEBUG,"Calo","CylindricalEndcapCalorimeter: built layer %d -> %s",layer_num,layer_name.c_str());
0074       ++layer_num;
0075     }
0076   }
0077   envelope.setDimensions(rmin,rmax,totWidth/2);
0078   // Set attributes of slice
0079   envelopeVol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
0080 
0081   DetElement   sdet(det_name,x_det.id());
0082   Assembly     assembly(det_name+"_assembly");
0083   Volume       motherVol = description.pickMotherVolume(sdet);
0084   PlacedVolume phv = motherVol.placeVolume(assembly);
0085   phv.addPhysVolID("system",sdet.id());
0086   sdet.setPlacement(phv);
0087 
0088   DetElement   sdetA(sdet,det_name+(reflect ? "_A" : ""),x_det.id());
0089   phv = assembly.placeVolume(envelopeVol,Position(0,0,zmin+totWidth/2));
0090   phv.addPhysVolID("barrel",1);
0091   sdetA.setPlacement(phv);
0092 
0093   if ( reflect )   {
0094     phv=assembly.placeVolume(envelopeVol,Transform3D(RotationZ(M_PI),Position(0,0,-zmin-totWidth/2)));
0095     phv.addPhysVolID("barrel",2);
0096     /// Create the detector element for the opposite side....
0097     DetElement   sdetB(sdet,det_name+"_B",x_det.id());
0098     sdetB.setPlacement(phv);
0099   }
0100   return sdet;
0101 }
0102 
0103 DECLARE_DETELEMENT(Lhe_CylindricalEndcapCalorimeter,create_detector)