TrkAssn_module.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////
2 // \file TrkAssn_module.cc
3 // \brief Module to write associations between prongs, tracks, and vertices and the slices they belong too
4 // \version $Id: TrkAssn_module.cc,v 1.3 2013-01-30 21:28:53 raddatz Exp $
5 // \author Nick Raddatz
6 ////////////////////////////////////////////////////////////////////////////
7 
8 #include <string>
9 
10 // Framework includes
14 #include "fhiclcpp/ParameterSet.h"
15 
16 // Nova includes
17 #include "RecoBase/Track.h"
18 #include "RecoBase/Cluster.h"
19 #include "RecoBase/CellHit.h"
20 #include "RecoBase/Prong.h"
21 #include "RecoBase/Vertex.h"
22 #include "Utilities/AssociationUtil.h"
23 
24 
25 namespace trk {
26  class TrkAssn : public art::EDProducer {
27  public:
28  explicit TrkAssn(fhicl::ParameterSet const& pset);
29  virtual ~TrkAssn();
30  void produce(art::Event& evt);
31  void reconfigure(const fhicl::ParameterSet& p);
32 
33  private:
34  std::string fTrackInput; // Input for tracks
35  std::string fSliceInput; // Input for slices
36  std::string fProngInput; // Input for prongs
37  std::string fVertexInput; // Input for verticies
38  };
39 }
40 
41 namespace trk{
42 
43 
44  //......................................................................
46  {
47  reconfigure(pset);
48  produces< art::Assns<rb::Cluster, rb::Track> >();
49  produces< art::Assns<rb::Cluster, rb::Prong> >();
50  produces< art::Assns<rb::Cluster, rb::Vertex> >();
51  }
52 
53  //......................................................................
55  {
56  }
57 
58  //......................................................................
60  {
61  fTrackInput = pset.get< std::string >("TrackInput") ;
62  fSliceInput = pset.get< std::string >("SliceInput") ;
63  fProngInput = pset.get< std::string >("ProngInput") ;
64  fVertexInput = pset.get< std::string >("VertexInput");
65  }
66  //......................................................................
67  /// Reconstruction method for this module. Provides read-write access
68  /// to the event data.
69 
71  {
72  // Declare a container for Track objects to be stored in the art::event
73  std::unique_ptr< art::Assns<rb::Cluster,rb::Track> > assns(new art::Assns<rb::Cluster, rb::Track>);
74  std::unique_ptr< art::Assns<rb::Cluster,rb::Prong> > passns(new art::Assns<rb::Cluster, rb::Prong>);
75  std::unique_ptr< art::Assns<rb::Cluster,rb::Vertex> > vassns(new art::Assns<rb::Cluster, rb::Vertex>);
76 
77  // define a vector holding slices
79  evt.getByLabel(fSliceInput,slicecol);
80 
81  // define a vector holding tracks
83  evt.getByLabel(fTrackInput,trkcol);
84 
86  evt.getByLabel(fProngInput,pcol);
87 
89  evt.getByLabel(fVertexInput,vcol);
90 
91  std::vector<bool> foundsl;
92  for(unsigned int i = 0; i<trkcol->size();++i){
93  foundsl.push_back(false);
94  }
95 
96  std::vector<bool> foundslp;
97  for(unsigned int i = 0; i<pcol->size();++i){
98  foundslp.push_back(false);
99  }
100 
101  std::vector<bool> foundslv;
102  for(unsigned int i = 0; i<vcol->size();++i){
103  foundslv.push_back(false);
104  }
105 
106  // loop over the slices
107  for(unsigned int isl = 0; isl<slicecol->size(); ++isl){
108  // get the vector of cell hits for this slice
109  art::Ptr<rb::Cluster> slice(slicecol,isl);
110  art::PtrVector<rb::CellHit> slicehits = slice->AllCells();
111  // loop over the tracks
112  std::vector<art::Ptr<rb::Track> > slicetrks;
113  for(unsigned int itrk = 0; itrk<trkcol->size(); ++itrk){
114  art::Ptr<rb::Track> track(trkcol,itrk);
115  if(foundsl[itrk]){ continue; }
116  if(track->NCell() < 1){ continue; }
117  // any hit on the track should only belong to one slice so take the first one
118  art::Ptr<rb::CellHit> trkhit = track->Cell(0);
119  // loop over the slice hits and see if this on is in the list
120  bool foundtrkhit = false;
121  for(unsigned int ihit = 0; ihit<slicehits.size(); ++ihit){
122  if(trkhit == slicehits[ihit]){
123  foundtrkhit = true;
124  break;
125  }
126  }
127  if(foundtrkhit){
128  foundsl[itrk] = true;
129  // add this track to the vector of tracks to be associated with this slice
130  slicetrks.push_back(track);
131  }
132  }
133  // loop over the prongs
134  std::vector<art::Ptr<rb::Prong> > sliceprongs;
135  for(unsigned int ip = 0; ip<pcol->size(); ++ip){
136  art::Ptr<rb::Prong> prong(pcol,ip);
137  if(foundslp[ip]){ continue; }
138  if(prong->NCell() < 1){ continue; }
139  // any hit in the prong should only belong to one slice so take the first one
140  art::Ptr<rb::CellHit> phit = prong->Cell(0);
141  // loop over the slice hits and see if this on is in the list
142  bool foundphit = false;
143  for(unsigned int ihit = 0; ihit<slicehits.size(); ++ihit){
144  if(phit == slicehits[ihit]){
145  foundphit = true;
146  break;
147  }
148  }
149  if(foundphit){
150  foundslp[ip] = true;
151  // add this prong to the vector of prongs to be associated with this slice
152  sliceprongs.push_back(prong);
153  }
154  }
155  // loop over the verticies
156  std::vector<art::Ptr<rb::Vertex> > slicevertex;
157  for(unsigned int iv = 0; iv<vcol->size(); ++iv){
158  art::Ptr<rb::Vertex> vert(vcol,iv);
159  if(foundslv[iv]){ continue; }
160  // vertex time should fall inside a slice
161  if ((vert->GetT() >= slice->MinTNS()) && (vert->GetT() <= slice->MaxTNS())){
162  foundslv[iv] = true;
163  // add this vertex to the vector of verticies to be associated with this slice
164  slicevertex.push_back(vert);
165  }
166  }
167  if(slicetrks.size()>0){
168  util::CreateAssn(*this,evt,slice,slicetrks,*(assns.get()));
169  }
170  if(sliceprongs.size()>0){
171  util::CreateAssn(*this,evt,slice,sliceprongs,*(passns.get()));
172  }
173  if(slicevertex.size()>0){
174  util::CreateAssn(*this,evt,slice,slicevertex,*(vassns.get()));
175  }
176  }
177 
178  evt.put(std::move(assns));
179  evt.put(std::move(passns));
180  evt.put(std::move(vassns));
181  }
182 
183  //......................................................................
184 }
185 
186 namespace trk{
187 
189 
190 }
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.
std::string fVertexInput
unsigned int NCell(geo::View_t view) const
Number of cells in view view.
Definition: Cluster.cxx:134
const char * p
Definition: xmltok.h:285
std::string fSliceInput
TString ip
Definition: loadincs.C:5
std::string fProngInput
DEFINE_ART_MODULE(TestTMapFile)
void reconfigure(const fhicl::ParameterSet &p)
art::PtrVector< rb::CellHit > AllCells() const
Get all cells from both views.
Definition: Cluster.cxx:180
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Track finder for cosmic rays.
double MinTNS() const
Definition: Cluster.cxx:482
T get(std::string const &key) const
Definition: ParameterSet.h:231
void produce(art::Event &evt)
Vertex location in position and time.
double MaxTNS() const
Definition: Cluster.cxx:528
size_type size() const
Definition: PtrVector.h:308
TrkAssn(fhicl::ParameterSet const &pset)
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
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
double GetT() const
Definition: Vertex.h:26
Float_t track
Definition: plot.C:35
virtual ~TrkAssn()
std::string fTrackInput