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",
""))
40 fDetectorProperties = std::make_unique<detinfo::DetectorPropertiesData const>(detectorProperties);
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 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);
360 TVector3& start, TVector3&
end, TVector3& startmom, TVector3& endmom,
361 unsigned int tpc,
unsigned int cstat)
const
368 int n = part.NumberTrajectoryPoints();
374 if (part.TrackId() == findTrackID)
std::cout <<
">>> length, mcpart: " << part << std::endl;
377 for(
int i = 0; i <
n; ++i)
379 TVector3 posInTPC(0.,0.,0.);
380 TVector3 posVec = part.Position(i).Vect();
381 double pos[] = {posVec.X(),posVec.Y(),posVec.Z()};
385 unsigned int cstat(0);
395 if (part.TrackId() == findTrackID)
396 std::cout <<
" --> traj point: " << i <<
", pos: " << posVec.X() <<
"/" << posVec.Y() <<
"/" << posVec.Z() <<
", active pos: " << activePos.X() <<
"/" << activePos.Y() <<
"/" << activePos.Z() << std::endl;
400 posInTPC = TVector3(activePos.X() + tpcGeo.
ActiveHalfWidth(), activePos.Y(), activePos.Z());
401 }
catch(...) {
continue;}
412 if (part.TrackId() == findTrackID)
413 std::cout <<
" ==> tpc: " << tpc <<
", cstat: " << cstat <<
", ticks: " << ticks << std::endl;
422 startmom = part.Momentum(i).Vect();
427 result += disp.Mag();
432 endmom = part.Momentum(i).Vect();
435 if (part.TrackId() == findTrackID)
439 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
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