Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14: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     : Jongho.Lee
0011 //
0012 //==========================================================================
0013 //
0014 // Specialized generic detector constructor
0015 // 
0016 //==========================================================================
0017 #include "DD4hep/DetFactoryHelper.h"
0018 #include "DD4hep/Printout.h"
0019 
0020 using namespace std;
0021 using namespace dd4hep;
0022 using namespace dd4hep::detail;
0023 
0024 static Ref_t create_element(Detector& description, xml_h e, Ref_t sens)  {
0025   xml_det_t  x_det  (e);
0026   xml_comp_t x_box      = x_det.envelope();
0027   xml_dim_t  pos        = x_det.position();
0028   string     det_name   = x_det.nameStr();
0029   DetElement det(det_name,x_det.id());
0030   //double     env_dz     .dz()/2.0;
0031   double     env_width  = x_box.width();
0032   double     env_length = x_box.length();
0033   double     env_height = x_box.height();
0034   // If the cone should be removed and replaced by an assembly,
0035   // comment the upper to and enable the lower line
0036   Assembly   env_vol(det_name);
0037   PlacedVolume pv;
0038   SensitiveDetector sd = sens;
0039 
0040   sd.setType("tracker");
0041   // Set visualization, limits and region (if present)
0042   env_vol.setRegion(description, x_det.regionStr());
0043   env_vol.setLimitSet(description, x_det.limitsStr());
0044   env_vol.setVisAttributes(description, x_det.visStr());
0045   printout(INFO,"CODEX-b box","%s width=%g length=%g height= %g",
0046            det_name.c_str(), env_width, env_length, env_height  );
0047  
0048   ///// Test for 1 layer into a CODEXb-box /////
0049   int type_st_num = 0;
0050   for(xml_coll_t i(x_det, _U(station)); i; ++i, ++type_st_num) {
0051     xml_comp_t station  = i;
0052     double    st_width  = station.width();
0053     double    st_thick  = station.thickness();
0054     double    st_height = station.height();
0055     double    st_x      = station.x()+pos.x()-env_width;
0056     double    st_y      = station.y()+pos.y();
0057     double    st_z      = station.z()+pos.z();
0058     int       st_repeat = station.repeat(); 
0059     double    st_gap       = station.gap();
0060     string    st_nam = _toString(type_st_num, "CODEX_station_type_%d");
0061     Box       st_box(st_thick, st_height, st_width);
0062     Material  st_mat(description.material(station.attr<string>(_U(material))));
0063     Volume    st_vol(st_nam,st_box,st_mat);
0064     st_vol.setVisAttributes(description, station.visStr());
0065 
0066     int type_la_num = 0;
0067     xml_comp_t layer       = x_det.child(_U(layer));
0068     double    la_width     = layer.width();
0069     double    la_thick     = layer.thickness();
0070     double    la_height    = layer.height();
0071     //double    la_gap       = layer.gap();
0072     double    la_x         = 0;
0073     double    la_y         = 0;
0074     double    la_z         = 0;
0075     int       la_repeat    = layer.repeat();
0076     double    la_pitch     = layer.distance();
0077     string    la_nam       = _toString(type_la_num, "CODEX_layer_type_%d");
0078     Box       la_box(la_thick, la_height, la_width);
0079     Material  la_mat(description.material(layer.attr<string>(_U(material))));
0080     Volume    la_vol(la_nam, la_box, la_mat);
0081 
0082     la_vol.setVisAttributes(description, layer.visStr());
0083 
0084     if( layer.isSensitive() ) {
0085       la_vol.setSensitiveDetector(sd);
0086     }
0087 
0088     la_x = -st_thick + la_pitch/2.0;
0089     vector<PlacedVolume> la_places;
0090     for(int k=0, layer_number=1; k < la_repeat; ++k, ++layer_number)   {
0091       pv = st_vol.placeVolume(la_vol,Position(la_x, la_y, la_z));
0092       pv.addPhysVolID("layer", layer_number);
0093       printout(INFO, "CODEX-b-layer"," Station: %s layer %d x=%g y=%g z=%g", st_vol.name(), layer_number, la_x, la_y, la_z);
0094       la_places.push_back(pv);
0095       la_x += la_pitch; 
0096     }
0097     
0098     for (int j=0, station_number=1; j < st_repeat; ++j, ++station_number )    {
0099       DetElement st_det(det, _toString(station_number, "Station%d"), x_det.id());
0100       pv = env_vol.placeVolume(st_vol, Position(st_x, st_y, st_z));
0101       pv.addPhysVolID("station", station_number);
0102       st_det.setPlacement(pv);
0103       printout(INFO, "CODEX-b-station"," Station: %d x=%g y=%g z=%g", station_number,st_x, st_y, st_z);
0104       for(int k=0, layer_number=1; k < la_repeat; ++k, ++layer_number)   {
0105         DetElement la_det(st_det, _toString(layer_number, "Layer%d"), x_det.id());
0106         la_det.setPlacement(la_places[k]);
0107       }
0108       st_x += st_gap; 
0109     } // station loop
0110   }
0111 
0112   if ( x_det.isSensitive() )   {   
0113     xml_dim_t sd_typ = x_det.child(_U(sensitive));
0114     env_vol.setSensitiveDetector(sens);
0115     sd.setType(sd_typ.typeStr());
0116   }
0117   Volume mother = description.pickMotherVolume(det);
0118   //Transform3D trafo(Position(pos.x(),pos.y(),pos.z()));
0119   //Direction dir = trafo*Direction(0,0,1.);
0120   pv = mother.placeVolume(env_vol);
0121   if ( x_det.hasAttr(_U(id)) )  {
0122     pv.addPhysVolID("system",x_det.id());
0123   }
0124   det.setPlacement(pv);
0125   return det;
0126 }
0127 
0128 DECLARE_DETELEMENT(DD4hep_CODEXb_layer,create_element)