HoughVertex_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \brief Find event vertex using a Hough transform
3 /// \author Christopher Backhouse - bckhouse@caltech.edu
4 ////////////////////////////////////////////////////////////////////////
5 
11 #include "fhiclcpp/ParameterSet.h"
12 
13 #include "Geometry/Geometry.h"
15 #include "RecoBase/Cluster.h"
16 #include "RecoBase/CellHit.h"
17 #include "RecoBase/FilterList.h"
18 #include "RecoBase/Vertex.h"
19 #include "Utilities/AssociationUtil.h"
20 
22 
23 #include "TH2.h"
24 
25 #include <string>
26 
27 namespace hv
28 {
29  /// Find event vertex using a Hough transform
31  {
32  public:
33  explicit HoughVertex(const fhicl::ParameterSet& pset);
34  virtual ~HoughVertex();
35 
36  void produce(art::Event& evt);
37 
38  protected:
40  double fErrorScale;
43 
45 
46  bool fSaveMaps;
47  };
48 
49  //......................................................................
51  : fSliceLabel(pset.get<std::string>("SliceLabel")),
52  fErrorScale(pset.get<double>("ErrorScale")),
53  fMaxHitsUsedPerView(pset.get<double>("MaxHitsUsedPerView")),
54  fObeyPreselection(pset.get<bool>("ObeyPreselection")),
55  fAlg(pset.get<fhicl::ParameterSet>("VertexAlgPSet")),
56  fSaveMaps(pset.get<bool>("SaveMaps"))
57  {
58  produces<std::vector<rb::Vertex>>();
59  // Vertices are associated with the slice they came from
60  produces<art::Assns<rb::Vertex, rb::Cluster>>();
61 
62  if(fSaveMaps) produces<std::vector<TH2F>>();
63  }
64 
65  //......................................................................
67  {
68  }
69 
70  //......................................................................
72  {
73  std::unique_ptr<std::vector<rb::Vertex>> vtxcol(new std::vector<rb::Vertex>);
74  std::unique_ptr<std::vector<TH2F>> histcol(new std::vector<TH2F>);
75  // Associate vertices with the slice they came from
76  std::unique_ptr<art::Assns<rb::Vertex, rb::Cluster>> assns(new art::Assns<rb::Vertex, rb::Cluster>);
77 
79 
81  evt.getByLabel(fSliceLabel, slices);
82 
83  for(unsigned int sliceIdx = 0; sliceIdx < slices->size(); ++sliceIdx){
84  if(fObeyPreselection && rb::IsFiltered(evt, slices, sliceIdx)) continue;
85 
86  const rb::Cluster& slice = (*slices)[sliceIdx];
87  if(slice.IsNoise()) continue;
88 
89  std::vector<Vector2D> xhits, yhits;
90 
91  for(unsigned int hitIdx = 0; hitIdx < slice.NCell(); ++hitIdx){
92  const rb::CellHit& chit = *slice.Cell(hitIdx);
93 
94  TVector3 xyz;
95  const geo::CellGeo* geocell = geom->Plane(chit.Plane())->Cell(chit.Cell());
96  geocell->GetCenter(xyz);
97  const float dz = (2*geocell->HalfD())/sqrt(12) * fErrorScale;
98  const float dv = (2*geocell->HalfW())/sqrt(12) * fErrorScale;
99 
100  if(chit.View() == geo::kX){
101  xhits.push_back(Vector2D(xyz.Z(), xyz.X(), dz, dv));
102  }
103  else{
104  yhits.push_back(Vector2D(xyz.Z(), xyz.Y(), dz, dv));
105  }
106  } // end for hitIdx
107 
108  // Vertexing time goes quadratically as the number of hits. Only use the
109  // N most-upstream hits in each view.
110  std::sort(xhits.begin(), xhits.end());
111  std::sort(yhits.begin(), yhits.end());
112  while(xhits.size() > fMaxHitsUsedPerView) xhits.pop_back();
113  while(yhits.size() > fMaxHitsUsedPerView) yhits.pop_back();
114 
115  // Do all the actual work
116  TVector3 vtx;
117  if(fSaveMaps){
118  TH2F *xmap, *ymap;
119 
120  vtx = fAlg.FindVertex(xhits, yhits, &xmap, &ymap);
121 
122  xmap->SetName(TString::Format("xmap_slice%d", sliceIdx));
123  ymap->SetName(TString::Format("ymap_slice%d", sliceIdx));
124 
125  xmap->SetTitle(TString::Format("X view Hough map, slice %d", sliceIdx));
126  ymap->SetTitle(TString::Format("Y view Hough map, slice %d", sliceIdx));
127 
128  histcol->push_back(*xmap);
129  histcol->push_back(*ymap);
130 
131  delete xmap;
132  delete ymap;
133  }
134  else{
135  vtx = fAlg.FindVertex(xhits, yhits);
136  }
137 
138  vtxcol->push_back(rb::Vertex(vtx, slice.MeanTNS()));
139  // Associate most recently added vertex with the slice
140  util::CreateAssn(*this, evt, *vtxcol,
141  art::Ptr<rb::Cluster>(slices, sliceIdx), *assns);
142  } // end for sliceIdx
143 
144  evt.put(std::move(vtxcol));
145  if(fSaveMaps) evt.put(std::move(histcol));
146  evt.put(std::move(assns));
147  }
148 
150 
151 } // namespace
152 //////////////////////////////////////////////////////////////////////////
A 3D position and time representing an interaction vertex.
Definition: Vertex.h:15
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
double HalfD() const
Definition: CellGeo.cxx:205
unsigned int NCell(geo::View_t view) const
Number of cells in view view.
Definition: Cluster.cxx:134
void GetCenter(double *xyz, double localz=0.0) const
Definition: CellGeo.cxx:159
HoughVertexAlg fAlg
unsigned short Plane() const
Definition: CellHit.h:39
std::string fSliceLabel
geo::View_t View() const
Definition: CellHit.h:41
T sqrt(T number)
Definition: d0nt_math.hpp:156
Find event vertex using a Hough transform.
Vertical planes which measure X.
Definition: PlaneGeo.h:28
double HalfW() const
Definition: CellGeo.cxx:191
A collection of associated CellHits.
Definition: Cluster.h:47
const PlaneGeo * Plane(unsigned int i) const
DEFINE_ART_MODULE(TestTMapFile)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
unsigned short Cell() const
Definition: CellHit.h:40
double dz[NP][NC]
bool IsFiltered(const art::Event &evt, art::Ptr< T > x, const std::vector< std::string > &labels)
Is this Ptr marked "filtered out"?
Definition: FilterList.h:96
Find event vertex using a Hough transform.
Vertex location in position and time.
Find event vertex using a Hough transform.
void produce(art::Event &evt)
art::Ptr< rb::CellHit > Cell(geo::View_t view, unsigned int viewIdx) const
Get the ith cell from view view.
Definition: Cluster.cxx:145
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
HoughVertex(const fhicl::ParameterSet &pset)
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
double MeanTNS(rb::AveragingScheme scheme=kDefaultScheme) const
Definition: Cluster.cxx:554
void geom(int which=0)
Definition: geom.C:163
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
bool IsNoise() const
Is the noise flag set?
Definition: Cluster.h:163
TVector3 FindVertex(const std::vector< Vector2D > &xhits, const std::vector< Vector2D > &yhits, TH2F **xmap=0, TH2F **ymap=0) const
Encapsulate the cell geometry.
Definition: CellGeo.h:25
Encapsulate the geometry of one entire detector (near, far, ndos)