GCNGraphMaker2D_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file GCNGraphMaker2D_module.cc
3 // \brief Producer module for creating three 2D CVN Graph objects
4 // \author Leigh H. Whitehead - leigh.howard.whitehead@cern.ch
5 ////////////////////////////////////////////////////////////////////////
6 
7 // C/C++ includes
8 #include <iostream>
9 #include <sstream>
10 
11 // Framework includes
16 #include "fhiclcpp/ParameterSet.h"
20 #include "canvas/Persistency/Common/FindManyP.h"
21 
22 // LArSoft includes
25 
29 
30 namespace cvn {
31 
33  public:
34  explicit GCNGraphMaker2D(fhicl::ParameterSet const& pset);
36 
37  void produce(art::Event& evt);
38  void beginJob();
39  void endJob();
40 
41 
42 
43  private:
44  /// Module label for input space points
46 
47  /// Minimum charge to created a graph node from a pixel
49 
50  /// Radius for calculating number of neighbours
52 
53  };
54 
55 
56 
57  //.......................................................................
59  fPixelMapLabel (pset.get<std::string> ("PixelMapLabel")),
60  fChargeThreshold (pset.get<float> ("ChargeThreshold")),
61  fNeighbourPixels (pset.get<float>("NeighbourPixels"))
62  {
63  produces< std::vector<cvn::GCNGraph> >();
64  }
65 
66  //......................................................................
68  {
69  //======================================================================
70  // Clean up any memory allocated by your module
71  //======================================================================
72  }
73 
74  //......................................................................
76  { }
77 
78  //......................................................................
80  {
81  }
82 
83  //......................................................................
85  {
86  auto pixelMaps = evt.getValidHandle<std::vector<cvn::PixelMap>>(fPixelMapLabel);
87 
88  // Create the Graph vector and fill it if we have enough hits
89  std::unique_ptr<std::vector<cvn::GCNGraph>> graphs(new std::vector<cvn::GCNGraph>);
90 
91  if(pixelMaps->size() > 0){
92 
93  cvn::GCNFeatureUtils graphUtil;
94 
95  // Get the three graphs from the pixel map
96  // These graphs contain N nodes with (wire,time) position and (charge) features
97  std::vector<cvn::GCNGraph> graphs2D = graphUtil.ExtractGraphsFromPixelMap(pixelMaps->at(0),fChargeThreshold);
98 
99  // For each of the graphs we want to add a number of neighbours feature
100  for(cvn::GCNGraph g : graphs2D){
101  std::map<unsigned int, unsigned int> neighbourMap = graphUtil.Get2DGraphNeighbourMap(g,fNeighbourPixels);
102  std::cout << "Built graph with " << g.GetNumberOfNodes() << " nodes" << std::endl;
103  for(unsigned int n = 0; n < g.GetNumberOfNodes(); ++n){
104  cvn::GCNGraphNode &node = g.GetNodeEditable(n);
105  node.AddFeature(neighbourMap.at(n));
106  }
107  // Add the graph to the output vector
108  graphs->push_back(g);
109  }
110 
111  }
112  // Write our graph to the event
113  evt.put(std::move(graphs));
114  }
115 
117 } // end namespace cvn
118 ////////////////////////////////////////////////////////////////////////
119 
120 
121 
122 
123 
124 
125 
static constexpr double g
Definition: Units.h:144
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
GCNGraph, basic input for the GCN.
Definition: GCNGraph.h:18
STL namespace.
PixelMap for CVN.
Utility class for truth labels.
std::string fPixelMapLabel
Module label for input space points.
float fNeighbourPixels
Radius for calculating number of neighbours.
GCNGraphMaker2D(fhicl::ParameterSet const &pset)
float fChargeThreshold
Minimum charge to created a graph node from a pixel.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::void_t< T > n
def move(depos, offset)
Definition: depos.py:107
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
Declaration of signal hit object.
void AddFeature(float feature)
Add a node feature.
GCNGraph for GCN.
std::vector< cvn::GCNGraph > ExtractGraphsFromPixelMap(const cvn::PixelMap &pm, const float chargeThreshold) const
Convert a pixel map into three 2D GCNGraph objects.
Utilities for calculating feature values for the GCN.
void produce(art::Event &evt)
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
std::map< unsigned int, unsigned int > Get2DGraphNeighbourMap(const cvn::GCNGraph &g, const unsigned int npixel) const
Get the neighbours map <graph node, neighbours> for the three 2D graph in 2 box (npixel+1) around the...
QTextStream & endl(QTextStream &s)
Class containing some utility functions for all things CVN.