Skip to content
Snippets Groups Projects
MRich_geo.cpp 18.34 KiB
//
// Author     : Whit Armstrong (warmstrong@anl.gov)
//
#include <XML/Helper.h>
#include "TMath.h"
#include "TString.h"
#include "DDRec/Surface.h"
#include "DDRec/DetectorData.h"
#include "DD4hep/OpticalSurfaces.h"
#include "DD4hep/DetFactoryHelper.h"
#include "DD4hep/Printout.h"
#include "GeometryHelpers.h"
#include "Math/Vector3D.h"
#include "Math/AxisAngle.h"
#include "Math/VectorUtil.h"

using namespace std;
using namespace dd4hep;
using namespace dd4hep::rec;

using Placements = vector<PlacedVolume>;



static Ref_t createDetector(Detector& description, xml::Handle_t e, SensitiveDetector sens){
  xml_det_t      x_det    = e;
  Material       air      = description.material("AirOptical");
  Material       vacuum   = description.vacuum();
  string         det_name = x_det.nameStr();
  DetElement     sdet(det_name, x_det.id());
  Assembly       assembly(det_name);
  sens.setType("photoncounter");
  OpticalSurfaceManager surfMgr = description.surfaceManager();

  // read module positions
  std::vector<std::pair<double,double>> positions;
  for (xml_coll_t x_positions_i(x_det, _Unicode(positions)); x_positions_i; ++x_positions_i) {
    xml_comp_t x_positions = x_positions_i;
    for (xml_coll_t x_position_i(x_positions, _U(position)); x_position_i; ++x_position_i) {
      xml_comp_t x_position = x_position_i;
      positions.push_back(
        std::make_pair(x_positions.scale() * x_position.x() * mm,
                       x_positions.scale() * x_position.y() * mm));
    }
  }

  bool projective = getAttrOrDefault(x_det, _Unicode(projective), false);
  bool reflect    = x_det.reflect(true);

  PlacedVolume pv;

  map<string, Volume>     modules;
  map<string, Placements> sensitives;
  map<string, Volume>     module_assemblies;
  std::map<std::string,DetElement> module_assembly_delements;

  int                     n_sensor = 1;

  xml::Component dims   = x_det.dimensions();
  auto           rmin   = dims.rmin();
  auto           rmax   = dims.rmax();
  auto           length = dims.length();
  auto           zmin   = dims.zmin();
  auto           zpos   = zmin + length / 2;

  // expect only one module (for now)
  xml_comp_t x_mod = x_det.child(_U(module));
  string     mod_name            = x_mod.nameStr();
  double     mod_width           = getAttrOrDefault(x_mod, _U(width), 130.0 * mm);
  double     mod_height          = getAttrOrDefault(x_mod, _U(height), 130.0 * mm);