Skip to content
Snippets Groups Projects
PolyconeSupport_geo.cpp 2.13 KiB
Newer Older
//==========================================================================
Markus Frank's avatar
Markus Frank committed
//  AIDA Detector description implementation 
//--------------------------------------------------------------------------
Markus Frank's avatar
Markus Frank committed
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
// For the licensing terms see $DD4hepINSTALL/LICENSE.
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
// Author     : M.Frank
//
//==========================================================================
//
// Specialized generic detector constructor
// 
//==========================================================================
#include "DD4hep/DetFactoryHelper.h"

using namespace std;
Markus Frank's avatar
Markus Frank committed
using namespace dd4hep;
using namespace dd4hep::detail;
Markus Frank's avatar
Markus Frank committed
static Ref_t create_detector(Detector& description, xml_h e, Ref_t sens)  {
  xml_det_t  x_det = e;
  string     name  = x_det.nameStr();
  DetElement sdet (name,x_det.id());
Markus Frank's avatar
Markus Frank committed
  Material   mat  (description.material(x_det.materialStr()));
  vector<double> rmin,rmax,z;
  int num = 0;

  for(xml_coll_t c(e,_U(zplane)); c; ++c, ++num)  {
    xml_comp_t dim(c);
    rmin.push_back(dim.rmin());
    rmax.push_back(dim.rmax());
    z.push_back(dim.z()); //Dropped division by 2 in z. Half length not needed
  }
  if ( num < 2 )  {
    throw runtime_error("PolyCone["+name+"]> Not enough Z planes. minimum is 2!");
  }
  Polycone   cone  (0,2*M_PI,rmin,rmax,z);
  Volume     det_vol(name, cone, mat);
Markus Frank's avatar
Markus Frank committed
  PlacedVolume pv = description.pickMotherVolume(sdet).placeVolume(det_vol);
  sdet.setPlacement(pv);
Markus Frank's avatar
Markus Frank committed
  det_vol.setVisAttributes(description, x_det.visStr());
  det_vol.setLimitSet(description, x_det.limitsStr());
  det_vol.setRegion(description, x_det.regionStr());
  if ( x_det.isSensitive() )   {
    SensitiveDetector sd = sens;
    xml_dim_t sd_typ = x_det.child(_U(sensitive));
    det_vol.setSensitiveDetector(sens);
    sd.setType(sd_typ.typeStr());
  }

  if ( x_det.hasAttr(_U(id)) )  {
    int det_id = x_det.id();
    pv.addPhysVolID("system",det_id);
  }
  return sdet;
}

Markus Frank's avatar
Markus Frank committed
DECLARE_DETELEMENT(DD4hep_PolyconeSupport,create_detector)
DECLARE_DEPRECATED_DETELEMENT(PolyconeSupport,create_detector)