vertexfinder1_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: vertexfinder1
3 // Plugin Type: producer (art v2_11_02)
4 // File: vertexfinder1_module.cc
5 //
6 // Generated at Thu Jul 12 16:15:30 2018 by Thomas Junk using cetskelgen
7 // from cetlib version v3_03_01.
8 ////////////////////////////////////////////////////////////////////////
9 
18 #include "fhiclcpp/ParameterSet.h"
21 
23 #include "Reco/vertex1algs.h"
24 
25 #include <memory>
26 
27 namespace gar {
28  namespace rec {
29 
30  class vertexfinder1 : public art::EDProducer {
31  public:
32  explicit vertexfinder1(fhicl::ParameterSet const & p);
33  // The compiler-generated destructor is fine for non-base
34  // classes without bare pointers or other resource use.
35 
36  // Plugins should not be copied or assigned.
37  vertexfinder1(vertexfinder1 const &) = delete;
38  vertexfinder1(vertexfinder1 &&) = delete;
39  vertexfinder1 & operator = (vertexfinder1 const &) = delete;
41 
42  // Required functions.
43  void produce(art::Event & e) override;
44 
45  private:
46 
49  float fRCut;
50  float fDCut;
53 
54  // Stub to check that the track is vertexable
55  bool goodTrack(TrackPar trk, TrackEnd usebeg);
56 
57  };
58 
59 
61  {
62  fTrackLabel = p.get<std::string>("TrackLabel","track");
63  fChisquaredCut = p.get<float>("ChisquaredPerDOFCut",5.0);
64  fRCut = p.get<float>("RCut", 12.0); // endpoints must be within this distnace in cm
65  fDCut = p.get<float>("DCut", 2.0); // doca must be smaller than this in cm
66  fNTPCClusCut = p.get<int>("NTPCClusCut",20); // dimensionless
67  fPrintLevel = p.get<int>("PrintLevel",0);
68 
69  art::InputTag trackTag(fTrackLabel);
70  consumes< std::vector<rec::Track> >(trackTag);
71 
72  // Produce vertex, associated tracks & ends. TrackEnd is defined in Track.h
73  produces< std::vector<rec::Vertex> >();
74  produces< art::Assns<rec::Track, rec::Vertex, rec::TrackEnd> >();
75  }
76 
78  std::unique_ptr< std::vector<rec::Vertex> >
79  vtxCol(new std::vector<rec::Vertex>);
80  std::unique_ptr< art::Assns<rec::Track, rec::Vertex, rec::TrackEnd> >
82 
83  auto trackHandle = e.getValidHandle< std::vector<Track> >(fTrackLabel);
84  auto const& tracks = *trackHandle;
85 
86  auto const vtxPtrMaker = art::PtrMaker<rec::Vertex>(e);
87  auto const trackPtrMaker = art::PtrMaker<rec::Track>(e, trackHandle.id());
88 
89  size_t nTrack = tracks.size();
90  std::vector<int> usedflag_beg(nTrack,0); // to tell if we've used a track yet or not.
91  std::vector<int> usedflag_end(nTrack,0); // to tell if we've used a track yet or not.
92 
93  if (nTrack>=2) {
94 
95  // For each track, build a vector of ends that can be vertexed with it. Include
96  // the number of the track for later ouroboros test
97 
98  std::vector< std::tuple<TrackPar,TrackEnd,int> > trackParEnds;
99  for (size_t iTrack=0; iTrack<nTrack-1; ++iTrack) {
100  TrackPar thisTrack = tracks.at(iTrack);
101  // Build that vector for each of the 2 ends of the track
102  for (int fin=0; fin<2; ++fin) {
103  trackParEnds.clear();
104  TrackEnd thisTrackEnd(fin == 0 ? 1 : 0);
105  if (! goodTrack(thisTrack,thisTrackEnd)) continue;
106  trackParEnds.emplace_back( std::make_tuple(thisTrack,thisTrackEnd,iTrack) );
107  TVector3 thisEndinSpace;
108  if (thisTrackEnd == TrackEndBeg)
109  {
110  usedflag_beg.at(iTrack) = 1;
111  thisEndinSpace = thisTrack.getXYZBeg();
112  }
113  else
114  {
115  usedflag_end.at(iTrack) = 1;
116  thisEndinSpace = thisTrack.getXYZEnd();
117  }
118 
119  // Loop over other trackends to see what is close
120  for (size_t jTrack=iTrack+1; jTrack<nTrack; ++jTrack) {
121  TrackPar thatTrack = tracks.at(jTrack);
122  for (int fin2=0; fin2<2; ++fin2)
123  {
124  TrackEnd thatTrackEnd(fin2 == 0 ? 1 : 0);
125  if (thatTrackEnd == TrackEndBeg && usedflag_beg.at(jTrack) != 0) continue;
126  if (thatTrackEnd == TrackEndEnd && usedflag_end.at(jTrack) != 0) continue;
127  if (!goodTrack(thatTrack,thatTrackEnd)) continue;
128  TVector3 thatEndinSpace;
129  if (thatTrackEnd == TrackEndBeg)
130  {
131  thatEndinSpace = thatTrack.getXYZBeg();
132  }
133  else
134  {
135  thatEndinSpace = thatTrack.getXYZEnd();
136  }
137 
138  if ( (thisEndinSpace-thatEndinSpace).Mag() > fRCut) continue;
139 
140 
141  // call the fitter to see what the docas are and cut on the doca
142 
143  std::vector<TrackPar> vtracks;
144  std::vector<TrackEnd> usebeg;
145  vtracks.push_back(thisTrack);
146  vtracks.push_back(thatTrack);
147  usebeg.push_back(thisTrackEnd);
148  usebeg.push_back(thatTrackEnd);
149  std::vector<float> xyz(3,0);
150  std::vector< std::vector<float> > covmat;
151  std::vector<float> doca;
152  float chisquared=0;
153  double time;
154 
155  if (gar::rec::fitVertex(vtracks,xyz,chisquared,covmat,time,usebeg,doca) == 0)
156  {
157  if (doca.at(0) < fDCut && doca.at(1) < fDCut)
158  {
159  if (thatTrackEnd == TrackEndBeg)
160  {
161  usedflag_beg.at(jTrack) = 1;
162  }
163  else
164  {
165  usedflag_end.at(jTrack) = 1;
166  }
167  trackParEnds.emplace_back( std::make_tuple(thatTrack,thatTrackEnd,jTrack) );
168  continue; // don't add the other end of the same track
169  } // end if doca test
170  } // end if vertex fit succeeded
171  } // end loop over jtrack end
172  } // End loop over jTrack
173 
174  size_t nTrackEnds = trackParEnds.size();
175 
176  if ( nTrackEnds>=2) {
177  // Feed the vertexable ends into the vertex finder
178  std::vector<TrackPar> vtracks;
179  std::vector<TrackEnd> usebeg;
180  for (size_t iTrackEnd=0; iTrackEnd<nTrackEnds; ++iTrackEnd) {
181  vtracks.push_back( std::get<TrackPar>(trackParEnds[iTrackEnd]) );
182  usebeg.push_back ( std::get<1>(trackParEnds[iTrackEnd]) );
183  }
184  std::vector<float> xyz(3,0);
185  std::vector< std::vector<float> > covmat;
186  std::vector<float> doca;
187  float chisquared=0;
188  double time;
189  if (gar::rec::fitVertex(vtracks,xyz,chisquared,covmat,time,usebeg,doca) == 0) {
190  float cmv[9];
191  size_t icounter=0;
192  for (size_t i=0; i<3;++i) {
193  for (size_t j=0; j<3; ++j) {
194  cmv[icounter] = covmat.at(i).at(j);
195  }
196  }
197 
198  // Save vertex & its tracks into vectors that will be written
199  // to event.
200  vtxCol->emplace_back(xyz.data(),cmv,time);
201  auto const vtxpointer = vtxPtrMaker(vtxCol->size()-1);
202  for (size_t i=0; i<trackParEnds.size(); ++i) {
203  TrackEnd endInVertex = std::get<1>(trackParEnds[i]);
204  auto const trackpointer = trackPtrMaker( std::get<2>(trackParEnds[i]) );
205  trkVtxAssns->addSingle(trackpointer,vtxpointer,endInVertex);
206  }
207  } // end if (fitVertex...)
208  }
209  } // end loop on 2 ends of iTrack
210  } // end loop on iTrack
211  } // End test for nTrack>=2; might put empty vertex list & Assns into event
212  e.put(std::move(vtxCol));
213  e.put(std::move(trkVtxAssns));
214  } // end produce method.
215 
216 
217  //--------------------------------------------------------------------------------------------------
218 
219  // goodTrack returns true if the track can be used in vertexing
220 
222  {
223  int trknclus = trk.getNTPCClusters();
224  if ( trknclus < fNTPCClusCut ) return false;
225  return true; // just a stub for now
226  }
227 
229 
230  } // namespace rec
231 } // namespace gar
vertexfinder1 & operator=(vertexfinder1 const &)=delete
rec
Definition: tracks.py:88
int TrackEnd
Definition: Track.h:32
int fitVertex(std::vector< TrackPar > &tracks, std::vector< float > &xyz, float &chisquared, std::vector< std::vector< float > > &covmat, double &time, std::vector< TrackEnd > usebeg, std::vector< float > &doca)
Definition: vertex1algs.cxx:8
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
TrackEnd const TrackEndEnd
Definition: Track.h:33
void produce(art::Event &e) override
TVector3 getXYZEnd() const
Definition: TrackPar.cxx:316
TVector3 getXYZBeg() const
Definition: TrackPar.cxx:310
const double e
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
def move(depos, offset)
Definition: depos.py:107
vertexfinder1(fhicl::ParameterSet const &p)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Definition: DataViewImpl.h:441
p
Definition: test.py:223
bool goodTrack(TrackPar trk, TrackEnd usebeg)
size_t getNTPCClusters() const
Definition: TrackPar.cxx:172
Definition: tracks.py:1
General GArSoft Utilities.
TrackEnd const TrackEndBeg
Definition: Track.h:33