All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
quad::QuadVtx Class Reference
Inheritance diagram for quad::QuadVtx:

Public Member Functions

 QuadVtx (const fhicl::ParameterSet &pset)
 
void beginJob () override
 
void produce (art::Event &evt) override
 

Private Member Functions

bool FindVtx (const detinfo::DetectorPropertiesData &detProp, const std::vector< recob::Hit > &hits, TVector3 &vtx, int evt) const
 

Private Attributes

std::string fHitLabel
 
bool fSavePlots
 
const geo::GeometryCoregeom
 

Detailed Description

Definition at line 74 of file QuadVtx_module.cc.

Constructor & Destructor Documentation

quad::QuadVtx::QuadVtx ( const fhicl::ParameterSet &  pset)
explicit

Definition at line 97 of file QuadVtx_module.cc.

98  : EDProducer(pset)
99  , fHitLabel(pset.get<std::string>("HitLabel"))
100  , fSavePlots(pset.get<bool>("SavePlots"))
101  {
102  produces<std::vector<recob::Vertex>>();
103  }
std::string fHitLabel

Member Function Documentation

void quad::QuadVtx::beginJob ( )
override

Definition at line 107 of file QuadVtx_module.cc.

108  {
109  geom = art::ServiceHandle<const geo::Geometry>()->provider();
110  }
const geo::GeometryCore * geom
bool quad::QuadVtx::FindVtx ( const detinfo::DetectorPropertiesData detProp,
const std::vector< recob::Hit > &  hits,
TVector3 &  vtx,
int  evt 
) const
private

Definition at line 392 of file QuadVtx_module.cc.

396  {
397  if (hits.empty()) return false;
398 
399  std::vector<std::vector<Pt2D>> pts;
400  std::vector<TVector3> dirs;
401 
402  GetPts2D(detProp, hits, pts, dirs, geom);
403 
404  double minx = +1e9;
405  double maxx = -1e9;
406  double minz[3] = {+1e9, +1e9, +1e9};
407  double maxz[3] = {-1e9, -1e9, -1e9};
408  for (int view = 0; view < 3; ++view) {
409  for (const Pt2D& p : pts[view]) {
410  minx = std::min(minx, p.x);
411  maxx = std::max(maxx, p.x);
412  minz[view] = std::min(minz[view], p.z);
413  maxz[view] = std::max(maxz[view], p.z);
414  }
415  }
416 
417  // Add some padding
418  for (int view = 0; view < 3; ++view) {
419  minz[view] -= 100;
420  maxz[view] += 100;
421  }
422  minx -= 20;
423  maxx += 20;
424 
425  // Don't allow the vertex further downstream in z (view 0) than 25% of the
426  // hits.
427  std::vector<float> zs;
428  zs.reserve(pts[0].size());
429  for (const Pt2D& p : pts[0])
430  zs.push_back(p.z);
431  auto mid = zs.begin() + zs.size() / 4;
432  if (mid != zs.end()) {
433  std::nth_element(zs.begin(), mid, zs.end());
434  maxz[0] = *mid;
435  }
436 
437  std::vector<HeatMap> hms;
438  hms.reserve(3);
439  for (int view = 0; view < 3; ++view) {
440  if (pts[view].empty()) return false;
441 
442  std::vector<Line2D> lines;
443  LinesFromPoints(pts[view], lines);
444 
445  if (lines.empty()) return false;
446 
447  // Approximately cm bins
448  hms.emplace_back(maxz[view] - minz[view], minz[view], maxz[view], maxx - minx, minx, maxx);
449  MapFromLines(lines, hms.back());
450  } // end for view
451 
452  vtx = FindPeak3D(hms, dirs);
453 
454  std::vector<HeatMap> hms_zoom;
455  hms_zoom.reserve(3);
456  for (int view = 0; view < 3; ++view) {
457  const double x0 = vtx.X();
458  const double z0 = vtx.Dot(dirs[view]);
459 
460  std::vector<Line2D> lines;
461  LinesFromPoints(pts[view], lines, z0, x0, 2.5);
462 
463  if (lines.empty()) return false; // How does this happen??
464 
465  // mm granularity
466  hms_zoom.emplace_back(50, z0 - 2.5, z0 + 2.5, 50, x0 - 2.5, x0 + 2.5);
467 
468  MapFromLines(lines, hms_zoom.back());
469  }
470 
471  vtx = FindPeak3D(hms_zoom, dirs);
472 
473  if (fSavePlots) {
474  art::TFileDirectory evt_dir =
475  art::ServiceHandle<art::TFileService>()->mkdir(TString::Format("evt%d", evt).Data());
476 
477  for (int view = 0; view < 3; ++view) {
478  art::TFileDirectory view_dir = evt_dir.mkdir(TString::Format("view%d", view).Data());
479 
480  TGraph* gpts = view_dir.makeAndRegister<TGraph>("hits", "");
481  for (const Pt2D& p : pts[view])
482  gpts->SetPoint(gpts->GetN(), p.z, p.x);
483 
484  view_dir.makeAndRegister<TH2F>("hmap", "", *hms[view].AsTH2());
485 
486  view_dir.makeAndRegister<TH2F>("hmap_zoom", "", *hms_zoom[view].AsTH2());
487 
488  const double x = vtx.X();
489  const double z = vtx.Dot(dirs[view]);
490  view_dir.makeAndRegister<TGraph>("vtx3d", "", 1, &z, &x);
491  } // end for view
492  } // end if saving plots
493 
494  return true;
495  }
process_name opflash particleana ie ie ie z
void GetPts2D(const detinfo::DetectorPropertiesData &detProp, const std::vector< recob::Hit > &hits, std::vector< std::vector< Pt2D >> &pts, std::vector< TVector3 > &dirs, const geo::GeometryCore *geom)
TVector3 FindPeak3D(const std::vector< HeatMap > &hs, const std::vector< TVector3 > &dirs) noexcept
process_name opflash particleana ie x
pdgs p
Definition: selectors.fcl:22
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void MapFromLines(const std::vector< Line2D > &lines, HeatMap &hm)
void LinesFromPoints(const std::vector< Pt2D > &pts, std::vector< Line2D > &lines, float z0=0, float x0=0, float R=-1)
TCEvent evt
Definition: DataStructs.cxx:8
const geo::GeometryCore * geom
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
void quad::QuadVtx::produce ( art::Event &  evt)
override

Definition at line 499 of file QuadVtx_module.cc.

500  {
501  auto vtxcol = std::make_unique<std::vector<recob::Vertex>>();
502 
503  art::Handle<std::vector<recob::Hit>> hits;
504  evt.getByLabel(fHitLabel, hits);
505 
506  auto const detProp =
507  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt);
508  TVector3 vtx;
509  if (FindVtx(detProp, *hits, vtx, evt.event())) {
510  vtxcol->emplace_back(
511  recob::Vertex::Point_t(vtx.X(), vtx.Y(), vtx.Z()), recob::Vertex::SMatrixSym33(), 0, 0);
512  }
513 
514  evt.put(std::move(vtxcol));
515  }
unsigned int event
Definition: DataStructs.h:634
tracking::SMatrixSym33 SMatrixSym33
Definition: Vertex.h:40
tracking::Point_t Point_t
Definition: Vertex.h:39
bool FindVtx(const detinfo::DetectorPropertiesData &detProp, const std::vector< recob::Hit > &hits, TVector3 &vtx, int evt) const
std::string fHitLabel
TCEvent evt
Definition: DataStructs.cxx:8
auto const detProp

Member Data Documentation

std::string quad::QuadVtx::fHitLabel
private

Definition at line 87 of file QuadVtx_module.cc.

bool quad::QuadVtx::fSavePlots
private

Definition at line 89 of file QuadVtx_module.cc.

const geo::GeometryCore* quad::QuadVtx::geom
private

Definition at line 91 of file QuadVtx_module.cc.


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