SparsePixelMap.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file SparsePixelMap.cxx
3 /// \brief Sparse pixel map for CVN
4 /// \author Jeremy Hewes - jhewes15@fnal.gov
5 ////////////////////////////////////////////////////////////////////////
6 
7 #include <iostream>
10 
11 
12 namespace cvn {
13 
14  SparsePixelMap::SparsePixelMap(unsigned int dim, unsigned int views, bool usePixelTruth)
15  : fDim(dim), fViews(views), fUsePixelTruth(usePixelTruth)
16  {
17  fCoordinates.resize(fViews);
18  fFeatures.resize(fViews);
19  if (fUsePixelTruth) {
20  fPixelPDGs.resize(fViews);
21  fPixelTrackIDs.resize(fViews);
22  fPixelEnergies.resize(fViews);
23  fProcesses.resize(fViews);
24 // *******************************************
25  }
26  }
27 
28  /// Default AddHit implementation, which just adds pixel value and coordinates
29  void SparsePixelMap::AddHit(unsigned int view, std::vector<float> coordinates,
30  std::vector<float> features) {
31 
32  if (coordinates.size() != fDim) {
34  << "Coordinate vector with size " << coordinates.size()
35  << " does not match sparse pixel map dimension " << fDim;
36  }
37 
38  if (fUsePixelTruth) {
40  << "Pixel truth is enabled for this SparsePixelMap, so you must include pixel PDG and "
41  << "track ID when calling AddHit.";
42  }
43 
44  fCoordinates[view].push_back(coordinates);
45  fFeatures[view].push_back(features);
46  }
47 
48  /// AddHit function that includes per-pixel truth labelling for segmentation
49  void SparsePixelMap::AddHit(unsigned int view, std::vector<float> coordinates,
50  std::vector<float> features, std::vector<int> pdgs, std::vector<int> tracks,
51  std::vector<float> energies, std::vector<std::string> processes) {
52 
53  if (coordinates.size() != fDim) {
55  << "Coordinate vector with size " << coordinates.size()
56  << " does not match sparse pixel map dimension " << fDim;
57  }
58 
59  if (!fUsePixelTruth) {
61  << "Pixel truth is disabled for this SparsePixelMap, but AddHit call includes "
62  << "pixel PDG, track ID and Energy";
63  }
64 
65  fCoordinates[view].push_back(coordinates);
66  fFeatures[view].push_back(features);
67  fPixelPDGs[view].push_back(pdgs);
68  fPixelTrackIDs[view].push_back(tracks);
69  fPixelEnergies[view].push_back(energies);
70  fProcesses[view].push_back(processes);
71 
72  }
73 
74  std::vector<unsigned int> SparsePixelMap::GetNPixels() const {
75 
76  std::vector<unsigned int> ret(fViews);
77  for (size_t it = 0; it < fViews; ++it) {
78  ret[it] = fFeatures[it].size();
79  }
80  return ret;
81  }
82 
83 } // namespace cvn
coordinates
Definition: geo_types.h:121
void AddHit(unsigned int view, std::vector< float > coordinates, std::vector< float > features)
Default AddHit implementation, which just adds pixel value and coordinates.
std::vector< std::vector< std::vector< std::string > > > fProcesses
unsigned int fViews
Number of views.
std::vector< std::vector< std::vector< int > > > fPixelPDGs
True particle PDG responsible for pixel.
std::vector< std::vector< std::vector< int > > > fPixelTrackIDs
G4 track IDs responsible for pixelel.
std::vector< std::vector< std::vector< float > > > fFeatures
Features of non-zero pixels.
Utility class for truth labels.
const char features[]
Definition: feature_tests.c:2
std::vector< unsigned int > GetNPixels() const
std::vector< std::vector< std::vector< float > > > fCoordinates
Coordinates of non-zero pixels.
std::vector< std::vector< std::vector< float > > > fPixelEnergies
bool fUsePixelTruth
Whether to use a per-pixel ground truth for pixel segmentation.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Definition: tracks.py:1
Sparse pixel map for CVN.
unsigned int fDim
Dimensionality of each pixel map.