diff --git a/DataProducts/inc/SurfaceId.hh b/DataProducts/inc/SurfaceId.hh index aebf016d5b..d38fb54b9a 100644 --- a/DataProducts/inc/SurfaceId.hh +++ b/DataProducts/inc/SurfaceId.hh @@ -38,10 +38,12 @@ namespace mu2e { CRV_StrongBack=280, // CRV module Al strongback (tracker-side support plate) DS_HatchConcrete=300, // detector-area hatch concrete block approximation EMC_Disk_0_Outer=310, EMC_Disk_0_Inner, EMC_Disk_1_Inner, EMC_Disk_1_Outer, // calorimeter disk bounding surfaces - EMC_Disk_0_Front, EMC_Disk_1_Front, EMC_Disk_0_Back, EMC_Disk_1_Back + EMC_Disk_0_Front, EMC_Disk_1_Front, EMC_Disk_0_Back, EMC_Disk_1_Back, + EMC_Disk_0_FrontPanel=320, EMC_Disk_1_FrontPanel, // calorimeter front panel material (index 0-2 = layers, 3 = cooling pipes) + EMC_Disk_0_InnerRing=322, EMC_Disk_1_InnerRing // calorimeter case inner rings (index 0,1 = Al via case front, hole; 2,3 = CF ring via its inner radius, case front; 4 = Al via CF ring inner radius) }; // Update this counter whenever you add/remove surface IDs from the enum above. - static constexpr std::size_t nSurfaceIds = 72; + static constexpr std::size_t nSurfaceIds = 76; static std::string const& typeName(); static std::map const& names(); }; diff --git a/DataProducts/src/SurfaceId.cc b/DataProducts/src/SurfaceId.cc index e0ae7611d7..88d641af38 100644 --- a/DataProducts/src/SurfaceId.cc +++ b/DataProducts/src/SurfaceId.cc @@ -88,7 +88,11 @@ namespace mu2e { std::make_pair(SurfaceIdEnum::EMC_Disk_0_Front, "EMC_Disk_0_Front"), std::make_pair(SurfaceIdEnum::EMC_Disk_1_Front, "EMC_Disk_1_Front"), std::make_pair(SurfaceIdEnum::EMC_Disk_0_Back, "EMC_Disk_0_Back"), - std::make_pair(SurfaceIdEnum::EMC_Disk_1_Back, "EMC_Disk_1_Back") + std::make_pair(SurfaceIdEnum::EMC_Disk_1_Back, "EMC_Disk_1_Back"), + std::make_pair(SurfaceIdEnum::EMC_Disk_0_FrontPanel, "EMC_Disk_0_FrontPanel"), + std::make_pair(SurfaceIdEnum::EMC_Disk_1_FrontPanel, "EMC_Disk_1_FrontPanel"), + std::make_pair(SurfaceIdEnum::EMC_Disk_0_InnerRing, "EMC_Disk_0_InnerRing"), + std::make_pair(SurfaceIdEnum::EMC_Disk_1_InnerRing, "EMC_Disk_1_InnerRing") }; constexpr std::size_t nSurfaceIdNames = sizeof(surfaceIdNames)/sizeof(surfaceIdNames[0]); diff --git a/GeometryService/inc/KinKalGeomMaker.hh b/GeometryService/inc/KinKalGeomMaker.hh index 33418c33aa..71b911b618 100644 --- a/GeometryService/inc/KinKalGeomMaker.hh +++ b/GeometryService/inc/KinKalGeomMaker.hh @@ -10,6 +10,7 @@ #include namespace mu2e { class DetectorSystem; + class CaloG4Info; class KinKalGeomMaker { public: explicit KinKalGeomMaker(int debug) : debug_(debug) {} @@ -19,6 +20,7 @@ namespace mu2e { void makeDS(); void makeTarget(); void makeCalo(); + void makeCaloPipes(CaloG4Info const& g4info, SurfaceId const& sid, KinKal::VEC3 const& center); void makeCRV(); void makePassiveMaterials(); // append one averaged rectangular concrete passive-material plane (see .cc) diff --git a/GeometryService/src/DiskCalorimeterMaker.cc b/GeometryService/src/DiskCalorimeterMaker.cc index eb2f2f337d..a74ba4868e 100644 --- a/GeometryService/src/DiskCalorimeterMaker.cc +++ b/GeometryService/src/DiskCalorimeterMaker.cc @@ -112,6 +112,9 @@ namespace mu2e { calo_->G4Info_.set("FPOuterRadius", config.getDouble("calorimeter.FPOuterRadius") ); //Front plate outer radius calo_->G4Info_.set("FPFoamZLength", config.getDouble("calorimeter.FPFoamZLength") ); //Thickness of foam inside front plate calo_->G4Info_.set("FPCarbonZLength", config.getDouble("calorimeter.FPCarbonZLength") ); //Z length of carbon fiber panel on front plate + calo_->G4Info_.set("FPFoamMaterial", config.getString("calorimeter.FPFoamMaterial") ); //Material of foam inside front plate + calo_->G4Info_.set("FPCarbonMaterial", config.getString("calorimeter.FPCarbonMaterial") ); //Material of carbon fiber panels on front plate + calo_->G4Info_.set("innerCFRingMaterial", config.getString("calorimeter.innerCFRingMaterial") ); //Material of carbon fiber ring inside disk calo_->G4Info_.set("FPCoolPipeTorRadius", config.getDouble("calorimeter.FPCoolPipeTorRadius") ); //Tor radius of front plate outer cooling pipe calo_->G4Info_.set("FPCoolPipeRadius", config.getDouble("calorimeter.FPCoolPipeRadius") ); //Inner radius of front plate outer cooling pipe calo_->G4Info_.set("FPCoolPipeThickness", config.getDouble("calorimeter.FPCoolPipeThickness") ); //Thickness of front plate outer cooling pipe diff --git a/GeometryService/src/KinKalGeomMaker.cc b/GeometryService/src/KinKalGeomMaker.cc index 6192a5775c..8b1c62c741 100644 --- a/GeometryService/src/KinKalGeomMaker.cc +++ b/GeometryService/src/KinKalGeomMaker.cc @@ -96,6 +96,126 @@ namespace mu2e { kkg_->map_.emplace(std::make_pair(SurfaceId(SurfaceIdEnum::EMC_Disk_1_Front),std::static_pointer_cast(calo.EMC_Disk_1_FrontPtr()))); kkg_->map_.emplace(std::make_pair(SurfaceId(SurfaceIdEnum::EMC_Disk_0_Back),std::static_pointer_cast(calo.EMC_Disk_0_BackPtr()))); kkg_->map_.emplace(std::make_pair(SurfaceId(SurfaceIdEnum::EMC_Disk_1_Back),std::static_pointer_cast(calo.EMC_Disk_1_BackPtr()))); + + // Crystal case inner support (see caloBuildCase in Mu2eG4/src/constructDiskCalorimeter.cc): the case runs from the + // crystal caps to the back of the crystals, and holds solid aluminium rings at its front, middle and back, between + // the case inner radius and the carbon fiber ring that separates them from the crystals + auto const& g4info = calo_det.G4Info(); + double const capthick = g4info.get("crystalCapZLength"); + double const caselen = g4info.get("diskCaseZLength"); + double const alrin = g4info.get("diskInAlRingRIn"); + double const alzlen = g4info.get("diskInAlRingZLength"); + double const cfrin = g4info.get("diskInCFRingRIn"); + double const cfrout = g4info.get("diskInCFRingROut"); + // KinKal material for the aluminium (G4_Al) rings, named per subsystem like the front panel pipes + std::array const ringmats = {"CaloRingAl",g4info.get("innerCFRingMaterial")}; + static const SurfaceIdEnum::enum_type ringsid[2] = {SurfaceIdEnum::EMC_Disk_0_InnerRing, SurfaceIdEnum::EMC_Disk_1_InnerRing}; + for(int idisk=0; idisk < 2; ++idisk){ + using Support = KKGeom::CaloInnerSupport; + double const zfront = toDetectorZ(calo_det.disk(idisk).diskInfo().frontFaceCenter().z() - capthick); + double const zback = zfront + caselen; + double const zmid = 0.5*(zfront+zback); + auto const center = det->toDetector(calo_det.disk(idisk).diskInfo().origin()); + Support support(ringsid[idisk],VEC3(center.x(),center.y(),zfront),alrin,cfrin,cfrout,zfront,zback,ringmats); + support.addRing(Support::Ring{alrin,cfrin,zfront,zfront+alzlen,Support::aluminium}); + support.addRing(Support::Ring{alrin,cfrin,zmid-0.5*alzlen,zmid+0.5*alzlen,Support::aluminium}); + support.addRing(Support::Ring{alrin,cfrin,zback-alzlen,zback,Support::aluminium}); + support.addRing(Support::Ring{cfrin,cfrout,zfront,zback,Support::carbon}); + kkg_->map_.emplace(std::make_pair(support.surfaceId(Support::alFront),std::static_pointer_cast(support.front()))); + kkg_->map_.emplace(std::make_pair(support.surfaceId(Support::alHole),std::static_pointer_cast(support.inner()))); + kkg_->map_.emplace(std::make_pair(support.surfaceId(Support::cfRing),std::static_pointer_cast(support.cfInner()))); + kkg_->map_.emplace(std::make_pair(support.surfaceId(Support::cfFront),std::static_pointer_cast(support.front()))); + kkg_->map_.emplace(std::make_pair(support.surfaceId(Support::alRing),std::static_pointer_cast(support.cfInner()))); + kkg_->caloInnerSupports_.push_back(std::move(support)); + } + + // Front panel passive material: a carbon fiber / foam / carbon fiber sandwich directly upstream of the + // crystal caps (see caloBuildFrontPlate in Mu2eG4/src/constructDiskCalorimeter.cc). Each layer is an + // annulus carrying its full thickness; index 0 is the upstream carbon skin, 1 the foam, 2 the downstream skin. + // The cooling pipes embedded in the foam (index 3) are described by their centerlines, see makeCaloPipes + if(!g4info.get("hasFrontPanel")) return; + double const fprin = g4info.get("FPInnerRadius"); + double const fprout = g4info.get("FPOuterRadius"); + double const carbonthick = g4info.get("FPCarbonZLength"); + double const foamthick = g4info.get("FPFoamZLength"); + std::string const carbonmat = g4info.get("FPCarbonMaterial"); + std::string const foammat = g4info.get("FPFoamMaterial"); + static const SurfaceIdEnum::enum_type fpsid[2] = {SurfaceIdEnum::EMC_Disk_0_FrontPanel, SurfaceIdEnum::EMC_Disk_1_FrontPanel}; + for(int idisk=0; idisk < 2; ++idisk){ + // the front panel ends where the crystal caps begin + double const fpback = calo_det.disk(idisk).diskInfo().frontFaceCenter().z() - capthick; + double const zlayer[3] = {fpback - 1.5*carbonthick - foamthick, fpback - carbonthick - 0.5*foamthick, fpback - 0.5*carbonthick}; + double const thick[3] = {carbonthick, foamthick, carbonthick}; + std::string const* mat[3] = {&carbonmat, &foammat, &carbonmat}; + for(int ilayer=0; ilayer < 3; ++ilayer){ + SurfaceId sid(fpsid[idisk],ilayer); + auto annulus = std::make_shared(VEC3(0.0,0.0,1.0),VEC3(1.0,0.0,0.0),VEC3(0.0,0.0,toDetectorZ(zlayer[ilayer])),fprin,fprout); + kkg_->caloMaterialPlanes_.emplace_back(sid,annulus,*mat[ilayer],thick[ilayer]); + kkg_->map_.emplace(std::make_pair(sid,std::static_pointer_cast(annulus))); + } + // the pipe centerlines lie one pipe radius downstream of the upstream face of the foam + double const zpipe = fpback - carbonthick - foamthick + g4info.get("pipeRadius"); + auto const center = det->toDetector(calo_det.disk(idisk).diskInfo().origin()); + makeCaloPipes(g4info,SurfaceId(fpsid[idisk],3),VEC3(center.x(),center.y(),toDetectorZ(zpipe))); + } + } + + // Cooling pipes of a calorimeter front panel, reproducing caloBuildFrontPlate in Mu2eG4/src/constructDiskCalorimeter.cc: + // for each pipe a large torus arc (placed twice, rotated by pi), a small bending torus and a straight section running out + // to the manifold (each placed 4 times, mirrored in x and y), plus the outer manifold torus. G4 rotations by pi about + // z, y and x map (x,y) to (-x,-y), (-x,y) and (x,-y) respectively. Pipe interiors are foam, already in the foam layer. + void KinKalGeomMaker::makeCaloPipes(CaloG4Info const& g4info, SurfaceId const& sid, VEC3 const& center) { + using Pipes = KKGeom::CaloFrontPanelPipes; + double const deg = M_PI/180.0; + int const npipes = g4info.get("nPipes"); + double const prout = g4info.get("pipeRadius"); + double const prin = prout - g4info.get("pipeThickness"); + double const radSmTor = g4info.get("radSmTor"); + double const xsmall = g4info.get("xsmall"); + double const xdistance = g4info.get("xdistance"); + auto const torRadius = g4info.get>("pipeTorRadius"); + auto const largeTorPhi = g4info.get>("largeTorPhi"); + auto const smallTorPhi = g4info.get>("smallTorPhi"); + auto const yposition = g4info.get>("yposition"); + auto const straightEndPhi = g4info.get>("straightEndPhi"); + double const coolTorRadius = g4info.get("FPCoolPipeTorRadius"); + double const coolrout = g4info.get("FPCoolPipeRadius"); + double const coolrin = coolrout - g4info.get("FPCoolPipeThickness"); + double const fprin = g4info.get("FPInnerRadius"); + double const fprout = g4info.get("FPOuterRadius"); + double const cx = center.X(), cy = center.Y(); + + auto plane = std::make_shared(VEC3(0.0,0.0,1.0),VEC3(1.0,0.0,0.0),center,fprin,coolTorRadius+coolrout); + // KinKal material for the aluminium (G4_Al) pipe walls, named per subsystem like the CRV strongback + Pipes pipes(sid,plane,"CaloPipeAl"); + for(int ipipe=0; ipipe < npipes; ++ipipe){ + double const angle = 0.5*largeTorPhi.at(ipipe)*deg; + double const sAngle = smallTorPhi.at(ipipe)*deg; + double const sx = xsmall + xdistance*ipipe; + double const sy = yposition.at(ipipe); + double const sephi = straightEndPhi.at(ipipe)*deg; + // large torus + for(double sign : {1.0,-1.0}) + pipes.addArc(Pipes::Arc{cx,cy,sign,sign,torRadius.at(ipipe),-angle*0.9975,2*angle*0.9975,prout,prin}); + // small bending torus + for(auto const& [xs,ys] : {std::pair(1.0,1.0),std::pair(-1.0,-1.0),std::pair(-1.0,1.0),std::pair(1.0,-1.0)}) + pipes.addArc(Pipes::Arc{cx+xs*sx,cy+ys*sy,xs,ys,radSmTor,angle-sAngle+M_PI,sAngle,prout,prin}); + // straight section, shortened by 2 mm at each end as in G4 + double const xend = (coolTorRadius - coolrout)*std::sin(sephi); + double const yend = (coolTorRadius - coolrout)*std::cos(sephi); + double const xstart = sx - radSmTor*std::cos(sephi); + double const ystart = sy + radSmTor*std::sin(sephi); + double const slen = std::sqrt((xend-xstart)*(xend-xstart) + (yend-ystart)*(yend-ystart)); + double const ux = (xend-xstart)/slen, uy = (yend-ystart)/slen; + for(auto const& [xs,ys] : {std::pair(1.0,1.0),std::pair(-1.0,1.0),std::pair(-1.0,-1.0),std::pair(1.0,-1.0)}) + pipes.addLine(Pipes::Line{cx+xs*(xstart+2.0*ux),cy+ys*(ystart+2.0*uy),cx+xs*(xend-2.0*ux),cy+ys*(yend-2.0*uy),prout,prin}); + } + // manifold torus around the panel, placed rotated by pi about y + double const pipeTotalSep = torRadius.back() - torRadius.front(); + double const angMax = 0.5*M_PI - std::asin((g4info.get("pipeInitSeparation")+pipeTotalSep)/fprout) - 0.1; + pipes.addArc(Pipes::Arc{cx,cy,-1.0,1.0,coolTorRadius,angMax,2*M_PI-2*angMax,coolrout,coolrin}); + kkg_->map_.emplace(std::make_pair(sid,std::static_pointer_cast(plane))); + kkg_->caloFrontPanelPipes_.push_back(std::move(pipes)); } // sort by transverse distance diff --git a/KinKalGeom/CMakeLists.txt b/KinKalGeom/CMakeLists.txt index b1d00db582..5aa3e52cb8 100644 --- a/KinKalGeom/CMakeLists.txt +++ b/KinKalGeom/CMakeLists.txt @@ -1,6 +1,8 @@ cet_make_library( SOURCE src/Calo.cc + src/CaloFrontPanelPipes.cc + src/CaloInnerSupport.cc src/KinKalGeom.cc src/KKMaterial.cc src/KKStrawMaterial.cc diff --git a/KinKalGeom/inc/CaloFrontPanelPipes.hh b/KinKalGeom/inc/CaloFrontPanelPipes.hh new file mode 100644 index 0000000000..547f7f752f --- /dev/null +++ b/KinKalGeom/inc/CaloFrontPanelPipes.hh @@ -0,0 +1,53 @@ +// +// Cooling pipes embedded in a calorimeter disk front panel, modeled as thin-walled tubes whose centerlines lie in a +// single z plane. KinKal can't intersect tori, so the pipes are represented by their centerlines (arcs and straight +// segments) in that plane: a track crossing the plane within a tube radius of a centerline crosses the pipe walls. +// The material depth along z is the chord through the tube walls at the crossing point, which is then treated as a +// thin shell by the extrapolation. +// original author: Sophie Middleton (2026) +// +#ifndef KinKalGeom_CaloFrontPanelPipes_hh +#define KinKalGeom_CaloFrontPanelPipes_hh +#include "Offline/DataProducts/inc/SurfaceId.hh" +#include "KinKal/General/Vectors.hh" +#include "KinKal/Geometry/Annulus.hh" +#include +#include +#include +namespace mu2e { + namespace KKGeom { + class CaloFrontPanelPipes { + public: + using AnnPtr = std::shared_ptr; + // circular arc centerline: points center + (xsign*rtor*cos(phi), ysign*rtor*sin(phi)) for phi in [phi0,phi0+dphi]. + // The signs reproduce the pi rotations used to place mirrored copies of the same torus. + struct Arc { + double cx_, cy_, xsign_, ysign_, rtor_, phi0_, dphi_; + double rout_, rin_; // tube outer and inner radius + }; + // straight centerline from (x0,y0) to (x1,y1) + struct Line { + double x0_, y0_, x1_, y1_; + double rout_, rin_; + }; + CaloFrontPanelPipes(SurfaceId const& sid, AnnPtr const& plane, std::string const& material) : + sid_(sid), plane_(plane), material_(material) {} + void addArc(Arc const& arc) { arcs_.push_back(arc); } + void addLine(Line const& line) { lines_.push_back(line); } + auto const& surfaceId() const { return sid_; } + auto const& plane() const { return plane_; } + auto const& material() const { return material_; } + auto const& arcs() const { return arcs_; } + auto const& lines() const { return lines_; } + // material depth along z (mm) through the pipe walls at a position in the pipe plane; 0 if no pipe is crossed + double wallDepth(KinKal::VEC3 const& pos) const; + private: + SurfaceId sid_; + AnnPtr plane_; // plane containing the pipe centerlines, bounded by the pipe extent + std::string material_; // pipe wall material + std::vector arcs_; + std::vector lines_; + }; + } +} +#endif diff --git a/KinKalGeom/inc/CaloInnerSupport.hh b/KinKalGeom/inc/CaloInnerSupport.hh new file mode 100644 index 0000000000..46c40a9bfa --- /dev/null +++ b/KinKalGeom/inc/CaloInnerSupport.hh @@ -0,0 +1,72 @@ +// +// Inner support of a calorimeter disk crystal case: three solid aluminium rings (front, middle and back) and a thin +// carbon fiber ring between them and the crystals, see caloBuildCase in Mu2eG4/src/constructDiskCalorimeter.cc. +// A track reaches this material either through the upstream face of the case, just behind the front panel, or from +// the disk hole, through the inner cylinder of the case. It is described by the (r,z) cross sections of the rings, +// and the material crossed is the straight-line path through them from the entry point until the track reaches the +// crystals, returns to the hole or leaves the case. Once a track has reached the crystals it showers, so only the +// entry into the case is considered. +// original author: Sophie Middleton (2026) +// +#ifndef KinKalGeom_CaloInnerSupport_hh +#define KinKalGeom_CaloInnerSupport_hh +#include "Offline/DataProducts/inc/SurfaceId.hh" +#include "KinKal/General/Vectors.hh" +#include "KinKal/Geometry/Annulus.hh" +#include "KinKal/Geometry/Cylinder.hh" +#include "KinKal/Geometry/Plane.hh" +#include +#include +#include +#include +namespace mu2e { + namespace KKGeom { + class CaloInnerSupport { + public: + using AnnPtr = std::shared_ptr; + using CylPtr = std::shared_ptr; + using PlanePtr = std::shared_ptr; + enum Material { aluminium=0, carbon, nmaterials }; + // the ways a track can cross the support material, used as the surface Id index: + // aluminium entered through the case front or from the hole, the carbon fiber ring entered from its inner + // radius, or end-on through the case front, and aluminium entered from the carbon fiber ring inner radius + enum Crossing { alFront=0, alHole, cfRing, cfFront, alRing, ncrossings }; + // ring cross section in (r,z), z in detector coordinates + struct Ring { + double rin_, rout_, zmin_, zmax_; + Material mat_; + }; + // the case spans [zfront,zback] between radius rin and the crystals at rcrystal; the carbon fiber ring + // starts at rcf + CaloInnerSupport(SurfaceIdEnum::enum_type sid, KinKal::VEC3 const& center, double rin, double rcf, double rcrystal, + double zfront, double zback, std::array const& materials); + void addRing(Ring const& ring) { rings_.push_back(ring); } + SurfaceId surfaceId(Crossing xing) const { return SurfaceId(sid_,int(xing)); } + static Material material(Crossing xing) { return xing == alFront || xing == alHole || xing == alRing ? aluminium : carbon; } + auto const& materialName(Material mat) const { return materials_[mat]; } + auto const& front() const { return front_; } // case front between the hole and the crystals + auto const& frontPlane() const { return frontplane_; } // unbounded plane of the case front, to find where a track reaches it + auto const& inner() const { return inner_; } // case inner cylinder + auto const& cfInner() const { return cfinner_; } // carbon fiber ring inner cylinder + auto const& rings() const { return rings_; } + double rin() const { return inner_->radius(); } + double rcf() const { return cfinner_->radius(); } + double rcrystal() const { return rcrystal_; } + double transverseRadius(KinKal::VEC3 const& pos) const { return (pos - center_).Rho(); } + // straight-line path length (mm) through each material from an entry point on the case surface in the given + // direction, until the track reaches the crystals, goes back into the hole or leaves the case + std::array pathLengths(KinKal::VEC3 const& pos, KinKal::VEC3 const& dir) const; + private: + SurfaceIdEnum::enum_type sid_; + KinKal::VEC3 center_; // disk axis position at the case front + double rcrystal_; + PlanePtr frontplane_; + AnnPtr front_; + CylPtr inner_; + CylPtr cfinner_; + std::array materials_; // KinKal material names + std::vector rings_; + }; + } +} +#endif diff --git a/KinKalGeom/inc/KinKalGeom.hh b/KinKalGeom/inc/KinKalGeom.hh index adc5579b47..505ac5bfa1 100644 --- a/KinKalGeom/inc/KinKalGeom.hh +++ b/KinKalGeom/inc/KinKalGeom.hh @@ -10,6 +10,8 @@ #include "Offline/KinKalGeom/inc/DetectorSolenoid.hh" #include "Offline/KinKalGeom/inc/CRV.hh" #include "Offline/KinKalGeom/inc/Calo.hh" +#include "Offline/KinKalGeom/inc/CaloFrontPanelPipes.hh" +#include "Offline/KinKalGeom/inc/CaloInnerSupport.hh" #include "Offline/DataProducts/inc/SurfaceId.hh" #include "KinKal/Geometry/Surface.hh" #include "KinKal/Geometry/Plane.hh" @@ -53,6 +55,13 @@ namespace mu2e { auto const& calo() const {return calo_; } auto const& CRV() const {return crv_; } auto const& passiveMaterialPlanes() const { return passiveMaterialPlanes_; } + // calorimeter front panel layers, kept apart from passiveMaterialPlanes as they are crossed by + // downstream tracks on their way to the calo disks, not by the CRV extrapolation + auto const& caloMaterialPlanes() const { return caloMaterialPlanes_; } + // cooling pipes inside the calorimeter front panels, one entry per disk + auto const& caloFrontPanelPipes() const { return caloFrontPanelPipes_; } + // aluminium and carbon fiber rings at the inner edge of the crystal case, one entry per disk + auto const& caloInnerSupports() const { return caloInnerSupports_; } private: // local copy of detector objects; these hold the actual (typed) surface objects std::unique_ptr tracker_; @@ -61,6 +70,9 @@ namespace mu2e { std::unique_ptr calo_; std::unique_ptr crv_; PassiveMaterialPlaneCollection passiveMaterialPlanes_; + PassiveMaterialPlaneCollection caloMaterialPlanes_; + std::vector caloFrontPanelPipes_; + std::vector caloInnerSupports_; // the map used to find surfaces by Id KKGMap map_; // allow GeometryService to access internals, to avoid link loop diff --git a/KinKalGeom/src/CaloFrontPanelPipes.cc b/KinKalGeom/src/CaloFrontPanelPipes.cc new file mode 100644 index 0000000000..770c405633 --- /dev/null +++ b/KinKalGeom/src/CaloFrontPanelPipes.cc @@ -0,0 +1,44 @@ +#include "Offline/KinKalGeom/inc/CaloFrontPanelPipes.hh" +#include +#include +namespace mu2e { + namespace KKGeom { + namespace { + // chord length through the walls of a tube whose axis is at transverse distance dist from a line along z + double wallChord(double dist, double rout, double rin) { + if(dist >= rout) return 0.0; + double chord = 2.0*std::sqrt(rout*rout - dist*dist); + if(dist < rin) chord -= 2.0*std::sqrt(rin*rin - dist*dist); + return chord; + } + } + + double CaloFrontPanelPipes::wallDepth(KinKal::VEC3 const& pos) const { + // the pipes don't overlap, so the closest centerline is the only one that can be crossed + double depth(0.0); + for(auto const& arc : arcs_){ + // transform into the frame of the unmirrored arc + double qx = arc.xsign_*(pos.X() - arc.cx_); + double qy = arc.ysign_*(pos.Y() - arc.cy_); + double phi = std::atan2(qy,qx) - arc.phi0_; + phi -= 2.0*M_PI*std::floor(phi/(2.0*M_PI)); // [0,2pi) + double dist; + if(phi <= arc.dphi_){ + dist = std::fabs(std::sqrt(qx*qx+qy*qy) - arc.rtor_); + } else { // beyond the arc ends: distance to the nearest end + double dx0 = qx - arc.rtor_*std::cos(arc.phi0_), dy0 = qy - arc.rtor_*std::sin(arc.phi0_); + double dx1 = qx - arc.rtor_*std::cos(arc.phi0_+arc.dphi_), dy1 = qy - arc.rtor_*std::sin(arc.phi0_+arc.dphi_); + dist = std::sqrt(std::min(dx0*dx0+dy0*dy0,dx1*dx1+dy1*dy1)); + } + depth = std::max(depth,wallChord(dist,arc.rout_,arc.rin_)); + } + for(auto const& line : lines_){ + double lx = line.x1_ - line.x0_, ly = line.y1_ - line.y0_; + double frac = std::clamp(((pos.X()-line.x0_)*lx + (pos.Y()-line.y0_)*ly)/(lx*lx+ly*ly),0.0,1.0); + double dx = pos.X() - (line.x0_ + frac*lx), dy = pos.Y() - (line.y0_ + frac*ly); + depth = std::max(depth,wallChord(std::sqrt(dx*dx+dy*dy),line.rout_,line.rin_)); + } + return depth; + } + } +} diff --git a/KinKalGeom/src/CaloInnerSupport.cc b/KinKalGeom/src/CaloInnerSupport.cc new file mode 100644 index 0000000000..73fa554cc4 --- /dev/null +++ b/KinKalGeom/src/CaloInnerSupport.cc @@ -0,0 +1,39 @@ +#include "Offline/KinKalGeom/inc/CaloInnerSupport.hh" +namespace mu2e { + namespace KKGeom { + using KinKal::VEC3; + + CaloInnerSupport::CaloInnerSupport(SurfaceIdEnum::enum_type sid, VEC3 const& center, double rin, double rcf, double rcrystal, + double zfront, double zback, std::array const& materials) : + sid_(sid), center_(center.X(),center.Y(),zfront), rcrystal_(rcrystal), + frontplane_(std::make_shared(VEC3(0.0,0.0,1.0),VEC3(1.0,0.0,0.0),center_)), + front_(std::make_shared(VEC3(0.0,0.0,1.0),VEC3(1.0,0.0,0.0),center_,rin,rcrystal)), + inner_(std::make_shared(VEC3(0.0,0.0,1.0),VEC3(center.X(),center.Y(),0.5*(zfront+zback)),rin,0.5*(zback-zfront))), + cfinner_(std::make_shared(VEC3(0.0,0.0,1.0),VEC3(center.X(),center.Y(),0.5*(zfront+zback)),rcf,0.5*(zback-zfront))), + materials_(materials) {} + + std::array CaloInnerSupport::pathLengths(VEC3 const& pos, VEC3 const& dir) const { + // step along the line: the rings are a few mm to cm thick, and the path is at most a few cm + static const double step(0.1); // mm + static const double maxpath(300.0); // mm + double const rin = inner_->radius(); + double const zmin = center_.Z(); + double const zmax = zmin + 2.0*inner_->halfLength(); + std::array paths{}; + auto udir = dir.Unit(); + // start half a step inside, so a point on the entry surface isn't counted as being in the hole + for(double s = 0.5*step; s < maxpath; s += step){ + auto pt = pos + s*udir; + double r = transverseRadius(pt); + if(r < rin || r >= rcrystal_ || pt.Z() < zmin || pt.Z() > zmax) break; + for(auto const& ring : rings_){ + if(r >= ring.rin_ && r < ring.rout_ && pt.Z() >= ring.zmin_ && pt.Z() < ring.zmax_){ + paths[ring.mat_] += step; + break; + } + } + } + return paths; + } + } +} diff --git a/Mu2eKinKal/fcl/prolog.fcl b/Mu2eKinKal/fcl/prolog.fcl index 346792ef1b..6e67d512d7 100644 --- a/Mu2eKinKal/fcl/prolog.fcl +++ b/Mu2eKinKal/fcl/prolog.fcl @@ -392,6 +392,7 @@ Mu2eKinKal : { ToCRV : false ToCaloD0 : true ToCaloD1 : true + ToCaloMaterial : false # calo front panel material; off until validated against MC truth } LHSEEDXTRAP : { @@ -501,6 +502,7 @@ Mu2eKinKal : { KKFitSettings : { @table::Mu2eKinKal.KKFIT MaxSeedStrawHitDt : 200.0 # ns; drop seed hits whose TOCA lands on another turn of the seed helix + AddCaloMaterial : false # off until validated against MC truth; add the calorimeter front panel material crossed within the fit range SampleSurfaces : ["ST_Outer","ST_Front","ST_Back"] # these are additional surfaces; surfaces used in extrapolation are also sampled # save trajectories in the Detector region SaveDomains : true diff --git a/Mu2eKinKal/inc/CaloMaterialLayers.hh b/Mu2eKinKal/inc/CaloMaterialLayers.hh new file mode 100644 index 0000000000..d4d8e8f574 --- /dev/null +++ b/Mu2eKinKal/inc/CaloMaterialLayers.hh @@ -0,0 +1,81 @@ +// +// Uniform view of the calorimeter front panel material: the fixed-thickness layers and the cooling pipes, whose +// thickness depends on where the track crosses the pipe plane, and of the crystal case inner support rings. Used both +// to add this material to fits that include a CaloHit and to extrapolate fits without one through the calorimeter. +// +#ifndef Mu2eKinKal_CaloMaterialLayers_hh +#define Mu2eKinKal_CaloMaterialLayers_hh +#include "Offline/KinKalGeom/inc/KinKalGeom.hh" +#include "Offline/KinKalGeom/inc/CaloFrontPanelPipes.hh" +#include "Offline/DataProducts/inc/SurfaceId.hh" +#include "KinKal/Geometry/Plane.hh" +#include "KinKal/Geometry/ParticleTrajectoryIntersect.hh" +#include "KinKal/Trajectory/ParticleTrajectory.hh" +#include +#include +#include +#include +#include +#include +namespace mu2e { + struct CaloMaterialLayer { + std::shared_ptr surface_; + SurfaceId sid_; + std::string const* material_; + double thickness_; // fixed thickness, for layers + KKGeom::CaloFrontPanelPipes const* pipes_ = nullptr; // position-dependent thickness, for pipes + // material depth along the plane normal at a crossing position; 0 means no material is crossed + double thickness(KinKal::VEC3 const& pos) const { return pipes_ ? pipes_->wallDepth(pos) : thickness_; } + }; + + inline std::vector caloMaterialLayers(KinKalGeom const& kkg) { + std::vector layers; + for(auto const& plane : kkg.caloMaterialPlanes()) + layers.push_back(CaloMaterialLayer{plane.surface_,plane.sid_,&plane.material_,plane.thickness_}); + for(auto const& pipes : kkg.caloFrontPanelPipes()) + layers.push_back(CaloMaterialLayer{pipes.plane(),pipes.surfaceId(),&pipes.material(),0.0,&pipes}); + return layers; + } + + // A crossing of a calorimeter crystal case inner support material, with the path length through that material + struct CaloSupportXing { + KKGeom::CaloInnerSupport::Crossing xing_; + KinKal::Intersection inter_; + double path_; + // effective thickness that gives a shell crossing at this intersection the path length through the material + double thickness() const { return path_*std::fabs(inter_.norm_.Dot(inter_.pdir_)); } + }; + + // Find the support material crossed by a track entering the crystal case. The track must reach the case front moving + // downstream: if it does so at the crystals it showers there and never crosses the rings; if it does so in the disk + // hole, it enters the case where it first crosses the inner cylinder. The aluminium and carbon fiber rings span the + // case length side by side in radius, so the first material is placed where the track enters the case and the second + // where it then crosses the carbon fiber ring inner radius (outwards into the carbon fiber, or inwards into the + // aluminium when entering the case front on the carbon fiber), so they are at different times. + template std::vector caloSupportXings(KinKal::ParticleTrajectory const& ptraj, + KKGeom::CaloInnerSupport const& support, KinKal::TimeRange const& trange, double tol) { + using Support = KKGeom::CaloInnerSupport; + std::vector xings; + auto finter = KinKal::intersect(ptraj,*support.frontPlane(),trange,tol); + if(!finter.good() || finter.pdir_.Z() <= 0.0) return xings; + double rfront = support.transverseRadius(finter.pos_); + if(rfront >= support.rcrystal()) return xings; + bool fromhole = rfront < support.rin(); + auto entry = fromhole ? KinKal::intersect(ptraj,*support.inner(),KinKal::TimeRange(finter.time_,trange.end()),tol) + : KinKal::intersect(ptraj,*support.front(),trange,tol); + if(!entry.good()) return xings; + auto paths = support.pathLengths(entry.pos_,entry.pdir_); + bool oncf = !fromhole && rfront >= support.rcf(); + auto first = oncf ? Support::carbon : Support::aluminium; + auto second = oncf ? Support::aluminium : Support::carbon; + if(paths[first] > 0.0) + xings.push_back(CaloSupportXing{oncf ? Support::cfFront : fromhole ? Support::alHole : Support::alFront,entry,paths[first]}); + if(paths[second] > 0.0){ + auto cfinter = KinKal::intersect(ptraj,*support.cfInner(),KinKal::TimeRange(entry.time_,trange.end()),tol); + if(cfinter.good() && cfinter.time_ > entry.time_) + xings.push_back(CaloSupportXing{oncf ? Support::alRing : Support::cfRing,cfinter,paths[second]}); + } + return xings; + } +} +#endif diff --git a/Mu2eKinKal/inc/KKExtrap.hh b/Mu2eKinKal/inc/KKExtrap.hh index 1bdb08cac2..e3afd07daa 100644 --- a/Mu2eKinKal/inc/KKExtrap.hh +++ b/Mu2eKinKal/inc/KKExtrap.hh @@ -16,6 +16,7 @@ #include "Offline/Mu2eKinKal/inc/ExtrapolateCRVRegion.hh" #include "Offline/Mu2eKinKal/inc/ExtrapolateCylinders.hh" #include "Offline/Mu2eKinKal/inc/ExtrapolatePlanes.hh" +#include "Offline/Mu2eKinKal/inc/CaloMaterialLayers.hh" #include "Offline/Mu2eKinKal/inc/KKShellXing.hh" #include "Offline/KinKalGeom/inc/KKMaterial.hh" #include "KinKal/Geometry/ParticleTrajectoryIntersect.hh" @@ -52,6 +53,8 @@ namespace mu2e { template bool extrapolateTSDA(KKTrack& ktrk,TimeDir tdir) const; template void extrapolateDSMaterial(KKTrack& ktrk,TimeDir tdir) const; template void extrapolatePassiveMaterial(KKTrack& ktrk,TimeDir tdir) const; + template void extrapolateCaloMaterial(KKTrack& ktrk,TimeDir tdir) const; + template bool extrapolateCaloSupport(KKTrack& ktrk,KKGeom::CaloInnerSupport const& support,double& tstart) const; template void extrapolateCRV(KKTrack& ktrk,TimeDir tdir) const; template void extrapolateOPA(KKTrack& ktrk, double tstart, TimeDir tdir) const; template void toTrackerPerimeter(KKTrack& ktrk) const; @@ -61,7 +64,7 @@ namespace mu2e { int debug_; double btol_, intertol_, maxdt_, maxdtstep_, minv_; bool backToTracker_, extrapolateOPA_, toTrackerPerimeter_, upstream_, toCRV_; - bool toCaloD0_, toCaloD1_; + bool toCaloD0_, toCaloD1_, toCaloMaterial_; // IPA/ST thicknesses are nominal literals, consistent with the rest of KinKalGeom, whose IPA // (single Cylinder) and ST (uniform Annulus foils) surfaces are themselves hard-coded nominal // placeholders (see KinKalGeomMaker::makeDS/makeTarget). Sourcing these from the real geometry @@ -84,7 +87,8 @@ namespace mu2e { upstream_(extrapconfig.Upstream()), toCRV_(extrapconfig.ToCRV()), toCaloD0_(extrapconfig.ToCaloD0()), - toCaloD1_(extrapconfig.ToCaloD1()) + toCaloD1_(extrapconfig.ToCaloD1()), + toCaloMaterial_(extrapconfig.ToCaloMaterial()) {} inline void KKExtrap::checkConfig(KinKal::Config const& config) const { @@ -143,6 +147,8 @@ namespace mu2e { // first moves DS shell crossings onto interior pieces where they are dropped (see PR #2059) // the calo is downstream of the tracker, opposite to the upstream direction tdir TimeDir calotdir = tdir == TimeDir::forwards ? TimeDir::backwards : TimeDir::forwards; + // the front panels sit upstream of the disk faces, so their material must be added before the disk extension + if(toCaloMaterial_)extrapolateCaloMaterial(ktrk,calotdir); if(toCaloD0_)toCaloDisk(ktrk,0,t0,calotdir); if(toCaloD1_)toCaloDisk(ktrk,1,t0,calotdir); } @@ -461,6 +467,127 @@ namespace mu2e { } while(extrapPlanes.intersections().size()>0); } + // Extrapolate through the calorimeter front panel layers and their cooling pipes (both disks), adding their material + // effects. All are described by planes normal to z, so visit them in z order along the extrapolation direction: extend + // the fit to each plane's z, then add a crossing if the track intersects the plane within the extension (ie it doesn't + // pass through the hole) and, for the pipe planes, if it crosses a pipe wall there. + // The search starts at the last measurement, not at the end of the fit: the fit extends past its last measurement, + // possibly into the front panel, and its end can move on refit, so crossings between the two would otherwise be lost. + // Crossings can only be added in the last trajectory piece, so one before it is skipped: crossings inside the fit + // are added by KKFit AddCaloMaterial, which can refit. + // Layers already in the fit are skipped, and if an earlier pass (ie ToCRV) took the fit past the calorimeter no + // front panel material is added. + // Tracks moving downstream then cross the crystal case inner support rings of a disk after its front panel, see + // extrapolateCaloSupport. + template void KKExtrap::extrapolateCaloMaterial(KKTrack& ktrk,TimeDir tdir) const { + using KKMATRECXING = KKShellXing; + GeomHandle kkg_h; + GeomHandle kkmat_h; + auto layers = caloMaterialLayers(*kkg_h); + if(layers.empty() && kkg_h->caloInnerSupports().empty()) return; + auto const& ftraj = ktrk.fitTraj(); + auto arange = ktrk.activeRange(); + // a measurement (ie the CaloHit) can be beyond the end of the fit + double tstart = std::clamp(tdir == TimeDir::forwards ? arange.end() : arange.begin(),ftraj.range().begin(),ftraj.range().end()); + // order the layers along the direction of motion in z at the start of the extrapolation + double zdir = ftraj.direction(tstart).Z()*KinKal::timeDirSign(tdir); + std::sort(layers.begin(),layers.end(),[zdir](auto const& a,auto const& b){ + return zdir > 0 ? a.surface_->center().Z() < b.surface_->center().Z() : a.surface_->center().Z() > b.surface_->center().Z(); }); + std::vector supports; + if(tdir == TimeDir::forwards && zdir > 0.0) + for(auto const& support : kkg_h->caloInnerSupports())supports.push_back(&support); + std::sort(supports.begin(),supports.end(),[](auto a,auto b){ return a->front()->center().Z() < b->front()->center().Z(); }); + auto nextsupport = supports.begin(); + bool usable(true); + for(auto const& layer : layers) { + while(usable && nextsupport != supports.end() && (*nextsupport)->front()->center().Z() < layer.surface_->center().Z()) + usable = extrapolateCaloSupport(ktrk,**nextsupport++,tstart); + if(!usable) break; + bool infit(false); + for(auto const& matxing : ktrk.caloMaterialPlaneXings()) + if(matxing->surfaceId() == layer.sid_){ infit = true; break; } + if(infit){ + if(debug_ > 0)std::cout << "Calo front panel crossing " << layer.sid_ << " already in the fit" << std::endl; + continue; + } + ExtrapolateToZ toLayer(maxdt_,maxdtstep_,btol_,intertol_,layer.surface_->center().Z(),debug_); + if(!ktrk.extrapolate(tdir,toLayer)){ usable = false; break; } // the fit is no longer usable + TimeRange testrange = tdir == TimeDir::forwards ? TimeRange(tstart,ftraj.range().end()) : TimeRange(ftraj.range().begin(),tstart); + auto inter = KinKal::intersect(ftraj,*layer.surface_,testrange,intertol_,tdir); + if(debug_ > 1)std::cout << "Calo front panel " << layer.sid_ << " " << inter << std::endl; + if(!inter.good()) continue; + double thickness = layer.thickness(inter.pos_); + if(thickness <= 0.0) continue; // between the pipes + auto const& reftrajptr = tdir == TimeDir::backwards ? ftraj.frontPtr() : ftraj.backPtr(); + // a crossing can only be added at the end of the fit; one before it is skipped + if(!reftrajptr->range().inRange(inter.time_)){ + if(debug_ > 0)std::cout << "Skipping calo front panel crossing " << layer.sid_ << " not at the end of the fit" << std::endl; + continue; + } + auto matxingptr = std::make_shared(layer.surface_,layer.sid_,*kkmat_h->material(*layer.material_), + inter,reftrajptr,thickness,intertol_); + if(debug_ > 2){ + double dmom, paramomvar, perpmomvar; + matxingptr->materialEffects(dmom,paramomvar,perpmomvar); + std::cout << layer.sid_ << " thickness " << thickness << " Xing dmom " << dmom << " para momsig " << sqrt(paramomvar) + << " perp momsig " << sqrt(perpmomvar) << " before append mom = " << reftrajptr->momentum(); + } + ktrk.addMaterialPlaneXing(matxingptr,tdir); + if(debug_ > 2){ + auto const& newtrajptr = tdir == TimeDir::backwards ? ftraj.frontPtr() : ftraj.backPtr(); + std::cout << " after append mom = " << newtrajptr->momentum() << std::endl; + } + // the next layer must be crossed after this one + tstart = inter.time_; + } + while(usable && nextsupport != supports.end()) + usable = extrapolateCaloSupport(ktrk,**nextsupport++,tstart); + } + + // Extrapolate forwards through the inner support rings of a calorimeter crystal case, see caloSupportXings: extend the + // fit to the case front and, if the track is then in the disk hole, to the back of the case, and add the crossings + // found after tstart. As for the front panel, crossings can only be added in the last trajectory piece, and rings + // already in the fit are skipped. Returns false if the fit is no longer usable. + template bool KKExtrap::extrapolateCaloSupport(KKTrack& ktrk,KKGeom::CaloInnerSupport const& support,double& tstart) const { + using Support = KKGeom::CaloInnerSupport; + using KKMATRECXING = KKShellXing; + using KKMATCYLXING = KKShellXing; + static const TimeDir tdir(TimeDir::forwards); + GeomHandle kkmat_h; + auto ringid = support.surfaceId(Support::alFront).id(); + auto isring = [&ringid](auto const& matxing){ return matxing->surfaceId().id() == ringid; }; + if(std::any_of(ktrk.caloMaterialPlaneXings().begin(),ktrk.caloMaterialPlaneXings().end(),isring) || + std::any_of(ktrk.caloMaterialCylXings().begin(),ktrk.caloMaterialCylXings().end(),isring)){ + if(debug_ > 0)std::cout << "Calo inner ring crossing " << support.surfaceId(Support::alFront) << " already in the fit" << std::endl; + return true; + } + auto const& ftraj = ktrk.fitTraj(); + double zfront = support.front()->center().Z(); + ExtrapolateToZ toFront(maxdt_,maxdtstep_,btol_,intertol_,zfront,debug_); + if(!ktrk.extrapolate(tdir,toFront)) return false; + if(support.transverseRadius(ftraj.position3(ftraj.range().end())) < support.rin()){ + ExtrapolateToZ toBack(maxdt_,maxdtstep_,btol_,intertol_,zfront + 2.0*support.inner()->halfLength(),debug_); + if(!ktrk.extrapolate(tdir,toBack)) return false; + } + for(auto const& sxing : caloSupportXings(ftraj,support,TimeRange(tstart,ftraj.range().end()),intertol_)){ + auto sid = support.surfaceId(sxing.xing_); + auto const& reftrajptr = ftraj.backPtr(); + if(!reftrajptr->range().inRange(sxing.inter_.time_)){ + if(debug_ > 0)std::cout << "Skipping calo inner ring crossing " << sid << " not at the end of the fit" << std::endl; + continue; + } + auto const& dmat = *kkmat_h->material(support.materialName(Support::material(sxing.xing_))); + if(debug_ > 1)std::cout << "Calo inner ring crossing " << sid << " path " << sxing.path_ << " " << sxing.inter_ << std::endl; + if(sxing.xing_ == Support::alFront || sxing.xing_ == Support::cfFront) + ktrk.addMaterialPlaneXing(std::make_shared(support.front(),sid,dmat,sxing.inter_,reftrajptr,sxing.thickness(),intertol_),tdir); + else + ktrk.addMaterialCylXing(std::make_shared(sxing.xing_ == Support::alHole ? support.inner() : support.cfInner(), + sid,dmat,sxing.inter_,reftrajptr,sxing.thickness(),intertol_),tdir); + tstart = sxing.inter_.time_; + } + return true; + } + template void KKExtrap::extrapolateCRV(KKTrack& ktrk,TimeDir tdir) const { using KKCRVXING = KKShellXing; using KKMATRECXING = KKShellXing; // strongback (passive) plane diff --git a/Mu2eKinKal/inc/KKFit.hh b/Mu2eKinKal/inc/KKFit.hh index a316fea4c6..27493298c9 100644 --- a/Mu2eKinKal/inc/KKFit.hh +++ b/Mu2eKinKal/inc/KKFit.hh @@ -32,6 +32,8 @@ #include "Offline/RecoDataProducts/inc/KalIntersection.hh" #include "Offline/DataProducts/inc/SurfaceId.hh" #include "Offline/KinKalGeom/inc/KinKalGeom.hh" +#include "Offline/Mu2eKinKal/inc/CaloMaterialLayers.hh" +#include "Offline/Mu2eKinKal/inc/KKShellXing.hh" // geometry #include "Offline/KinKalGeom/inc/Tracker.hh" // KinKal includes @@ -131,10 +133,11 @@ namespace mu2e { KKTRK const& kktrk, ComboHitCollection const& chcol, KKSTRAWHITCOL& hits,KKSTRAWXINGCOL& addexings) const; void addStraws(Tracker const& tracker, KKTRK const& kktrk, KKSTRAWXINGCOL& addexings) const; void addCaloHit(Calorimeter const& calo, KKTRK& kktrk, CCHandle cchandle, KKCALOHITCOL& hits) const; + void addCaloMaterial(KKTRK& kktrk) const; void sampleFit(KKTRK const& kktrk,KalIntersectionCollection& inters) const; // sample fit at the surfaces specified in the config int print_; unsigned minNStrawHits_; - bool matcorr_, addhits_, addmat_, usecalo_; // flags + bool matcorr_, addhits_, addmat_, usecalo_, addcalomat_; // flags KKSTRAWHITCLUSTERER shclusterer_; // functor to cluster KKStrawHits // CaloHit configuration double caloDt_; // calo time offset; should come from proditions TODO! @@ -175,6 +178,7 @@ namespace mu2e { addhits_(fitconfig.addHits()), addmat_(fitconfig.addMaterial()), usecalo_(fitconfig.useCaloCluster()), + addcalomat_(fitconfig.addCaloMaterial()), shclusterer_(StrawIdMask(fitconfig.strawHitClusterLevel()),fitconfig.strawHitClusterDeltaStraw(),fitconfig.strawHitClusterDeltaT()), caloDt_(fitconfig.caloDt()), caloPosRes_(fitconfig.caloPosRes()), @@ -400,6 +404,78 @@ namespace mu2e { << addstrawxings.size() << " Straw Xings" << std::endl; } kktrk.extendTrack(exconfig,addstrawhits,addstrawxings,addcalohits); + if(matcorr_ && addcalomat_ && kktrk.fitStatus().usable())addCaloMaterial(kktrk); + } + + // Add the calorimeter front panel material crossed between the tracker and the end of the fit to the fit. The + // crossings are found by intersecting the fit trajectory with the front panels, from the straw hit nearest the + // calorimeter end of the fit (the CaloHit if there is one, otherwise the end at larger z) to that end of the fit. + // The search runs to the end of the fit, not just to the CaloHit: the fit extends past its last measurement, and + // KKExtrap only adds crossings beyond the end of the fit, so crossings between the two would otherwise be lost. + // Adding material moves the trajectory downstream of it, which can move a crossing near the panel inner edge from + // the hole onto the panel, so the search is repeated after each refit for the layers not yet in the fit. + // The crystal case inner support rings crossed by tracks entering the case at its inner edge are added the same way. + // Front panel material isn't added when the fit is regrown TODO + template void KKFit::addCaloMaterial(KKTRK& kktrk) const { + using KKMATRECXING = typename KKTRK::KKMATRECXING; + static const unsigned maxpass(3); + GeomHandle kkg_h; + GeomHandle kkmat_h; + auto layers = caloMaterialLayers(*kkg_h); + for(unsigned ipass=0; ipass < maxpass && kktrk.fitStatus().usable(); ++ipass){ + // the refit replaces the fit trajectory + auto const& ptraj = kktrk.fitTraj(); + double tcalo; + if(kktrk.caloHits().size() > 0) + tcalo = kktrk.caloHits().front()->time(); + else + tcalo = ptraj.position3(ptraj.range().end()).Z() > ptraj.position3(ptraj.range().begin()).Z() ? ptraj.range().end() : ptraj.range().begin(); + // search between the last straw hit and the end of the fit beyond the CaloHit + double tlast = tcalo < ptraj.range().mid() ? ptraj.range().end() : ptraj.range().begin(); + for(auto const& strawhit : kktrk.strawHits()){ + double tstraw = strawhit->time(); + if(fabs(tstraw-tcalo) < fabs(tlast-tcalo))tlast = tstraw; + } + double tend = tcalo > tlast ? ptraj.range().end() : ptraj.range().begin(); + TimeRange srange(std::min(tlast,tend),std::max(tlast,tend)); + typename KKTRK::KKMATRECXINGCOL matxings; + for(auto const& layer : layers){ + // only add each layer once + bool infit(false); + for(auto const& matxing : kktrk.caloMaterialPlaneXings()) + if(matxing->surfaceId() == layer.sid_){ infit = true; break; } + if(infit)continue; + auto inter = KinKal::intersect(ptraj,*layer.surface_,srange,intertol_); + if(!inter.good())continue; + double thickness = layer.thickness(inter.pos_); + if(thickness <= 0.0)continue; + matxings.push_back(std::make_shared(layer.surface_,layer.sid_,*kkmat_h->material(*layer.material_), + inter,ptraj.nearestTraj(inter.time_),thickness,intertol_)); + if(print_ > 1)std::cout << "Adding calo front panel material " << layer.sid_ << " pass " << ipass << " thickness " << thickness << " " << inter << std::endl; + } + // crystal case inner support rings: entered at most once per disk, through the case front or from the hole + typename KKTRK::KKMATCYLXINGCOL cylxings; + for(auto const& support : kkg_h->caloInnerSupports()){ + using Support = KKGeom::CaloInnerSupport; + auto ringid = support.surfaceId(Support::alFront).id(); + auto isring = [&ringid](auto const& matxing){ return matxing->surfaceId().id() == ringid; }; + if(std::any_of(kktrk.caloMaterialPlaneXings().begin(),kktrk.caloMaterialPlaneXings().end(),isring) || + std::any_of(kktrk.caloMaterialCylXings().begin(),kktrk.caloMaterialCylXings().end(),isring))continue; + for(auto const& sxing : caloSupportXings(ptraj,support,srange,intertol_)){ + auto sid = support.surfaceId(sxing.xing_); + auto const& dmat = *kkmat_h->material(support.materialName(Support::material(sxing.xing_))); + auto reftraj = ptraj.nearestTraj(sxing.inter_.time_); + if(sxing.xing_ == Support::alFront || sxing.xing_ == Support::cfFront) + matxings.push_back(std::make_shared(support.front(),sid,dmat,sxing.inter_,reftraj,sxing.thickness(),intertol_)); + else + cylxings.push_back(std::make_shared(sxing.xing_ == Support::alHole ? support.inner() : support.cfInner(), + sid,dmat,sxing.inter_,reftraj,sxing.thickness(),intertol_)); + if(print_ > 1)std::cout << "Adding calo inner ring material " << sid << " pass " << ipass << " path " << sxing.path_ << " " << sxing.inter_ << std::endl; + } + } + if(matxings.empty() && cylxings.empty())break; + kktrk.addCaloMaterialXings(matxings,cylxings); + } } template void KKFit::addStrawHits(Tracker const& tracker,StrawResponse const& strawresponse, BFieldMap const& kkbf, @@ -898,8 +974,22 @@ namespace mu2e { crvxing->materialEffects(dmom,paramomvar,perpmomvar); inters.emplace_back(ktraj.stateEstimate(crvxing->time()),XYZVectorF(ktraj.bnom()),crvxing->surfaceId(),crvxing->intersection(),dmom); } - // generic passive material Xings are only filled during extrapolation; saving them in the KalSeed is optional + // generic passive material Xings are filled during extrapolation, calorimeter material Xings during the fit; saving them in the KalSeed is optional if(savematxings_){ + for(auto const& matxing : kktrk.caloMaterialCylXings()){ + double stime = matxing->time() - epsilon; + auto const& ktraj = ptraj.nearestPiece(stime); + double dmom,paramomvar,perpmomvar; + matxing->materialEffects(dmom,paramomvar,perpmomvar); + inters.emplace_back(ktraj.stateEstimate(matxing->time()),XYZVectorF(ktraj.bnom()),matxing->surfaceId(),matxing->intersection(),dmom); + } + for(auto const& matxing : kktrk.caloMaterialPlaneXings()){ + double stime = matxing->time() - epsilon; + auto const& ktraj = ptraj.nearestPiece(stime); + double dmom,paramomvar,perpmomvar; + matxing->materialEffects(dmom,paramomvar,perpmomvar); + inters.emplace_back(ktraj.stateEstimate(matxing->time()),XYZVectorF(ktraj.bnom()),matxing->surfaceId(),matxing->intersection(),dmom); + } for(auto const& matxing : kktrk.materialCylXings()){ double stime = matxing->time() - epsilon; auto const& ktraj = ptraj.nearestPiece(stime); diff --git a/Mu2eKinKal/inc/KKFitSettings.hh b/Mu2eKinKal/inc/KKFitSettings.hh index e71eb2cd53..0736672a60 100644 --- a/Mu2eKinKal/inc/KKFitSettings.hh +++ b/Mu2eKinKal/inc/KKFitSettings.hh @@ -71,6 +71,7 @@ namespace mu2e { fhicl::Atom addHits { Name("AddHits"), Comment("Add hits to the fit") }; fhicl::Atom addMaterial { Name("AddMaterial"), Comment("Add materials to the fit") }; fhicl::Atom useCaloCluster { Name("UseCaloCluster"), Comment("Use CaloCluster in the fit") }; + fhicl::Atom addCaloMaterial { Name("AddCaloMaterial"), Comment("Add the calorimeter front panel material crossed within the fit range"), false }; fhicl::Atom minNStrawHits { Name("MinNStrawHits"), Comment("Minimum number of straw hits to attempt a fit") }; fhicl::Atom strawHitClusterDeltaStraw { Name("StrawHitClusterDeltaStraw"), Comment("Maximum straw index difference between StrawHits in StrawHitClusters") }; fhicl::Atom strawHitClusterDeltaT { Name("StrawHitClusterDeltaT"), Comment("Maximum time difference between StrawHits in StrawHitClusters") }; @@ -129,6 +130,7 @@ namespace mu2e { fhicl::Atom ToCRV { Name("ToCRV"), Comment("Extrapolate tracks to the CRV modules") }; fhicl::Atom ToCaloD0 { Name("ToCaloD0"), Comment("Extrapolate tracks to the calorimeter disk0 surfaces") }; fhicl::Atom ToCaloD1 { Name("ToCaloD1"), Comment("Extrapolate tracks to the calorimeter disk1 surfaces") }; + fhicl::Atom ToCaloMaterial { Name("ToCaloMaterial"), Comment("Add material effects from the calorimeter front panels when extrapolating to the calorimeter disks"), false }; }; } } diff --git a/Mu2eKinKal/inc/KKShellXing.hh b/Mu2eKinKal/inc/KKShellXing.hh index 135c88c9e1..f9b9897708 100644 --- a/Mu2eKinKal/inc/KKShellXing.hh +++ b/Mu2eKinKal/inc/KKShellXing.hh @@ -82,9 +82,17 @@ namespace mu2e { if(neartrajptr != reftrajptr_){ // traj has changed; try intersecting with this piece reftrajptr_ = neartrajptr; - inter_ = KinKal::intersect(*reftrajptr_,*surf_, reftrajptr_->range(),tol_); - // I should test if this is in range, but there's a missing piece in the ptraj intersection here that I don't know what direction, - // to go, and there can be multiple intersections. Not clear if there's a good answer here TODO + auto newinter = KinKal::intersect(*reftrajptr_,*surf_, reftrajptr_->range(),tol_); + // a crossing inside the fit can move into a neighboring piece (ie when the fit is split into BField domains): + // search the full trajectory near the previous crossing + if(!(newinter.onsurface_ && newinter.inrange_)){ + static const double dt(1.0); // ns + newinter = KinKal::intersect(ptraj,*surf_,KinKal::TimeRange(inter_.time_-dt,inter_.time_+dt),tol_); + if(newinter.onsurface_ && newinter.inrange_)reftrajptr_ = ptraj.nearestTraj(newinter.time_); + } + // keep the previous crossing rather than one with an invalid time if the surface can't be found + if(newinter.onsurface_ && newinter.inrange_)inter_ = newinter; + // there can be multiple intersections. Not clear if there's a good answer here TODO } } diff --git a/Mu2eKinKal/inc/KKTrack.hh b/Mu2eKinKal/inc/KKTrack.hh index 3f6412726d..86bb035cde 100644 --- a/Mu2eKinKal/inc/KKTrack.hh +++ b/Mu2eKinKal/inc/KKTrack.hh @@ -93,6 +93,8 @@ namespace mu2e { this->clone_pointer_collection(crvxings_, rhs.CRVXings(), context); this->clone_pointer_collection(matcylxings_, rhs.materialCylXings(), context); this->clone_pointer_collection(matrecxings_, rhs.materialPlaneXings(), context); + this->clone_pointer_collection(calomatcylxings_, rhs.caloMaterialCylXings(), context); + this->clone_pointer_collection(calomatrecxings_, rhs.caloMaterialPlaneXings(), context); this->clone_pointer_collection(strawhitclusters_, rhs.strawHitClusters(), context); } @@ -136,6 +138,8 @@ namespace mu2e { void addMaterialCylXing(KKMATCYLXINGPTR const& matxing,TimeDir const& tdir); // add passive rectangular material Xing void addMaterialPlaneXing(KKMATRECXINGPTR const& matxing,TimeDir const& tdir); + // add calorimeter planar and cylindrical material Xings inside the fit range, refitting the track + void addCaloMaterialXings(KKMATRECXINGCOL const& planexings, KKMATCYLXINGCOL const& cylxings); // add IPA Xing void addIPAXing(KKIPAXINGPTR const& ipaxing,TimeDir const& tdir); // add ST Xing @@ -156,6 +160,8 @@ namespace mu2e { KKCRVXINGCOL const& CRVXings() const { return crvxings_; } KKMATCYLXINGCOL const& materialCylXings() const { return matcylxings_; } KKMATRECXINGCOL const& materialPlaneXings() const { return matrecxings_; } + KKMATCYLXINGCOL const& caloMaterialCylXings() const { return calomatcylxings_; } + KKMATRECXINGCOL const& caloMaterialPlaneXings() const { return calomatrecxings_; } KKINTERCOL const& intersections() const { return inters_; } KKCALOHITCOL const& caloHits() const { return calohits_; } void printFit(std::ostream& ost=std::cout,int detail=0) const; @@ -177,6 +183,8 @@ namespace mu2e { KKCRVXINGCOL crvxings_; // crv crossings using in extrapolation KKMATCYLXINGCOL matcylxings_; // passive cylindrical material crossings used in extrapolation KKMATRECXINGCOL matrecxings_; // passive planar material crossings used in extrapolation + KKMATCYLXINGCOL calomatcylxings_; // calorimeter cylindrical material crossings used in the fit + KKMATRECXINGCOL calomatrecxings_; // calorimeter planar material crossings used in the fit KKINTERCOL inters_; // other recorded intersections KKSTRAWHITCLUSTERCOL strawhitclusters_; // straw hit clusters used in this fit // utility function to convert to generic types @@ -324,6 +332,20 @@ namespace mu2e { matcylxings_.push_back(matxingptr); } + template void KKTrack::addCaloMaterialXings(KKMATRECXINGCOL const& planexings, KKMATCYLXINGCOL const& cylxings) { + EXINGCOL exings; + for(auto const& matxing : planexings)exings.emplace_back(std::static_pointer_cast(matxing)); + for(auto const& matxing : cylxings)exings.emplace_back(std::static_pointer_cast(matxing)); + MEASCOL nohits; + // refit with a single meta-iteration at the final temperature and no updaters, so the hit states are kept. + // Replaying the full schedule re-anneals and re-runs the hit updaters, which can change hits and fail good fits + auto matconfig = this->config(); + matconfig.schedule_ = KinKal::Config::Schedule{KinKal::MetaIterConfig(matconfig.schedule().back().temperature())}; + this->extend(matconfig,nohits,exings); + for(auto const& matxing : planexings)calomatrecxings_.emplace_back(matxing); + for(auto const& matxing : cylxings)calomatcylxings_.emplace_back(matxing); + } + template void KKTrack::addMaterialPlaneXing(KKMATRECXINGPTR const& matxingptr,TimeDir const& tdir) { // convert to a generic Xing std::shared_ptr> exptr = std::static_pointer_cast>(matxingptr); diff --git a/TrackerConditions/data/MaterialsList.data b/TrackerConditions/data/MaterialsList.data index b64702c210..33f0529fa7 100644 --- a/TrackerConditions/data/MaterialsList.data +++ b/TrackerConditions/data/MaterialsList.data @@ -5,6 +5,8 @@ #Materials_list # generic materials ------------------------------------------------------------------------------------------------ air 0.001290 0. 0. +2 73.7e-2 Nitrogen 0 26.3e-2 Oxygen 0 36.66000 90.0000 -30 0.0 1.0 gas +# G4 name for air, used by geometries that replace detector material with air (ie geom_common_trackerVST.txt) +G4_AIR 0.001290 0. 0. +2 73.7e-2 Nitrogen 0 26.3e-2 Oxygen 0 36.66000 90.0000 -30 0.0 1.0 gas vacuum 1.0e-25 1. 1.01 0 -10 -20 -30 -270.42 2.961e-23 gas Target 2.700000 0. 0. +1 100.0e-2 Aluminum 0 24.01000 106.40000 -30 20.0 1.0 solid Lexan 1.20 0. 0. -3 5 Hydrogen 0 5 Carbon 0 2 Oxygen 0 41.46 84.7 -30 20.0 1.0 solid @@ -30,6 +32,15 @@ cathode 5.2 0. 0. +2 86.4e-2 Copper 0 13.6e-2 straw-wall 1 -10 # effective straw wall + gas material, assuming uniform mass distribution straw_15um 1.927e-2 0.0 0.0 +2 91.3e-2 straw-wall 1 8.7e-2 straw-gas 1 -10 -20 -30 20.0 1.0 solid straw_25um 3.068e-2 0.0 0.0 +2 94.6e-2 straw-wall 1 5.4e-2 straw-gas 1 -10 -20 -30 20.0 1.0 solid +# Calorimeter front panel materials, translated from Mu2eG4/src/ConstructMaterials.cc (names match calorimeter.FPFoamMaterial/FPCarbonMaterial) +AluminumHoneycomb 0.03 0. 0. +1 100.0e-2 Aluminum 0 -10 -20 -30 20.0 1.0 solid +CarbonFiber_resin 1.1 0. 0. -3 5 Hydrogen 0 5 Carbon 0 2 Oxygen 0 -10 -20 -30 20.0 1.0 solid +# calorimeter front panel cooling pipe walls (G4_Al) +CaloPipeAl 2.700000 0. 0. +1 100.0e-2 Aluminum 0 24.01000 106.40000 -30 20.0 1.0 solid +# calorimeter crystal case inner rings (G4_Al) +CaloRingAl 2.700000 0. 0. +1 100.0e-2 Aluminum 0 24.01000 106.40000 -30 20.0 1.0 solid +# 46% (by mass) 1.8 g/cm3 carbon fibers in resin: density 0.46*1.8 + 0.54*1.1 +CarbonFiber 1.422 0. 0. +2 46.0e-2 Carbon 0 54.0e-2 CarbonFiber_resin 1 -10 -20 -30 20.0 1.0 solid # DS materials NbTi 6.5 0.0 0.0 +2 0.65 Niobium 0 0.35 Titanium 0 -10 -20 -30 20.0 1.0 solid # Pure aluminium (2.700 g/cm3) passive materials, named per subsystem so the surface/material is