13 #include "nusimdata/SimulationBase/MCTruth.h"
18 #include "canvas/Persistency/Common/FindMany.h"
28 : fHitProducerLabel(config.
get<art::InputTag>(
"HitProducerLabel",
"")),
29 fMCTruthProducerLabel(config.
get<art::InputTag>(
"MCTruthProducerLabel",
"")),
30 fAssnsProducerLabel(config.
get<art::InputTag>(
"MCTrackAssnsProducerLabel",
"")),
31 fTrackProducerLabel(config.
get<art::InputTag>(
"TrackProducerLabel",
"")),
32 fLocalDirName(config.
get<
std::
string>(
"LocalDirName",
""))
48 fNTracks = std::make_unique<TH1F>(
"NTrueTracks",
"Number of tracks;number of tracks;events", 100, 0., 200.);
50 fNHitsPerTrack = std::make_unique<TH1F>(
"NHitsPerTrack",
"Number Hits/Track", 250, 0., 250.);
52 fTrackLength = std::make_unique<TH1F>(
"TrackLength",
"Length; track length(cm)", 200, 0., 200.);
54 fTrackLenVsHits = std::make_unique<TH2F>(
"TrackLenVsHits",
"Length;Hits", 200, 0., 200., 250, 0., 250.);
56 fNHitsPerPrimary = std::make_unique<TH1F>(
"NHitsPerPrimary",
"Number Hits/Primary;log(# hits)", 15, 0.5, 3.5);
58 fPrimaryLength = std::make_unique<TH1F>(
"PrimaryLength",
"Length of Primary;length(cm)", 50, 0., 350.);
60 fPrimaryLenVsHits = std::make_unique<TH2F>(
"PrimaryLenVsHits",
"Length;Hits", 50, 0., 350., 250, 0., 2500.);
63 fNHitsPerReco = std::make_unique<TH1F>(
"PrimaryRecoNHits",
"Number Hits/Track;log(# hits)", 15, 0.5, 3.5);
65 fDeltaNHits = std::make_unique<TH1F>(
"DeltaNHits",
"Delta Number Hits", 100, -200., 200.);
67 fPrimaryRecoLength = std::make_unique<TH1F>(
"PrimaryRecLength",
"Length of Reco; length(cm)", 50, 0., 350.);
69 fDeltaTrackLen = std::make_unique<TH1F>(
"DeltaTrackLen",
"Delta Track Length", 100, -100., 100.);
72 fPrimaryEfficiency = std::make_unique<TH1F>(
"PrimaryEfficiency",
"Efficiency", 101, 0., 1.01);
74 fPrimaryCompleteness = std::make_unique<TH1F>(
"PrimaryCompleteness",
"Completeness", 101, 0., 1.01);
76 fPrimaryPurity = std::make_unique<TH1F>(
"PrimaryPurity",
"Purity", 101, 0., 1.01);
79 fPrimaryEffVsMom = std::make_unique<TProfile>(
"PrimaryEffVsMom",
"Efficiency vs Momentum;Momentum(GeV/c);Efficiency", 25, 0.1, 1.10, 0., 1.1);
81 fPrimaryCompVsMom = std::make_unique<TProfile>(
"PrimaryCompVsMom",
"Completeness vs Momentum;Momentum(GeV/c);Completeness", 25, 0.1, 1.10, 0., 1.1);
83 fPrimaryPurityVsMom = std::make_unique<TProfile>(
"PrimaryPurVsMom",
"Purity vs Momentum;Momentum(GeV/c);Purity", 25, 0.1, 1.10, 0., 1.1);
86 fPrimaryEffVsLen = std::make_unique<TProfile>(
"PrimaryEffVsLen",
"Efficiency vs Length; length; Efficiency", 30, 0., 300., 0., 1.1);
88 fPrimaryCompVsLen = std::make_unique<TProfile>(
"PrimaryCompVsLen",
"Completeness vs Length; length; Completeness", 30, 0., 300., 0., 1.1);
90 fPrimaryPurityVsLen = std::make_unique<TProfile>(
"PrimaryPurVsLen",
"Purity vs Length; length; Purity", 30, 0., 300., 0., 1.1);
93 fPrimaryEffVsHits = std::make_unique<TProfile>(
"PrimaryEffVsHits",
"Efficiency vs # Hits", 50, 0., 2000., 0., 1.1);
95 fPrimaryCompVsHits = std::make_unique<TProfile>(
"PrimaryCompVsHits",
"Completeness vs # Hits", 50, 0., 2000., 0., 1.1);
97 fPrimaryPurityVsHits = std::make_unique<TProfile>(
"PrimaryPurityVsHits",
"Purity vs # Hits", 50, 0., 2000., 0., 1.1);
100 fPrimaryEffVsLogHits = std::make_unique<TProfile>(
"PrimaryEffVsLogHits",
"Efficiency vs log(# Hits);log(# Hits);Efficiency", 15, 0.5, 3.5, 0., 1.1);
102 fPrimaryCompVsLogHits = std::make_unique<TProfile>(
"PrimaryCompVsLogHits",
"Completeness vs log(# Hits);log(# Hits);Completeness)", 15, 0.5, 3.5, 0., 1.1);
104 fPrimaryPurityVsLogHits = std::make_unique<TProfile>(
"PrimaryPurityVsLogHits",
"Purity vs log(# Hits);log(# Hits);Purity)", 15, 0.5, 3.5, 0., 1.1);
120 const auto& mcParticleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fMCTruthProducerLabel);
123 const auto& hitHandle =
event.getValidHandle<std::vector<recob::Hit>>(
fHitProducerLabel);
126 art::FindMany<recob::Hit, anab::BackTrackerHitMatchingData> hitsPerMCParticle(mcParticleHandle, event,
fAssnsProducerLabel);
129 using HitToPartVecMap = std::map<const recob::Hit*,std::set<const simb::MCParticle*>>;
130 using PartToHitVecMap = std::map<const simb::MCParticle*, std::set<const recob::Hit*>>;
132 HitToPartVecMap hitToPartVecMap;
133 PartToHitVecMap partToHitVecMap;
136 for(
int mcIdx = 0; mcIdx < mcParticleHandle->size(); mcIdx++)
140 const simb::MCParticle& mcParticle = mcParticleHandle->at(mcIdx);
142 std::vector<const recob::Hit*> hitsVec = hitsPerMCParticle.at(mcIdx);
144 for(
const auto&
hit : hitsVec)
146 hitToPartVecMap[
hit].insert(&mcParticle);
147 partToHitVecMap[&mcParticle].insert(
hit);
155 const auto& trackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTrackProducerLabel);
161 using TrackToParticleSetMap = std::map<const recob::Track*, std::set<const simb::MCParticle*>>;
162 using ParticleToTrackSetMap = std::map<const simb::MCParticle*, std::set<const recob::Track*>>;
163 using ParticleToHitSetMap = std::map<const simb::MCParticle*, std::set<const recob::Hit*>>;
164 using TrackToPartHitSetMap = std::map<const recob::Track*, ParticleToHitSetMap>;
165 using TrackToHitsVecMap = std::map<const recob::Track*, std::vector<const recob::Hit*>>;
167 TrackToParticleSetMap trackToParticleSetMap;
168 ParticleToTrackSetMap particleToTrackSetMap;
170 TrackToPartHitSetMap trackToPartHitSetMap;
171 TrackToHitsVecMap trackToHitsVecMap;
174 for(
int trkIdx = 0; trkIdx < trackHandle->size(); trkIdx++)
178 std::vector<const recob::Hit*> hitsVec = hitsPerTrack.at(trkIdx);
180 trackToHitsVecMap[&
track] = hitsVec;
182 ParticleToHitSetMap& particleToHitSetMap = trackToPartHitSetMap[&
track];
184 for(
const auto&
hit : hitsVec)
186 HitToPartVecMap::iterator partItr = hitToPartVecMap.find(
hit);
188 if (partItr != hitToPartVecMap.end())
190 for(
const auto& particle : partItr->second)
192 particleToHitSetMap[particle].insert(
hit);
193 trackToParticleSetMap[&
track].insert(particle);
194 particleToTrackSetMap[particle].insert(&track);
205 const simb::MCParticle& primaryParticle = mcParticleHandle->at(0);
207 ParticleToTrackSetMap::iterator partTrackItr = particleToTrackSetMap.find(&primaryParticle);
210 int numPrimaryHitsTotal = partToHitVecMap[&primaryParticle].size();
214 if (numPrimaryHitsTotal > 0)
217 float efficiency(0.);
218 float completeness(0.);
224 if (partTrackItr != particleToTrackSetMap.end())
227 for(
const auto& track : partTrackItr->second)
229 if (trackToPartHitSetMap[track][partTrackItr->first].size() > numTrackHits)
232 numTrackHits = trackToPartHitSetMap[
track][partTrackItr->first].size();
238 int numPrimaryHitsMatch = numTrackHits;
239 int numTrackHitsTotal = trackToHitsVecMap[bestTrack].size();
241 completeness = float(numPrimaryHitsMatch) / float(numPrimaryHitsTotal);
242 purity = float(numPrimaryHitsMatch) / float(numTrackHitsTotal);
244 if (completeness > 0.2) efficiency = 1.;
256 double mcTrackLen =
length(primaryParticle, xOffset, mcstart, mcend, mcstartmom, mcendmom);
257 double trackLen = 0.;
259 if (bestTrack) trackLen =
length(bestTrack);
261 fNTracks->Fill(partToHitVecMap.size(), 1.);
270 fDeltaNHits->Fill(numTrackHits -
int(partToHitVecMap[&primaryParticle].
size()), 1.);
273 for(
int mcIdx = 0; mcIdx < mcParticleHandle->size(); mcIdx++)
277 const simb::MCParticle& mcParticle = mcParticleHandle->at(mcIdx);
279 if (!partToHitVecMap[&mcParticle].
empty())
282 double secTrackLen =
length(mcParticle, xOffset, mcstart, mcend, mcstartmom, mcendmom);
301 double partMom = primaryParticle.P();
310 double logNumHits = std::log10(numPrimaryHitsTotal);
363 TVector3& start, TVector3&
end, TVector3& startmom, TVector3& endmom,
364 unsigned int tpc,
unsigned int cstat)
const
371 int n = part.NumberTrajectoryPoints();
377 if (part.TrackId() == findTrackID)
std::cout <<
">>> length, mcpart: " << part << std::endl;
380 for(
int i = 0; i <
n; ++i)
382 TVector3 posInTPC(0.,0.,0.);
383 TVector3 posVec = part.Position(i).Vect();
384 double pos[] = {posVec.X(),posVec.Y(),posVec.Z()};
388 unsigned int cstat(0);
398 if (part.TrackId() == findTrackID)
399 std::cout <<
" --> traj point: " << i <<
", pos: " << posVec.X() <<
"/" << posVec.Y() <<
"/" << posVec.Z() <<
", active pos: " << activePos.X() <<
"/" << activePos.Y() <<
"/" << activePos.Z() << std::endl;
403 posInTPC = TVector3(activePos.X() + tpcGeo.
ActiveHalfWidth(), activePos.Y(), activePos.Z());
404 }
catch(...) {
continue;}
415 if (part.TrackId() == findTrackID)
416 std::cout <<
" ==> tpc: " << tpc <<
", cstat: " << cstat <<
", ticks: " << ticks << std::endl;
425 startmom = part.Momentum(i).Vect();
430 result += disp.Mag();
435 endmom = part.Momentum(i).Vect();
438 if (part.TrackId() == findTrackID)
442 std::cout <<
">>> Track #" << findTrackID <<
", pos: " << posVec.X() <<
", " << posVec.Y() <<
", " << posVec.Z() <<
", ticks: " << ticks <<
", nearest Y wire: ";
std::unique_ptr< TH1 > fPrimaryCompleteness
art::InputTag fAssnsProducerLabel
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Point GetActiveVolumeCenter() const
Returns the center of the TPC active volume in world coordinates [cm].
std::unique_ptr< TProfile > fPrimaryEffVsLen
std::unique_ptr< TH1 > fPrimaryPurity
const geo::GeometryCore * geometry
std::string fLocalDirName
double ActiveHalfHeight() const
Half height (associated with y coordinate) of active TPC volume [cm].
Declaration of signal hit object.
std::unique_ptr< TH1 > fPrimaryEfficiency
Geometry information for a single TPC.
std::unique_ptr< TProfile > fPrimaryCompVsLogHits
art::InputTag fHitProducerLabel
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
tick ticks
Alias for common language habits.
std::unique_ptr< TProfile > fPrimaryPurityVsMom
geo::TPCGeo const & PositionToTPC(geo::Point_t const &point) const
Returns the TPC at specified location.
std::unique_ptr< TProfile > fPrimaryPurityVsLen
std::unique_ptr< TH1 > fPrimaryRecoLength
double Length(size_t p=0) const
Access to various track properties.
double ActiveHalfWidth() const
Half width (associated with x coordinate) of active TPC volume [cm].
std::unique_ptr< detinfo::DetectorPropertiesData const > fDetectorProperties
std::unique_ptr< TProfile > fPrimaryCompVsMom
auto end(FixedBins< T, C > const &) noexcept
MCAssociations(fhicl::ParameterSet const &config)
std::unique_ptr< TH1 > fPrimaryLength
std::unique_ptr< TProfile > fPrimaryEffVsHits
std::unique_ptr< TH1 > fNHitsPerReco
Description of geometry of one entire detector.
double ActiveLength() const
Length (associated with z coordinate) of active TPC volume [cm].
void doTrackHitMCAssociations(gallery::Event &)
std::unique_ptr< TProfile > fPrimaryCompVsHits
std::unique_ptr< TProfile > fPrimaryEffVsLogHits
std::unique_ptr< TProfile > fPrimaryPurityVsLogHits
std::unique_ptr< TH2 > fTrackLenVsHits
geo::GeometryCore const * fGeometry
std::unique_ptr< TH1 > fDeltaTrackLen
std::unique_ptr< TH1 > fNHitsPerPrimary
geo::WireID NearestWireID(geo::Point_t const &point, geo::PlaneID const &planeid) const
Returns the ID of wire closest to position in the specified TPC.
double length(const recob::Track *) const
std::unique_ptr< TH1 > fTrackLength
art::InputTag fMCTruthProducerLabel
bool empty(FixedBins< T, C > const &) noexcept
BEGIN_PROLOG could also be cout
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
void setup(const geo::GeometryCore &, const detinfo::DetectorPropertiesData &, TDirectory *)
std::unique_ptr< TProfile > fPrimaryEffVsMom