Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 08:59:20

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 
0019 using namespace std;
0020 using namespace dd4hep;
0021 using namespace dd4hep::detail;
0022 
0023 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens)  {
0024   xml_det_t  x_det     = e;
0025   string     det_name  = x_det.nameStr();
0026   Material   air       = description.air();
0027   DetElement sdet        (det_name,x_det.id());
0028   Assembly   assembly    (det_name+"_assembly");
0029   PlacedVolume pv;
0030   int n = 0;
0031   xml::Component  pos  = x_det.position();
0032 
0033   for(xml_coll_t i(x_det,_U(layer)); i; ++i, ++n)  {
0034     xml_comp_t x_layer = i;
0035     string  l_name = det_name+_toString(n,"_layer%d");
0036     double  outer_z = x_layer.outer_z();
0037     double  rmin = x_layer.inner_r();
0038     double  r    = rmin;
0039     DetElement layer(sdet,_toString(n,"layer%d"),x_layer.id());
0040     Tube    l_tub (rmin,2*rmin,outer_z);
0041     Volume  l_vol(l_name,l_tub,air);
0042     int im = 0;
0043 
0044     for(xml_coll_t j(x_layer,_U(slice)); j; ++j, ++im)  {
0045       // If slices are only given a thickness attribute, they are radially concentric slices
0046       // If slices are given an inner_z attribute, they are longitudinal slices with equal rmin
0047       xml_comp_t x_slice = j;
0048       Material mat = description.material(x_slice.materialStr());
0049       string s_name= l_name+_toString(im,"_slice%d");
0050       double thickness = x_slice.thickness();
0051       double s_outer_z = dd4hep::getAttrOrDefault(x_slice, _Unicode(outer_z), outer_z);
0052       double s_inner_z = dd4hep::getAttrOrDefault(x_slice, _Unicode(inner_z), 0.0*dd4hep::cm);
0053       Tube   s_tub(r,r+thickness,(s_inner_z > 0? 0.5*(s_outer_z-s_inner_z): s_outer_z),2*M_PI);
0054       Volume s_vol(s_name, s_tub, mat);
0055 
0056       if ( x_slice.isSensitive() ) {
0057         sens.setType("tracker");
0058         s_vol.setSensitiveDetector(sens);
0059       }
0060       // Set Attributes
0061       s_vol.setAttributes(description,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
0062       if (s_inner_z > 0) {
0063         // Place off-center volumes twice
0064         Position s_pos(0, 0, 0.5*(s_outer_z+s_inner_z));
0065         pv = l_vol.placeVolume(s_vol, -s_pos);
0066         pv = l_vol.placeVolume(s_vol, +s_pos);
0067       } else {
0068         r += thickness;
0069         pv = l_vol.placeVolume(s_vol);
0070       }
0071       // Slices have no extra id. Take the ID of the layer!
0072       pv.addPhysVolID("slice",im);
0073     }
0074     l_tub.setDimensions(rmin,r,outer_z);
0075     //cout << l_name << " " << rmin << " " << r << " " << z << endl;
0076     l_vol.setVisAttributes(description,x_layer.visStr());
0077       
0078     pv = assembly.placeVolume(l_vol);
0079     pv.addPhysVolID("layer",n);
0080     layer.setPlacement(pv);
0081   }
0082   if ( x_det.hasAttr(_U(combineHits)) ) {
0083     sdet.setCombineHits(x_det.combineHits(),sens);
0084   }
0085 
0086   pv = description.pickMotherVolume(sdet).placeVolume(assembly,Position(pos.x(),pos.y(),pos.z()));
0087   pv.addPhysVolID("system",sdet.id()).addPhysVolID("barrel",0);
0088   sdet.setPlacement(pv);
0089   return sdet;
0090 }
0091 
0092 DECLARE_DETELEMENT(athena_SolenoidCoil,create_detector)