RegCNNVtxHandler.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file RegCNNVtxHandler.cxx
3 /// \brief RegCNNVtxHandler
4 /// \author Ilsoo Seong - iseong@uci.edu
5 ////////////////////////////////////////////////////////////////////////
6 
7 #include <cassert>
8 #include <iostream>
9 #include <ostream>
10 #include <algorithm>
11 
12 #include "canvas/Persistency/Common/FindManyP.h"
15 
18 
19 namespace cnn
20 {
22  fHitsModuleLabel (pset.get<std::string> ("HitsModuleLabel")),
23  fTFHandler1st (pset.get<fhicl::ParameterSet> ("TFNetHandler1st")),
24  fTFHandler2nd (pset.get<fhicl::ParameterSet> ("TFNetHandler2nd")),
25  fTdcWidth (pset.get<unsigned short> ("TdcWidth")),
26  fWireLength (pset.get<unsigned short> ("WireLength")),
27  fTimeResolution (pset.get<unsigned short> ("TimeResolution")),
28  fWireResolution (pset.get<unsigned short> ("WireResolution")),
29  fGlobalWireMethod (pset.get<int> ("GlobalWireMethod")),
30 // fProngOnly (pset.get<bool> ("ProngOnly")),
31  fProducer (fWireLength, fWireResolution, fTdcWidth, fTimeResolution, fGlobalWireMethod, 0, 1)
32  {
33  }
34  std::vector<float> RegCNNVtxHandler::GetVertex(detinfo::DetectorClocksData const& clockData,
35  detinfo::DetectorPropertiesData const& detProp,
36  art::Event &evt, const RegPixelMap &pixelmap){
37 
38  std::vector< art::Ptr< recob::Hit > > hitlist;
39  auto hitListHandle = evt.getHandle< std::vector< recob::Hit > >(fHitsModuleLabel);
40  if (hitListHandle)
41  art::fill_ptr_vector(hitlist, hitListHandle);
42  art::FindManyP<recob::Wire> fmwire(hitListHandle, evt, fHitsModuleLabel);
43 
44  /// Load in the pixel map
45  // get vertex
46  std::vector <float> Result(3, -99999);
47  if (pixelmap.fInPM){
48  std::vector<float> networkOutput(6, -99999);
49  networkOutput = fTFHandler1st.Predict(pixelmap);
50  FindGlobalVertices(pixelmap, networkOutput);
51  std::vector <float> center_of_mass(7,0);
52  for (int ii = 0; ii < 6; ii++){
53  center_of_mass[ii] = networkOutput[ii];
54  }
55  networkOutput[1] += 7; networkOutput[5] += 7;
56  networkOutput[3] -= 9;
57 
59  pm = fProducer.CreateMap(clockData, detProp, hitlist, fmwire, networkOutput);
60  if (pm.fInPM){
61  center_of_mass[6] = (float)(pm.fTPC%4); // add TPC info
62  Result = fTFHandler2nd.Predict(pm, center_of_mass);
63  }
64  } // end of pixelmap
65  return Result;
66  } // end og GetVertex
67 
68 
69  void RegCNNVtxHandler::FindGlobalVertices(const RegPixelMap& pm, std::vector<float> &outputs)
70  {
71  for (int ii = 0; ii < 3; ii++){
72  float vtx_wire = outputs[ii*2+1];
73  float vtx_tick = outputs[ii*2];
74  float dwire = pm.fNWire/2-vtx_wire;
75  float dtick = (pm.fNTdc/2-vtx_tick)*pm.fNTRes;
76  float cm_wire = pm.fBound.fFirstWire[ii]+pm.fNWire/2-dwire;
77  float cm_tdc = pm.fBound.fFirstTDC[ii]+pm.fNTdc*pm.fNTRes/2-dtick;
78  outputs[ii*2+1] = cm_wire;
79  outputs[ii*2] = cm_tdc;
80  }
81  }
82  void RegCNNVtxHandler::getCM(const RegPixelMap& pm, float* cm_list)
83  {
84  for (int ii = 0; ii < 3; ii++){
85  float mean_wire = pm.fBound.fFirstWire[ii]+pm.fNWire/2;
86  float mean_tdc = pm.fBound.fFirstTDC[ii]+pm.fNTdc*pm.fNTRes/2;
87  cm_list[2*ii] = mean_tdc;
88  cm_list[2*ii+1] = mean_wire;
89  }
90  }
91 
92 
93 
94 }
RegPixelMapProducer fProducer
RegPixelMap CreateMap(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, std::vector< art::Ptr< recob::Hit > > const &cluster, art::FindManyP< recob::Wire > const &fmwire)
int fFirstTDC[3]
Minimum TDC in each view, inclusive.
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
unsigned int fNTdc
Number of tdcs, width of pixel map.
Definition: RegPixelMap.h:86
RegPixelMap, basic input to CNN neural net.
Definition: RegPixelMap.h:22
unsigned int fInPM
Definition: RegPixelMap.h:88
unsigned int fNWire
Number of wires, length of pixel map.
Definition: RegPixelMap.h:84
int fFirstWire[3]
Minimum wire, inclusive.
void FindGlobalVertices(const RegPixelMap &pm, std::vector< float > &outputs)
STL namespace.
RegCNNBoundary fBound
Definition: RegPixelMap.h:104
cnn::TFRegNetHandler fTFHandler1st
cnn::TFRegNetHandler fTFHandler2nd
void getCM(const RegPixelMap &pm, float *cm_list)
std::vector< float > Predict(const RegPixelMap &pm)
Return prediction arrays for RegPixelMap.
unsigned int fTPC
Definition: RegPixelMap.h:89
std::string fHitsModuleLabel
Defines an enumeration for cellhit classification.
Declaration of signal hit object.
Contains all timing reference information for the detector.
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int fNTRes
Definition: RegPixelMap.h:87
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
std::vector< float > GetVertex(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, art::Event &evt, const RegPixelMap &pixelmap)
RegCNNVtxHandler(const fhicl::ParameterSet &pset)