LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
lar_dl_content::DlSecondaryVertexingAlgorithm Class Reference

DeepLearningTrackShowerIdAlgorithm class. More...

#include "DlSecondaryVertexingAlgorithm.h"

Inheritance diagram for lar_dl_content::DlSecondaryVertexingAlgorithm:
lar_dl_content::DlVertexingBaseAlgorithm

Classes

class  Canvas
 

Public Types

typedef std::map< std::pair< int, int >, std::vector< const pandora::CaloHit * > > PixelToCaloHitsMap
 

Public Member Functions

 DlSecondaryVertexingAlgorithm ()
 Default constructor. More...
 
 ~DlSecondaryVertexingAlgorithm ()
 

Protected Types

typedef std::pair< int, int > Pixel
 
typedef std::vector< PixelPixelVector
 

Protected Member Functions

void GetHitRegion (const pandora::CaloHitList &caloHitList, float &xMin, float &xMax, float &zMin, float &zMax) const
 
void GetCanvasParameters (const LArDLHelper::TorchOutput &networkOutput, const PixelVector &pixelVector, int &columnOffset, int &rowOffset, int &width, int &height) const
 Determines the parameters of the canvas for extracting the vertex location. The network predicts the distance that each pixel associated with a hit is located from the vertex, but says nothing about the direction. As a result, the ring describing the potential vertices associated with that hit can extend beyond the original canvas size. This function returns the size of the required canvas and the offset for the bottom left corner. More...
 

Protected Attributes

bool m_trainingMode
 Training mode. More...
 
std::string m_trainingOutputFile
 Output file name for training examples. More...
 
std::string m_inputVertexListName
 Input vertex list name if 2nd pass. More...
 
std::string m_outputVertexListName
 Output vertex list name. More...
 
pandora::StringVector m_caloHitListNames
 Names of input calo hit lists. More...
 
LArDLHelper::TorchModel m_modelU
 The model for the U view. More...
 
LArDLHelper::TorchModel m_modelV
 The model for the V view. More...
 
LArDLHelper::TorchModel m_modelW
 The model for the W view. More...
 
int m_pass
 The pass of the train/infer step. More...
 
int m_nClasses
 The number of distance classes. More...
 
int m_height
 The height of the images. More...
 
int m_width
 The width of the images. More...
 
float m_driftStep
 The size of a pixel in the drift direction in cm (most relevant in pass 2) More...
 
std::vector< double > m_thresholds
 Distance class thresholds. More...
 
std::string m_volumeType
 The name of the fiducial volume type for the monitoring output. More...
 

Private Types

typedef std::map< pandora::HitType, Canvas * > CanvasViewMap
 

Private Member Functions

pandora::StatusCode Run ()
 
pandora::StatusCode ReadSettings (const pandora::TiXmlHandle xmlHandle)
 
pandora::StatusCode PrepareTrainingSample ()
 
pandora::StatusCode Infer ()
 
pandora::StatusCode MakeNetworkInputFromHits (const pandora::CaloHitList &caloHits, const pandora::HitType view, const float xMin, const float xMax, const float zMin, const float zMax, LArDLHelper::TorchInput &networkInput, PixelVector &pixelVector) const
 
pandora::StatusCode GetNetworkVertices (const CanvasViewMap &canvases, pandora::CartesianPointVector &positionVector) const
 
pandora::StatusCode GetVerticesFromCanvas (const Canvas &canvas, pandora::CartesianPointVector &vertices) const
 
bool GrowPeak (const Canvas &canvas, int col, int row, float intensity, std::vector< std::pair< int, int >> &peak) const
 Determine if the pixel under consideration is part of a peak and grow that peak to include all connected pixels of equal value. More...
 
pandora::StatusCode MakeCandidateVertexList (const pandora::CartesianPointVector &positions)
 Create a vertex list from the candidate vertices. More...
 

Private Attributes

int m_event
 The current event number. More...
 
bool m_visualise
 Whether or not to visualise the candidate vertices. More...
 
bool m_writeTree
 Whether or not to write validation details to a ROOT tree. More...
 
std::string m_rootTreeName
 The ROOT tree name. More...
 
std::string m_rootFileName
 The ROOT file name. More...
 
std::mt19937 m_rng
 The random number generator. More...
 

Detailed Description

DeepLearningTrackShowerIdAlgorithm class.

Definition at line 28 of file DlSecondaryVertexingAlgorithm.h.

Member Typedef Documentation

typedef std::map<pandora::HitType, Canvas *> lar_dl_content::DlSecondaryVertexingAlgorithm::CanvasViewMap
private

Definition at line 63 of file DlSecondaryVertexingAlgorithm.h.

typedef std::pair<int, int> lar_dl_content::DlVertexingBaseAlgorithm::Pixel
protectedinherited

Definition at line 41 of file DlVertexingBaseAlgorithm.h.

typedef std::map<std::pair<int, int>, std::vector<const pandora::CaloHit *> > lar_dl_content::DlVertexingBaseAlgorithm::PixelToCaloHitsMap
inherited

Definition at line 31 of file DlVertexingBaseAlgorithm.h.

typedef std::vector<Pixel> lar_dl_content::DlVertexingBaseAlgorithm::PixelVector
protectedinherited

Definition at line 42 of file DlVertexingBaseAlgorithm.h.

Constructor & Destructor Documentation

lar_dl_content::DlSecondaryVertexingAlgorithm::DlSecondaryVertexingAlgorithm ( )

Default constructor.

Definition at line 33 of file DlSecondaryVertexingAlgorithm.cc.

References m_rng, m_visualise, and m_writeTree.

33  :
34  m_event{-1},
35  m_visualise{false},
36  m_writeTree{false},
37  m_rng(static_cast<std::mt19937::result_type>(std::chrono::high_resolution_clock::now().time_since_epoch().count()))
38 {
39 }
std::mt19937 m_rng
The random number generator.
bool m_visualise
Whether or not to visualise the candidate vertices.
bool m_writeTree
Whether or not to write validation details to a ROOT tree.
lar_dl_content::DlSecondaryVertexingAlgorithm::~DlSecondaryVertexingAlgorithm ( )

Definition at line 41 of file DlSecondaryVertexingAlgorithm.cc.

References e, m_rootFileName, m_rootTreeName, and m_writeTree.

42 {
43  if (m_writeTree)
44  {
45  try
46  {
47  PANDORA_MONITORING_API(SaveTree(this->GetPandora(), m_rootTreeName, m_rootFileName, "RECREATE"));
48  }
49  catch (StatusCodeException e)
50  {
51  std::cout << "VertexAssessmentAlgorithm: Unable to write to ROOT tree" << std::endl;
52  }
53  }
54 }
bool m_writeTree
Whether or not to write validation details to a ROOT tree.
Float_t e
Definition: plot.C:35

Member Function Documentation

void lar_dl_content::DlVertexingBaseAlgorithm::GetCanvasParameters ( const LArDLHelper::TorchOutput networkOutput,
const PixelVector pixelVector,
int &  columnOffset,
int &  rowOffset,
int &  width,
int &  height 
) const
protectedinherited

Determines the parameters of the canvas for extracting the vertex location. The network predicts the distance that each pixel associated with a hit is located from the vertex, but says nothing about the direction. As a result, the ring describing the potential vertices associated with that hit can extend beyond the original canvas size. This function returns the size of the required canvas and the offset for the bottom left corner.

Parameters
networkOutputThe TorchOutput object populated by the network inference step
pixelVectorThe vector of populated pixels
columnOffsetThe output column offset for the canvas
rowOffsetThe output row offset for the canvas
widthThe output width for the canvas
heightThe output height for the canvas

Definition at line 165 of file DlVertexingBaseAlgorithm.cc.

References col, lar_dl_content::DlVertexingBaseAlgorithm::m_height, lar_dl_content::DlVertexingBaseAlgorithm::m_thresholds, and lar_dl_content::DlVertexingBaseAlgorithm::m_width.

Referenced by lar_dl_content::DlVertexingAlgorithm::Infer(), and Infer().

167 {
168  const double scaleFactor{std::sqrt(m_height * m_height + m_width * m_width)};
169  // output is a 1 x num_classes x height x width tensor
170  // we want the maximum value in the num_classes dimension (1) for every pixel
171  auto classes{torch::argmax(networkOutput, 1)};
172  // the argmax result is a 1 x height x width tensor where each element is a class id
173  auto classesAccessor{classes.accessor<int64_t, 3>()};
174  int colOffsetMin{0}, colOffsetMax{0}, rowOffsetMin{0}, rowOffsetMax{0};
175  for (const auto &[row, col] : pixelVector)
176  {
177  const auto cls{classesAccessor[0][row][col]};
178  const double threshold{m_thresholds[cls]};
179  if (threshold > 0. && threshold < 1.)
180  {
181  const int distance = static_cast<int>(std::round(std::ceil(scaleFactor * threshold)));
182  if ((row - distance) < rowOffsetMin)
183  rowOffsetMin = row - distance;
184  if ((row + distance) > rowOffsetMax)
185  rowOffsetMax = row + distance;
186  if ((col - distance) < colOffsetMin)
187  colOffsetMin = col - distance;
188  if ((col + distance) > colOffsetMax)
189  colOffsetMax = col + distance;
190  }
191  }
192  colOffset = colOffsetMin < 0 ? -colOffsetMin : 0;
193  rowOffset = rowOffsetMin < 0 ? -rowOffsetMin : 0;
194  width = std::max(colOffsetMax + colOffset + 1, m_width);
195  height = std::max(rowOffsetMax + rowOffset + 1, m_height);
196 }
std::vector< double > m_thresholds
Distance class thresholds.
Int_t col[ntarg]
Definition: Style.C:29
void lar_dl_content::DlVertexingBaseAlgorithm::GetHitRegion ( const pandora::CaloHitList &  caloHitList,
float &  xMin,
float &  xMax,
float &  zMin,
float &  zMax 
) const
protectedinherited

Definition at line 50 of file DlVertexingBaseAlgorithm.cc.

References util::begin(), lar_dl_content::DlVertexingBaseAlgorithm::m_caloHitListNames, lar_dl_content::DlVertexingBaseAlgorithm::m_driftStep, lar_dl_content::DlVertexingBaseAlgorithm::m_height, lar_dl_content::DlVertexingBaseAlgorithm::m_inputVertexListName, lar_dl_content::DlVertexingBaseAlgorithm::m_pass, lar_dl_content::DlVertexingBaseAlgorithm::m_width, x, and z.

Referenced by lar_dl_content::DlVertexingAlgorithm::Infer(), Infer(), lar_dl_content::DlVertexingAlgorithm::PrepareTrainingSample(), and PrepareTrainingSample().

51 {
52  xMin = std::numeric_limits<float>::max();
53  xMax = -std::numeric_limits<float>::max();
54  zMin = std::numeric_limits<float>::max();
55  zMax = -std::numeric_limits<float>::max();
56  // Find the range of x and z values in the view
57  for (const CaloHit *pCaloHit : caloHitList)
58  {
59  const float x{pCaloHit->GetPositionVector().GetX()};
60  const float z{pCaloHit->GetPositionVector().GetZ()};
61  xMin = std::min(x, xMin);
62  xMax = std::max(x, xMax);
63  zMin = std::min(z, zMin);
64  zMax = std::max(z, zMax);
65  }
66 
67  if (caloHitList.empty())
68  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
69 
70  const HitType view{caloHitList.front()->GetHitType()};
71  const bool isU{view == TPC_VIEW_U}, isV{view == TPC_VIEW_V}, isW{view == TPC_VIEW_W};
72  if (!(isU || isV || isW))
73  throw StatusCodeException(STATUS_CODE_NOT_ALLOWED);
74 
75  // ATTN If wire w pitches vary between TPCs, exception will be raised in initialisation of lar pseudolayer plugin
76  const LArTPC *const pTPC(this->GetPandora().GetGeometry()->GetLArTPCMap().begin()->second);
77  const float pitch(view == TPC_VIEW_U ? pTPC->GetWirePitchU() : view == TPC_VIEW_V ? pTPC->GetWirePitchV() : pTPC->GetWirePitchW());
78 
79  if (m_pass > 1)
80  {
81  const VertexList *pVertexList(nullptr);
82  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, m_inputVertexListName, pVertexList));
83  if (pVertexList->empty())
84  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
85  const CartesianVector &vertex{pVertexList->front()->GetPosition()};
86 
87  // Get hit distribution left/right asymmetry
88  int nHitsLeft{0}, nHitsRight{0};
89  const double xVtx{vertex.GetX()};
90  for (const std::string &listname : m_caloHitListNames)
91  {
92  const CaloHitList *pCaloHitList(nullptr);
93  PANDORA_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, listname, pCaloHitList));
94  if (pCaloHitList->empty())
95  continue;
96  for (const CaloHit *const pCaloHit : *pCaloHitList)
97  {
98  const CartesianVector &pos{pCaloHit->GetPositionVector()};
99  if (pos.GetX() <= xVtx)
100  ++nHitsLeft;
101  else
102  ++nHitsRight;
103  }
104  }
105  const int nHitsTotal{nHitsLeft + nHitsRight};
106  if (nHitsTotal == 0)
107  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
108  const float xAsymmetry{nHitsLeft / static_cast<float>(nHitsTotal)};
109 
110  // Vertices
111  const LArTransformationPlugin *transform{this->GetPandora().GetPlugins()->GetLArTransformationPlugin()};
112  double zVtx{0.};
113  if (isW)
114  zVtx += transform->YZtoW(vertex.GetY(), vertex.GetZ());
115  else if (isV)
116  zVtx += transform->YZtoV(vertex.GetY(), vertex.GetZ());
117  else
118  zVtx = transform->YZtoU(vertex.GetY(), vertex.GetZ());
119 
120  // Get hit distribution upstream/downstream asymmetry
121  int nHitsUpstream{0}, nHitsDownstream{0};
122  for (const CaloHit *const pCaloHit : caloHitList)
123  {
124  const CartesianVector &pos{pCaloHit->GetPositionVector()};
125  if (pos.GetZ() <= zVtx)
126  ++nHitsUpstream;
127  else
128  ++nHitsDownstream;
129  }
130  const int nHitsViewTotal{nHitsUpstream + nHitsDownstream};
131  if (nHitsViewTotal == 0)
132  throw StatusCodeException(STATUS_CODE_NOT_FOUND);
133  const float zAsymmetry{nHitsUpstream / static_cast<float>(nHitsViewTotal)};
134 
135  const float xSpan{m_driftStep * (m_width - 1)};
136  xMin = xVtx - xAsymmetry * xSpan;
137  xMax = xMin + (m_driftStep * (m_width - 1));
138  const float zSpan{pitch * (m_height - 1)};
139  zMin = zVtx - zAsymmetry * zSpan;
140  zMax = zMin + zSpan;
141  }
142 
143  // Avoid unreasonable rescaling of very small hit regions, pixels are assumed to be 0.5cm in x and wire pitch in z
144  // ATTN: Rescaling is to a size 1 pixel smaller than the intended image to ensure all hits fit within an imaged binned
145  // to be one pixel wider than this
146  const float xRange{xMax - xMin}, zRange{zMax - zMin};
147  const float minXSpan{m_driftStep * (m_width - 1)};
148  if (xRange < minXSpan)
149  {
150  const float padding{0.5f * (minXSpan - xRange)};
151  xMin -= padding;
152  xMax += padding;
153  }
154  const float minZSpan{pitch * (m_height - 1)};
155  if (zRange < minZSpan)
156  {
157  const float padding{0.5f * (minZSpan - zRange)};
158  zMin -= padding;
159  zMax += padding;
160  }
161 }
Float_t x
Definition: compare.C:6
int m_pass
The pass of the train/infer step.
Double_t z
Definition: plot.C:276
float m_driftStep
The size of a pixel in the drift direction in cm (most relevant in pass 2)
pandora::StringVector m_caloHitListNames
Names of input calo hit lists.
std::string m_inputVertexListName
Input vertex list name if 2nd pass.
HitType
Definition: HitType.h:12
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
std::list< Vertex > VertexList
Definition: DCEL.h:169
vertex reconstruction
StatusCode lar_dl_content::DlSecondaryVertexingAlgorithm::GetNetworkVertices ( const CanvasViewMap canvases,
pandora::CartesianPointVector &  positionVector 
) const
private

Definition at line 334 of file DlSecondaryVertexingAlgorithm.cc.

References lar_dl_content::VertexTuple::GetChi2(), lar_dl_content::VertexTuple::GetComponents(), and GetVerticesFromCanvas().

Referenced by Infer().

335 {
336  CartesianPointVector verticesU, verticesV, verticesW;
337  this->GetVerticesFromCanvas(*canvases.at(TPC_VIEW_U), verticesU);
338  this->GetVerticesFromCanvas(*canvases.at(TPC_VIEW_V), verticesV);
339  this->GetVerticesFromCanvas(*canvases.at(TPC_VIEW_W), verticesW);
340 
341  std::vector<VertexTuple> vertexTuples;
342  int nEmptyLists{(verticesU.empty() ? 1 : 0) + (verticesV.empty() ? 1 : 0) + (verticesW.empty() ? 1 : 0)};
343 
344  if (nEmptyLists == 0)
345  {
346  for (const CartesianVector &vertexU : verticesU)
347  {
348  for (const CartesianVector &vertexV : verticesV)
349  {
350  for (const CartesianVector &vertexW : verticesW)
351  {
352  const float xMin{std::min({vertexU.GetX(), vertexV.GetX(), vertexW.GetX()})};
353  const float xMax{std::max({vertexU.GetX(), vertexV.GetX(), vertexW.GetX()})};
354  if ((xMax - xMin) < 10.f)
355  {
356  const VertexTuple &tuple{VertexTuple(this->GetPandora(), vertexU, vertexV, vertexW)};
357  if (tuple.GetChi2() < 1)
358  vertexTuples.emplace_back(tuple);
359  }
360  }
361  }
362  }
363  }
364  else if (nEmptyLists == 1)
365  {
366  if (verticesU.empty())
367  {
368  for (const CartesianVector &vertexV : verticesV)
369  {
370  for (const CartesianVector &vertexW : verticesW)
371  {
372  const float xMin{std::min({vertexV.GetX(), vertexW.GetX()})};
373  const float xMax{std::max({vertexV.GetX(), vertexW.GetX()})};
374  if ((xMax - xMin) < 10.f)
375  {
376  const VertexTuple &tuple{VertexTuple(this->GetPandora(), vertexV, vertexW, TPC_VIEW_V, TPC_VIEW_W)};
377  if (tuple.GetChi2() < 1)
378  vertexTuples.emplace_back(tuple);
379  }
380  }
381  }
382  }
383  else if (verticesV.empty())
384  {
385  for (const CartesianVector &vertexU : verticesU)
386  {
387  for (const CartesianVector &vertexW : verticesW)
388  {
389  const float xMin{std::min({vertexU.GetX(), vertexW.GetX()})};
390  const float xMax{std::max({vertexU.GetX(), vertexW.GetX()})};
391  if ((xMax - xMin) < 10.f)
392  {
393  const VertexTuple &tuple{VertexTuple(this->GetPandora(), vertexU, vertexW, TPC_VIEW_U, TPC_VIEW_W)};
394  if (tuple.GetChi2() < 1)
395  vertexTuples.emplace_back(tuple);
396  }
397  }
398  }
399  }
400  else
401  {
402  for (const CartesianVector &vertexU : verticesU)
403  {
404  for (const CartesianVector &vertexV : verticesV)
405  {
406  const float xMin{std::min({vertexU.GetX(), vertexV.GetX()})};
407  const float xMax{std::max({vertexU.GetX(), vertexV.GetX()})};
408  if ((xMax - xMin) < 10.f)
409  {
410  const VertexTuple &tuple{VertexTuple(this->GetPandora(), vertexU, vertexV, TPC_VIEW_U, TPC_VIEW_V)};
411  if (tuple.GetChi2() < 1)
412  vertexTuples.emplace_back(tuple);
413  }
414  }
415  }
416  }
417  }
418  else
419  {
420  std::cout << "Insufficient 2D vertices to reconstruct a 3D vertex" << std::endl;
421  return STATUS_CODE_NOT_FOUND;
422  }
423 
424  // Sort the vertex tuples here and pick the unique ones that look sound
425  std::sort(vertexTuples.begin(), vertexTuples.end(),
426  [](const VertexTuple &tuple1, const VertexTuple &tuple2)
427  {
428  const CartesianPointVector &components1{tuple1.GetComponents()};
429  const CartesianPointVector &components2{tuple2.GetComponents()};
430  if (components1.size() == components2.size())
431  return tuple1.GetChi2() < tuple2.GetChi2();
432  else
433  return components1.size() > components2.size();
434  });
435 
436  CartesianPointVector used;
437  for (const VertexTuple &tuple : vertexTuples)
438  {
439  const CartesianPointVector &components{tuple.GetComponents()};
440  bool isAvailable{true};
441  for (const CartesianVector &component : components)
442  {
443  if (std::find(used.begin(), used.end(), component) != used.end())
444  {
445  isAvailable = false;
446  break;
447  }
448  }
449  if (!isAvailable || (components.size() < 3 && tuple.GetChi2() > 0.1))
450  continue;
451 
452  positionVector.emplace_back(tuple.GetPosition());
453  for (const CartesianVector &component : components)
454  used.emplace_back(component);
455  }
456 
457  return STATUS_CODE_SUCCESS;
458 }
pandora::StatusCode GetVerticesFromCanvas(const Canvas &canvas, pandora::CartesianPointVector &vertices) const
StatusCode lar_dl_content::DlSecondaryVertexingAlgorithm::GetVerticesFromCanvas ( const Canvas canvas,
pandora::CartesianPointVector &  vertices 
) const
private

Definition at line 462 of file DlSecondaryVertexingAlgorithm.cc.

References util::begin(), col, GrowPeak(), lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_canvas, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_colOffset, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_height, lar_dl_content::DlVertexingBaseAlgorithm::m_height, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_rowOffset, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_view, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_width, lar_dl_content::DlVertexingBaseAlgorithm::m_width, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_xMax, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_xMin, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_zMax, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_zMin, pt, r, x, and z.

Referenced by GetNetworkVertices().

463 {
464  // ATTN If wire w pitches vary between TPCs, exception will be raised in initialisation of lar pseudolayer plugin
465  const LArTPC *const pTPC(this->GetPandora().GetGeometry()->GetLArTPCMap().begin()->second);
466 
467  HitType view{canvas.m_view};
468  const float pitch(view == TPC_VIEW_U ? pTPC->GetWirePitchU() : view == TPC_VIEW_V ? pTPC->GetWirePitchV() : pTPC->GetWirePitchW());
469  const float driftStep{0.5f};
470 
471  const double dx{((canvas.m_xMax + 0.5f * driftStep) - (canvas.m_xMin - 0.5f * driftStep)) / m_width};
472  const double dz{((canvas.m_zMax + 0.5f * pitch) - (canvas.m_zMin - 0.5f * pitch)) / m_height};
473 
474  float maxIntensity{0.f};
475  for (int xp = 0; xp < m_width; ++xp)
476  {
477  int xpp{xp + canvas.m_colOffset};
478  if (xpp >= canvas.m_width)
479  continue;
480 
481  for (int zp = 0; zp < m_height; ++zp)
482  {
483  int zpp{zp + canvas.m_rowOffset};
484  if (zpp >= canvas.m_height)
485  continue;
486 
487  const float localIntensity{canvas.m_canvas[zpp][xpp]};
488  if (localIntensity > maxIntensity)
489  maxIntensity = localIntensity;
490  }
491  }
492  const float threshold{maxIntensity * 0.3f};
493 
494  std::vector<std::vector<std::pair<int, int>>> peaks;
495  for (int xp = 0; xp < m_width; ++xp)
496  {
497  int xpp{xp + canvas.m_colOffset};
498  if (xpp >= canvas.m_width)
499  continue;
500 
501  for (int zp = 0; zp < m_height; ++zp)
502  {
503  int zpp{zp + canvas.m_rowOffset};
504  if (zpp >= canvas.m_height)
505  continue;
506  const float localIntensity{canvas.m_canvas[zpp][xpp]};
507 
508  std::vector<std::pair<int, int>> peak;
509  bool hasLowNeighbour{false};
510  for (int dr = -1; dr <= 1; ++dr)
511  {
512  for (int dc = -1; dc <= 1; ++dc)
513  {
514  if (dr == 0 && dc == 0)
515  continue;
516  const int r{zpp + dr}, c{xpp + dc};
517  if (r < 0 || r >= canvas.m_height || c < 0 || c >= canvas.m_width)
518  continue;
519 
520  const float neighborIntensity{canvas.m_canvas[r][c]};
521  if (localIntensity > neighborIntensity)
522  {
523  hasLowNeighbour = true;
524  }
525  else if (localIntensity < neighborIntensity)
526  {
527  hasLowNeighbour = false;
528  break;
529  }
530  }
531  }
532  if (hasLowNeighbour && localIntensity > threshold)
533  this->GrowPeak(canvas, xpp, zpp, localIntensity, peak);
534  if (!peak.empty())
535  peaks.emplace_back(peak);
536  }
537  }
538 
539  for (const auto &peak : peaks)
540  {
541  float row{0}, col{0};
542  for (const auto &pixel : peak)
543  {
544  row += pixel.second - canvas.m_rowOffset;
545  col += pixel.first - canvas.m_colOffset;
546  }
547  row /= peak.size();
548  col /= peak.size();
549 
550  const float x{static_cast<float>(col * dx + canvas.m_xMin)};
551  const float z{static_cast<float>(row * dz + canvas.m_zMin)};
552  CartesianVector pt(x, 0, z);
553  vertices.emplace_back(pt);
554  }
555 
556  return STATUS_CODE_SUCCESS;
557 }
Float_t x
Definition: compare.C:6
TRandom r
Definition: spectrum.C:23
Double_t z
Definition: plot.C:276
Int_t col[ntarg]
Definition: Style.C:29
TMarker * pt
Definition: egs.C:25
HitType
Definition: HitType.h:12
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
bool GrowPeak(const Canvas &canvas, int col, int row, float intensity, std::vector< std::pair< int, int >> &peak) const
Determine if the pixel under consideration is part of a peak and grow that peak to include all connec...
bool lar_dl_content::DlSecondaryVertexingAlgorithm::GrowPeak ( const Canvas canvas,
int  col,
int  row,
float  intensity,
std::vector< std::pair< int, int >> &  peak 
) const
private

Determine if the pixel under consideration is part of a peak and grow that peak to include all connected pixels of equal value.

Parameters
canvasThe canvas within which peaks are sought
colThe column of the pixel under consideration
rowThe row of the pixel under consideration
intensityThe target intensity of the candidate peak
peakThe output vector of pixels constituting the peak under consideration
Returns
true if we found a better peak while growing the current region, false otherwise

Definition at line 561 of file DlSecondaryVertexingAlgorithm.cc.

References col, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_canvas, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_height, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_visited, lar_dl_content::DlSecondaryVertexingAlgorithm::Canvas::m_width, and r.

Referenced by GetVerticesFromCanvas().

562 {
563  // if (col >= 0 && col < canvas.m_width && row >= 0 && row < canvas.m_height)
564  // {
565  // std::cout << "Visited: " << canvas.m_visited[row][col] << " " <<
566  // }
567  if (col < 0 || col >= canvas.m_width || row < 0 || row >= canvas.m_height || canvas.m_visited[row][col] || canvas.m_canvas[row][col] < intensity)
568  return false;
569 
570  // Check that no adjacent pixel is larger than this one
571  for (int dc = -1; dc <= 1; ++dc)
572  {
573  const int c{col + dc};
574  if (c < 0 || c >= canvas.m_width)
575  continue;
576 
577  for (int dr = -1; dr <= 1; ++dr)
578  {
579  const int r{row + dr};
580  if (r < 0 || r >= canvas.m_height)
581  continue;
582 
583  if (dr == 0 && dc == 0)
584  continue;
585 
586  const float neighborIntensity{canvas.m_canvas[r][c]};
587  if (neighborIntensity > intensity)
588  return false;
589  }
590  }
591 
592  // Need to check we aren't growing into a higher peak, if we are restart from the current pixel
593  float localIntensity{canvas.m_canvas[row][col]};
594  if (localIntensity > intensity)
595  {
596  intensity = localIntensity;
597  for (const auto &pixel : peak)
598  canvas.m_visited[pixel.second][pixel.first] = false;
599  peak.clear();
600  //std::cout << ". New size " << peak.size() << " new intensity " << intensity << std::endl;
601  this->GrowPeak(canvas, col, row, intensity, peak);
602  return true;
603  }
604 
605  // Add pixel to the peak
606  canvas.m_visited[row][col] = true;
607  peak.emplace_back(std::make_pair(col, row));
608  //std::cout << " Added" << std::endl;
609 
610  for (int dc = -1; dc <= 1; ++dc)
611  {
612  for (int dr = -1; dr <= 1; ++dr)
613  {
614  if (dr == 0 && dc == 0)
615  continue;
616  //std::cout << " Adjacent (" << (row + i) << "," << (col + j) << ")" << std::endl;
617  bool reset{this->GrowPeak(canvas, col + dc, row + dr, intensity, peak)};
618  // If we started growing a non-peak region, stop looking relative to the previous peak
619  if (reset)
620  return reset;
621  }
622  }
623 
624  return false;
625 }
TRandom r
Definition: spectrum.C:23
Int_t col[ntarg]
Definition: Style.C:29
bool GrowPeak(const Canvas &canvas, int col, int row, float intensity, std::vector< std::pair< int, int >> &peak) const
Determine if the pixel under consideration is part of a peak and grow that peak to include all connec...
StatusCode lar_dl_content::DlSecondaryVertexingAlgorithm::Infer ( )
private

Definition at line 178 of file DlSecondaryVertexingAlgorithm.cc.

References col, lar_dl_content::LArCanvasHelper::DrawRing(), f, lar_dl_content::LArDLHelper::Forward(), lar_dl_content::DlVertexingBaseAlgorithm::GetCanvasParameters(), lar_dl_content::DlVertexingBaseAlgorithm::GetHitRegion(), GetNetworkVertices(), lar_dl_content::DlVertexingBaseAlgorithm::m_caloHitListNames, lar_dl_content::DlVertexingBaseAlgorithm::m_height, lar_dl_content::DlVertexingBaseAlgorithm::m_modelU, lar_dl_content::DlVertexingBaseAlgorithm::m_modelV, lar_dl_content::DlVertexingBaseAlgorithm::m_modelW, lar_dl_content::DlVertexingBaseAlgorithm::m_nClasses, lar_dl_content::DlVertexingBaseAlgorithm::m_thresholds, lar_dl_content::DlVertexingBaseAlgorithm::m_width, MakeCandidateVertexList(), and MakeNetworkInputFromHits().

Referenced by Run().

179 {
180  // Get boundaries for hits and make x dimension common
181  std::map<HitType, float> wireMin, wireMax;
182  float driftMin{std::numeric_limits<float>::max()}, driftMax{-std::numeric_limits<float>::max()};
183  for (const std::string &listname : m_caloHitListNames)
184  {
185  const CaloHitList *pCaloHitList{nullptr};
186  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, listname, pCaloHitList));
187  if (pCaloHitList->empty())
188  continue;
189 
190  HitType view{pCaloHitList->front()->GetHitType()};
191  float viewDriftMin{driftMin}, viewDriftMax{driftMax};
192  this->GetHitRegion(*pCaloHitList, viewDriftMin, viewDriftMax, wireMin[view], wireMax[view]);
193  driftMin = std::min(viewDriftMin, driftMin);
194  driftMax = std::max(viewDriftMax, driftMax);
195  }
196 
197  CanvasViewMap canvases;
198  canvases[TPC_VIEW_U] = nullptr;
199  canvases[TPC_VIEW_V] = nullptr;
200  canvases[TPC_VIEW_W] = nullptr;
201  CartesianPointVector vertexCandidatesU, vertexCandidatesV, vertexCandidatesW;
202  for (const std::string &listname : m_caloHitListNames)
203  {
204  const CaloHitList *pCaloHitList{nullptr};
205  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, listname, pCaloHitList));
206  if (pCaloHitList->empty())
207  continue;
208 
209  HitType view{pCaloHitList->front()->GetHitType()};
211  PixelVector pixelVector;
212  this->MakeNetworkInputFromHits(*pCaloHitList, view, driftMin, driftMax, wireMin[view], wireMax[view], input, pixelVector);
213 
214  // Run the input through the trained model
216  inputs.push_back(input);
218  switch (view)
219  {
220  case TPC_VIEW_U:
221  LArDLHelper::Forward(m_modelU, inputs, output);
222  break;
223  case TPC_VIEW_V:
224  LArDLHelper::Forward(m_modelV, inputs, output);
225  break;
226  default:
227  LArDLHelper::Forward(m_modelW, inputs, output);
228  break;
229  }
230 
231  int colOffset{0}, rowOffset{0}, canvasWidth{m_width}, canvasHeight{m_height};
232  this->GetCanvasParameters(output, pixelVector, colOffset, rowOffset, canvasWidth, canvasHeight);
233  canvases[view] = new Canvas(view, canvasWidth, canvasHeight, colOffset, rowOffset, driftMin, driftMax, wireMin[view], wireMax[view]);
234  // we want the maximum value in the num_classes dimension (1) for every pixel
235  auto classes{torch::argmax(output, 1)};
236  // the argmax result is a 1 x height x width tensor where each element is a class id
237  auto classesAccessor{classes.accessor<long, 3>()};
238  const double scaleFactor{std::sqrt(m_height * m_height + m_width * m_width)};
239  std::map<int, bool> haveSeenMap;
240  for (const auto &[row, col] : pixelVector)
241  {
242  const auto cls{classesAccessor[0][row][col]};
243  if (cls > 0 && cls < m_nClasses)
244  {
245  const int inner{static_cast<int>(std::round(std::ceil(scaleFactor * m_thresholds[cls - 1])))};
246  const int outer{static_cast<int>(std::round(std::ceil(scaleFactor * m_thresholds[cls])))};
248  canvases[view]->m_canvas, row + rowOffset, col + colOffset, inner, outer, 1.f / (outer * outer - inner * inner));
249  }
250  }
251  }
252 
253  CartesianPointVector vertexVector;
254  this->GetNetworkVertices(canvases, vertexVector);
255 
256  if (!vertexVector.empty())
257  {
258  StatusCode status{this->MakeCandidateVertexList(vertexVector)};
259 
260  for (const HitType view : {TPC_VIEW_U, TPC_VIEW_V, TPC_VIEW_W})
261  {
262  if (canvases[view])
263  delete canvases[view];
264  }
265 
266  return status;
267  }
268  else
269  {
270  for (const HitType view : {TPC_VIEW_U, TPC_VIEW_V, TPC_VIEW_W})
271  {
272  if (canvases[view])
273  delete canvases[view];
274  }
275 
276  return STATUS_CODE_SUCCESS;
277  }
278 }
pandora::StatusCode GetNetworkVertices(const CanvasViewMap &canvases, pandora::CartesianPointVector &positionVector) const
pandora::StatusCode MakeNetworkInputFromHits(const pandora::CaloHitList &caloHits, const pandora::HitType view, const float xMin, const float xMax, const float zMin, const float zMax, LArDLHelper::TorchInput &networkInput, PixelVector &pixelVector) const
LArDLHelper::TorchModel m_modelU
The model for the U view.
std::vector< double > m_thresholds
Distance class thresholds.
TFile f
Definition: plotHisto.C:6
static void DrawRing(float **canvas, const int row, const int col, const int inner, const int outer, const float weight)
Add a filled ring to the specified canvas. The ring has an inner radius based on the minimum predicte...
Int_t col[ntarg]
Definition: Style.C:29
pandora::StringVector m_caloHitListNames
Names of input calo hit lists.
void GetHitRegion(const pandora::CaloHitList &caloHitList, float &xMin, float &xMax, float &zMin, float &zMax) const
static void Forward(TorchModel &model, const TorchInputVector &input, TorchOutput &output)
Run a deep learning model.
Definition: LArDLHelper.cc:41
void GetCanvasParameters(const LArDLHelper::TorchOutput &networkOutput, const PixelVector &pixelVector, int &columnOffset, int &rowOffset, int &width, int &height) const
Determines the parameters of the canvas for extracting the vertex location. The network predicts the ...
pandora::StatusCode MakeCandidateVertexList(const pandora::CartesianPointVector &positions)
Create a vertex list from the candidate vertices.
LArDLHelper::TorchModel m_modelW
The model for the W view.
HitType
Definition: HitType.h:12
std::map< pandora::HitType, Canvas * > CanvasViewMap
int m_nClasses
The number of distance classes.
LArDLHelper::TorchModel m_modelV
The model for the V view.
std::vector< torch::jit::IValue > TorchInputVector
Definition: LArDLHelper.h:27
StatusCode lar_dl_content::DlSecondaryVertexingAlgorithm::MakeCandidateVertexList ( const pandora::CartesianPointVector &  positions)
private

Create a vertex list from the candidate vertices.

Parameters
candidatesThe candidate positions with which to create the list.
Returns
The StatusCode resulting from the function

Definition at line 629 of file DlSecondaryVertexingAlgorithm.cc.

References lar_dl_content::DlVertexingBaseAlgorithm::m_outputVertexListName.

Referenced by Infer().

630 {
631  const VertexList *pVertexList{nullptr};
632  std::string temporaryListName;
633  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::CreateTemporaryListAndSetCurrent(*this, pVertexList, temporaryListName));
634 
635  for (const CartesianVector &position : positions)
636  {
637  PandoraContentApi::Vertex::Parameters parameters;
638  parameters.m_position = position;
639  parameters.m_vertexLabel = VERTEX_INTERACTION;
640  parameters.m_vertexType = VERTEX_3D;
641 
642  const Vertex *pVertex(nullptr);
643  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::Vertex::Create(*this, parameters, pVertex));
644  }
645  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::SaveList<Vertex>(*this, m_outputVertexListName));
646 
647  return STATUS_CODE_SUCCESS;
648 }
std::string m_outputVertexListName
Output vertex list name.
boost::graph_traits< ModuleGraph >::vertex_descriptor Vertex
Definition: ModuleGraph.h:25
std::list< Vertex > VertexList
Definition: DCEL.h:169
StatusCode lar_dl_content::DlSecondaryVertexingAlgorithm::MakeNetworkInputFromHits ( const pandora::CaloHitList &  caloHits,
const pandora::HitType  view,
const float  xMin,
const float  xMax,
const float  zMin,
const float  zMax,
LArDLHelper::TorchInput networkInput,
PixelVector pixelVector 
) const
private

Definition at line 282 of file DlSecondaryVertexingAlgorithm.cc.

References util::begin(), col, lar_dl_content::LArDLHelper::InitialiseInput(), lar_dl_content::DlVertexingBaseAlgorithm::m_height, lar_dl_content::DlVertexingBaseAlgorithm::m_pass, lar_dl_content::DlVertexingBaseAlgorithm::m_width, value, x, and z.

Referenced by Infer().

284 {
285  // ATTN If wire w pitches vary between TPCs, exception will be raised in initialisation of lar pseudolayer plugin
286  const LArTPC *const pTPC(this->GetPandora().GetGeometry()->GetLArTPCMap().begin()->second);
287  const float pitch(view == TPC_VIEW_U ? pTPC->GetWirePitchU() : view == TPC_VIEW_V ? pTPC->GetWirePitchV() : pTPC->GetWirePitchW());
288  const float driftStep{0.5f};
289 
290  // Determine the bin edges
291  std::vector<double> xBinEdges(m_width + 1);
292  std::vector<double> zBinEdges(m_height + 1);
293  xBinEdges[0] = xMin - 0.5f * driftStep;
294  const double dx = ((xMax + 0.5f * driftStep) - xBinEdges[0]) / m_width;
295  for (int i = 1; i < m_width + 1; ++i)
296  xBinEdges[i] = xBinEdges[i - 1] + dx;
297  zBinEdges[0] = zMin - 0.5f * pitch;
298  const double dz = ((zMax + 0.5f * pitch) - zBinEdges[0]) / m_height;
299  for (int i = 1; i < m_height + 1; ++i)
300  zBinEdges[i] = zBinEdges[i - 1] + dz;
301 
302  LArDLHelper::InitialiseInput({1, 1, m_height, m_width}, networkInput);
303  auto accessor = networkInput.accessor<float, 4>();
304 
305  for (const CaloHit *pCaloHit : caloHits)
306  {
307  const float x{pCaloHit->GetPositionVector().GetX()};
308  const float z{pCaloHit->GetPositionVector().GetZ()};
309  if (m_pass > 1)
310  {
311  if (x < xMin || x > xMax || z < zMin || z > zMax)
312  continue;
313  }
314  const float adc{pCaloHit->GetMipEquivalentEnergy()};
315  const int pixelX{static_cast<int>(std::floor((x - xBinEdges[0]) / dx))};
316  const int pixelZ{static_cast<int>(std::floor((z - zBinEdges[0]) / dz))};
317  accessor[0][0][pixelZ][pixelX] += adc;
318  }
319  for (int row = 0; row < m_height; ++row)
320  {
321  for (int col = 0; col < m_width; ++col)
322  {
323  const float value{accessor[0][0][row][col]};
324  if (value > 0)
325  pixelVector.emplace_back(std::make_pair(row, col));
326  }
327  }
328 
329  return STATUS_CODE_SUCCESS;
330 }
Float_t x
Definition: compare.C:6
int m_pass
The pass of the train/infer step.
Double_t z
Definition: plot.C:276
Int_t col[ntarg]
Definition: Style.C:29
double value
Definition: spectrum.C:18
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:82
static void InitialiseInput(const at::IntArrayRef dimensions, TorchInput &tensor)
Create a torch input tensor.
Definition: LArDLHelper.cc:34
StatusCode lar_dl_content::DlSecondaryVertexingAlgorithm::PrepareTrainingSample ( )
private

Definition at line 70 of file DlSecondaryVertexingAlgorithm.cc.

References lar_content::LArEventTopology::ConstructVisibleHierarchy(), lar_dl_content::DlVertexingBaseAlgorithm::GetHitRegion(), lar_content::LArEventTopology::GetVertices(), lar_dl_content::DlVertexingBaseAlgorithm::m_caloHitListNames, m_event, lar_dl_content::DlVertexingBaseAlgorithm::m_trainingOutputFile, lar_dl_content::DlVertexingBaseAlgorithm::m_volumeType, and lar_content::LArEventTopology::PruneHierarchy().

Referenced by Run().

71 {
72  const CaloHitList *pCaloHitList2D{nullptr};
73  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, "CaloHitList2D", pCaloHitList2D));
74  LArEventTopology eventTopology(*pCaloHitList2D);
75  eventTopology.ConstructVisibleHierarchy();
76  eventTopology.PruneHierarchy();
77  CartesianPointVector vertices;
78  eventTopology.GetVertices(vertices);
79 
80  // Only train on events where there is a vertex in the fiducial volume
81  bool hasFiducialVertex{false};
82  for (const CartesianVector &vertex : vertices)
83  {
84  if (LArVertexHelper::IsInFiducialVolume(this->GetPandora(), vertex, m_volumeType))
85  {
86  hasFiducialVertex = true;
87  break;
88  }
89  }
90 
91  if (!hasFiducialVertex)
92  return STATUS_CODE_SUCCESS;
93 
94  const MCParticleList *pMCParticleList(nullptr);
95  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetCurrentList(*this, pMCParticleList));
97  LArMCParticleHelper::GetMCToHitsMap(pCaloHitList2D, pMCParticleList, mcToHitsMap);
98  MCParticleList hierarchy;
99  LArMCParticleHelper::CompleteMCHierarchy(mcToHitsMap, hierarchy);
100 
101  // Get boundaries for hits and make x dimension common
102  std::map<HitType, float> wireMin, wireMax;
103  float driftMin{std::numeric_limits<float>::max()}, driftMax{-std::numeric_limits<float>::max()};
104  for (const std::string &listname : m_caloHitListNames)
105  {
106  const CaloHitList *pCaloHitList{nullptr};
107  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, listname, pCaloHitList));
108  if (pCaloHitList->empty())
109  continue;
110 
111  HitType view{pCaloHitList->front()->GetHitType()};
112  float viewDriftMin{driftMin}, viewDriftMax{driftMax};
113  this->GetHitRegion(*pCaloHitList, viewDriftMin, viewDriftMax, wireMin[view], wireMax[view]);
114  driftMin = std::min(viewDriftMin, driftMin);
115  driftMax = std::max(viewDriftMax, driftMax);
116  }
117  for (const std::string &listname : m_caloHitListNames)
118  {
119  const CaloHitList *pCaloHitList(nullptr);
120  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, PandoraContentApi::GetList(*this, listname, pCaloHitList));
121  if (pCaloHitList->empty())
122  continue;
123 
124  HitType view{pCaloHitList->front()->GetHitType()};
125 
126  const std::string trainingFilename{m_trainingOutputFile + "_" + listname + ".csv"};
127  const unsigned long nVertices{vertices.size()};
128  unsigned long nHits{0};
129 
130  LArMvaHelper::MvaFeatureVector featureVector;
131  featureVector.emplace_back(static_cast<double>(m_event));
132  featureVector.emplace_back(static_cast<double>(nVertices));
133  // Vertices
134  const LArTransformationPlugin *transform{this->GetPandora().GetPlugins()->GetLArTransformationPlugin()};
135  for (const CartesianVector &vertex : vertices)
136  {
137  switch (view)
138  {
139  case TPC_VIEW_U:
140  featureVector.emplace_back(vertex.GetX());
141  featureVector.emplace_back(transform->YZtoU(vertex.GetY(), vertex.GetZ()));
142  break;
143  case TPC_VIEW_V:
144  featureVector.emplace_back(vertex.GetX());
145  featureVector.emplace_back(transform->YZtoV(vertex.GetY(), vertex.GetZ()));
146  break;
147  default:
148  featureVector.emplace_back(vertex.GetX());
149  featureVector.emplace_back(transform->YZtoW(vertex.GetY(), vertex.GetZ()));
150  break;
151  }
152  }
153 
154  // Retain the hit region
155  featureVector.emplace_back(driftMin);
156  featureVector.emplace_back(driftMax);
157  featureVector.emplace_back(wireMin[view]);
158  featureVector.emplace_back(wireMax[view]);
159 
160  for (const CaloHit *pCaloHit : *pCaloHitList)
161  {
162  featureVector.emplace_back(static_cast<double>(pCaloHit->GetPositionVector().GetX()));
163  featureVector.emplace_back(static_cast<double>(pCaloHit->GetPositionVector().GetZ()));
164  featureVector.emplace_back(static_cast<double>(pCaloHit->GetMipEquivalentEnergy()));
165  ++nHits;
166  }
167  featureVector.insert(featureVector.begin() + 2 + 2 * nVertices + 4, static_cast<double>(nHits));
168  // Only write out the feature vector if there were enough hits in the region of interest
169  if (nHits > 10)
170  LArMvaHelper::ProduceTrainingExample(trainingFilename, true, featureVector);
171  }
172 
173  return STATUS_CODE_SUCCESS;
174 }
std::unordered_map< const pandora::MCParticle *, pandora::CaloHitList > MCContributionMap
MvaTypes::MvaFeatureVector MvaFeatureVector
Definition: LArMvaHelper.h:75
LArEventTopology class.
std::string m_trainingOutputFile
Output file name for training examples.
pandora::StringVector m_caloHitListNames
Names of input calo hit lists.
void GetHitRegion(const pandora::CaloHitList &caloHitList, float &xMin, float &xMax, float &zMin, float &zMax) const
HitType
Definition: HitType.h:12
std::string m_volumeType
The name of the fiducial volume type for the monitoring output.
vertex reconstruction
StatusCode lar_dl_content::DlSecondaryVertexingAlgorithm::ReadSettings ( const pandora::TiXmlHandle  xmlHandle)
private

Definition at line 652 of file DlSecondaryVertexingAlgorithm.cc.

References m_rootFileName, m_rootTreeName, lar_dl_content::DlVertexingBaseAlgorithm::m_trainingMode, m_visualise, m_writeTree, and lar_dl_content::DlVertexingBaseAlgorithm::ReadSettings().

653 {
654  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, DlVertexingBaseAlgorithm::ReadSettings(xmlHandle));
655 
656  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "Visualise", m_visualise));
657 
658  if (!m_trainingMode)
659  {
660  PANDORA_RETURN_RESULT_IF_AND_IF(STATUS_CODE_SUCCESS, STATUS_CODE_NOT_FOUND, !=, XmlHelper::ReadValue(xmlHandle, "WriteTree", m_writeTree));
661  if (m_writeTree)
662  {
663  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "RootTreeName", m_rootTreeName));
664  PANDORA_RETURN_RESULT_IF(STATUS_CODE_SUCCESS, !=, XmlHelper::ReadValue(xmlHandle, "RootFileName", m_rootFileName));
665  }
666  }
667 
668  return STATUS_CODE_SUCCESS;
669 }
pandora::StatusCode ReadSettings(const pandora::TiXmlHandle xmlHandle)
bool m_visualise
Whether or not to visualise the candidate vertices.
bool m_writeTree
Whether or not to write validation details to a ROOT tree.
StatusCode lar_dl_content::DlSecondaryVertexingAlgorithm::Run ( )
private

Definition at line 58 of file DlSecondaryVertexingAlgorithm.cc.

References Infer(), m_event, lar_dl_content::DlVertexingBaseAlgorithm::m_trainingMode, and PrepareTrainingSample().

59 {
60  ++m_event;
61 
62  if (m_trainingMode)
63  return this->PrepareTrainingSample();
64  else
65  return this->Infer();
66 
67  return STATUS_CODE_SUCCESS;
68 }

Member Data Documentation

pandora::StringVector lar_dl_content::DlVertexingBaseAlgorithm::m_caloHitListNames
protectedinherited
int lar_dl_content::DlSecondaryVertexingAlgorithm::m_event
private

The current event number.

Definition at line 129 of file DlSecondaryVertexingAlgorithm.h.

Referenced by PrepareTrainingSample(), and Run().

std::string lar_dl_content::DlVertexingBaseAlgorithm::m_inputVertexListName
protectedinherited
LArDLHelper::TorchModel lar_dl_content::DlVertexingBaseAlgorithm::m_modelU
protectedinherited
LArDLHelper::TorchModel lar_dl_content::DlVertexingBaseAlgorithm::m_modelV
protectedinherited
LArDLHelper::TorchModel lar_dl_content::DlVertexingBaseAlgorithm::m_modelW
protectedinherited
int lar_dl_content::DlVertexingBaseAlgorithm::m_nClasses
protectedinherited
std::string lar_dl_content::DlVertexingBaseAlgorithm::m_outputVertexListName
protectedinherited
std::mt19937 lar_dl_content::DlSecondaryVertexingAlgorithm::m_rng
private

The random number generator.

Definition at line 134 of file DlSecondaryVertexingAlgorithm.h.

Referenced by DlSecondaryVertexingAlgorithm().

std::string lar_dl_content::DlSecondaryVertexingAlgorithm::m_rootFileName
private

The ROOT file name.

Definition at line 133 of file DlSecondaryVertexingAlgorithm.h.

Referenced by ReadSettings(), and ~DlSecondaryVertexingAlgorithm().

std::string lar_dl_content::DlSecondaryVertexingAlgorithm::m_rootTreeName
private

The ROOT tree name.

Definition at line 132 of file DlSecondaryVertexingAlgorithm.h.

Referenced by ReadSettings(), and ~DlSecondaryVertexingAlgorithm().

std::vector<double> lar_dl_content::DlVertexingBaseAlgorithm::m_thresholds
protectedinherited
bool lar_dl_content::DlVertexingBaseAlgorithm::m_trainingMode
protectedinherited
std::string lar_dl_content::DlVertexingBaseAlgorithm::m_trainingOutputFile
protectedinherited
bool lar_dl_content::DlSecondaryVertexingAlgorithm::m_visualise
private

Whether or not to visualise the candidate vertices.

Definition at line 130 of file DlSecondaryVertexingAlgorithm.h.

Referenced by DlSecondaryVertexingAlgorithm(), and ReadSettings().

std::string lar_dl_content::DlVertexingBaseAlgorithm::m_volumeType
protectedinherited
bool lar_dl_content::DlSecondaryVertexingAlgorithm::m_writeTree
private

Whether or not to write validation details to a ROOT tree.

Definition at line 131 of file DlSecondaryVertexingAlgorithm.h.

Referenced by DlSecondaryVertexingAlgorithm(), ReadSettings(), and ~DlSecondaryVertexingAlgorithm().


The documentation for this class was generated from the following files: