Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Validation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ cet_make_library(
src/ValTimeCluster.cc
src/ValTriggerInfo.cc
src/ValTriggerResults.cc
src/ValTrkCrvMatch.cc
src/ValTrkCrvMatchMC.cc
LIBRARIES PUBLIC

Offline::DataProducts
Expand Down
66 changes: 66 additions & 0 deletions Validation/inc/ValTrkCrvMatch.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#ifndef ValTrkCrvMatch_HH_
#define ValTrkCrvMatch_HH_

#include "Offline/RecoDataProducts/inc/TrkCrvMatch.hh"
#include "Offline/Validation/inc/ValTrkCrvSectorAxis.hh"
#include "KinKal/General/Vectors.hh"
#include "art/Framework/Principal/Event.h"
#include "art_root_io/TFileDirectory.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TProfile.h"
#include <cstdint>
#include <map>
#include <string>

namespace mu2e {

// track-CRV association: candidate counts, residuals and chi2 per CRV sector, dv against slope (alignment monitor),
// predicted vs matched sector, layer probe
class ValTrkCrvMatch {
public:
ValTrkCrvMatch(std::string name) : _name(name) {}
int declare(const art::TFileDirectory& tfs);
int fill(const TrkCrvMatchCollection& coll, art::Event const& event);
std::string& name() { return _name; }

private:
std::string _name;
struct Plane { // a sector of this job's geometry: centre, across-bar direction, normal, dv vs slope
KinKal::VEC3 c, v, w;
TProfile* p = nullptr;
};
ValTrkCrvSectorAxis _axis;
std::map<int, Plane> _plane; // by axis bin
std::map<int16_t, int> _shieldBin; // product shield index (sector_) -> axis bin, from the crossings
static constexpr double _planeTol = 1.0; // max distance of a crossing from the job's sector mid-plane [mm]

TH1D* _hVer;
TH1D* _hNTrk;
TH1D* _hNCand;
TH1D* _hNGeom;
TH1D* _hNXing;
TH1D* _hDtRef;
TH1D* _hDtRefBest;
TH1D* _hDtRefToF;
TH1D* _hChi2;
TH1D* _hNShare;
TH1D* _hFlags;
TH1D* _hXingShield;
TH1D* _hXingGeomShield;
TH2D* _hDtXing;
TH2D* _hDu;
TH2D* _hDv;
TH2D* _hPredMatched;
TH1D* _hSlopeNoGeom;
TH1D* _hProbePred;
TH1D* _hProbeHit;
TH1D* _hProbeInCluster;
TH1D* _hProbeDBar;
TH1D* _hProbeDt;
TH1D* _hProbePE;
TH1D* _hProbeDu;
};
} // namespace mu2e

#endif
44 changes: 44 additions & 0 deletions Validation/inc/ValTrkCrvMatchMC.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef ValTrkCrvMatchMC_HH_
#define ValTrkCrvMatchMC_HH_

#include "Offline/MCDataProducts/inc/TrkCrvMatchMC.hh"
#include "Offline/Validation/inc/ValTrkCrvSectorAxis.hh"
#include "art/Framework/Principal/Event.h"
#include "art_root_io/TFileDirectory.h"
#include "TH1D.h"
#include "TH2D.h"
#include <string>

namespace mu2e {

// track-CRV association truth: relation of the best candidates, own-cluster association and crossing truth per
// CRV sector, reco crossings against the true crossings
class ValTrkCrvMatchMC {
public:
ValTrkCrvMatchMC(std::string name) : _name(name) {}
int declare(const art::TFileDirectory& tfs);
int fill(const TrkCrvMatchMCCollection& coll, art::Event const& event);
std::string& name() { return _name; }

private:
std::string _name;
ValTrkCrvSectorAxis _axis;

TH1D* _hVer;
TH1D* _hBestGeomRel;
TH1D* _hBestTimeRel;
TH1D* _hGeomCandRel;
TH1D* _hTimeCandRel;
TH1D* _hTrueClu;
TH1D* _hTrueCluGeom;
TH1D* _hTrueCluBest;
TH1D* _hRecoXing;
TH1D* _hRecoXingTrue;
TH1D* _hTrueXing;
TH1D* _hTrueXingFound;
TH2D* _hXingDist;
TH2D* _hXingDt;
};
} // namespace mu2e

#endif
47 changes: 47 additions & 0 deletions Validation/inc/ValTrkCrvSectorAxis.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef ValTrkCrvSectorAxis_HH_
#define ValTrkCrvSectorAxis_HH_

#include "Offline/DataProducts/inc/SurfaceId.hh"
#include "TAxis.h"
#include <map>
#include <string>
#include <vector>

namespace mu2e {

// fixed, labelled histogram axis of the CRV sector SurfaceIds, so the per-sector histograms do not depend on the job
// geometry; the last bin collects sectors without a SurfaceId
class ValTrkCrvSectorAxis {
public:
ValTrkCrvSectorAxis() {
for (auto const& [id, name] : SurfaceIdDetail::names()) {
if (name.rfind("CRV_", 0) != 0 || id == SurfaceIdDetail::CRV_StrongBack) continue;
_byName[name] = _bin[id] = static_cast<int>(_names.size());
_names.push_back(name);
}
_names.push_back("unknown");
}
int n() const { return static_cast<int>(_names.size()); }
int unknown() const { return n() - 1; }
double lo() const { return -0.5; }
double hi() const { return n() - 0.5; }
int bin(SurfaceId const& sid) const {
auto it = _bin.find(sid.id().id());
return it == _bin.end() ? unknown() : it->second;
}
int bin(std::string const& name) const {
auto it = _byName.find(name);
return it == _byName.end() ? unknown() : it->second;
}
void label(TAxis* ax) const {
for (int i = 0; i < n(); ++i) ax->SetBinLabel(i + 1, _names[i].c_str());
}

private:
std::map<SurfaceIdDetail::enum_type, int> _bin;
std::map<std::string, int> _byName;
std::vector<std::string> _names;
};
} // namespace mu2e

#endif
125 changes: 125 additions & 0 deletions Validation/src/ValTrkCrvMatch.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include "Offline/Validation/inc/ValTrkCrvMatch.hh"
#include "Offline/GeometryService/inc/GeomHandle.hh"
#include "Offline/KinKalGeom/inc/KinKalGeom.hh"
#include <cmath>

int mu2e::ValTrkCrvMatch::declare(const art::TFileDirectory& tfs) {
int ns = _axis.n();
double lo = _axis.lo(), hi = _axis.hi();
_hVer = tfs.make<TH1D>("Ver", "Version Number", 101, -0.5, 100.0);
_hNTrk = tfs.make<TH1D>("NTrk", "N tracks", 21, -0.5, 20.5);
_hNCand = tfs.make<TH1D>("NCand", "N candidates per track", 51, -0.5, 50.5);
_hNGeom = tfs.make<TH1D>("NGeom", "N geometric candidates per track", 21, -0.5, 20.5);
_hNXing = tfs.make<TH1D>("NXing", "N CRV crossings per track", 11, -0.5, 10.5);
_hDtRef = tfs.make<TH1D>("dtRef", "t_{trk}(ref) - t_{cluster}, all candidates;ns", 200, -1000., 1000.);
_hDtRefBest = tfs.make<TH1D>("dtRefBest", "t_{trk}(ref) - t_{cluster}, best candidate;ns", 200, -400., 400.);
_hDtRefToF = tfs.make<TH1D>("dtRefToF", "dtRef - flight time, best candidate;ns", 200, -400., 400.);
_hChi2 = tfs.make<TH1D>("chi2ndof", "#chi^{2}/ndof, best in sector", 100, 0., 20.);
_hNShare = tfs.make<TH1D>("NShare", "tracks sharing the cluster", 11, -0.5, 10.5);
_hFlags = tfs.make<TH1D>("Flags", "candidate flag bits", 16, -0.5, 15.5);
_hXingShield = tfs.make<TH1D>("XingShield", "CRV crossings per sector", ns, lo, hi);
_hXingGeomShield = tfs.make<TH1D>("XingGeomShield", "crossings with a geometric candidate in their sector", ns, lo, hi);
_hDtXing = tfs.make<TH2D>("dtXing", "t_{cluster} - t_{trk} at the plane, best in sector;cluster sector;ns", ns, lo, hi, 100, -100., 100.);
_hDu = tfs.make<TH2D>("du", "cluster - track along the bars, best in sector;cluster sector;mm", ns, lo, hi, 100, -3000., 3000.);
_hDv = tfs.make<TH2D>("dv", "cluster - track across the bars, best in sector;cluster sector;mm", ns, lo, hi, 100, -500., 500.);
_hPredMatched = tfs.make<TH2D>("PredMatched", "best geometric candidate;reference crossing sector;cluster sector", ns, lo, hi, ns, lo, hi);
_hSlopeNoGeom = tfs.make<TH1D>("SlopeNoGeom", "best in sector, not in dvVsSlope: sector not in this job's geometry;cluster sector", ns, lo, hi);
for (TH1* h : {static_cast<TH1*>(_hXingShield), static_cast<TH1*>(_hXingGeomShield), static_cast<TH1*>(_hDtXing),
static_cast<TH1*>(_hDu), static_cast<TH1*>(_hDv), static_cast<TH1*>(_hPredMatched), static_cast<TH1*>(_hSlopeNoGeom)})
_axis.label(h->GetXaxis());
_axis.label(_hPredMatched->GetYaxis());

// dv vs slope needs the sector directions, from this job's geometry: one profile per sector it has
GeomHandle<KinKalGeom> kkg;
for (auto const& sec : kkg->CRV()->sectors()) {
int b = _axis.bin(sec.sname_);
if (b == _axis.unknown() || _plane.count(b)) continue;
auto& pl = _plane[b];
pl.c = sec.sector_->center();
pl.v = sec.sector_->vDirection();
pl.w = sec.sector_->normal();
pl.p = tfs.make<TProfile>(("dvVsSlope_" + sec.sname_).c_str(), ("dv vs across-bar slope, " + sec.sname_ + ";slope;dv [mm]").c_str(), 40, -2., 2.);
}
_hProbePred = tfs.make<TH1D>("ProbePred", "layer probe: predicted bar per layer", 6, -0.5, 5.5);
_hProbeHit = tfs.make<TH1D>("ProbeHit", "layer probe: pulse found per layer", 6, -0.5, 5.5);
_hProbeInCluster = tfs.make<TH1D>("ProbeInCluster", "layer probe: pulse in a cluster per layer", 6, -0.5, 5.5);
_hProbeDBar = tfs.make<TH1D>("ProbeDBar", "layer probe: selected - predicted bar", 21, -10.5, 10.5);
_hProbeDt = tfs.make<TH1D>("ProbeDt", "layer probe: pulse - predicted time;ns", 100, -60., 60.);
_hProbePE = tfs.make<TH1D>("ProbePE", "layer probe: PEs", 100, 0., 200.);
_hProbeDu = tfs.make<TH1D>("ProbeDu", "layer probe: two-end position - predicted;mm", 100, -1500., 1500.);
return 0;
}

int mu2e::ValTrkCrvMatch::fill(const mu2e::TrkCrvMatchCollection& coll, art::Event const& event) {
// increment this by 1 any time the definitions of the histograms or the
// histogram contents change, and will not match previous versions
_hVer->Fill(1.0);

// a cluster's sector: the SurfaceId of a crossing with the same shield index in the product's geometry
auto clusterBin = [&](int16_t shield) {
auto it = _shieldBin.find(shield);
return it == _shieldBin.end() ? _axis.unknown() : it->second;
};
_hNTrk->Fill(coll.size());
for (auto const& m : coll) {
for (auto const& x : m.xings_) _shieldBin[x.sector_] = _axis.bin(x.sid_);
_hNCand->Fill(m.cands_.size());
_hNXing->Fill(m.xings_.size());
int ngeom = 0;
for (auto const& c : m.cands_) {
_hDtRef->Fill(c.dtRef_);
_hNShare->Fill(c.nShare_);
for (int b = 0; b < 16; ++b)
if (c.flags_ & (1u << b)) _hFlags->Fill(b);
if (!c.hasFlag(TrkCrvCandidate::geomCand)) continue;
++ngeom;
if (!c.hasFlag(TrkCrvCandidate::bestInSector)) continue;
int b = clusterBin(c.sector_);
if (c.ndof_ > 0) _hChi2->Fill(c.chi2_ / c.ndof_);
_hDtXing->Fill(b, c.dtXing_);
if (!c.hasFlag(TrkCrvCandidate::singleEnded)) _hDu->Fill(b, c.du_);
_hDv->Fill(b, c.dv_);
if (c.xing_ < 0 || static_cast<size_t>(c.xing_) >= m.xings_.size()) continue;
// the job's directions apply only if its plane of the reference crossing's sector holds that crossing
auto const& x = m.xings_[c.xing_];
auto ix = _plane.find(_axis.bin(x.sid_));
auto ic = _plane.find(b);
KinKal::VEC3 pos(x.pos_.X(), x.pos_.Y(), x.pos_.Z());
if (ix == _plane.end() || ic == _plane.end() || std::fabs((pos - ix->second.c).Dot(ix->second.w)) > _planeTol) {
_hSlopeNoGeom->Fill(b);
continue;
}
KinKal::VEC3 dir(x.dir_.X(), x.dir_.Y(), x.dir_.Z());
double dw = dir.Dot(ic->second.w);
if (std::fabs(dw) > 1e-3) ic->second.p->Fill(dir.Dot(ic->second.v) / dw, c.dv_);
}
_hNGeom->Fill(ngeom);
int best = m.bestGeom_ >= 0 ? m.bestGeom_ : m.bestTime_;
if (best >= 0) {
_hDtRefBest->Fill(m.cands_[best].dtRef_);
_hDtRefToF->Fill(m.cands_[best].dtRefToF_);
}
if (m.bestGeom_ >= 0) {
auto const& c = m.cands_[m.bestGeom_];
if (c.xing_ >= 0 && static_cast<size_t>(c.xing_) < m.xings_.size())
_hPredMatched->Fill(_axis.bin(m.xings_[c.xing_].sid_), clusterBin(c.sector_));
}
for (auto const& x : m.xings_) {
_hXingShield->Fill(_axis.bin(x.sid_));
if (x.best_ >= 0) _hXingGeomShield->Fill(_axis.bin(x.sid_));
for (size_t L = 0; L < x.layers_.size(); ++L) {
auto const& p = x.layers_[L];
if (p.bar_ < 0) continue;
_hProbePred->Fill(L);
if (p.dBar_ == INT8_MAX) continue;
_hProbeHit->Fill(L);
if (p.inCluster_) _hProbeInCluster->Fill(L);
_hProbeDBar->Fill(p.dBar_);
_hProbeDt->Fill(p.dt_);
_hProbePE->Fill(p.pe_);
if (!std::isnan(p.uTdiv_)) _hProbeDu->Fill(p.uTdiv_ - p.uPred_);
}
}
}
return 0;
}
71 changes: 71 additions & 0 deletions Validation/src/ValTrkCrvMatchMC.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "Offline/Validation/inc/ValTrkCrvMatchMC.hh"
#include <cmath>

int mu2e::ValTrkCrvMatchMC::declare(const art::TFileDirectory& tfs) {
int ns = _axis.n();
double lo = _axis.lo(), hi = _axis.hi();
_hVer = tfs.make<TH1D>("Ver", "Version Number", 101, -0.5, 100.0);
_hBestGeomRel = tfs.make<TH1D>("BestGeomRel", "best geometric candidate, MCRelationship to the track's particle: 0 no MC, 1 unrelated, 2 same, 3 daughter, 4 mother, 5 sibling, 6 udaughter, 7 umother, 8 usibling", 9, -0.5, 8.5);
_hBestTimeRel = tfs.make<TH1D>("BestTimeRel", "best time candidate, MCRelationship to the track's particle", 9, -0.5, 8.5);
_hGeomCandRel = tfs.make<TH1D>("GeomCandRel", "all geometric candidates, MCRelationship", 9, -0.5, 8.5);
_hTimeCandRel = tfs.make<TH1D>("TimeCandRel", "time-only candidates, MCRelationship", 9, -0.5, 8.5);
_hTrueClu = tfs.make<TH1D>("TrueClu", "own cluster of the track's particle per sector", ns, lo, hi);
_hTrueCluGeom = tfs.make<TH1D>("TrueCluGeom", "own cluster is a geometric candidate", ns, lo, hi);
_hTrueCluBest = tfs.make<TH1D>("TrueCluBest", "own cluster is the best in its sector", ns, lo, hi);
_hRecoXing = tfs.make<TH1D>("RecoXing", "reco crossings per sector", ns, lo, hi);
_hRecoXingTrue = tfs.make<TH1D>("RecoXingTrue", "reco crossings with a true crossing of the same sector", ns, lo, hi);
_hTrueXing = tfs.make<TH1D>("TrueXing", "true crossings of the track's particle per sector", ns, lo, hi);
_hTrueXingFound = tfs.make<TH1D>("TrueXingFound", "true crossings with a reco crossing", ns, lo, hi);
_hXingDist = tfs.make<TH2D>("XingDist", "|reco - true crossing|;sector;mm", ns, lo, hi, 100, 0., 500.);
_hXingDt = tfs.make<TH2D>("XingDt", "reco - true crossing time;sector;ns", ns, lo, hi, 100, -20., 20.);
for (TH1* h : {static_cast<TH1*>(_hTrueClu), static_cast<TH1*>(_hTrueCluGeom), static_cast<TH1*>(_hTrueCluBest),
static_cast<TH1*>(_hRecoXing), static_cast<TH1*>(_hRecoXingTrue), static_cast<TH1*>(_hTrueXing),
static_cast<TH1*>(_hTrueXingFound), static_cast<TH1*>(_hXingDist), static_cast<TH1*>(_hXingDt)})
_axis.label(h->GetXaxis());
return 0;
}

int mu2e::ValTrkCrvMatchMC::fill(const mu2e::TrkCrvMatchMCCollection& coll, art::Event const& event) {
// increment this by 1 any time the definitions of the histograms or the
// histogram contents change, and will not match previous versions
_hVer->Fill(1.0);

for (auto const& mc : coll) {
if (mc.match_.isNull() || !mc.match_.isAvailable()) continue;
auto const& m = *mc.match_;
if (mc.cands_.size() != m.cands_.size()) continue;
auto relBin = [](TrkCrvCandidateMC const& cm) { return cm.hasMC_ ? cm.rel_.relationship() + 2 : 0; }; // 0 no MC, 1 none, 2 same, ...
if (m.bestGeom_ >= 0) _hBestGeomRel->Fill(relBin(mc.cands_[m.bestGeom_]));
if (m.bestTime_ >= 0) _hBestTimeRel->Fill(relBin(mc.cands_[m.bestTime_]));
for (size_t j = 0; j < m.cands_.size(); ++j)
(m.cands_[j].hasFlag(TrkCrvCandidate::geomCand) ? _hGeomCandRel : _hTimeCandRel)->Fill(relBin(mc.cands_[j]));
for (auto const& xm : mc.xings_) {
if (xm.rel_ != MCRelationship::same) continue;
int b = _axis.bin(xm.sid_);
if (xm.geom_) {
_hTrueXing->Fill(b);
if (xm.recoXing_ >= 0) _hTrueXingFound->Fill(b);
}
if (xm.trueCluster_ < 0) continue;
_hTrueClu->Fill(b);
if (xm.trueCand_ < 0 || static_cast<size_t>(xm.trueCand_) >= m.cands_.size()) continue;
auto const& c = m.cands_[xm.trueCand_];
if (!c.hasFlag(TrkCrvCandidate::geomCand)) continue;
_hTrueCluGeom->Fill(b);
if (c.hasFlag(TrkCrvCandidate::bestInSector)) _hTrueCluBest->Fill(b);
}
for (size_t ir = 0; ir < m.xings_.size() && ir < mc.recoXingTruth_.size(); ++ir) {
auto const& rx = m.xings_[ir];
int b = _axis.bin(rx.sid_);
_hRecoXing->Fill(b);
int t = mc.recoXingTruth_[ir];
if (t < 0 || static_cast<size_t>(t) >= mc.xings_.size()) continue;
_hRecoXingTrue->Fill(b);
auto const& xm = mc.xings_[t];
if (!xm.geom_ || xm.rel_ != MCRelationship::same) continue;
_hXingDist->Fill(b, std::sqrt((rx.pos_ - xm.pos_).Mag2()));
_hXingDt->Fill(b, rx.time_ - xm.time_);
}
}
return 0;
}
6 changes: 6 additions & 0 deletions Validation/src/Validation_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "Offline/Validation/inc/ValTimeCluster.hh"
#include "Offline/Validation/inc/ValTriggerInfo.hh"
#include "Offline/Validation/inc/ValTriggerResults.hh"
#include "Offline/Validation/inc/ValTrkCrvMatch.hh"
#include "Offline/Validation/inc/ValTrkCrvMatchMC.hh"
#include "art/Framework/Core/EDAnalyzer.h"
#include "art_root_io/TFileService.h"
#include "fhiclcpp/types/Atom.h"
Expand Down Expand Up @@ -103,6 +105,8 @@ class Validation : public art::EDAnalyzer {
std::vector<std::shared_ptr<ValComboHit>> _stht;
std::vector<std::shared_ptr<ValTriggerResults>> _trrs;
std::vector<std::shared_ptr<ValTriggerInfo>> _tris;
std::vector<std::shared_ptr<ValTrkCrvMatch>> _tcrv;
std::vector<std::shared_ptr<ValTrkCrvMatchMC>> _tcmc;

// Loop over the products of type T and
// call fill() on validation histogram class V to make histograms.
Expand Down Expand Up @@ -155,6 +159,8 @@ void mu2e::Validation::analyze(art::Event const& event) {
analyzeProduct<TimeClusterCollection, ValTimeCluster>(_tmcl, event);
analyzeProduct<HelixSeedCollection, ValHelixSeed>(_hxsd, event);
analyzeProduct<KalSeedCollection, ValKalSeed>(_klsd, event);
analyzeProduct<TrkCrvMatchCollection, ValTrkCrvMatch>(_tcrv, event);
analyzeProduct<TrkCrvMatchMCCollection, ValTrkCrvMatchMC>(_tcmc, event);
analyzeProduct<STMWaveformDigiCollection, ValSTMWaveformDigi>(_stmw, event);
analyzeProduct<STMWaveformDigiCollectionMap, ValSTMWaveformDigi>(_stmw, event);
analyzeProduct<art::TriggerResults, ValTriggerResults>(_trrs, event);
Expand Down