Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 08:19:48

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/Utilities.h"
0020 
0021 using namespace std;
0022 using namespace dd4hep;
0023 using namespace dd4hep::detail;
0024 
0025 static Ref_t create_element(Detector& description, xml_h e, Ref_t)  {
0026   xml_det_t  x_det  (e);
0027   string     det_name = x_det.nameStr();
0028   DetElement sdet(det_name, x_det.id());
0029   Volume     vol;
0030 
0031   bool useRot = x_det.hasChild(_U(rotation));
0032   bool usePos = x_det.hasChild(_U(position));
0033   Position    pos;
0034   RotationZYX rot;
0035 
0036   sdet.setType("compound");
0037   xml::setDetectorTypeFlag( e, sdet ) ;
0038 
0039   if( usePos ) {
0040     pos = Position(x_det.position().x(), x_det.position().y(), x_det.position().z());
0041   }
0042   if( useRot ) {
0043     rot = RotationZYX(x_det.rotation().x(), x_det.rotation().y(), x_det.rotation().z());
0044   }
0045 
0046   if ( x_det.hasChild(_U(shape)) )  {
0047     xml_comp_t x_shape = x_det.child(_U(shape));
0048     string     type  = x_shape.typeStr();
0049     Solid      solid = xml::createShape(description, type, x_shape);
0050     Material   mat   = description.material(x_shape.materialStr());
0051     printout(DEBUG,det_name,"+++ Creating detector assembly with shape of type:%s",type.c_str());
0052     vol = Volume(det_name,solid,mat);
0053   }
0054   else  {
0055     printout(DEBUG,det_name,"+++ Creating detector assembly without shape");
0056     vol = Assembly(det_name);
0057   }
0058 
0059   vol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
0060 
0061   Volume mother = description.pickMotherVolume(sdet);
0062   PlacedVolume pv;
0063   if( useRot && usePos ){
0064     pv =  mother.placeVolume(vol, Transform3D(rot, pos));
0065   } else if( useRot ){
0066     pv =  mother.placeVolume(vol, rot);
0067   } else if( usePos ){
0068     pv =  mother.placeVolume(vol, pos);
0069   } else {
0070     pv = mother.placeVolume(vol);
0071   }
0072   sdet.setPlacement(pv);
0073   for(xml_coll_t c(x_det,_U(composite)); c; ++c)  {
0074     xml_dim_t component = c;
0075     string nam = component.nameStr();
0076     description.declareParent(nam, sdet);
0077   }
0078   return sdet;
0079 }
0080 
0081 DECLARE_DETELEMENT(DD4hep_SubdetectorAssembly,create_element)