LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
vertex::PrimaryVertexFinder Class Reference
Inheritance diagram for vertex::PrimaryVertexFinder:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 PrimaryVertexFinder (fhicl::ParameterSet const &pset)
 
void beginJob ()
 
void produce (art::Event &evt)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
void fillProductDescriptions ()
 
void registerProducts (ProductDescriptions &productsToRegister)
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
std::unique_ptr< Worker > makeWorker (WorkerParams const &wp)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Protected Member Functions

ConsumesCollector & consumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Private Member Functions

double StartPointSeperation (recob::SpacePoint sp1, recob::SpacePoint sp2)
 
bool IsInVertexCollection (int a, std::vector< std::vector< int >> vertex_collection)
 
int IndexInVertexCollection (int a, int b, std::vector< std::vector< int >> vertex_collection)
 
bool IsInNewVertex (int a, std::vector< int > newvertex)
 
double gammavalue (TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
 
double alphavalue (double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
 
double MinDist (double alpha, double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
 
TVector3 PointOnExtendedTrack (double alphagamma, TVector3 startpoint, TVector3 dircos)
 

Private Attributes

std::string fTrackModuleLabel
 
double fVertexWindow
 
TH2F * fNoTracks
 
TH1F * fLength_1stTrack
 
TH1F * fLength_2ndTrack
 
TH1F * fLength_3rdTrack
 
TH1F * fLength_4thTrack
 
TH1F * fLength_5thTrack
 

Detailed Description

Definition at line 41 of file PrimaryVertexFinder_module.cc.

Member Typedef Documentation

Definition at line 17 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::detail::Producer::Table = Modifier::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 26 of file Producer.h.

Constructor & Destructor Documentation

vertex::PrimaryVertexFinder::PrimaryVertexFinder ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 92 of file PrimaryVertexFinder_module.cc.

References fTrackModuleLabel, and fVertexWindow.

92  : EDProducer{pset}
93  {
94  fTrackModuleLabel = pset.get<std::string>("TrackModuleLabel");
95  fVertexWindow = pset.get<double>("VertexWindow");
96 
97  produces<std::vector<recob::Vertex>>();
98  produces<art::Assns<recob::Vertex, recob::Hit>>();
99  produces<art::Assns<recob::Vertex, recob::Track>>();
100  produces<art::Assns<recob::Vertex, recob::Shower>>();
101  }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6

Member Function Documentation

double vertex::PrimaryVertexFinder::alphavalue ( double  gamma,
TVector3  startpoint1,
TVector3  startpoint2,
TVector3  dircos1,
TVector3  dircos2 
)
private

Definition at line 465 of file PrimaryVertexFinder_module.cc.

Referenced by produce().

470 {
471  double alpha = (gamma * (dircos1 * dircos2)) + (startpoint2 * dircos1) - (startpoint1 * dircos1);
472 
473  return alpha;
474 }
void vertex::PrimaryVertexFinder::beginJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 104 of file PrimaryVertexFinder_module.cc.

References fLength_1stTrack, fLength_2ndTrack, fLength_3rdTrack, fLength_4thTrack, fLength_5thTrack, and fNoTracks.

105  {
106  // get access to the TFile service
108 
109  // fNoVertices= tfs->make<TH2F>("fNoVertices", ";Event No; No of vertices", 100,0, 100, 30, 0, 30);
110  fNoTracks = tfs->make<TH2F>("fNoTracks", ";Event No; No of Tracks", 10, 0, 10, 10, 0, 10);
111  fLength_1stTrack = tfs->make<TH1F>("fLength_Track1", "Muon Track Length", 100, 0, 100);
112  fLength_2ndTrack = tfs->make<TH1F>("fLength_Track2", "2nd Track Length", 100, 0, 100);
113  fLength_3rdTrack = tfs->make<TH1F>("fLength_Track3", "3rd Track Length", 100, 0, 100);
114  fLength_4thTrack = tfs->make<TH1F>("fLength_Track4", "4th Track Length", 100, 0, 100);
115  fLength_5thTrack = tfs->make<TH1F>("fLength_Track5", "5th Track Length", 100, 0, 100);
116  }
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::consumes ( InputTag const &  tag)
protectedinherited

Definition at line 61 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumes().

62  {
63  return collector_.consumes<T, BT>(tag);
64  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ProductToken< T > consumes(InputTag const &)
ConsumesCollector & art::ModuleBase::consumesCollector ( )
protectedinherited

Definition at line 57 of file ModuleBase.cc.

References art::ModuleBase::collector_.

58  {
59  return collector_;
60  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::consumesMany ( )
protectedinherited

Definition at line 75 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesMany().

76  {
77  collector_.consumesMany<T, BT>();
78  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::consumesView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::consumesView ( InputTag const &  tag)
inherited

Definition at line 68 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesView().

69  {
70  return collector_.consumesView<T, BT>(tag);
71  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > consumesView(InputTag const &)
void art::detail::Producer::doBeginJob ( SharedResources const &  resources)
inherited

Definition at line 22 of file Producer.cc.

References art::detail::Producer::beginJobWithFrame(), and art::detail::Producer::setupQueues().

23  {
24  setupQueues(resources);
25  ProcessingFrame const frame{ScheduleID{}};
26  beginJobWithFrame(frame);
27  }
virtual void setupQueues(SharedResources const &)=0
virtual void beginJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doBeginRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 65 of file Producer.cc.

References art::detail::Producer::beginRunWithFrame(), art::RangeSet::forRun(), art::RunPrincipal::makeRun(), r, art::RunPrincipal::runID(), and art::ModuleContext::scheduleID().

66  {
67  auto r = rp.makeRun(mc, RangeSet::forRun(rp.runID()));
68  ProcessingFrame const frame{mc.scheduleID()};
69  beginRunWithFrame(r, frame);
70  r.commitProducts();
71  return true;
72  }
TRandom r
Definition: spectrum.C:23
virtual void beginRunWithFrame(Run &, ProcessingFrame const &)=0
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
bool art::detail::Producer::doBeginSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 85 of file Producer.cc.

References art::detail::Producer::beginSubRunWithFrame(), art::RangeSet::forSubRun(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::SubRunPrincipal::subRunID().

86  {
87  auto sr = srp.makeSubRun(mc, RangeSet::forSubRun(srp.subRunID()));
88  ProcessingFrame const frame{mc.scheduleID()};
89  beginSubRunWithFrame(sr, frame);
90  sr.commitProducts();
91  return true;
92  }
virtual void beginSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
void art::detail::Producer::doEndJob ( )
inherited

Definition at line 30 of file Producer.cc.

References art::detail::Producer::endJobWithFrame().

31  {
32  ProcessingFrame const frame{ScheduleID{}};
33  endJobWithFrame(frame);
34  }
virtual void endJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doEndRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 75 of file Producer.cc.

References art::detail::Producer::endRunWithFrame(), art::RunPrincipal::makeRun(), r, art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

76  {
77  auto r = rp.makeRun(mc, rp.seenRanges());
78  ProcessingFrame const frame{mc.scheduleID()};
79  endRunWithFrame(r, frame);
80  r.commitProducts();
81  return true;
82  }
TRandom r
Definition: spectrum.C:23
virtual void endRunWithFrame(Run &, ProcessingFrame const &)=0
bool art::detail::Producer::doEndSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 95 of file Producer.cc.

References art::detail::Producer::endSubRunWithFrame(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

96  {
97  auto sr = srp.makeSubRun(mc, srp.seenRanges());
98  ProcessingFrame const frame{mc.scheduleID()};
99  endSubRunWithFrame(sr, frame);
100  sr.commitProducts();
101  return true;
102  }
virtual void endSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
bool art::detail::Producer::doEvent ( EventPrincipal ep,
ModuleContext const &  mc,
std::atomic< std::size_t > &  counts_run,
std::atomic< std::size_t > &  counts_passed,
std::atomic< std::size_t > &  counts_failed 
)
inherited

Definition at line 105 of file Producer.cc.

References art::detail::Producer::checkPutProducts_, e, art::EventPrincipal::makeEvent(), art::detail::Producer::produceWithFrame(), and art::ModuleContext::scheduleID().

110  {
111  auto e = ep.makeEvent(mc);
112  ++counts_run;
113  ProcessingFrame const frame{mc.scheduleID()};
114  produceWithFrame(e, frame);
115  e.commitProducts(checkPutProducts_, &expectedProducts<InEvent>());
116  ++counts_passed;
117  return true;
118  }
bool const checkPutProducts_
Definition: Producer.h:70
Float_t e
Definition: plot.C:35
virtual void produceWithFrame(Event &, ProcessingFrame const &)=0
void art::detail::Producer::doRespondToCloseInputFile ( FileBlock const &  fb)
inherited

Definition at line 44 of file Producer.cc.

References art::detail::Producer::respondToCloseInputFileWithFrame().

45  {
46  ProcessingFrame const frame{ScheduleID{}};
48  }
virtual void respondToCloseInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToCloseOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 58 of file Producer.cc.

References art::detail::Producer::respondToCloseOutputFilesWithFrame().

59  {
60  ProcessingFrame const frame{ScheduleID{}};
62  }
virtual void respondToCloseOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenInputFile ( FileBlock const &  fb)
inherited

Definition at line 37 of file Producer.cc.

References art::detail::Producer::respondToOpenInputFileWithFrame().

38  {
39  ProcessingFrame const frame{ScheduleID{}};
41  }
virtual void respondToOpenInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 51 of file Producer.cc.

References art::detail::Producer::respondToOpenOutputFilesWithFrame().

52  {
53  ProcessingFrame const frame{ScheduleID{}};
55  }
virtual void respondToOpenOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::Modifier::fillProductDescriptions ( )
inherited

Definition at line 10 of file Modifier.cc.

References art::ProductRegistryHelper::fillDescriptions(), and art::ModuleBase::moduleDescription().

11  {
13  }
void fillDescriptions(ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
double vertex::PrimaryVertexFinder::gammavalue ( TVector3  startpoint1,
TVector3  startpoint2,
TVector3  dircos1,
TVector3  dircos2 
)
private

Definition at line 452 of file PrimaryVertexFinder_module.cc.

Referenced by produce().

456 {
457  double gamma = ((startpoint1 * dircos2) - (startpoint2 * dircos2) +
458  ((dircos1 * dircos2) * (startpoint2 * dircos1)) -
459  ((dircos1 * dircos2) * (startpoint1 * dircos1))) /
460  (1 - ((dircos1 * dircos2) * (dircos1 * dircos2)));
461 
462  return gamma;
463 }
std::array< std::vector< ProductInfo >, NumBranchTypes > const & art::ModuleBase::getConsumables ( ) const
inherited

Definition at line 43 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::getConsumables().

44  {
45  return collector_.getConsumables();
46  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables() const
int vertex::PrimaryVertexFinder::IndexInVertexCollection ( int  a,
int  b,
std::vector< std::vector< int >>  vertex_collection 
)
private

Definition at line 422 of file PrimaryVertexFinder_module.cc.

References util::begin().

Referenced by produce().

426 {
427  int index = -1;
428  for (unsigned int i = 0; i < vertex_collection.size(); i++) {
429  for (std::vector<int>::iterator itr = vertex_collection[i].begin();
430  itr < vertex_collection[i].end();
431  ++itr) {
432  if (a == *itr || b == *itr) index = i;
433  }
434  }
435  return index;
436 }
intermediate_table::iterator iterator
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
bool vertex::PrimaryVertexFinder::IsInNewVertex ( int  a,
std::vector< int >  newvertex 
)
private

Definition at line 438 of file PrimaryVertexFinder_module.cc.

Referenced by produce().

439 {
440  int flag = 0;
441  for (unsigned int i = 0; i < newvertex.size(); i++) {
442  if (a == newvertex[i]) {
443  flag = 1;
444  break;
445  }
446  }
447 
448  if (flag == 1) return true;
449  return false;
450 }
bool vertex::PrimaryVertexFinder::IsInVertexCollection ( int  a,
std::vector< std::vector< int >>  vertex_collection 
)
private

Definition at line 402 of file PrimaryVertexFinder_module.cc.

References util::begin().

Referenced by produce().

405 {
406  int flag = 0;
407 
408  for (unsigned int i = 0; i < vertex_collection.size(); i++) {
409  for (std::vector<int>::iterator itr = vertex_collection[i].begin();
410  itr < vertex_collection[i].end();
411  ++itr) {
412  if (a == *itr) {
413  flag = 1;
414  break;
415  }
416  }
417  }
418  if (flag == 1) return true;
419  return false;
420 }
intermediate_table::iterator iterator
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
std::unique_ptr< Worker > art::ModuleBase::makeWorker ( WorkerParams const &  wp)
inherited

Definition at line 37 of file ModuleBase.cc.

References art::ModuleBase::doMakeWorker(), and art::NumBranchTypes.

38  {
39  return doMakeWorker(wp);
40  }
virtual std::unique_ptr< Worker > doMakeWorker(WorkerParams const &wp)=0
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::mayConsume ( InputTag const &  tag)
protectedinherited

Definition at line 82 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsume().

83  {
84  return collector_.mayConsume<T, BT>(tag);
85  }
ProductToken< T > mayConsume(InputTag const &)
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::mayConsumeMany ( )
protectedinherited

Definition at line 96 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeMany().

97  {
98  collector_.mayConsumeMany<T, BT>();
99  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::mayConsumeView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::mayConsumeView ( InputTag const &  tag)
inherited

Definition at line 89 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeView().

90  {
91  return collector_.mayConsumeView<T, BT>(tag);
92  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > mayConsumeView(InputTag const &)
double vertex::PrimaryVertexFinder::MinDist ( double  alpha,
double  gamma,
TVector3  startpoint1,
TVector3  startpoint2,
TVector3  dircos1,
TVector3  dircos2 
)
private

Definition at line 476 of file PrimaryVertexFinder_module.cc.

Referenced by produce().

482 {
483  TVector3 mindis_vector = startpoint1 - startpoint2 + alpha * dircos1 - gamma * dircos2;
484  double mindis = mindis_vector.Mag();
485  return mindis;
486 }
ModuleDescription const & art::ModuleBase::moduleDescription ( ) const
inherited

Definition at line 13 of file ModuleBase.cc.

References art::errors::LogicError.

Referenced by art::OutputModule::doRespondToOpenInputFile(), art::OutputModule::doWriteEvent(), art::Modifier::fillProductDescriptions(), art::OutputModule::makePlugins_(), art::OutputWorker::OutputWorker(), reco::shower::LArPandoraModularShowerCreation::produce(), art::Modifier::registerProducts(), and art::OutputModule::registerProducts().

14  {
15  if (md_.has_value()) {
16  return *md_;
17  }
18 
20  "There was an error while calling moduleDescription().\n"}
21  << "The moduleDescription() base-class member function cannot be called\n"
22  "during module construction. To determine which module is "
23  "responsible\n"
24  "for calling it, find the '<module type>:<module "
25  "label>@Construction'\n"
26  "tag in the message prefix above. Please contact artists@fnal.gov\n"
27  "for guidance.\n";
28  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
TVector3 vertex::PrimaryVertexFinder::PointOnExtendedTrack ( double  alphagamma,
TVector3  startpoint,
TVector3  dircos 
)
private

Definition at line 488 of file PrimaryVertexFinder_module.cc.

References DEFINE_ART_MODULE.

Referenced by produce().

491 {
492  TVector3 PointOnExtendedTrack = startpoint + (alphagamma * dircos);
493  return PointOnExtendedTrack;
494 }
TVector3 PointOnExtendedTrack(double alphagamma, TVector3 startpoint, TVector3 dircos)
void vertex::PrimaryVertexFinder::produce ( art::Event evt)
virtual
Todo:
replace with the real query when this module is updated to look for showers too

Implements art::EDProducer.

Definition at line 119 of file PrimaryVertexFinder_module.cc.

References alphavalue(), util::begin(), util::CreateAssn(), util::end(), art::EventID::event(), fLength_1stTrack, fLength_2ndTrack, fLength_3rdTrack, fLength_4thTrack, fLength_5thTrack, fNoTracks, fTrackModuleLabel, fVertexWindow, gammavalue(), art::ProductRetriever::getByLabel(), hits(), art::Event::id(), IndexInVertexCollection(), IsInNewVertex(), IsInVertexCollection(), art::Ptr< T >::key(), MF_LOG_VERBATIM, MinDist(), PointOnExtendedTrack(), art::Event::put(), sort_pred2(), StartPointSeperation(), track, lar::dump::vector(), x, y, and z.

120  {
121 
122  mf::LogInfo("PrimaryVertexFinder")
123  << "------------------------------------------------------------------------------";
124 
125  // std::cout << "run : " << evt.Header().Run() << std::endl;
126  // std::cout << "subrun : " << evt.Header().Subrun() << std::endl;
127  //std::cout << "event : " << evt.Header().Event() << std::endl;
128 
129  mf::LogInfo("PrimaryVertexFinder") << "event : " << evt.id().event();
130 
132 
133  //mf::LogInfo("PrimaryVertexFinder") << "I am in Primary vertex finder " << std::endl;
134 
135  art::Handle<std::vector<recob::Track>> trackListHandle;
136  evt.getByLabel(fTrackModuleLabel, trackListHandle);
137 
138  //Point to a collection of vertices to output.
139  std::unique_ptr<std::vector<recob::Vertex>> vcol(new std::vector<recob::Vertex>);
140  std::unique_ptr<art::Assns<recob::Vertex, recob::Hit>> vhassn(
142  std::unique_ptr<art::Assns<recob::Vertex, recob::Track>> vtassn(
144  std::unique_ptr<art::Assns<recob::Vertex, recob::Shower>> vsassn(
146 
147  std::vector<recob::Track> const& trkIn = *trackListHandle;
148 
149  mf::LogInfo("PrimaryVertexFinder") << "number of tracks in this event = " << trkIn.size();
150  fNoTracks->Fill(evt.id().event(), trkIn.size());
151 
152  std::vector<recob::SpacePoint> startpoints_vec; // first space point of each track
153 
154  std::vector<TVector3> startvec;
155  TVector3 startXYZ;
156 
157  std::vector<TVector3> endvec;
158  TVector3 endXYZ;
159 
160  std::vector<TVector3> dircosvec;
161  TVector3 dircosXYZ;
162 
163  std::vector<std::pair<art::Ptr<recob::Track>, double>> trackpair;
164 
165  art::FindMany<recob::SpacePoint> TrackSpacePoints(trackListHandle, evt, fTrackModuleLabel);
166 
167  for (unsigned int i = 0; i < trkIn.size(); ++i) {
168  recob::Track::Point_t start, end;
169  std::tie(start, end) = trkIn[i].Extent();
170  startXYZ.SetXYZ(start.X(), start.Y(), start.Z());
171  endXYZ.SetXYZ(end.X(), end.Y(), end.Z());
172 
173  double length = (endXYZ - startXYZ).Mag(); // (endvec[i]-startvec[i]).Mag();
174  //mf::LogInfo("PrimaryVertexFinder") << "Track length calculated = " << length << std::endl;
175  trackpair.push_back(std::pair<art::Ptr<recob::Track>, double>({trackListHandle, i}, length));
176  }
177 
178  for (size_t i = 0; i < trackpair.size(); ++i) {
179  mf::LogInfo("PrimaryVertexFinder") << "track id is = " << (trackpair[i].first)->ID()
180  << " track length = " << (trackpair[i].second);
181  }
182 
183  std::sort(trackpair.rbegin(), trackpair.rend(), sort_pred2);
184 
185  mf::LogInfo("PrimaryVertexFinder") << "AFTER SORTING ";
186  for (size_t i = 0; i < trackpair.size(); ++i) {
187  mf::LogInfo("PrimaryVertexFinder") << "track id is = " << (trackpair[i].first)->ID()
188  << " track length = " << (trackpair[i].second);
189  }
190 
191  if (trackpair.size() > 0) fLength_1stTrack->Fill(trackpair[0].second);
192 
193  if (trackpair.size() > 1) fLength_2ndTrack->Fill(trackpair[1].second);
194 
195  if (trackpair.size() > 2) fLength_3rdTrack->Fill(trackpair[2].second);
196 
197  if (trackpair.size() > 3) fLength_4thTrack->Fill(trackpair[3].second);
198 
199  if (trackpair.size() > 4) fLength_5thTrack->Fill(trackpair[4].second);
200 
201  for (size_t j = 0; j < trackpair.size(); ++j) { //loop over tracks
202  art::Ptr<recob::Track> const& track = trackpair[j].first;
203 
204  // the index of this track in the query is the same as its position in
205  // the data product:
206  std::vector<recob::SpacePoint const*> const& spacepoints = TrackSpacePoints.at(track.key());
207 
208  startXYZ = trackpair[j].first->Vertex<TVector3>();
209  endXYZ = trackpair[j].first->End<TVector3>();
210  dircosXYZ = trackpair[j].first->VertexDirection<TVector3>();
211 
212  startvec.push_back(startXYZ);
213  endvec.push_back(endXYZ);
214  dircosvec.push_back(dircosXYZ);
215 
216  mf::LogInfo("PrimaryVertexFinder") << "PrimaryVertexFinder got " << spacepoints.size()
217  << " 3D spacepoint(s) from Track3Dreco.cxx";
218 
219  // save the first SpacePoint of each Track... from now the SpacePoint ID represents the Track ID!!
220  startpoints_vec.emplace_back(spacepoints[0]->XYZ(),
221  spacepoints[0]->ErrXYZ(),
222  spacepoints[0]->Chisq(),
223  startpoints_vec.size());
224 
225  } // loop over tracks
226 
227  for (size_t i = 0; i < startvec.size(); ++i) { //trackpair.size()
228  mf::LogInfo("PrimaryVertexFinder") << "Tvector3 start point SORTED = ";
229  startvec[i].Print();
230  }
231  for (size_t i = 0; i < dircosvec.size(); ++i) { //trackpair.size()
232  mf::LogInfo("PrimaryVertexFinder") << "Tvector3 dir cos SORTED = ";
233  dircosvec[i].Print();
234  }
235 
236  std::vector<std::vector<int>> vertex_collection_int;
237  std::vector<std::vector<TVector3>> vertexcand_vec;
238 
239  for (unsigned int i = 0; i < trackpair.size(); ++i) {
240  for (unsigned int j = i + 1; j < trackpair.size(); ++j) {
241  mf::LogInfo("PrimaryVertexFinder")
242  << "distance between " << i << " and " << j << " = "
243  << StartPointSeperation(startpoints_vec[i], startpoints_vec[j]);
244  double GAMMA = gammavalue(startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
245  double ALPHA = alphavalue(GAMMA, startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
246  double MINDIST =
247  MinDist(ALPHA, GAMMA, startvec[i], startvec[j], dircosvec[i], dircosvec[j]);
248  mf::LogInfo("PrimaryVertexFinder")
249  << "alpha = " << ALPHA << " gamma = " << GAMMA << " MINIMUM DISTANCE = " << MINDIST;
250 
251  TVector3 TRACK1POINT = PointOnExtendedTrack(ALPHA, startvec[i], dircosvec[i]);
252  TVector3 TRACK2POINT = PointOnExtendedTrack(GAMMA, startvec[j], dircosvec[j]);
253 
254  mf::LogInfo("PrimaryVertexFinder") << "POINTS ON THE TRACKS ARE:: ";
255  TRACK1POINT.Print();
256  TRACK2POINT.Print();
257 
258  //if(StartPointSeperation(startpoints_vec[i], startpoints_vec[j])<fVertexWindow){ ///// correct this
259  //if(MINDIST<2 && trackpair[i].second >30 && trackpair[j].second >30){
260  if (MINDIST < fVertexWindow && ((TRACK1POINT - startvec[i]).Mag()) < fVertexWindow) {
261 
262  if ((!IsInVertexCollection(i, vertex_collection_int)) &&
263  (!IsInVertexCollection(j, vertex_collection_int))) {
264  std::vector<int> newvertex_int;
265  std::vector<TVector3> vertexcand;
266  newvertex_int.push_back(i);
267  newvertex_int.push_back(j);
268  vertex_collection_int.push_back(newvertex_int);
269  //newvertex.clear();
270  vertexcand.push_back(TRACK1POINT);
271  vertexcand.push_back(TRACK2POINT);
272  vertexcand_vec.push_back(vertexcand);
273  }
274  else {
275  int index = IndexInVertexCollection(i, j, vertex_collection_int);
276  //mf::LogInfo("PrimaryVertexFinder") << "index where a new vertex will be added = " << index << std::endl;
277  if (!IsInNewVertex(i, vertex_collection_int[index])) {
278  vertex_collection_int[index].push_back(i);
279  vertexcand_vec[index].push_back(TRACK1POINT); //need to fix for delta rays
280  }
281  if (!IsInNewVertex(j, vertex_collection_int[index])) {
282  vertex_collection_int[index].push_back(j);
283  vertexcand_vec[index].push_back(TRACK2POINT); //need to fix for delta rays
284  }
285  }
286  } // end else
287  }
288  }
289 
290  //now add the unmatched track IDs to the collection
291  for (size_t i = 0; i < trackpair.size(); ++i) {
292  if (!IsInVertexCollection(i, vertex_collection_int)) {
293  //if(trackpair[i].second>30){
294  std::vector<int> temp;
295  std::vector<TVector3> temp1;
296  temp.push_back(i);
297  temp1.push_back(startvec[i]);
298  vertex_collection_int.push_back(temp);
299  vertexcand_vec.push_back(temp1);
300  //}
301  }
302  }
303 
304  // indices (in their data products) of tracks and showers connected to the vertex
305  std::vector<size_t> vTrackIndices, vShowerIndices;
306 
307  // find the hits of all the tracks
308  art::FindManyP<recob::Hit> TrackHits(trackListHandle, evt, fTrackModuleLabel);
309 
310  // find the hits of all the showers
311  // art::FindManyP<recob::Hit> ShowerHits(showerListHandle, evt, fShowerModuleLabel);
313  art::FindManyP<recob::Hit> ShowerHits(
315 
316  for (size_t i = 0; i < vertex_collection_int.size(); ++i) {
317  double x = 0.;
318  double y = 0.;
319  double z = 0.;
320  int elemsize = 0.;
321  for (std::vector<int>::iterator itr = vertex_collection_int[i].begin();
322  itr < vertex_collection_int[i].end();
323  ++itr) {
324  mf::LogInfo("PrimaryVertexFinder")
325  << "vector elements at index " << i << " are " << *itr
326  << "\ntrack original ID = " << (trackpair[*itr].first)->ID();
327  // save the index in the data product of this track
328  vTrackIndices.push_back(trackpair[*itr].first.key());
329  }
330  mf::LogInfo("PrimaryVertexFinder") << "------------";
331 
332  for (std::vector<TVector3>::iterator itr = vertexcand_vec[i].begin();
333  itr < vertexcand_vec[i].end();
334  ++itr) {
335  //calculate sum of x, y and z of a vertex
336  x += (*itr).X();
337  y += (*itr).Y();
338  z += (*itr).Z();
339  elemsize = vertexcand_vec[i].size();
340  }
341 
342  double avgx = x / elemsize;
343  double avgy = y / elemsize;
344  double avgz = z / elemsize;
345 
346  Double_t vtxcoord[3];
347  vtxcoord[0] = avgx;
348  vtxcoord[1] = avgy;
349  vtxcoord[2] = avgz;
350 
351  recob::Vertex the3Dvertex(vtxcoord, vcol->size());
352  vcol->push_back(the3Dvertex);
353 
354  if (!vTrackIndices.empty()) {
355  // associate the tracks and their hits with the vertex
357  evt, *vtassn, vcol->size() - 1, vTrackIndices.begin(), vTrackIndices.end());
358  for (size_t tIndex : vTrackIndices) {
359  std::vector<art::Ptr<recob::Hit>> const& hits = TrackHits.at(tIndex);
360  util::CreateAssn(evt, *vcol, hits, *vhassn);
361  }
362  vTrackIndices.clear();
363  } // if tracks
364 
365  if (!vShowerIndices.empty()) {
366  // associate the showers and their hits with the vertex
368  evt, *vsassn, vcol->size() - 1, vShowerIndices.begin(), vShowerIndices.end());
369  for (size_t sIndex : vShowerIndices) {
370  std::vector<art::Ptr<recob::Hit>> const& hits = ShowerHits.at(sIndex);
371  util::CreateAssn(evt, *vcol, hits, *vhassn);
372  }
373  vShowerIndices.clear();
374  } // if showers
375 
376  } // end loop over vertex_collection_ind
377 
378  MF_LOG_VERBATIM("Summary") << std::setfill('-') << std::setw(175) << "-" << std::setfill(' ');
379  MF_LOG_VERBATIM("Summary") << "PrimaryVertexFinder Summary:";
380  for (size_t i = 0; i < vcol->size(); ++i)
381  MF_LOG_VERBATIM("Summary") << vcol->at(i);
382 
383  evt.put(std::move(vcol));
384  evt.put(std::move(vtassn));
385  evt.put(std::move(vhassn));
386  evt.put(std::move(vsassn));
387 
388  } // end of produce
Float_t x
Definition: compare.C:6
intermediate_table::iterator iterator
TVector3 PointOnExtendedTrack(double alphagamma, TVector3 startpoint, TVector3 dircos)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
Definition of vertex object for LArSoft.
Definition: Vertex.h:35
bool IsInNewVertex(int a, std::vector< int > newvertex)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
void hits()
Definition: readHits.C:15
key_type key() const noexcept
Definition: Ptr.h:166
double MinDist(double alpha, double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
double StartPointSeperation(recob::SpacePoint sp1, recob::SpacePoint sp2)
bool sort_pred2(const std::pair< art::Ptr< recob::Track >, double > &left, const std::pair< art::Ptr< recob::Track >, double > &right)
#define MF_LOG_VERBATIM(category)
tracking::Point_t Point_t
Definition: Track.h:52
EventNumber_t event() const
Definition: EventID.h:116
double gammavalue(TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
double alphavalue(double gamma, TVector3 startpoint1, TVector3 startpoint2, TVector3 dircos1, TVector3 dircos2)
bool IsInVertexCollection(int a, std::vector< std::vector< int >> vertex_collection)
Float_t track
Definition: plot.C:35
int IndexInVertexCollection(int a, int b, std::vector< std::vector< int >> vertex_collection)
EventID id() const
Definition: Event.cc:23
void art::Modifier::registerProducts ( ProductDescriptions productsToRegister)
inherited

Definition at line 16 of file Modifier.cc.

References art::ModuleBase::moduleDescription(), and art::ProductRegistryHelper::registerProducts().

17  {
18  ProductRegistryHelper::registerProducts(productsToRegister,
20  }
void registerProducts(ProductDescriptions &productsToRegister, ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
void art::ModuleBase::setModuleDescription ( ModuleDescription const &  md)
inherited

Definition at line 31 of file ModuleBase.cc.

References art::ModuleBase::md_.

32  {
33  md_ = md;
34  }
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void art::ModuleBase::sortConsumables ( std::string const &  current_process_name)
inherited

Definition at line 49 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::sortConsumables().

50  {
51  // Now that we know we have seen all the consumes declarations,
52  // sort the results for fast lookup later.
53  collector_.sortConsumables(current_process_name);
54  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
void sortConsumables(std::string const &current_process_name)
double vertex::PrimaryVertexFinder::StartPointSeperation ( recob::SpacePoint  sp1,
recob::SpacePoint  sp2 
)
private

Definition at line 392 of file PrimaryVertexFinder_module.cc.

References x, recob::SpacePoint::XYZ(), y, and z.

Referenced by produce().

394 {
395  double x = (sp2.XYZ()[0]) - (sp1.XYZ()[0]);
396  double y = (sp2.XYZ()[1]) - (sp1.XYZ()[1]);
397  double z = (sp2.XYZ()[2]) - (sp1.XYZ()[2]);
398  double distance = std::sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));
399  return distance;
400 }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Double_t z
Definition: plot.C:276
const Double32_t * XYZ() const
Definition: SpacePoint.h:78

Member Data Documentation

TH1F* vertex::PrimaryVertexFinder::fLength_1stTrack
private

Definition at line 73 of file PrimaryVertexFinder_module.cc.

Referenced by beginJob(), and produce().

TH1F* vertex::PrimaryVertexFinder::fLength_2ndTrack
private

Definition at line 74 of file PrimaryVertexFinder_module.cc.

Referenced by beginJob(), and produce().

TH1F* vertex::PrimaryVertexFinder::fLength_3rdTrack
private

Definition at line 75 of file PrimaryVertexFinder_module.cc.

Referenced by beginJob(), and produce().

TH1F* vertex::PrimaryVertexFinder::fLength_4thTrack
private

Definition at line 76 of file PrimaryVertexFinder_module.cc.

Referenced by beginJob(), and produce().

TH1F* vertex::PrimaryVertexFinder::fLength_5thTrack
private

Definition at line 77 of file PrimaryVertexFinder_module.cc.

Referenced by beginJob(), and produce().

TH2F* vertex::PrimaryVertexFinder::fNoTracks
private

Definition at line 72 of file PrimaryVertexFinder_module.cc.

Referenced by beginJob(), and produce().

std::string vertex::PrimaryVertexFinder::fTrackModuleLabel
private

Definition at line 50 of file PrimaryVertexFinder_module.cc.

Referenced by PrimaryVertexFinder(), and produce().

double vertex::PrimaryVertexFinder::fVertexWindow
private

Definition at line 51 of file PrimaryVertexFinder_module.cc.

Referenced by PrimaryVertexFinder(), and produce().


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