5 const art::Ptr<recob::Hit>
hit,
bool rollup_unsaved_ids) {
6 std::map<int,double> id_to_energy_map;
7 art::ServiceHandle<cheat::BackTrackerService> bt_serv;
8 std::vector<sim::TrackIDE> track_ides = bt_serv->HitToTrackIDEs(clockData, hit);
9 for (
unsigned int idIt = 0; idIt < track_ides.size(); ++idIt) {
10 int id = track_ides.at(idIt).trackID;
11 if (rollup_unsaved_ids)
id =
std::abs(
id);
12 double energy = track_ides.at(idIt).energy;
13 id_to_energy_map[id]+=energy;
16 double likely_particle_contrib_energy = -99999;
17 int likely_track_id = 0;
18 for (std::map<int,double>::iterator mapIt = id_to_energy_map.begin(); mapIt != id_to_energy_map.end(); mapIt++){
19 double particle_contrib_energy = mapIt->second;
20 if (particle_contrib_energy > likely_particle_contrib_energy){
21 likely_particle_contrib_energy = particle_contrib_energy;
22 likely_track_id = mapIt->first;
25 return likely_track_id;
31 art::ServiceHandle<cheat::BackTrackerService> bt_serv;
32 std::map<int,double> trackIDToEDepMap;
33 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
34 art::Ptr<recob::Hit>
hit = *hitIt;
35 std::vector<sim::TrackIDE> trackIDs = bt_serv->HitToTrackIDEs(clockData, hit);
36 for (
unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
37 int id = trackIDs[idIt].trackID;
38 if (rollup_unsaved_ids)
id =
std::abs(
id);
39 trackIDToEDepMap[id] += trackIDs[idIt].energy;
44 double maxenergy = -1;
45 int objectTrack = -99999;
46 for (std::map<int,double>::iterator mapIt = trackIDToEDepMap.begin(); mapIt != trackIDToEDepMap.end(); mapIt++){
47 double energy = mapIt->second;
48 double trackid = mapIt->first;
49 if (energy > maxenergy){
51 objectTrack = trackid;
62 std::map<int,double> trackMap;
63 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
64 art::Ptr<recob::Hit>
hit = *hitIt;
66 trackMap[trackID] += hit->Integral();
70 double highestCharge = 0;
71 int objectTrack = -99999;
72 for (std::map<int,double>::iterator trackIt = trackMap.begin(); trackIt != trackMap.end(); ++trackIt) {
73 if (trackIt->second > highestCharge) {
74 highestCharge = trackIt->second;
75 objectTrack = trackIt->first;
85 std::map<int,int> trackMap;
86 for (
std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
87 art::Ptr<recob::Hit>
hit = *hitIt;
93 int objectTrack = -99999;
94 int highestCount = -1;
95 int NHighestCounts = 0;
96 for (std::map<int,int>::iterator trackIt = trackMap.begin(); trackIt != trackMap.end(); ++trackIt) {
97 if (trackIt->second > highestCount) {
98 highestCount = trackIt->second;
99 objectTrack = trackIt->first;
102 else if (trackIt->second == highestCount){
106 if (NHighestCounts > 1){
107 std::cout<<
"RecoUtils::TrueParticleIDFromTotalRecoHits - There are " << NHighestCounts <<
" particles which tie for highest number of contributing hits (" << highestCount<<
" hits). Using RecoUtils::TrueParticleIDFromTotalTrueEnergy instead."<<std::endl;
116 double vtx[3] = {position.X(), position.Y(), position.Z()};
118 art::ServiceHandle<geo::Geometry> geom;
119 geo::TPCID idtpc = geom->FindTPCAtPosition(vtx);
121 if (geom->HasTPC(idtpc))
124 double minx = tpcgeo.
MinX();
double maxx = tpcgeo.
MaxX();
125 double miny = tpcgeo.
MinY();
double maxy = tpcgeo.
MaxY();
126 double minz = tpcgeo.
MinZ();
double maxz = tpcgeo.
MaxZ();
128 for (
size_t c = 0; c < geom->Ncryostats(); c++)
131 for (
size_t t = 0; t < cryostat.
NTPC(); t++)
134 if (tpcg.
MinX() < minx) minx = tpcg.
MinX();
135 if (tpcg.
MaxX() > maxx) maxx = tpcg.
MaxX();
136 if (tpcg.
MinY() < miny) miny = tpcg.
MinY();
137 if (tpcg.
MaxY() > maxy) maxy = tpcg.
MaxY();
138 if (tpcg.
MinZ() < minz) minz = tpcg.
MinZ();
139 if (tpcg.
MaxZ() > maxz) maxz = tpcg.
MaxZ();
144 double dista = fabs(minx - position.X());
145 double distb = fabs(position.X() - maxx);
146 if ((position.X() > minx) && (position.X() < maxx) &&
147 (dista > distance_buffer) && (distb > distance_buffer)) inside =
true;
149 dista = fabs(maxy - position.Y());
150 distb = fabs(position.Y() - miny);
151 if (inside && (position.Y() > miny) && (position.Y() < maxy) &&
152 (dista > distance_buffer) && (distb > distance_buffer)) inside =
true;
155 dista = fabs(maxz - position.Z());
156 distb = fabs(position.Z() - minz);
157 if (inside && (position.Z() > minz) && (position.Z() < maxz) &&
158 (dista > distance_buffer) && (distb > distance_buffer)) inside =
true;
167 if (track->NumberTrajectoryPoints()==1)
return length;
169 for (
size_t i_tp = 0; i_tp < track->NumberTrajectoryPoints()-1; i_tp++){
170 TVector3 this_point(track->TrajectoryPoint(i_tp).position.X(),track->TrajectoryPoint(i_tp).position.Y(),track->TrajectoryPoint(i_tp).position.Z());
172 std::cout<<
"RecoUtils::CalculateTrackLength - Current trajectory point not in the TPC volume. Skip over this point in the track length calculation"<<std::endl;
175 TVector3 next_point(track->TrajectoryPoint(i_tp+1).position.X(),track->TrajectoryPoint(i_tp+1).position.Y(),track->TrajectoryPoint(i_tp+1).position.Z());
177 std::cout<<
"RecoUtils::CalculateTrackLength - Next trajectory point not in the TPC volume. Skip over this point in the track length calculation"<<std::endl;
181 length+=(next_point-this_point).Mag();
int TrueParticleIDFromTotalTrueEnergy(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
double CalculateTrackLength(const art::Ptr< recob::Track > track)
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.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
double MinZ() const
Returns the world z coordinate of the start of the box.
unsigned int NTPC() const
Number of TPCs in this cryostat.
int TrueParticleIDFromTotalRecoHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
const PlaneGeo & GetElement(PlaneID const &planeid) const
The data type to uniquely identify a TPC.
double MaxY() const
Returns the world y coordinate of the end of the box.
Contains all timing reference information for the detector.
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.
int TrueParticleIDFromTotalRecoCharge(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
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)
bool IsInsideTPC(TVector3 position, double distance_buffer)