// helper method to get the closest daughter DetElement to the position starting from the given DetElement DetElement IDDecoder::getClosestDaughter(const DetElement& det, const Position& position) { DetElement result; // check if we have a shape and see if we are inside if (det.volume().isValid() and det.volume().solid().isValid()) { double globalPosition[3] = { position.x(), position.y(), position.z() }; double localPosition[3] = { 0., 0., 0. }; det.worldTransformation().MasterToLocal(globalPosition, localPosition); if (det.volume().solid()->Contains(localPosition)) { result = det; } else { // assuming that any daughter shape would be inside this shape return DetElement(); } } const DetElement::Children& children = det.children(); DetElement::Children::const_iterator it = children.begin(); while (it != children.end()) { DetElement daughterDet = getClosestDaughter(it->second, position); if (daughterDet.isValid()) { result = daughterDet; break; } ++it; } return result; }
void Installer<UserData>::install(DetElement component, PlacedVolume pv) { Volume comp_vol = pv.volume(); if ( comp_vol.isSensitive() ) { Volume mod_vol = parentVolume(component); DD4hep::Geometry::PolyhedraRegular comp_shape(comp_vol.solid()), mod_shape(mod_vol.solid()); if ( !comp_shape.isValid() || !mod_shape.isValid() ) { invalidInstaller("Components and/or modules are not Trapezoid -- invalid shapes"); } else if ( !handleUsingCache(component,comp_vol) ) { DetElement par = component.parent(); const TGeoHMatrix& m = par.worldTransformation(); double dz = m.GetTranslation()[2]; const double* trans = placementTranslation(component); double half_mod_thickness = (mod_shape->GetZ(1)-mod_shape->GetZ(0))/2.0; double half_comp_thickness = (comp_shape->GetZ(1)-comp_shape->GetZ(0))/2.0; double si_position = trans[2]+half_mod_thickness; double outer_thickness = half_mod_thickness - si_position; double inner_thickness = half_mod_thickness + si_position; Vector3D u(1.,0.,0.), v(0.,1.,0.), n(0.,0.,1.), o(100.,100.,0.); std::cout << " Module: " << mod_shape.toString() << std::endl; std::cout << " Component: " << comp_shape.toString() << std::endl; std::cout << "dz:" << dz << " Si-pos:" << si_position << " Mod-thickness:" << half_mod_thickness << " Comp-thickness:" << half_comp_thickness << std::endl; VolPlane surf(comp_vol,Type(Type::Sensitive,Type::Measurement1D), inner_thickness, outer_thickness, u, v, n, o); addSurface(component,surf); } } }
static long cache(DetElement de) { const DetElement::Children& c = de.children(); de.worldTransformation(); de.parentTransformation(); de.placementPath(); de.path(); for (DetElement::Children::const_iterator i = c.begin(); i != c.end(); ++i) cache((*i).second); return 1; }
/** * Returns the global position from a given cell ID */ Position IDDecoder::position(const CellID& cell) const { double l[3]; double g[3]; DetElement det = this->detectorElement(cell); Position local = this->findReadout(det).segmentation().position(cell); local.GetCoordinates(l); // FIXME: direct lookup of transformations seems to be broken //const TGeoMatrix& localToGlobal = _volumeManager.worldTransformation(cell); const TGeoMatrix& localToGlobal = det.worldTransformation(); localToGlobal.LocalToMaster(l, g); return Position(g[0], g[1], g[2]); }
/** * Returns the cell ID from the local position in the given volume ID. */ CellID IDDecoder::cellIDFromLocal(const Position& local, const VolumeID volID) const { double l[3]; double g[3]; local.GetCoordinates(l); // FIXME: direct lookup of transformations seems to be broken //const TGeoMatrix& localToGlobal = _volumeManager.worldTransformation(volID); DetElement det = this->detectorElement(volID); const TGeoMatrix& localToGlobal = det.worldTransformation(); localToGlobal.LocalToMaster(l, g); Position global(g[0], g[1], g[2]); return this->findReadout(det).segmentation().cellID(local, global, volID); }