4 art::ServiceHandle<cheat::BackTrackerService> bt_serv;
5 std::map<int, float> trackIDToEDepMap;
6 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
7 art::Ptr<recob::Hit>
hit = *hitIt;
8 std::vector<sim::TrackIDE> trackIDs = bt_serv->HitToTrackIDEs(clockData, hit);
9 for (
unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
10 int id = trackIDs[idIt].trackID;
11 if (rollup_unsaved_ids)
id =
std::abs(
id);
13 trackIDToEDepMap[id] += trackIDs[idIt].energy;
17 std::vector<std::pair<int, float>> ret;
18 for (
auto const &pair: trackIDToEDepMap) {
26 art::ServiceHandle<cheat::BackTrackerService> bt;
29 const std::vector<art::Ptr<recob::Hit>> matched_reco_track_hits = bt->TrackIdToHits_Ps(clockData, mcparticle_id, reco_track_hits);
32 float matched_reco_energy = 0.;
33 float reco_energy = 0.;
34 for (
auto const &matched_reco_track_hit: matched_reco_track_hits) {
35 std::vector<sim::IDE> this_hit_IDEs = bt->HitToAvgSimIDEs(clockData, *matched_reco_track_hit);
36 for (
auto const &ide: this_hit_IDEs) {
37 reco_energy += ide.energy;
38 if (ide.trackID == mcparticle_id) {
39 matched_reco_energy += ide.energy;
44 return (reco_energy > 1
e-6) ? matched_reco_energy / reco_energy : 1.;
48 art::ServiceHandle<cheat::BackTrackerService> bt_serv;
52 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
53 art::Ptr<recob::Hit>
hit = *hitIt;
54 std::vector<sim::TrackIDE> trackIDs = bt_serv->HitToTrackIDEs(clockData, hit);
55 for (
unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
56 ret += trackIDs[idIt].energy;
64 art::ServiceHandle<cheat::BackTrackerService> bt;
67 const std::vector<const sim::IDE*> mcparticle_ides = bt->TrackIdToSimIDEs_Ps(mcparticle_id);
69 float mcparticle_energy = 0.;
70 for (
auto const &ide: mcparticle_ides) {
71 mcparticle_energy += ide->energy;
75 const std::vector<art::Ptr<recob::Hit>> matched_reco_track_hits = bt->TrackIdToHits_Ps(clockData, mcparticle_id, reco_track_hits);
78 float matched_reco_energy = 0.;
79 for (
auto const &matched_reco_track_hit: matched_reco_track_hits) {
80 std::vector<sim::IDE> this_hit_IDEs = bt->HitToAvgSimIDEs(clockData, *matched_reco_track_hit);
81 for (
auto const &ide: this_hit_IDEs) {
82 if (ide.trackID == mcparticle_id) {
83 matched_reco_energy += ide.energy;
88 return matched_reco_energy / mcparticle_energy;
93 art::ServiceHandle<cheat::ParticleInventoryService> particleInventory;
94 const sim::ParticleList& particles = particleInventory->ParticleList();
95 const sim::ParticleList::const_iterator part_iter = particles.find(g4ID);
96 if(part_iter == particles.end())
return g4ID;
98 auto temp_iter = part_iter;
99 int primary_id = part_iter->second->TrackId();
101 while (
std::abs(temp_iter->second->PdgCode()) == 11 || temp_iter->second->PdgCode() == 22)
103 primary_id = temp_iter->second->TrackId();
104 temp_iter = particles.find(temp_iter->second->Mother());
105 if(temp_iter == particles.end())
break;
float TrackPurity(const detinfo::DetectorClocksData &clockData, int mcparticle_id, const std::vector< art::Ptr< recob::Hit >> &reco_track_hits)
std::vector< std::pair< int, float > > AllTrueParticleIDEnergyMatches(const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
int GetShowerPrimary(const int g4ID)
Contains all timing reference information for the detector.
float TotalHitEnergy(const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit > > &hits)
float TrackCompletion(const detinfo::DetectorClocksData &clockData, int mcparticle_id, const std::vector< art::Ptr< recob::Hit >> &reco_track_hits)