Skip to content
Snippets Groups Projects
Select Git revision
  • cae61b361bb31c0c4890d25cf5bf4de08c6ea790
  • master default protected
  • drich-two-mirrors
  • 148-hcal-geometry-development
  • 144-irt-geometry
  • deathvalley-acts-dd4hep-plugin
  • canyonlands-acts-dd4hep-plugin
  • adjust-barrel-emcalo-geometry
  • 148-hcal-geometry-development-wdconinc-suggestion
  • WorkingGemTrd_MLmodel_andAnalysis
  • 144-test-small-sensor-overlap
  • 59-detailed-forward-gem-trd
  • vdesai-master-patch-09582
  • mriganka-branch02
  • zdemirog-master-patch-64142
  • weibin-master-patch-37475
  • vanekjan-master-patch-74522
  • lkosarzew-master-patch-25029
  • swapneshkhade-master-patch-16755
  • mlavinsky-master-patch-10431
  • niveditharam-master-patch-05822
  • deathvalley-v1.1
  • deathvalley-v1.0-1.5T
  • deathvalley-v1.0
  • canyonlands-v2.2
  • canyonlands-v2.1
  • canyonlands-v2.0
  • canyonlands-v1.2
  • canyonlands-v1.1
  • acadia-v2.1
  • canyonlands-v1.0
  • acadia-v2.0
  • acadia-v1.1
  • acadia-v1.0
  • acadia-v1.0-alpha
  • v0.2.0
  • v0.1.0
37 results

sphere_test.cpp

Blame
  • Whitney Armstrong's avatar
    Whitney Armstrong authored
    	modified:   compact/sphere_test.xml
    	modified:   src/sphere_test.cpp
    cae61b36
    History
    sphere_test.cpp 3.90 KiB
    #include <XML/Helper.h>
    #include "TMath.h"
    #include "TString.h"
    #include "GeometryHelpers.h"
    #include "Math/Point2D.h"
    #include "DDRec/Surface.h"
    #include "DDRec/DetectorData.h"
    #include "DD4hep/OpticalSurfaces.h"
    #include "DD4hep/DetFactoryHelper.h"
    #include "DD4hep/Printout.h"
    
    using namespace std;
    using namespace dd4hep;
    using namespace dd4hep::rec;
    
    // create the detector
    static Ref_t create_detector(Detector& desc, xml::Handle_t handle, SensitiveDetector sens) {
    
      xml::DetElement detElem = handle;
      std::string detName = detElem.nameStr();
      int detID = detElem.id();
    
      DetElement det(detName, detID);
      xml::Component dims = detElem.dimensions();
    
      // envelope
      double envx = dims.attr<double>(_Unicode(halflengthx));
      double envy = dims.attr<double>(_Unicode(halflengthy));
      double envz = dims.attr<double>(_Unicode(halflengthz));
      Box envShape(envx,envy,envz);
      auto envMat = desc.material(dd4hep::getAttrOrDefault(detElem, _Unicode(material), "AirOptical"));
      Volume envVol(detName + "_envelope", envShape, envMat);
      envVol.setVisAttributes(desc.visAttributes(detElem.visStr()));
    
      // build sphere --------------------------
      // attributes
      auto sphereMat = desc.material(detElem.child(_Unicode(sphere)).attr<std::string>(_Unicode(material)));
      auto sphereVis = desc.visAttributes(detElem.child(_Unicode(sphere)).attr<std::string>(_Unicode(vis)));
      double sphx = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(centerx));
      double sphy = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(centery));
      double sphz = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(centerz));
      double radius = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(radius));
      double thickness = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(thickness));
      double thetamin = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(thetamin));
      double thetamax = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(thetamax));
      double phimin = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(phimin));
      double phimax = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(phimax));
      double yrot = detElem.child(_Unicode(sphere)).attr<double>(_Unicode(yrot));
    
      // build box --------------------------
      // attributes
      auto boxMat = desc.material(detElem.child(_Unicode(sensor)).attr<std::string>(_Unicode(material)));
      auto boxVis = desc.visAttributes(detElem.child(_Unicode(sensor)).attr<std::string>(_Unicode(vis)));
      double boxx = detElem.child(_Unicode(sensor)).attr<double>(_Unicode(centerx));
      double boxy = detElem.child(_Unicode(sensor)).attr<double>(_Unicode(centery));
      double boxz = detElem.child(_Unicode(sensor)).attr<double>(_Unicode(centerz));
      double lx = detElem.child(_Unicode(sensor)).attr<double>(_Unicode(halflengthx));
      double ly = detElem.child(_Unicode(sensor)).attr<double>(_Unicode(halflengthy));
      double lz = detElem.child(_Unicode(sensor)).attr<double>(_Unicode(halflengthz));
    
      Sphere mirror_solid( radius-thickness, radius);//, thetamin, thetamax, phimin, phimax );
      IntersectionSolid mirror_solid2(mirror_solid, Box(lx,ly,lz), Position(0,0,radius-thickness));
      Volume sphereVol("mirror_v",mirror_solid2,sphereMat);
      sphereVol.setVisAttributes(sphereV);
      auto spherePV = envVol.placeVolume(sphereVol, Transform3D(RotationY(yrot)));
      DetElement sphereDE(det, "mirror_de", 0);
      sphereDE.setPlacement(spherePV);
    
      Box sensor_solid(lx,ly,lz);
      Volume boxVol("sensor_v",sensor_solid,boxMat);
      boxVol.setVisAttributes(boxVis);
      auto boxPV = envVol.placeVolume(boxVol);
      boxPV.addPhysVolID("sensor", 0);
      DetElement boxDE(det, "sensor_de", 0);
      boxDE.setPlacement(boxPV);
    
    
      // place mother volume ---------
      Volume motherVol = desc.pickMotherVolume(det);
      PlacedVolume envPV = motherVol.placeVolume(envVol, Position(0, 0, 0));
      envPV.addPhysVolID("system", detID);
      det.setPlacement(envPV);
    
      return det;
    };
    
    
    //@}
    
    // clang-format off
    DECLARE_DETELEMENT(athena_sphere_test, create_detector)