All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
icaruscode/icaruscode/RecoUtils/RecoUtils.cc
Go to the documentation of this file.
1 #include "RecoUtils.h"
2 
4  const art::Ptr<recob::Hit>& hit) {
5  double particleEnergy = 0;
6  int likelyTrackID = 0;
7  art::ServiceHandle<cheat::BackTrackerService> bt;
8  std::vector<sim::TrackIDE> trackIDs = bt->HitToTrackIDEs(clockData, hit);
9  for (unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
10  if (trackIDs.at(idIt).energy > particleEnergy) {
11  particleEnergy = trackIDs.at(idIt).energy;
12  likelyTrackID = trackIDs.at(idIt).trackID;
13  }
14  }
15  return likelyTrackID;
16 }
17 
18 
20  const std::vector<art::Ptr<recob::Hit> >& hits) {
21  art::ServiceHandle<cheat::BackTrackerService> bt;
22  std::map<int,double> trackIDToEDepMap;
23  for (std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
24  art::Ptr<recob::Hit> hit = *hitIt;
25  std::vector<sim::TrackIDE> trackIDs = bt->HitToTrackIDEs(clockData, hit);
26  for (unsigned int idIt = 0; idIt < trackIDs.size(); ++idIt) {
27  trackIDToEDepMap[trackIDs[idIt].trackID] += trackIDs[idIt].energy;
28  }
29  }
30 
31  //Loop over the map and find the track which contributes the highest energy to the hit vector
32  double maxenergy = -1;
33  int objectTrack = -99999;
34  for (std::map<int,double>::iterator mapIt = trackIDToEDepMap.begin(); mapIt != trackIDToEDepMap.end(); mapIt++){
35  double energy = mapIt->second;
36  double trackid = mapIt->first;
37  if (energy > maxenergy){
38  maxenergy = energy;
39  objectTrack = trackid;
40  }
41  }
42 
43  return objectTrack;
44 }
45 
46 
47 
49  const std::vector<art::Ptr<recob::Hit> >& hits) {
50  // Make a map of the tracks which are associated with this object and the charge each contributes
51  std::map<int,double> trackMap;
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  int trackID = TrueParticleID(clockData, hit);
55  trackMap[trackID] += hit->Integral();
56  }
57 
58  // Pick the track with the highest charge as the 'true track'
59  double highestCharge = 0;
60  int objectTrack = -99999;
61  for (std::map<int,double>::iterator trackIt = trackMap.begin(); trackIt != trackMap.end(); ++trackIt) {
62  if (trackIt->second > highestCharge) {
63  highestCharge = trackIt->second;
64  objectTrack = trackIt->first;
65  }
66  }
67  return objectTrack;
68 }
69 
70 
71 
73  const std::vector<art::Ptr<recob::Hit> >& hits) {
74  // Make a map of the tracks which are associated with this object and the number of hits they are the primary contributor to
75  std::map<int,int> trackMap;
76  for (std::vector<art::Ptr<recob::Hit> >::const_iterator hitIt = hits.begin(); hitIt != hits.end(); ++hitIt) {
77  art::Ptr<recob::Hit> hit = *hitIt;
78  int trackID = TrueParticleID(clockData, hit);
79  trackMap[trackID]++;
80  }
81 
82  // Pick the track which is the primary contributor to the most hits as the 'true track'
83  int objectTrack = -99999;
84  int highestCount = -1;
85  for (std::map<int,int>::iterator trackIt = trackMap.begin(); trackIt != trackMap.end(); ++trackIt) {
86  if (trackIt->second > highestCount) {
87  highestCount = trackIt->second;
88  objectTrack = trackIt->first;
89  }
90  }
91  return objectTrack;
92 }
93 
94 
95 
96 bool RecoUtils::IsInsideTPC(TVector3 position, double distance_buffer){
97  double vtx[3] = {position.X(), position.Y(), position.Z()};
98  bool inside = false;
99  art::ServiceHandle<geo::Geometry> geom;
100  geo::TPCID idtpc = geom->FindTPCAtPosition(vtx);
101 
102  if (geom->HasTPC(idtpc))
103  {
104  const geo::TPCGeo& tpcgeo = geom->GetElement(idtpc);
105  double minx = tpcgeo.MinX(); double maxx = tpcgeo.MaxX();
106  double miny = tpcgeo.MinY(); double maxy = tpcgeo.MaxY();
107  double minz = tpcgeo.MinZ(); double maxz = tpcgeo.MaxZ();
108 
109  for (size_t c = 0; c < geom->Ncryostats(); c++)
110  {
111  const geo::CryostatGeo& cryostat = geom->Cryostat(c);
112  for (size_t t = 0; t < cryostat.NTPC(); t++)
113  {
114  const geo::TPCGeo& tpcg = cryostat.TPC(t);
115  if (tpcg.MinX() < minx) minx = tpcg.MinX();
116  if (tpcg.MaxX() > maxx) maxx = tpcg.MaxX();
117  if (tpcg.MinY() < miny) miny = tpcg.MinY();
118  if (tpcg.MaxY() > maxy) maxy = tpcg.MaxY();
119  if (tpcg.MinZ() < minz) minz = tpcg.MinZ();
120  if (tpcg.MaxZ() > maxz) maxz = tpcg.MaxZ();
121  }
122  }
123 
124  //x
125  double dista = fabs(minx - position.X());
126  double distb = fabs(position.X() - maxx);
127  if ((position.X() > minx) && (position.X() < maxx) &&
128  (dista > distance_buffer) && (distb > distance_buffer)) inside = true;
129  //y
130  dista = fabs(maxy - position.Y());
131  distb = fabs(position.Y() - miny);
132  if (inside && (position.Y() > miny) && (position.Y() < maxy) &&
133  (dista > distance_buffer) && (distb > distance_buffer)) inside = true;
134  else inside = false;
135  //z
136  dista = fabs(maxz - position.Z());
137  distb = fabs(position.Z() - minz);
138  if (inside && (position.Z() > minz) && (position.Z() < maxz) &&
139  (dista > distance_buffer) && (distb > distance_buffer)) inside = true;
140  else inside = false;
141  }
142 
143  return inside;
144 
145 
146 
147 }
int TrueParticleIDFromTotalTrueEnergy(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
double MinX() const
Returns the world x coordinate of the start of the box.
Definition: BoxBoundedGeo.h:88
Geometry information for a single TPC.
Definition: TPCGeo.h:38
double MaxX() const
Returns the world x coordinate of the end of the box.
Definition: BoxBoundedGeo.h:91
process_name hit
Definition: cheaterreco.fcl:51
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
double MinZ() const
Returns the world z coordinate of the start of the box.
unsigned int NTPC() const
Number of TPCs in this cryostat.
Definition: CryostatGeo.h:181
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
Definition: TPCGeo.h:214
The data type to uniquely identify a TPC.
Definition: geo_types.h:386
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&#39;th TPC in the cryostat.
Definition: CryostatGeo.cxx:93
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.
int TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > hit, bool rollup_unsaved_ids=1)
bool IsInsideTPC(TVector3 position, double distance_buffer)