All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
RecoUtils Namespace Reference

Functions

int TrueParticleID (detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > hit, bool rollup_unsaved_ids=1)
 
int TrueParticleIDFromTotalTrueEnergy (detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
 
int TrueParticleIDFromTotalRecoCharge (detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
 
int TrueParticleIDFromTotalRecoHits (detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
 
bool IsInsideTPC (TVector3 position, double distance_buffer)
 
double CalculateTrackLength (const art::Ptr< recob::Track > track)
 
int TrueParticleID (const detinfo::DetectorClocksData &clockData, const art::Ptr< recob::Hit > &hit)
 
int TrueParticleIDFromTotalTrueEnergy (const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit > > &hits)
 
int TrueParticleIDFromTotalRecoCharge (const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit > > &hits)
 
int TrueParticleIDFromTotalRecoHits (const detinfo::DetectorClocksData &clockData, const std::vector< art::Ptr< recob::Hit > > &hits)
 

Function Documentation

double RecoUtils::CalculateTrackLength ( const art::Ptr< recob::Track track)

Definition at line 165 of file icaruscode/icaruscode/CRT/CRTUtils/RecoUtils.cc.

165  {
166  double length = 0;
167  if (track->NumberTrajectoryPoints()==1) return length; //Nothing to calculate if there is only one point
168 
169  for (size_t i_tp = 0; i_tp < track->NumberTrajectoryPoints()-1; i_tp++){ //Loop from the first to 2nd to last point
170  TVector3 this_point(track->TrajectoryPoint(i_tp).position.X(),track->TrajectoryPoint(i_tp).position.Y(),track->TrajectoryPoint(i_tp).position.Z());
171  if (!RecoUtils::IsInsideTPC(this_point,0)){
172  std::cout<<"RecoUtils::CalculateTrackLength - Current trajectory point not in the TPC volume. Skip over this point in the track length calculation"<<std::endl;
173  continue;
174  }
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());
176  if (!RecoUtils::IsInsideTPC(next_point,0)){
177  std::cout<<"RecoUtils::CalculateTrackLength - Next trajectory point not in the TPC volume. Skip over this point in the track length calculation"<<std::endl;
178  continue;
179  }
180 
181  length+=(next_point-this_point).Mag();
182  }
183  return length;
184 }
process_name use argoneut_mc_hitfinder track
BEGIN_PROLOG could also be cout
bool IsInsideTPC(TVector3 position, double distance_buffer)
bool RecoUtils::IsInsideTPC ( TVector3  position,
double  distance_buffer 
)

Definition at line 115 of file icaruscode/icaruscode/CRT/CRTUtils/RecoUtils.cc.

115  {
116  double vtx[3] = {position.X(), position.Y(), position.Z()};
117  bool inside = false;
118  art::ServiceHandle<geo::Geometry> geom;
119  geo::TPCID idtpc = geom->FindTPCAtPosition(vtx);
120 
121  if (geom->HasTPC(idtpc))
122  {
123  const geo::TPCGeo& tpcgeo = geom->GetElement(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();
127 
128  for (size_t c = 0; c < geom->Ncryostats(); c++)
129  {
130  const geo::CryostatGeo& cryostat = geom->Cryostat(c);
131  for (size_t t = 0; t < cryostat.NTPC(); t++)
132  {
133  const geo::TPCGeo& tpcg = cryostat.TPC(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();
140  }
141  }
142 
143  //x
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;
148  //y
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;
153  else inside = false;
154  //z
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;
159  else inside = false;
160  }
161 
162  return inside;
163 }
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
Geometry information for a single cryostat.
Definition: CryostatGeo.h:43
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
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.
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.
double MinY() const
Returns the world y coordinate of the start of the box.
int RecoUtils::TrueParticleID ( const detinfo::DetectorClocksData clockData,
const art::Ptr< recob::Hit > &  hit 
)

Definition at line 3 of file icaruscode/icaruscode/RecoUtils/RecoUtils.cc.

4  {
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 }
process_name hit
Definition: cheaterreco.fcl:51
int RecoUtils::TrueParticleID ( detinfo::DetectorClocksData const &  clockData,
const art::Ptr< recob::Hit hit,
bool  rollup_unsaved_ids = 1 
)

Definition at line 4 of file icaruscode/icaruscode/CRT/CRTUtils/RecoUtils.cc.

5  {
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;
14  }
15  //Now loop over the map to find the maximum contributor
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;
23  }
24  }
25  return likely_track_id;
26 }
process_name hit
Definition: cheaterreco.fcl:51
T abs(T value)
int RecoUtils::TrueParticleIDFromTotalRecoCharge ( const detinfo::DetectorClocksData clockData,
const std::vector< art::Ptr< recob::Hit > > &  hits 
)

Definition at line 48 of file icaruscode/icaruscode/RecoUtils/RecoUtils.cc.

49  {
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 }
process_name hit
Definition: cheaterreco.fcl:51
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
int TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > hit, bool rollup_unsaved_ids=1)
int RecoUtils::TrueParticleIDFromTotalRecoCharge ( detinfo::DetectorClocksData const &  clockData,
const std::vector< art::Ptr< recob::Hit > > &  hits,
bool  rollup_unsaved_ids = 1 
)

Definition at line 60 of file icaruscode/icaruscode/CRT/CRTUtils/RecoUtils.cc.

60  {
61  // Make a map of the tracks which are associated with this object and the charge each contributes
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;
65  int trackID = TrueParticleID(clockData, hit, rollup_unsaved_ids);
66  trackMap[trackID] += hit->Integral();
67  }
68 
69  // Pick the track with the highest charge as the 'true track'
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;
76  }
77  }
78  return objectTrack;
79 }
process_name hit
Definition: cheaterreco.fcl:51
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
int TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > hit, bool rollup_unsaved_ids=1)
int RecoUtils::TrueParticleIDFromTotalRecoHits ( const detinfo::DetectorClocksData clockData,
const std::vector< art::Ptr< recob::Hit > > &  hits 
)

Definition at line 72 of file icaruscode/icaruscode/RecoUtils/RecoUtils.cc.

73  {
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 }
process_name hit
Definition: cheaterreco.fcl:51
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
int TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > hit, bool rollup_unsaved_ids=1)
int RecoUtils::TrueParticleIDFromTotalRecoHits ( detinfo::DetectorClocksData const &  clockData,
const std::vector< art::Ptr< recob::Hit > > &  hits,
bool  rollup_unsaved_ids = 1 
)

Definition at line 83 of file icaruscode/icaruscode/CRT/CRTUtils/RecoUtils.cc.

83  {
84  // Make a map of the tracks which are associated with this object and the number of hits they are the primary contributor to
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;
88  int trackID = TrueParticleID(clockData, hit, rollup_unsaved_ids);
89  trackMap[trackID]++;
90  }
91 
92  // Pick the track which is the primary contributor to the most hits as the 'true track'
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;
100  NHighestCounts = 1;
101  }
102  else if (trackIt->second == highestCount){
103  NHighestCounts++;
104  }
105  }
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;
108  objectTrack = RecoUtils::TrueParticleIDFromTotalTrueEnergy(clockData, hits,rollup_unsaved_ids);
109  }
110  return objectTrack;
111 }
int TrueParticleIDFromTotalTrueEnergy(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
process_name hit
Definition: cheaterreco.fcl:51
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
BEGIN_PROLOG could also be cout
int TrueParticleID(detinfo::DetectorClocksData const &clockData, const art::Ptr< recob::Hit > hit, bool rollup_unsaved_ids=1)
int RecoUtils::TrueParticleIDFromTotalTrueEnergy ( const detinfo::DetectorClocksData clockData,
const std::vector< art::Ptr< recob::Hit > > &  hits 
)

Definition at line 19 of file icaruscode/icaruscode/RecoUtils/RecoUtils.cc.

20  {
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 }
process_name hit
Definition: cheaterreco.fcl:51
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
int RecoUtils::TrueParticleIDFromTotalTrueEnergy ( detinfo::DetectorClocksData const &  clockData,
const std::vector< art::Ptr< recob::Hit > > &  hits,
bool  rollup_unsaved_ids = 1 
)

Definition at line 30 of file icaruscode/icaruscode/CRT/CRTUtils/RecoUtils.cc.

30  {
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;
40  }
41  }
42 
43  //Loop over the map and find the track which contributes the highest energy to the hit vector
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){
50  maxenergy = energy;
51  objectTrack = trackid;
52  }
53  }
54 
55  return objectTrack;
56 }
process_name hit
Definition: cheaterreco.fcl:51
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
T abs(T value)