4 std::map<int,double> id_to_energy_map;
6 std::vector<sim::TrackIDE> track_ides = bt_serv->
HitToTrackIDEs(hit);
7 for (
unsigned int idIt = 0; idIt < track_ides.size(); ++idIt) {
8 int id = track_ides.at(idIt).trackID;
9 if (rollup_unsaved_ids)
id =
std::abs(
id);
10 double energy = track_ides.at(idIt).energy;
11 id_to_energy_map[id]+=energy;
14 double likely_particle_contrib_energy = -99999;
15 int likely_track_id = 0;
16 for (std::map<int,double>::iterator mapIt = id_to_energy_map.begin(); mapIt != id_to_energy_map.end(); mapIt++){
17 double particle_contrib_energy = mapIt->second;
18 if (particle_contrib_energy > likely_particle_contrib_energy){
19 likely_particle_contrib_energy = particle_contrib_energy;
20 likely_track_id = mapIt->first;
23 return likely_track_id;
30 std::map<int,double> trackIDToEDepMap;
31 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
32 art::Ptr<recob::Hit>
hit = *hitIt;
33 std::vector<sim::TrackIDE> trackIDs = bt_serv->
HitToTrackIDEs(hit);
34 for (
unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
35 int id = trackIDs[idIt].trackID;
36 if (rollup_unsaved_ids)
id =
std::abs(
id);
37 trackIDToEDepMap[id] += trackIDs[idIt].energy;
42 double maxenergy = -1;
43 int objectTrack = -99999;
44 for (std::map<int,double>::iterator mapIt = trackIDToEDepMap.begin(); mapIt != trackIDToEDepMap.end(); mapIt++){
45 double energy = mapIt->second;
46 double trackid = mapIt->first;
47 if (energy > maxenergy){
49 objectTrack = trackid;
60 std::map<int,double> trackMap;
61 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
62 art::Ptr<recob::Hit>
hit = *hitIt;
64 trackMap[trackID] += hit->Integral();
68 double highestCharge = 0;
69 int objectTrack = -99999;
70 for (std::map<int,double>::iterator trackIt = trackMap.begin(); trackIt != trackMap.end(); ++trackIt) {
71 if (trackIt->second > highestCharge) {
72 highestCharge = trackIt->second;
73 objectTrack = trackIt->first;
83 std::map<int,int> trackMap;
84 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
85 art::Ptr<recob::Hit>
hit = *hitIt;
91 int objectTrack = -99999;
92 int highestCount = -1;
93 int NHighestCounts = 0;
94 for (std::map<int,int>::iterator trackIt = trackMap.begin(); trackIt != trackMap.end(); ++trackIt) {
95 if (trackIt->second > highestCount) {
96 highestCount = trackIt->second;
97 objectTrack = trackIt->first;
100 else if (trackIt->second == highestCount){
104 if (NHighestCounts > 1){
105 std::cout<<
"SBNRecoUtils::TrueParticleIDFromTotalRecoHits - There are " << NHighestCounts <<
" particles which tie for highest number of contributing hits (" << highestCount<<
" hits). Using SBNRecoUtils::TrueParticleIDFromTotalTrueEnergy instead."<<std::endl;
114 double vtx[3] = {position.X(), position.Y(), position.Z()};
122 double minx = tpcgeo.
MinX();
double maxx = tpcgeo.
MaxX();
123 double miny = tpcgeo.
MinY();
double maxy = tpcgeo.
MaxY();
124 double minz = tpcgeo.
MinZ();
double maxz = tpcgeo.
MaxZ();
126 for (
size_t c = 0; c < geom->
Ncryostats(); c++)
129 for (
size_t t = 0; t < cryostat.
NTPC(); t++)
132 if (tpcg.
MinX() < minx) minx = tpcg.
MinX();
133 if (tpcg.
MaxX() > maxx) maxx = tpcg.
MaxX();
134 if (tpcg.
MinY() < miny) miny = tpcg.
MinY();
135 if (tpcg.
MaxY() > maxy) maxy = tpcg.
MaxY();
136 if (tpcg.
MinZ() < minz) minz = tpcg.
MinZ();
137 if (tpcg.
MaxZ() > maxz) maxz = tpcg.
MaxZ();
142 double dista = fabs(minx - position.X());
143 double distb = fabs(position.X() - maxx);
144 if ((position.X() > minx) && (position.X() < maxx) &&
145 (dista > distance_buffer) && (distb > distance_buffer)) inside =
true;
147 dista = fabs(maxy - position.Y());
148 distb = fabs(position.Y() - miny);
149 if (inside && (position.Y() > miny) && (position.Y() < maxy) &&
150 (dista > distance_buffer) && (distb > distance_buffer)) inside =
true;
153 dista = fabs(maxz - position.Z());
154 distb = fabs(position.Z() - minz);
155 if (inside && (position.Z() > minz) && (position.Z() < maxz) &&
156 (dista > distance_buffer) && (distb > distance_buffer)) inside =
true;
165 if (track->NumberTrajectoryPoints()==1)
return length;
167 for (
size_t i_tp = 0; i_tp < track->NumberTrajectoryPoints()-1; i_tp++){
168 TVector3 this_point(track->TrajectoryPoint(i_tp).position.X(),track->TrajectoryPoint(i_tp).position.Y(),track->TrajectoryPoint(i_tp).position.Z());
170 std::cout<<
"SBNRecoUtils::CalculateTrackLength - Current trajectory point not in the TPC volume. Skip over this point in the track length calculation"<<std::endl;
173 TVector3 next_point(track->TrajectoryPoint(i_tp+1).position.X(),track->TrajectoryPoint(i_tp+1).position.Y(),track->TrajectoryPoint(i_tp+1).position.Z());
175 std::cout<<
"SBNRecoUtils::CalculateTrackLength - Next trajectory point not in the TPC volume. Skip over this point in the track length calculation"<<std::endl;
179 length+=(next_point-this_point).Mag();
189 const std::vector<const sim::IDE*> mcparticle_ides = bt->
TrackIdToSimIDEs_Ps(mcparticle_id);
191 double mcparticle_energy = 0.;
192 for (
auto const &ide: mcparticle_ides) {
193 mcparticle_energy += ide->energy;
197 const std::vector<art::Ptr<recob::Hit>> matched_reco_track_hits = bt->
TrackIdToHits_Ps(mcparticle_id, reco_track_hits);
200 double matched_reco_energy = 0.;
201 for (
auto const &matched_reco_track_hit: matched_reco_track_hits) {
202 std::vector<sim::IDE> this_hit_IDEs = bt->
HitToAvgSimIDEs(*matched_reco_track_hit);
203 for (
auto const &ide: this_hit_IDEs) {
204 if (ide.trackID == mcparticle_id) {
205 matched_reco_energy += ide.energy;
210 return matched_reco_energy / mcparticle_energy;
CryostatGeo const & GetElement(geo::CryostatID const &cryoid) const
double MinX() const
Returns the world x coordinate of the start of the box.
Geometry information for a single TPC.
double MaxX() const
Returns the world x coordinate of the end of the box.
process_name use argoneut_mc_hitfinder track
Geometry information for a single cryostat.
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
cheat::BackTracker * GetBackTrackerProvider() const
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
double CalculateTrackLength(const core::ProviderManager &manager, const art::Ptr< recob::Track > track)
const geo::GeometryCore * GetGeometryProvider() const
geo::TPCID FindTPCAtPosition(double const worldLoc[3]) const
Returns the ID of the TPC at specified location.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Interface to LArSoft services.
double TrackCompletion(const core::ProviderManager &manager, int mcparticle_id, const std::vector< art::Ptr< recob::Hit >> &reco_track_hits)
std::vector< art::Ptr< recob::Hit > > TrackIdToHits_Ps(detinfo::DetectorClocksData const &clockData, int tkId, std::vector< art::Ptr< recob::Hit >> const &hitsIn) const
double MinZ() const
Returns the world z coordinate of the start of the box.
int TrueParticleIDFromTotalTrueEnergy(const core::ProviderManager &manager, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
bool IsInsideTPC(const core::ProviderManager &manager, TVector3 position, double distance_buffer)
unsigned int NTPC() const
Number of TPCs in this cryostat.
int TrueParticleID(const core::ProviderManager &manager, const art::Ptr< recob::Hit > hit, bool rollup_unsaved_ids=1)
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
The data type to uniquely identify a TPC.
Description of geometry of one entire detector.
double MaxY() const
Returns the world y coordinate of the end of the box.
int TrueParticleIDFromTotalRecoHits(const core::ProviderManager &manager, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
bool HasTPC(geo::TPCID const &tpcid) const
Returns whether we have the specified TPC.
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
double MaxZ() const
Returns the world z coordinate of the end of the box.
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
std::vector< sim::IDE > HitToAvgSimIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
double MinY() const
Returns the world y coordinate of the start of the box.
BEGIN_PROLOG could also be cout
int TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > hit, bool rollup_unsaved_ids=1)
int TrueParticleIDFromTotalRecoCharge(const core::ProviderManager &manager, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)