13 #include "nusimdata/SimulationBase/MCTruth.h"
16 #include "messagefacility/MessageLogger/MessageLogger.h"
22 #include "canvas/Persistency/Common/FindMany.h"
62 for(HitParticleAssociations::const_iterator partHitItr = partToHitAssns->begin(); partHitItr != partToHitAssns->end(); ++partHitItr)
64 const art::Ptr<simb::MCParticle>& mcParticle = partHitItr->first;
65 const art::Ptr<recob::Hit>& recoHit = partHitItr->second;
72 mf::LogDebug(
"MCTruthAssociations") <<
"Built maps with " << hitPartAssns.
fHitToPartVecMap.size() <<
" hits, " << hitPartAssns.
fPartToHitVecMap.size() <<
"\n";
80 for(
const auto& mcParticle : mcPartVec)
86 art::Ptr<simb::MCTruth> mcTruth = truthToPartAssns.at(mcParticle.key());
96 mf::LogDebug(
"MCTruthAssociations") <<
">>>> No MCTruth found for particle: " << *mcParticle <<
"\n";
116 const simb::MCParticle* mcParticle(0);
124 mf::LogWarning(
"MCTruthAssociations") <<
"can't find particle with track id "
125 <<
id <<
" in MCTruthParticleList"
126 <<
" returning null pointer";
146 throw cet::exception(
"MCTruthAssociations") <<
"attempting to find MCTruth index for "
147 <<
"out of range value: " <<
id
150 return trackTruthItr->second;
160 std::vector<const simb::MCParticle*> ret;
167 if (
TrackIDToMCTruth(TrackIDpair.first) == mct) ret.push_back(TrackIDpair.second);
182 std::vector<TrackIDE> trackIDEs;
187 HitToPartVecMap::const_iterator hitMatchPairItr = hitPartAssns.fHitToPartVecMap.find(hit);
189 if (hitMatchPairItr != hitPartAssns.fHitToPartVecMap.end())
191 size_t nTrackIDEs(hitMatchPairItr->second.size());
193 trackIDEs.reserve(nTrackIDEs);
195 for (
const auto& matchPair : hitMatchPairItr->second)
197 const simb::MCParticle* part = matchPair.first;
202 trackIDE.
trackID = part->TrackId();
207 trackIDEs.emplace_back(trackIDE);
224 std::vector<int>
const& tkIDs)
const
231 std::unordered_map<int, std::vector<art::Ptr<recob::Hit>>> trackIDHitVecMap;
233 for(
const auto&
hit : allHits)
237 for(
const auto trackIDE : trackIDEVec)
239 for(
auto trackID : tkIDs)
243 trackIDHitVecMap[trackID].push_back(
hit);
250 std::vector<std::vector<art::Ptr<recob::Hit>>> truHits;
252 for(
const auto& trackHitPair : trackIDHitVecMap) truHits.emplace_back(trackHitPair.second);
263 std::vector<TrackIDE> trackIDEVec = this->
HitToTrackID(hit.get());
269 std::unordered_map<int, TrackIDE> idToTrackIDEMap;
271 for(
const auto& trackID : trackIDEVec)
273 int eveTrackID = particleList.EveId(trackID.trackID);
274 TrackIDE& eveTrackIDE = idToTrackIDEMap[eveTrackID];
276 eveTrackIDE.
trackID = eveTrackID;
278 eveTrackIDE.
energy += trackID.energy;
283 std::vector<TrackIDE> eveTrackIDEVec;
285 for(
const auto& eveIDEPair : idToTrackIDEMap) eveTrackIDEVec.emplace_back(eveIDEPair.second);
287 return eveTrackIDEVec;
293 mf::LogWarning(
"MCTruthAssociations") <<
" ** HitToXYZ currently not implemented in MCTruthAssociations, return a zero point";
294 return std::vector<double>() = {0.,0.,0.};
300 mf::LogWarning(
"MCTruthAssociations") <<
" ** SpacePointHitsToXYZ currently not implemented in MCTruthAssociations, return a zero point";
301 return std::vector<double>() = {0.,0.,0.};
306 const std::vector< art::Ptr<recob::Hit> >& hitVec)
const
310 float total = hitVec.size();;
316 for(
const auto&
hit : hitVec)
320 for(
const auto& trackIDE : hitTrackIDEVec)
322 if (trackIDs.find(trackIDE.trackID) != trackIDs.end())
331 if(total > 0) purity = desired/total;
340 const std::vector< art::Ptr<recob::Hit> >& allHitVec,
351 for(
const auto&
hit : hitVec)
359 for(
const auto& trackIDE : hitTrackIDs)
361 if (trackIDs.find(trackIDE.trackID) != trackIDs.end() &&
371 for(
const auto&
hit : allHitVec)
376 if(
hit->View() != view && view !=
geo::k3D )
continue;
380 for (
const auto& trackIDE : hitTrackIDs)
382 if (trackIDs.find(trackIDE.trackID) != trackIDs.end() &&
391 double efficiency = 0.;
392 if(total > 0.) efficiency = desired/total;
399 const std::vector< art::Ptr<recob::Hit> >& hitVec)
const
409 for(
const auto&
hit : hitVec)
413 total +=
hit->Integral();
415 for(
const auto& trackIDE : hitTrackIDEVec)
417 if (trackIDs.find(trackIDE.trackID) != trackIDs.end())
419 desired +=
hit->Integral();
427 if(total > 0) purity = desired/total;
436 const std::vector< art::Ptr<recob::Hit> >& allHitVec,
447 for(
const auto&
hit : hitVec)
455 for(
const auto& trackIDE : hitTrackIDs)
457 if (trackIDs.find(trackIDE.trackID) != trackIDs.end() &&
460 desired +=
hit->Integral();
467 for(
const auto&
hit : allHitVec)
472 if(
hit->View() != view && view !=
geo::k3D )
continue;
476 for (
const auto& trackIDE : hitTrackIDs)
478 if (trackIDs.find(trackIDE.trackID) != trackIDs.end() &&
481 total +=
hit->Integral();
487 double efficiency = 0.;
488 if(total > 0.) efficiency = desired/total;
496 std::set<int> eveIDs;
499 for(
const auto& pl : particleList) eveIDs.insert(particleList.EveId(pl.first));
508 std::set<int> trackIDs;
511 for (
const auto& pl: particleList) trackIDs.insert(pl.first);
519 std::set<int> eveIDs;
521 for(
const auto&
hit : hitVec)
526 for(
const auto& trackIDE : ideVec) eveIDs.insert(trackIDE.trackID);
535 std::set<int> trackIDs;
537 for(
const auto&
hit : hitVec)
541 for(
const auto& trackIDE : trackIDEVec) trackIDs.insert(trackIDE.trackID);
557 const simb::MCParticle& part,
double dx,
558 TVector3& start, TVector3&
end, TVector3& startmom, TVector3& endmom,
559 unsigned int tpc,
unsigned int cstat)
const
573 int n = part.NumberTrajectoryPoints();
577 for(
int i = 0; i <
n; ++i)
579 TVector3 pos = part.Position(i).Vect();
588 if(pos.X() >= xmin &&
598 if(ticks >= 0. && ticks < readOutWindowSize)
603 startmom = part.Momentum(i).Vect();
608 result += disp.Mag();
613 endmom = part.Momentum(i).Vect();
std::pair< const simb::MCParticle *, const anab::BackTrackerHitMatchingData * > PartMatchDataPair
art::Assns< simb::MCParticle, recob::Hit, anab::BackTrackerHitMatchingData > HitParticleAssociations
list_type::const_iterator const_iterator
std::pair< const recob::Hit *, const anab::BackTrackerHitMatchingData * > HitMatchDataPair
MCTruthTruthVec fMCTruthVec
all the MCTruths for the event
double HitChargeCollectionEfficiency(std::set< int >, std::vector< art::Ptr< recob::Hit > > const &, std::vector< art::Ptr< recob::Hit > > const &, geo::View_t const &) const
std::vector< art::Ptr< simb::MCTruth >> MCTruthTruthVec
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
const geo::GeometryCore * geometry
const std::vector< std::vector< art::Ptr< recob::Hit > > > TrackIDsToHits(std::vector< art::Ptr< recob::Hit >> const &, std::vector< int > const &) const
HitToPartVecMap fHitToPartVecMap
Mapping from hits to associated MCParticle/data pairs.
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
Declaration of signal hit object.
HitPartAssnsList fHitPartAssnsVec
Container for the (multiple) associations.
float fMinHitEnergyFraction
Ionization energy from a Geant4 track.
std::vector< TrackIDE > HitToEveID(art::Ptr< recob::Hit > const &hit) const
unsigned int ReadOutWindowSize() const
process_name use argoneut_mc_hitfinder track
MCTruthTrackIDMap fTrackIDToMCTruthIndex
map of track ids to MCTruthList entry
PartToHitVecMap fPartToHitVecMap
Mapping from MCParticle to associated hit/data pairs.
art::FindOneP< simb::MCTruth > MCTruthAssns
std::vector< art::Ptr< simb::MCParticle >> MCParticleVec
tick ticks
Alias for common language habits.
MCTruthAssociations(fhicl::ParameterSet const &config)
float numElectrons
number of electrons from the particle detected on the wires
const simb::MCParticle * TrackIDToMotherParticle(int const &id) const
std::vector< TrackIDE > HitToTrackID(const recob::Hit *) const
int EveId(const int trackID) const
3-dimensional objects, potentially hits, clusters, prongs, etc.
list_type::value_type value_type
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
double length(const recob::Track *) const
float energy
energy from the particle with this trackID [MeV]
Example routine for calculating the "ultimate e-m mother" of a particle in a simulated event...
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
double Length(size_t p=0) const
Access to various track properties.
std::set< int > GetSetOfTrackIDs() const
This algorithm attempts to decode Track and Hit <–> MCParticle assocations.
std::set< int > GetSetOfEveIDs() const
void AdoptEveIdCalculator(MCTruthEveIdCalculator *) const
double HitCollectionPurity(std::set< int >, std::vector< art::Ptr< recob::Hit > > const &) const
const art::Ptr< simb::MCTruth > & TrackIDToMCTruth(int const &id) const
int trackID
Geant4 supplied trackID.
auto end(FixedBins< T, C > const &) noexcept
double ConvertXToTicks(double X, int p, int t, int c) const
double HitCollectionEfficiency(std::set< int >, std::vector< art::Ptr< recob::Hit > > const &, std::vector< art::Ptr< recob::Hit > > const &, geo::View_t const &) const
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
double HitChargeCollectionPurity(std::set< int >, std::vector< art::Ptr< recob::Hit > > const &) const
const simb::MCParticle * TrackIDToParticle(int const &id) const
Description of geometry of one entire detector.
const art::Ptr< simb::MCTruth > & ParticleToMCTruth(const simb::MCParticle *p) const
iterator find(const key_type &key)
const MCTruthParticleList & getParticleList() const
void Add(const simb::MCParticle *value)
std::vector< const HitParticleAssociations * > HitParticleAssociationsVec
std::vector< double > HitToXYZ(art::Ptr< recob::Hit > const &hit) const
std::vector< double > SpacePointHitsToXYZ(art::PtrVector< recob::Hit > const &hits) const
MCTruthParticleList fParticleList
ParticleList to map track ID to.
float energyFrac
fraction of hit energy from the particle with this trackID
2D representation of charge deposited in the TDC/wire plane
std::vector< const simb::MCParticle * > MCTruthToParticles(art::Ptr< simb::MCTruth > const &mct) const
geo::GeometryCore const * fGeometry
void setup(const HitParticleAssociationsVec &, const MCParticleVec &, const MCTruthAssns &, const geo::GeometryCore &)
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
const MCTruthTruthVec & MCTruthVector() const