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/VolumeBuilder.h"
0020 #include "XML/Utilities.h"
0021 #include <memory>
0022 
0023 using namespace std;
0024 using namespace dd4hep;
0025 using namespace dd4hep::detail;
0026 
0027 static Ref_t create_element(Detector& description, xml_h e, SensitiveDetector sens)  {
0028   //Builder  b(description);
0029   //return b.create(e, sens);
0030   xml_comp_t  x_det(e);
0031   xml_comp_t  x_env = e.child(_U(envelope));
0032   xml_comp_t  x_shp = x_env.child(_U(shape),false);
0033   xml_h       x_dbg = e.child(_U(debug),false);
0034   xml_h       x_pos, x_rot, x_tr;
0035   Volume      assembly;
0036   xml::tools::VolumeBuilder builder(description, e, sens);
0037 
0038   builder.debug = x_dbg != 0;
0039   builder.load(x_det, "include");
0040   builder.buildShapes(x_det);
0041   builder.buildShapes(x_env);
0042   builder.buildVolumes(x_det);
0043   builder.buildVolumes(x_env);
0044   
0045   // Now we build the envelope
0046   if ( !x_shp ) x_shp = x_env;
0047   if ( x_shp.typeStr() == "Assembly" )  {
0048     assembly = Assembly("lv"+builder.name);
0049   }
0050   else  {
0051     Material mat   = description.material(x_env.materialStr());
0052     Solid    solid = xml::createShape(description, x_shp.typeStr(), x_shp);
0053     assembly = Volume("lv"+builder.name, solid, mat);
0054   }
0055   /// Set generic associations
0056   assembly.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
0057   /// If specified more direct: use these ones.
0058   if ( x_env.hasAttr(_U(vis)) )
0059     assembly.setVisAttributes(description, x_env.visStr());
0060 
0061   if ( x_env.hasAttr(_U(region)) )
0062     assembly.setRegion(description, x_env.regionStr());
0063 
0064   if ( x_env.hasAttr(_U(limits)) )
0065     assembly.setLimitSet(description, x_env.limitsStr());
0066 
0067   if ( x_det.hasAttr(_U(sensitive)) )
0068     sens.setType(x_det.attr<string>(_U(sensitive)));
0069   else
0070     builder.detector.setType("compound");
0071 
0072   if ( x_env.hasAttr(_U(name)) )
0073     assembly->SetName(x_env.nameStr().c_str());
0074 
0075   builder.placeDaughters(builder.detector, assembly, x_env);
0076   builder.placeDaughters(builder.detector, assembly, x_det);
0077   x_pos = x_env.child(_U(position),false);
0078   x_rot = x_env.child(_U(rotation),false);
0079   x_tr  = x_env.child(_U(transformation),false);
0080   builder.placeDetector(assembly, (x_pos || x_rot || x_tr) ? x_env : x_det);
0081   printout(builder.debug ? ALWAYS : DEBUG, "VolumeBuilder",
0082            "+++ Created subdetector instance %s vis:",
0083            builder.name.c_str(), x_det.visStr().c_str());
0084   return builder.detector;
0085 }
0086 DECLARE_DETELEMENT(DD4hep_VolumeAssembly,create_element)