Repository navigation
Track-CRV association data product (TrkCrvMatch) with its MC truth (TrkCrvMatchMC) #2106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e2e5514
New tracker-CRV association data object.
RobMina f7eca12
Address PR review comments.
RobMina addceca
TrkCrvXingMC: MCRelationship replaces generation_; add MCRelationship…
RobMina f24602b
TrkCrvMatchMCMaker: stage-aware MCRelationship for candidate deposits…
RobMina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // | ||
| // CRV geometry used by the track-CRV association and its truth: the sector planes (KinKalGeom CRV rectangles, per | ||
| // CRSScintillatorShield index) and the dominant shield of a coincidence cluster. | ||
| // Sector frame: u along the bars (uDirection), v across the bars (vDirection), w the sector normal, all in the | ||
| // detector frame; TrkCrvMatch residuals and covariances are expressed in (u, v). | ||
| // | ||
| #ifndef CRVReco_TrkCrvGeom_hh | ||
| #define CRVReco_TrkCrvGeom_hh | ||
| #include "Offline/DataProducts/inc/SurfaceId.hh" | ||
| #include "KinKal/General/Vectors.hh" | ||
| #include "KinKal/Geometry/Rectangle.hh" | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace mu2e { | ||
| class CosmicRayShield; | ||
| class CrvCoincidenceCluster; | ||
|
|
||
| struct TrkCrvSector { | ||
| bool valid = false; // the shield has a KinKalGeom CRV rectangle | ||
| std::string name; // CRSScintillatorShield name | ||
| SurfaceId sid; // its SurfaceId (unknown if the name has none) | ||
| std::shared_ptr<KinKal::Rectangle> rect; // mid-plane rectangle, detector frame | ||
| KinKal::VEC3 center, u, v, w; // rectangle centre and axes | ||
| double uHalf = 0, vHalf = 0; // half lengths along u and v [mm] | ||
| }; | ||
|
|
||
| // one entry per CRSScintillatorShield, in shield order (the sector_ index of TrkCrvMatch); call once per run | ||
| std::vector<TrkCrvSector> trkCrvSectors(); | ||
| // the shield with the largest PE sum among the cluster's pulses, -1 if none; multiSector set if pulses span shields | ||
| int trkCrvDominantShield(CrvCoincidenceCluster const& cluster, CosmicRayShield const& crs, bool* multiSector = nullptr); | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // | ||
| // Track-CRV matching shared by the TrkCrvMatcher producer and any fit that uses CRV clusters as constraints, so that | ||
| // both apply one definition of a match. See TrkCrvMatch.hh for the output. | ||
| // | ||
| #ifndef CRVReco_TrkCrvMatchTool_hh | ||
| #define CRVReco_TrkCrvMatchTool_hh | ||
| #include "Offline/RecoDataProducts/inc/CrvCoincidenceCluster.hh" | ||
| #include "Offline/RecoDataProducts/inc/CrvRecoPulse.hh" | ||
| #include "Offline/RecoDataProducts/inc/KalSeed.hh" | ||
| #include "Offline/RecoDataProducts/inc/TrkCrvMatch.hh" | ||
| #include "Offline/CRVReco/inc/TrkCrvGeom.hh" | ||
| #include "Offline/DataProducts/inc/SurfaceId.hh" | ||
| #include "KinKal/General/Vectors.hh" | ||
| #include "canvas/Persistency/Common/Ptr.h" | ||
| #include "fhiclcpp/types/Atom.h" | ||
| #include "fhiclcpp/types/Sequence.h" | ||
| #include <cmath> | ||
| #include <map> | ||
| #include <set> | ||
| #include <string> | ||
| #include <tuple> | ||
| #include <unordered_map> | ||
| #include <vector> | ||
|
|
||
| namespace mu2e { | ||
| class CosmicRayShield; | ||
| class DetectorSystem; | ||
|
|
||
| class TrkCrvMatchTool { | ||
| public: | ||
| // physics settings have no C++ default: CRVReco/fcl/prolog_v12.fcl (TrkCrvMatcher) sets them with their sources | ||
| struct Config { | ||
| using Name = fhicl::Name; | ||
| using Comment = fhicl::Comment; | ||
| fhicl::Sequence<std::string> refSurfaces{Name("ReferenceSurfaces"), Comment("surfaces whose KalSeed intersection gives the track reference time; KalSeed t0 if none present")}; | ||
| fhicl::Atom<bool> earliestReference{Name("EarliestReference"), Comment("true: the earliest intersection on any of ReferenceSurfaces (the tracker entry); false: the first surface in list order present, nearest in time to t0")}; | ||
| fhicl::Sequence<double> dtRefWindow{Name("DtRefWindow"), Comment("storage window on t_track(ref) - t_cluster [ns]")}; | ||
| fhicl::Atom<double> dtRefCenter{Name("DtRefCenter"), Comment("dtRef value the time ranking is centred on [ns]")}; | ||
| fhicl::Sequence<double> dtXingWindow{Name("DtXingWindow"), Comment("storage window on t_cluster - t_track at the cluster plane [ns]")}; | ||
| fhicl::Atom<double> maxDv{Name("MaxDv"), Comment("storage window on |across-bar residual| [mm]")}; | ||
| fhicl::Atom<double> maxDu{Name("MaxDu"), Comment("storage window on |along-bar residual| for two-ended clusters [mm]")}; | ||
| fhicl::Atom<bool> doGeometric{Name("DoGeometric"), Comment("form geometric candidates from CRV KalIntersections")}; | ||
| fhicl::Atom<bool> requireSameSector{Name("RequireSameSector"), Comment("project only from a crossing of the cluster's own sector (A/B tests)"), false}; | ||
| fhicl::Sequence<double> sigmaV{Name("SigmaV"), Comment("CRV across-bar resolution [mm], indexed by the cluster's sector type (1 first; the last entry serves higher types); sector type numbering depends on the geometry")}; | ||
| fhicl::Sequence<double> sigmaU{Name("SigmaU"), Comment("CRV along-bar resolution of two-ended clusters [mm], by sector type")}; | ||
| fhicl::Sequence<double> sigmaT{Name("SigmaT"), Comment("CRV time resolution of two-ended clusters [ns], by sector type")}; | ||
| fhicl::Atom<double> sigmaTSingleEnded{Name("SigmaTSingleEnded"), Comment("CRV time resolution of single-ended clusters [ns]")}; | ||
| fhicl::Atom<double> trackErrorScale{Name("TrackErrorScale"), Comment("scale k on the propagated track position covariance: k^2 C + TrackPosErrQuad^2 I")}; | ||
| fhicl::Atom<double> trackPosErrQuad{Name("TrackPosErrQuad"), Comment("added in quadrature to the scaled track position errors [mm]")}; | ||
| fhicl::Atom<double> minTrackTimeErr{Name("MinTrackTimeErr"), Comment("floor on the (unscaled) track time error [ns]")}; | ||
| fhicl::Atom<double> timeOffset{Name("TimeOffset"), Comment("added to cluster and pulse times [ns]; test knob, data offsets belong in conditions"), 0.0}; | ||
| fhicl::Atom<bool> keepAll{Name("KeepAllClusters"), Comment("ignore every storage window (commissioning)"), false}; | ||
| fhicl::Atom<bool> layerProbe{Name("LayerProbe"), Comment("probe each layer of every crossed sector for pulses near the predicted bar; needs the reco pulses")}; | ||
| fhicl::Atom<bool> probeAllPulses{Name("ProbeAllPulses"), Comment("the pulse collection holds every reco pulse (true) or only the clustered ones, e.g. SelectReco (false)")}; | ||
| fhicl::Atom<int> probeBarWindow{Name("ProbeBarWindow"), Comment("layer probe: bars searched on each side of the predicted bar")}; | ||
| fhicl::Sequence<double> probeDtWindow{Name("ProbeDtWindow"), Comment("layer probe: window on pulse time - predicted pulse time [ns]")}; | ||
| fhicl::Atom<double> fiberSignalSpeed{Name("FiberSignalSpeed"), Comment("layer probe: signal speed in the fibres [mm/ns]")}; | ||
| fhicl::Atom<double> pulseDelay{Name("ProbePulseDelay"), Comment("layer probe: electronics and scintillation delay subtracted from pulse times [ns]")}; | ||
| }; | ||
| explicit TrkCrvMatchTool(Config const& conf); | ||
|
|
||
| void beginRun(); // caches the CRV geometry | ||
| // per-event inputs; pulses may be null (the layer probe then records predicted bars only) | ||
| void setEvent(std::vector<art::Ptr<CrvCoincidenceCluster>> const& clusters, CrvRecoPulseCollection const* pulses); | ||
| // one track; usedInFit lists the clusters its fit used as constraints | ||
| TrkCrvMatch match(art::Ptr<KalSeed> const& seed, std::vector<art::Ptr<CrvCoincidenceCluster>> const& usedInFit = {}) const; | ||
| // cross-track pass over one collection: nShare, bestForCluster, exclusive | ||
| void resolve(TrkCrvMatchCollection& matches) const; | ||
| bool probeActive() const { return layerProbe_; } | ||
| std::vector<TrkCrvSector> const& sectors() const { return sectors_; } // per shield index, after beginRun | ||
|
|
||
| private: | ||
| struct ClusterInfo { // per-event cluster quantities | ||
| KinKal::VEC3 pos; // detector frame | ||
| double time = 0; | ||
| int shield = -1; | ||
| int sectorType = 0; | ||
| bool multiSector = false; | ||
| bool singleEnded = false; | ||
| }; | ||
| double resolution(std::vector<double> const& tab, int sectorType) const; | ||
| TrkCrvPlaneCov errorModel(ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2>> const& cov) const; // k^2 C + a^2 I | ||
| void probe(TrkCrvXing& x, double speed) const; | ||
| static bool sameCluster(art::Ptr<CrvCoincidenceCluster> const& a, art::Ptr<CrvCoincidenceCluster> const& b); | ||
|
|
||
| std::vector<SurfaceId> refSurfaces_; | ||
| bool earliestRef_; | ||
| double dtRefLo_, dtRefHi_, dtRefCenter_, dtXingLo_, dtXingHi_, maxDv_, maxDu_; | ||
| bool doGeometric_, requireSameSector_; | ||
| std::vector<double> sigmaV_, sigmaU_, sigmaT_; | ||
| double sigmaTSingle_, trkErrScale_, posErrQuad_, minTimeErr_, timeOffset_; | ||
| bool keepAll_, layerProbe_, probeAllPulses_; | ||
| int probeBarWindow_; | ||
| double probeDtLo_, probeDtHi_, fiberSpeed_, pulseDelay_; | ||
|
|
||
| CosmicRayShield const* crs_ = nullptr; | ||
| DetectorSystem const* det_ = nullptr; | ||
| std::map<SurfaceId,int> sidToShield_; | ||
| std::vector<TrkCrvSector> sectors_; // indexed by shield | ||
|
|
||
| std::vector<art::Ptr<CrvCoincidenceCluster>> clusters_; | ||
| std::vector<ClusterInfo> cinfo_; | ||
| CrvRecoPulseCollection const* pulses_ = nullptr; | ||
| std::unordered_map<int, std::vector<size_t>> pulsesByBar_; // bar index -> pulses | ||
| std::set<std::tuple<int,int,double>> clusteredPulses_; // (bar, SiPM, time) of the pulses in clusters | ||
| }; | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // | ||
| // Temporary stand-in for a KinKal projection of a track state's spatial covariance onto a plane; replace with the | ||
| // KinKal implementation when it exists (both modules call only trkCrvPlaneCovariance). | ||
| // | ||
| #ifndef CRVReco_TrkCrvPlaneError_hh | ||
| #define CRVReco_TrkCrvPlaneError_hh | ||
| #include "KinKal/General/Vectors.hh" | ||
| #include "Math/SMatrix.h" | ||
| #include <cmath> | ||
|
|
||
| namespace mu2e { | ||
| using TrkCrvCov2 = ROOT::Math::SMatrix<double,2,2,ROOT::Math::MatRepSym<double,2>>; | ||
|
|
||
| // Covariance of the track position on the plane with normal w, in the in-plane axes (a, b), after a straight step of | ||
| // signed path length s from a state (position, momentum p) with 6x6 covariance C (position first). With d = p/|p| | ||
| // and P = I - d w^T/(d.w) (move along d onto the plane), the gradient of e.(position on the plane) is P^T e for the | ||
| // position block and (s/|p|)(I - d d^T) P^T e for the momentum block. s = 0 gives the covariance of the state itself, | ||
| // measured in the plane. Returns a zero matrix for a track parallel to the plane. | ||
| template<class COV> TrkCrvCov2 trkCrvPlaneCovariance(COV const& C, KinKal::VEC3 const& p, KinKal::VEC3 const& a, | ||
| KinKal::VEC3 const& b, KinKal::VEC3 const& w, double s) { | ||
| TrkCrvCov2 out; | ||
| double pm = std::sqrt(p.Mag2()); | ||
| if(pm <= 0) return out; | ||
| KinKal::VEC3 d = p / pm; | ||
| double dw = d.Dot(w); | ||
| if(std::fabs(dw) < 1e-3) return out; | ||
| double g[2][6]; | ||
| KinKal::VEC3 const* axes[2] = {&a, &b}; | ||
| for(int k = 0; k < 2; ++k) { | ||
| KinKal::VEC3 gp = *axes[k] - w * (d.Dot(*axes[k]) / dw); | ||
| KinKal::VEC3 gm = (s / pm) * (gp - d * d.Dot(gp)); | ||
| double gk[6] = {gp.X(), gp.Y(), gp.Z(), gm.X(), gm.Y(), gm.Z()}; | ||
| for(int i = 0; i < 6; ++i) g[k][i] = gk[i]; | ||
| } | ||
| for(int k = 0; k < 2; ++k) | ||
| for(int l = k; l < 2; ++l) { | ||
| double v = 0; | ||
| for(int i = 0; i < 6; ++i) for(int j = 0; j < 6; ++j) v += g[k][i] * C(i, j) * g[l][j]; | ||
| out(k, l) = v; | ||
| } | ||
| return out; | ||
| } | ||
| } | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #include "Offline/CRVReco/inc/TrkCrvGeom.hh" | ||
| #include "Offline/CosmicRayShieldGeom/inc/CosmicRayShield.hh" | ||
| #include "Offline/GeometryService/inc/GeomHandle.hh" | ||
| #include "Offline/KinKalGeom/inc/KinKalGeom.hh" | ||
| #include "Offline/RecoDataProducts/inc/CrvCoincidenceCluster.hh" | ||
| #include "messagefacility/MessageLogger/MessageLogger.h" | ||
| #include <map> | ||
|
|
||
| namespace mu2e { | ||
|
|
||
| std::vector<TrkCrvSector> trkCrvSectors() { | ||
| GeomHandle<CosmicRayShield> crs; | ||
| GeomHandle<KinKalGeom> kkg; | ||
| auto const& shields = crs->getCRSScintillatorShields(); | ||
| std::vector<TrkCrvSector> sectors(shields.size()); | ||
| std::map<std::string,int> nameToShield; | ||
| for(size_t i = 0; i < shields.size(); ++i) { | ||
| sectors[i].name = shields[i].getName(); | ||
| nameToShield[sectors[i].name] = static_cast<int>(i); | ||
| } | ||
| for(auto const& sec : kkg->CRV()->sectors()) { | ||
| auto it = nameToShield.find(sec.sname_); | ||
| if(it == nameToShield.end()) continue; | ||
| auto& g = sectors[it->second]; | ||
| g.valid = true; | ||
| g.rect = sec.sector_; | ||
| g.center = sec.sector_->center(); | ||
| g.u = sec.sector_->uDirection(); | ||
| g.v = sec.sector_->vDirection(); | ||
| g.w = sec.sector_->normal(); | ||
| g.uHalf = sec.sector_->uHalfLength(); | ||
| g.vHalf = sec.sector_->vHalfLength(); | ||
| try { g.sid = SurfaceId(sec.sname_); } | ||
| catch(std::exception const&) { mf::LogWarning("TrkCrvGeom") << "no SurfaceId for CRV sector " << sec.sname_; } | ||
| } | ||
| return sectors; | ||
| } | ||
|
|
||
| int trkCrvDominantShield(CrvCoincidenceCluster const& cluster, CosmicRayShield const& crs, bool* multiSector) { | ||
| std::map<int,double> pes; | ||
| for(auto const& rp : cluster.GetCrvRecoPulses()) pes[crs.getBar(rp->GetScintillatorBarIndex()).id().getShieldNumber()] += rp->GetPEs(); | ||
| int shield = -1; | ||
| double best = -1; | ||
| for(auto const& [s, pe] : pes) if(pe > best) { best = pe; shield = s; } | ||
| if(multiSector) *multiSector = pes.size() > 1; | ||
| return shield; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.