Back to home page

EIC code displayed by LXR

 
 

    


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

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 //
0015 // Display using:
0016 // $> geoDisplay examples/ClientTests/compact/BoxOfStraws.xml
0017 //
0018 //==========================================================================
0019 #include <DD4hep/DetFactoryHelper.h>
0020 #include <DD4hep/DD4hepUnits.h>
0021 #include <DD4hep/Printout.h>
0022 
0023 using namespace dd4hep;
0024 
0025 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens)  {
0026   double       tol     = 1e-5 * dd4hep::mm;
0027   xml_det_t    x_det   = e;
0028   xml_dim_t    x_box   = x_det.child(_U(box));
0029   xml_dim_t    x_rot   = x_det.child(_U(rotation));
0030   xml_dim_t    x_pos   = x_det.child(_U(position));
0031   xml_det_t    x_straw = x_det.child(_Unicode(straw));
0032   xml_det_t    x_gas   = x_det.child(_Unicode(gas));
0033   std::string  nam     = x_det.nameStr();
0034   const double thick   = x_straw.thickness();
0035   const double delta   = 2e0*x_straw.rmax();
0036   const int    num_x   = int(2e0*x_box.x() / delta);
0037   const int    num_z   = int(2e0*x_box.z() / (delta+2*tol));
0038 
0039   Tube   straw(0., x_straw.rmax()-tol, x_straw.y()-tol);
0040   Volume straw_vol("straw", straw, description.material(x_straw.materialStr()));
0041   straw_vol.setAttributes(description, x_straw.regionStr(), x_straw.limitsStr(), x_straw.visStr());
0042   
0043   Tube   straw_gas(0., straw.rMax()-thick, straw.dZ()-thick);
0044   Volume straw_gas_vol("gas", straw_gas, description.material(x_gas.materialStr()));
0045   straw_gas_vol.setAttributes(description, x_gas.regionStr(), x_gas.limitsStr(), x_gas.visStr());
0046 
0047   straw_vol.placeVolume(straw_gas_vol);
0048 
0049   printout(INFO, "BoxOfStraws", "%s: Straw: rmax: %7.3f y: %7.3f mat: %s vis: %s solid: %s",
0050            nam.c_str(), x_straw.rmax(), x_straw.y(), x_straw.materialStr().c_str(),
0051            x_straw.visStr().c_str(), straw.type());
0052   if( x_gas.hasChild(_U(sensitive)) )  {
0053     sens.setType("tracker");
0054     straw_gas_vol.setSensitiveDetector(sens);
0055   }
0056 
0057   // Envelope: make envelope box 'tol' bigger on each side, so that the straws
0058   Box    box(x_box.x()+tol, x_box.y()+tol, x_box.z()+tol);
0059   Volume box_vol(nam, box, description.air());
0060   box_vol.setAttributes(description, x_box.regionStr(), x_box.limitsStr(), x_box.visStr());
0061 
0062   Box    layer(x_box.x(), x_box.y(), x_straw.rmax());
0063   Volume layer_vol("layer", layer, description.air());
0064   layer_vol.setVisAttributes(description.visAttributes("VisibleGray"));
0065   
0066   printout(INFO, "BoxOfStraws", "%s: Layer:   nx: %7d nz: %7d delta: %7.3f", nam.c_str(), num_x, num_z, delta);
0067   Rotation3D rot(RotationZYX(0e0, 0e0, M_PI/2e0));
0068   for( int ix=0; ix < num_x; ++ix )  {
0069     double x = -box.x() + (double(ix)+0.5) * (delta + 2e0*tol);
0070     PlacedVolume pv = layer_vol.placeVolume(straw_vol, Transform3D(rot,Position(x, 0e0, 0e0)));
0071     pv.addPhysVolID("straw", ix);
0072   }
0073   for( int iz=0; iz < num_z; ++iz )  {
0074     // leave 'tol' space between the layers
0075     double z = -box.z() + (double(iz)+0.5) * (2.0*tol + delta);
0076     PlacedVolume pv = box_vol.placeVolume(layer_vol, Position(0e0, 0e0, z));
0077     pv.addPhysVolID("layer", iz);
0078   }
0079   printout(INFO, "BoxOfStraws", "%s: Created %d layers of %d straws each.", nam.c_str(), num_z, num_x);
0080   
0081   DetElement   sdet  (nam, x_det.id());
0082   Volume       mother(description.pickMotherVolume(sdet));
0083   Rotation3D   rot3D (RotationZYX(x_rot.z(0), x_rot.y(0), x_rot.x(0)));
0084   Transform3D  trafo (rot3D, Position(x_pos.x(0), x_pos.y(0), x_pos.z(0)));
0085   PlacedVolume pv = mother.placeVolume(box_vol, trafo);
0086   pv.addPhysVolID("system", x_det.id());
0087   sdet.setPlacement(pv);  // associate the placed volume to the detector element
0088   printout(INFO, "BoxOfStraws", "%s: Detector construction finished.", nam.c_str());
0089   return sdet;
0090 }
0091 
0092 DECLARE_DETELEMENT(DD4hep_BoxOfStraws,create_detector)