GCNFeatureUtils.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file GCNFeatureUtils.h
3 /// \brief Utilities for calculating feature values for the GCN
4 /// \author Leigh Whitehead - leigh.howard.whitehead@cern.ch
5 ////////////////////////////////////////////////////////////////////////
6 
7 #ifndef GCN_FEATURE_UTILS_H
8 #define GCN_FEATURE_UTILS_H
9 
10 #include <vector>
11 #include <tuple>
12 #include <string>
13 #include <map>
14 
15 #include "TVector3.h"
16 
18 #include "canvas/Persistency/Common/FindManyP.h"
23 namespace detinfo {
24  class DetectorClocksData;
25 }
26 
29 
30 namespace cvn
31 {
32  typedef std::tuple<int, int, int, float, float, float, float, float, float,
33  float, std::string, std::string> ptruth;
34 
35  /// Class containing some utility functions for all things CVN
37  {
38  public:
40  ~GCNFeatureUtils();
41 
42  /// Get primary true G4 ID for hit
43  int GetTrackIDFromHit(detinfo::DetectorClocksData const& clockData, const recob::Hit&) const;
44  /// Get closest trajectory point for true particle given reconstructed spacepoint
45  std::pair<unsigned int, float> GetClosestApproach(const recob::SpacePoint sp, const simb::MCParticle p) const;
46 
47  /// Get the number of neighbours within rangeCut cm of this space point
48  unsigned int GetSpacePointNeighbours(const recob::SpacePoint &sp, art::Event const &evt, const float rangeCut, const std::string &spLabel) const;
49  unsigned int GetSpacePointNeighbours(const recob::SpacePoint &sp, art::Event const &evt, const float rangeCut, const std::vector<art::Ptr<recob::SpacePoint>> &sps) const;
50  /// Get a map of the number of neighbours for each space point ID. Using this function is much less wasteful
51  /// than repeated calls to the above function
52  std::map<int,unsigned int> GetAllNeighbours(art::Event const &evt, const float rangeCut, const std::string &spLabel) const;
53  std::map<int,unsigned int> GetAllNeighbours(art::Event const &evt, const float rangeCut, const std::vector<art::Ptr<recob::SpacePoint>> &sps) const;
54 
55  /// Gets the number of nearest neigbours for each space point for a vector of cut values. Much more efficient that using the above functions multiple times.
56  std::vector<std::map<int,unsigned int>> GetNeighboursForRadii(art::Event const &evt, const std::vector<float>& rangeCuts, const std::string &spLabel) const;
57  std::vector<std::map<int,unsigned int>> GetNeighboursForRadii(art::Event const &evt, const std::vector<float>& rangeCuts, const std::vector<art::Ptr<recob::SpacePoint>> &sps) const;
58  std::vector<std::map<int,unsigned int>> GetNeighboursForRadii(art::Event const &evt, const std::vector<float>& rangeCuts, const std::map<unsigned int,art::Ptr<recob::SpacePoint>> &sps) const;
59 
60  /// Get the nearest neighbour map for the spacepoints. Returns a map of <nose_spacepoint_id,nearest_neighbour_spacepoint_id>
61  std::map<int,int> GetNearestNeighbours(art::Event const &evt, const std::string &spLabel) const;
62  std::map<int,int> GetNearestNeighbours(art::Event const &evt, const std::vector<art::Ptr<recob::SpacePoint>> &sps) const;
63 
64  /// Get the two nearest neighbours to use for calcuation of angles between them and the node in question
65  std::map<int,std::pair<int,int>> GetTwoNearestNeighbours(art::Event const &evt, const std::string &spLabel) const;
66  std::map<int,std::pair<int,int>> GetTwoNearestNeighbours(art::Event const &evt, const std::vector<art::Ptr<recob::SpacePoint>> &sps) const;
67  std::map<int,std::pair<int,int>> GetTwoNearestNeighbours(art::Event const &evt, const std::map<unsigned int,art::Ptr<recob::SpacePoint>> &sps) const;
68 
69  /// Get the angle and the dot product between the vector from the base node to its neighbours
70  void GetAngleAndDotProduct(const recob::SpacePoint &baseNode, const recob::SpacePoint &n1, const recob::SpacePoint &n2, float &dotProduct, float &angle) const;
71 
72  /// Use the association between space points and hits to return a charge
73  std::map<unsigned int, float> GetSpacePointChargeMap(std::vector<art::Ptr<recob::SpacePoint>> const& spacePoints,
74  std::vector<std::vector<art::Ptr<recob::Hit>>> const& sp2Hit) const;
75  std::map<unsigned int, float> GetSpacePointChargeMap(art::Event const &evt, const std::string &spLabel) const;
76 
77  // Mean RMS of the hits making up a spacepoint
78  std::map<unsigned int, float> GetSpacePointMeanHitRMSMap(art::Event const &evt, const std::string &spLabel) const;
79 
80  /// Get the true G4 ID for each spacepoint using energy matching
81  std::map<unsigned int, int> GetTrueG4ID(detinfo::DetectorClocksData const& clockData,
82  std::vector<art::Ptr<recob::SpacePoint>> const& spacePoints,
83  std::vector<std::vector<art::Ptr<recob::Hit>>> const& sp2Hit) const;
84  std::map<unsigned int, int> GetTrueG4ID(detinfo::DetectorClocksData const& clockData,
85  art::Event const& evt, const std::string &spLabel) const;
86  /// Get the true G4 ID for each spacepoint using energy matching
87  std::map<unsigned int, int> GetTrueG4IDFromHits(
88  detinfo::DetectorClocksData const& clockData,
89  std::vector<art::Ptr<recob::SpacePoint>> const& spacePoints,
90  std::vector<std::vector<art::Ptr<recob::Hit>>> const& sp2Hit) const;
91  std::map<unsigned int, int> GetTrueG4IDFromHits(
92  detinfo::DetectorClocksData const& clockData,
93  art::Event const& evt, const std::string &spLabel) const;
94 
95  /// Get the true pdg code for each spacepoint
96  std::map<unsigned int, int> GetTruePDG(
97  detinfo::DetectorClocksData const& clockData,
98  art::Event const& evt, const std::string &spLabel, bool useAbsoluteTrackID, bool useHits) const;
99  /// Get 2D hit features for a given spacepoint
100  std::map<unsigned int, std::vector<float>> Get2DFeatures(
101  std::vector<art::Ptr<recob::SpacePoint>> const& spacePoints,
102  std::vector<std::vector<art::Ptr<recob::Hit>>> const& sp2Hit) const;
103 
104  /// Convert a pixel map into three 2D GCNGraph objects
105  std::vector<cvn::GCNGraph> ExtractGraphsFromPixelMap(const cvn::PixelMap &pm, const float chargeThreshold) const;
106  /// Get the neighbours map <graph node, neighbours> for the three 2D graph in 2 box (npixel+1) around the pixel
107  std::map<unsigned int,unsigned int> Get2DGraphNeighbourMap(const cvn::GCNGraph &g, const unsigned int npixel) const;
108 
109  /// Get ground truth for spacepoint deghosting graph network
110  std::vector<float> GetNodeGroundTruth(detinfo::DetectorClocksData const& clockData,
111  std::vector<art::Ptr<recob::SpacePoint>> const& spacePoints,
113  float distCut,
114  std::vector<std::vector<float>>* dirTruth=nullptr) const;
115  /// Get hierarchy map from set of particles
116  std::map<unsigned int, unsigned int> GetParticleFlowMap(const std::set<unsigned int>& particles) const;
117 
118  static std::vector<ptruth> GetParticleTree(const cvn::GCNGraph* g);
119 
120  private:
121 
123 
124  };
125 
126 }
127 
128 #endif // GCN_FEATURE_UTILS_H
Algorithm to compute various geometrical relation among geometrical objects. In particular functions ...
Definition: GeoAlgo.h:43
static constexpr double g
Definition: Units.h:144
std::string string
Definition: nybbler.cc:12
GCNGraph, basic input for the GCN.
Definition: GCNGraph.h:18
struct vector vector
PixelMap for CVN.
Utility class for truth labels.
Particle class.
p
Definition: test.py:223
General LArSoft Utilities.
std::tuple< int, int, int, float, float, float, float, float, float, float, std::string, std::string > ptruth
Declaration of signal hit object.
Contains all timing reference information for the detector.
Class def header for a class GeoAlgo.
PixelMap, basic input to CVN neural net.
Definition: PixelMap.h:22
GCNGraph for GCN.
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
TCEvent evt
Definition: DataStructs.cxx:7
geoalgo::GeoAlgo fGeoAlgo
Class containing some utility functions for all things CVN.