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   int        det_id     = x_det.id();
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_thick  = x_box.thickness();
0032   double     env_length = x_box.length();
0033   double     env_height = x_box.height();
0034   Box        env_box(env_thick/2.0,env_length,env_height);
0035   Volume     env_vol(det_name,env_box,description.air());
0036   PlacedVolume pv;
0037   SensitiveDetector sd = sens;
0038 
0039   sd.setType("tracker");
0040   // Set visualization, limits and region (if present)
0041   env_vol.setRegion(description, x_det.regionStr());
0042   env_vol.setLimitSet(description, x_det.limitsStr());
0043   env_vol.setVisAttributes(description, x_det.visStr());
0044   printout(INFO,"CODEX-b box","%s thickness=%g length=%g height= %g",
0045            det_name.c_str(), env_thick, env_length, env_height  );
0046  
0047   /// Build the single layer volume:
0048   //int type_la_num = 0;
0049   //xml_comp_t layer       = x_det.child(_U(layer));
0050   //double    la_width     = layer.width();
0051   //double    la_thick     = layer.thickness();
0052   //double    la_height    = layer.height();
0053   ////double    la_gap       = layer.gap();
0054   //double    la_x         = 0;
0055   //double    la_y         = 0;
0056   //double    la_z         = 0;
0057   //string    la_nam       = _toString(type_la_num, "CODEX_layer_type_%d");
0058   //Box       la_box(la_thick, la_height, la_width);
0059   //Material  la_mat(description.material(layer.attr<string>(_U(material))));
0060   //Volume    la_vol(la_nam, la_box, la_mat);
0061 
0062   //la_vol.setVisAttributes(description, layer.visStr());
0063 
0064   //if( layer.isSensitive() ) {
0065   //  la_vol.setSensitiveDetector(sd);
0066   //}
0067 
0068   /// Now we build the staions
0069   int type_st_num = 0;
0070   typedef std::map<Volume,std::vector<PlacedVolume> > Stations;
0071   Stations station_layers;
0072   vector<Volume> station_vols;
0073   for(xml_coll_t i(x_det, _U(station)); i; ++i) {
0074     xml_comp_t station  = i;
0075     //xml_dim_t st_layers = station.child(_U(layers));
0076     xml_comp_t st_layers = station.child(_U(layers));
0077     int        st_N_lay  = st_layers.number();
0078     double     layer_gap = st_layers.gap();
0079     double     la_width  = st_layers.width();
0080     double     la_thick  = st_layers.thickness();
0081     double     la_height = st_layers.height();
0082     double     la_x      = 0;
0083     double     la_y      = 0;
0084     double     la_z      = 0;
0085     string     la_nam    = st_layers.nameStr();
0086     Box        la_box(la_thick, la_height, la_width);
0087     Material   la_mat(description.material(st_layers.attr<string>(_U(material))));
0088     Volume     la_vol(la_nam, la_box, la_mat);
0089 
0090     string     st_name   = station.nameStr();
0091     double     st_width  = station.width();
0092     double     layer_dist= layer_gap;
0093     double     st_thick  = (st_N_lay-1)*layer_dist/2.0 + layer_gap;
0094     double     st_height = station.height();
0095     string     st_nam    = _toString(type_st_num, "CODEX_sub_station_%d");
0096     Box        st_box(st_thick, st_height, st_width);
0097     Volume     st_vol(st_name,st_box,description.air());
0098 
0099     la_vol.setVisAttributes(description, st_layers.visStr());
0100     if( st_layers.isSensitive() ) {
0101       cout << "Station:" << st_name << " layer:" << la_nam << endl;
0102       la_vol.setSensitiveDetector(sd);
0103     }
0104     printout(INFO, "CODEX-b station size"," Thick: % g, width: % g, height: % g", st_thick, st_width, st_height);
0105 
0106     st_vol.setVisAttributes(description, station.visStr());
0107     station_vols.push_back(st_vol);
0108     la_x = -st_thick + layer_gap;
0109     for(int k=0; k < st_N_lay; ++k)   {
0110       pv = st_vol.placeVolume(la_vol,Position(la_x+la_box.x(), la_y, la_z));
0111       pv.addPhysVolID("layer", k+1);
0112       printout(INFO, "CODEX-b-layer"," Station: %s layer %d x=%g", st_vol.name(), k+1, la_x);
0113       station_layers[st_vol].push_back(pv);
0114       la_x += layer_dist;
0115     }
0116   }
0117 
0118   /// Now we build the super-staions
0119   Stations super_stations;
0120   int num_super = 0;
0121   vector<PlacedVolume> super_places;
0122   for(xml_coll_t i(x_det, _U(station)); i; ++i, ++num_super) {
0123     xml_comp_t station      = i;
0124     Volume     st_vol       = station_vols[num_super];
0125     double     st_dist      = station.distance();
0126     double     st_thick     = station.thickness();
0127     xml_dim_t  super_pos    = station.position();
0128     double     super_height = station.height();
0129     double     super_width  = station.width();
0130     int        super_repeat = station.repeat();
0131     double     super_angle  = station.angle(); 
0132     double     super_thick  = st_dist/2.0*(super_repeat-1) + st_thick*super_repeat;
0133     string     super_name   = station.nameStr();
0134     //Box        super_box(super_width+50.0,super_width+50.0,super_height+50.0);
0135     //Volume     super_vol(_toString(num_super,"Super%d"),super_box,description.air());
0136     Assembly   super_vol(_toString(num_super,"Super%d"));
0137 
0138     printout(INFO, "CODEX-b super station size"," Thick: % g, width: % g, height: % g", super_thick, super_width+30.0, super_height+30.0);
0139     double     face_x = -super_height;
0140     double     super_x = -super_thick + st_thick;
0141     double     inner_x = -st_dist*((super_repeat-1)/2.0); 
0142     for (int j=0; j < super_repeat; ++j )    {
0143       if( super_name.compare("face_station") == 0 && j < 2 ) { 
0144           Transform3D trafo(RotationZYX(0,0,0),Position(face_x, 0, 0)); 
0145           pv = super_vol.placeVolume(st_vol,trafo); 
0146       }
0147       if( super_name.compare("face_station") == 0 && j >=2 && j < 4 ) { 
0148           if( j == 2 ) face_x = -super_height; 
0149           Transform3D trafo(RotationZYX(0,super_angle,0),Position(0, 0, face_x)); 
0150           pv = super_vol.placeVolume(st_vol,trafo); 
0151       }
0152       if( super_name.compare("face_station") == 0 && j >=4 && j < 6 ) { 
0153           if( j == 4 ) face_x = -super_height; 
0154           Transform3D trafo(RotationZYX(super_angle,0,0),Position(0, face_x, 0)); 
0155           pv = super_vol.placeVolume(st_vol,trafo); 
0156       }  
0157       if( super_name.compare("inner_station") == 0 )   {
0158         pv = super_vol.placeVolume(st_vol, Position(inner_x, 0, 0));
0159       }
0160       //pv = super_vol.placeVolume(st_vol, Position(super_x, 0, 0));
0161       pv.addPhysVolID("station", j+1);
0162       printout(INFO, "CODEX-b-station"," Station: %d x=%g y=%g z=%g", j+1, inner_x);
0163       super_stations[st_vol].push_back(pv);
0164       super_x += st_dist + 2.0*st_thick;
0165       //inner_x += st_dist + 2.0*st_thick;
0166       inner_x += st_dist;
0167       face_x += 2.0*super_height + st_thick/10.;
0168     }
0169     pv = env_vol.placeVolume(super_vol,Position(super_pos.x(),super_pos.y(),super_pos.z()));
0170     pv.addPhysVolID("super", num_super+1);
0171     super_places.push_back(pv);
0172   }
0173 
0174   // Here we build the structural hierarchy of the detector elements
0175   num_super = 0;
0176   for(xml_coll_t i(x_det, _U(station)); i; ++i, ++num_super) {
0177     xml_comp_t station      = i;
0178     int        super_repeat = station.repeat();
0179     Volume     st_vol       = station_vols[num_super];
0180     DetElement super_de(det,_toString(num_super,"DeSuper%d"),det_id);
0181     super_de.setPlacement(super_places[num_super]);
0182     for (int j=0; j < super_repeat; ++j )    {
0183       DetElement station_de(super_de,_toString(j,"DeStation%d"),det_id);
0184       PlacedVolume station_pv = super_stations[st_vol][j];
0185       xml_dim_t st_layers = station.child(_U(layers));
0186       int       st_N_lay  = st_layers.number();
0187       station_de.setPlacement(station_pv);
0188       for(int k=0; k < st_N_lay; ++k)   {
0189         DetElement layer_de(station_de,_toString(k,"DeLayer%d"),det_id);
0190         PlacedVolume layer_pv = station_layers[st_vol][k];
0191         layer_de.setPlacement(layer_pv);
0192       }
0193     }
0194   }
0195   
0196   Volume mother = description.pickMotherVolume(det);
0197   xml_dim_t  pos = x_det.position();
0198   Transform3D trafo(Position(pos.x(),pos.y(),pos.z()));
0199   //Direction dir = trafo*Direction(0,0,1.);
0200   pv = mother.placeVolume(env_vol, trafo);
0201   if ( x_det.hasAttr(_U(id)) )  {
0202     pv.addPhysVolID("system",x_det.id());
0203   }
0204   det.setPlacement(pv);
0205   return det;
0206 }
0207 
0208 DECLARE_DETELEMENT(DD4hep_CODEXb_detector,create_element)