120 const auto& mcParticleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fMCTruthProducerLabel);
123 art::FindMany<recob::Hit, anab::BackTrackerHitMatchingData> hitsPerMCParticle(mcParticleHandle, event,
fAssnsProducerLabel);
126 using HitToPartVecMap = std::map<const recob::Hit*,std::set<const simb::MCParticle*>>;
127 using PartToHitVecMap = std::map<const simb::MCParticle*, std::set<const recob::Hit*>>;
129 HitToPartVecMap hitToPartVecMap;
130 PartToHitVecMap partToHitVecMap;
133 for(
size_t mcIdx = 0; mcIdx < mcParticleHandle->size(); mcIdx++)
137 const simb::MCParticle& mcParticle = mcParticleHandle->at(mcIdx);
139 std::vector<const recob::Hit*> hitsVec = hitsPerMCParticle.at(mcIdx);
141 for(
const auto&
hit : hitsVec)
143 hitToPartVecMap[
hit].insert(&mcParticle);
144 partToHitVecMap[&mcParticle].insert(
hit);
152 const auto& trackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTrackProducerLabel);
158 using TrackToParticleSetMap = std::map<const recob::Track*, std::set<const simb::MCParticle*>>;
159 using ParticleToTrackSetMap = std::map<const simb::MCParticle*, std::set<const recob::Track*>>;
160 using ParticleToHitSetMap = std::map<const simb::MCParticle*, std::set<const recob::Hit*>>;
161 using TrackToPartHitSetMap = std::map<const recob::Track*, ParticleToHitSetMap>;
162 using TrackToHitsVecMap = std::map<const recob::Track*, std::vector<const recob::Hit*>>;
164 TrackToParticleSetMap trackToParticleSetMap;
165 ParticleToTrackSetMap particleToTrackSetMap;
167 TrackToPartHitSetMap trackToPartHitSetMap;
168 TrackToHitsVecMap trackToHitsVecMap;
171 for(
size_t trkIdx = 0; trkIdx < trackHandle->size(); trkIdx++)
175 std::vector<const recob::Hit*> hitsVec = hitsPerTrack.at(trkIdx);
177 trackToHitsVecMap[&
track] = hitsVec;
179 ParticleToHitSetMap& particleToHitSetMap = trackToPartHitSetMap[&
track];
181 for(
const auto&
hit : hitsVec)
183 HitToPartVecMap::iterator partItr = hitToPartVecMap.find(
hit);
185 if (partItr != hitToPartVecMap.end())
187 for(
const auto& particle : partItr->second)
189 particleToHitSetMap[particle].insert(
hit);
190 trackToParticleSetMap[&
track].insert(particle);
191 particleToTrackSetMap[particle].insert(&track);
202 const simb::MCParticle& primaryParticle = mcParticleHandle->at(0);
204 ParticleToTrackSetMap::iterator partTrackItr = particleToTrackSetMap.find(&primaryParticle);
207 int numPrimaryHitsTotal = partToHitVecMap[&primaryParticle].size();
211 if (numPrimaryHitsTotal > 0)
214 float efficiency(0.);
215 float completeness(0.);
217 size_t numTrackHits(0);
221 if (partTrackItr != particleToTrackSetMap.end())
224 for(
const auto& track : partTrackItr->second)
226 if (trackToPartHitSetMap[track][partTrackItr->first].size() > numTrackHits)
229 numTrackHits = trackToPartHitSetMap[
track][partTrackItr->first].size();
235 int numPrimaryHitsMatch = numTrackHits;
236 int numTrackHitsTotal = trackToHitsVecMap[bestTrack].size();
238 completeness = float(numPrimaryHitsMatch) / float(numPrimaryHitsTotal);
239 purity = float(numPrimaryHitsMatch) / float(numTrackHitsTotal);
241 if (completeness > 0.2) efficiency = 1.;
253 double mcTrackLen =
length(primaryParticle, xOffset, mcstart, mcend, mcstartmom, mcendmom);
254 double trackLen = 0.;
256 if (bestTrack) trackLen =
length(bestTrack);
258 fNTracks->Fill(partToHitVecMap.size(), 1.);
267 fDeltaNHits->Fill(numTrackHits -
int(partToHitVecMap[&primaryParticle].
size()), 1.);
270 for(
size_t mcIdx = 0; mcIdx < mcParticleHandle->size(); mcIdx++)
274 const simb::MCParticle& mcParticle = mcParticleHandle->at(mcIdx);
276 if (!partToHitVecMap[&mcParticle].
empty())
279 double secTrackLen =
length(mcParticle, xOffset, mcstart, mcend, mcstartmom, mcendmom);
298 double partMom = primaryParticle.P();
307 double logNumHits = std::log10(numPrimaryHitsTotal);
std::unique_ptr< TH1 > fPrimaryCompleteness
art::InputTag fAssnsProducerLabel
std::unique_ptr< TProfile > fPrimaryEffVsLen
std::unique_ptr< TH1 > fPrimaryPurity
std::unique_ptr< TH1 > fPrimaryEfficiency
std::unique_ptr< TProfile > fPrimaryCompVsLogHits
std::unique_ptr< TProfile > fPrimaryPurityVsHits
std::unique_ptr< TProfile > fPrimaryCompVsLen
std::unique_ptr< TH2 > fPrimaryLenVsHits
std::size_t size(FixedBins< T, C > const &) noexcept
std::unique_ptr< TH1 > fNHitsPerTrack
process_name use argoneut_mc_hitfinder track
std::unique_ptr< TH1 > fNTracks
art::InputTag fTrackProducerLabel
std::unique_ptr< TH1 > fDeltaNHits
std::unique_ptr< TProfile > fPrimaryPurityVsMom
std::unique_ptr< TProfile > fPrimaryPurityVsLen
std::unique_ptr< TH1 > fPrimaryRecoLength
std::unique_ptr< TProfile > fPrimaryCompVsMom
std::unique_ptr< TH1 > fPrimaryLength
std::unique_ptr< TProfile > fPrimaryEffVsHits
std::unique_ptr< TH1 > fNHitsPerReco
std::unique_ptr< TProfile > fPrimaryCompVsHits
std::unique_ptr< TProfile > fPrimaryEffVsLogHits
std::unique_ptr< TProfile > fPrimaryPurityVsLogHits
std::unique_ptr< TH2 > fTrackLenVsHits
std::unique_ptr< TH1 > fDeltaTrackLen
std::unique_ptr< TH1 > fNHitsPerPrimary
double length(const recob::Track *) const
std::unique_ptr< TH1 > fTrackLength
art::InputTag fMCTruthProducerLabel
bool empty(FixedBins< T, C > const &) noexcept
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
std::unique_ptr< TProfile > fPrimaryEffVsMom